Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2014-11-21 14:03:30 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b3bb2cdf2b0d2a461c85380d760b4d0dca331711
b3bb2cdf
1 parent
30e7c38a
refine code, rename the human functions to prefixed with srs_human_
显示空白字符变更
内嵌
并排对比
正在显示
12 个修改的文件
包含
190 行增加
和
190 行删除
trunk/research/librtmp/srs_audio_raw_publish.c
trunk/research/librtmp/srs_bandwidth_check.c
trunk/research/librtmp/srs_detect_rtmp.c
trunk/research/librtmp/srs_flv_injecter.c
trunk/research/librtmp/srs_flv_parser.c
trunk/research/librtmp/srs_h264_raw_publish.c
trunk/research/librtmp/srs_ingest_flv.c
trunk/research/librtmp/srs_ingest_rtmp.c
trunk/research/librtmp/srs_play.c
trunk/research/librtmp/srs_publish.c
trunk/src/libs/srs_librtmp.cpp
trunk/src/libs/srs_librtmp.hpp
trunk/research/librtmp/srs_audio_raw_publish.c
查看文件 @
b3bb2cd
...
...
@@ -46,7 +46,7 @@ int read_audio_frame(char* audio_raw, int file_size, char** pp, char** pdata, in
char
*
p
=
*
pp
;
if
(
file_size
-
(
p
-
audio_raw
)
<
168
)
{
srs_
lib
_trace
(
"audio must be 160+8 bytes. left %d bytes."
,
srs_
human
_trace
(
"audio must be 160+8 bytes. left %d bytes."
,
file_size
-
(
p
-
audio_raw
));
return
-
1
;
}
...
...
@@ -83,32 +83,32 @@ int main(int argc, char** argv)
const
char
*
raw_file
=
argv
[
1
];
const
char
*
rtmp_url
=
argv
[
2
];
srs_
lib
_trace
(
"raw_file=%s, rtmp_url=%s"
,
raw_file
,
rtmp_url
);
srs_
human
_trace
(
"raw_file=%s, rtmp_url=%s"
,
raw_file
,
rtmp_url
);
// open file
int
raw_fd
=
open
(
raw_file
,
O_RDONLY
);
if
(
raw_fd
<
0
)
{
srs_
lib
_trace
(
"open audio raw file %s failed."
,
raw_fd
);
srs_
human
_trace
(
"open audio raw file %s failed."
,
raw_fd
);
goto
rtmp_destroy
;
}
off_t
file_size
=
lseek
(
raw_fd
,
0
,
SEEK_END
);
if
(
file_size
<=
0
)
{
srs_
lib
_trace
(
"audio raw file %s empty."
,
raw_file
);
srs_
human
_trace
(
"audio raw file %s empty."
,
raw_file
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"read entirely audio raw file, size=%dKB"
,
(
int
)(
file_size
/
1024
));
srs_
human
_trace
(
"read entirely audio raw file, size=%dKB"
,
(
int
)(
file_size
/
1024
));
char
*
audio_raw
=
(
char
*
)
malloc
(
file_size
);
if
(
!
audio_raw
)
{
srs_
lib
_trace
(
"alloc raw buffer failed for file %s."
,
raw_file
);
srs_
human
_trace
(
"alloc raw buffer failed for file %s."
,
raw_file
);
goto
rtmp_destroy
;
}
lseek
(
raw_fd
,
0
,
SEEK_SET
);
ssize_t
nb_read
=
0
;
if
((
nb_read
=
read
(
raw_fd
,
audio_raw
,
file_size
))
!=
file_size
)
{
srs_
lib
_trace
(
"buffer %s failed, expect=%dKB, actual=%dKB."
,
srs_
human
_trace
(
"buffer %s failed, expect=%dKB, actual=%dKB."
,
raw_file
,
(
int
)(
file_size
/
1024
),
(
int
)(
nb_read
/
1024
));
goto
rtmp_destroy
;
}
...
...
@@ -117,22 +117,22 @@ int main(int argc, char** argv)
srs_rtmp_t
rtmp
=
srs_rtmp_create
(
rtmp_url
);
if
(
srs_simple_handshake
(
rtmp
)
!=
0
)
{
srs_
lib
_trace
(
"simple handshake failed."
);
srs_
human
_trace
(
"simple handshake failed."
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"simple handshake success"
);
srs_
human
_trace
(
"simple handshake success"
);
if
(
srs_connect_app
(
rtmp
)
!=
0
)
{
srs_
lib
_trace
(
"connect vhost/app failed."
);
srs_
human
_trace
(
"connect vhost/app failed."
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"connect vhost/app success"
);
srs_
human
_trace
(
"connect vhost/app success"
);
if
(
srs_publish_stream
(
rtmp
)
!=
0
)
{
srs_
lib
_trace
(
"publish stream failed."
);
srs_
human
_trace
(
"publish stream failed."
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"publish stream success"
);
srs_
human
_trace
(
"publish stream success"
);
u_int32_t
timestamp
=
0
;
u_int32_t
time_delta
=
17
;
...
...
@@ -143,7 +143,7 @@ int main(int argc, char** argv)
char
*
data
=
NULL
;
int
size
=
0
;
if
(
read_audio_frame
(
audio_raw
,
file_size
,
&
p
,
&
data
,
&
size
)
<
0
)
{
srs_
lib
_trace
(
"read a frame from file buffer failed."
);
srs_
human
_trace
(
"read a frame from file buffer failed."
);
goto
rtmp_destroy
;
}
...
...
@@ -168,12 +168,12 @@ int main(int argc, char** argv)
sound_format
,
sound_rate
,
sound_size
,
sound_type
,
0
,
data
,
size
,
timestamp
)
!=
0
)
{
srs_
lib
_trace
(
"send audio raw data failed."
);
srs_
human
_trace
(
"send audio raw data failed."
);
goto
rtmp_destroy
;
}
srs_lib_trace
(
"sent packet: type=%s, time=%d, size=%d, codec=%d, rate=%d, sample=%d, channel=%d"
,
srs_type2string
(
SRS_RTMP_TYPE_AUDIO
),
timestamp
,
size
,
sound_format
,
sound_rate
,
sound_size
,
srs_human_trace
(
"sent packet: type=%s, time=%d, size=%d, codec=%d, rate=%d, sample=%d, channel=%d"
,
srs_human_flv_tag_type2string
(
SRS_RTMP_TYPE_AUDIO
),
timestamp
,
size
,
sound_format
,
sound_rate
,
sound_size
,
sound_type
);
// @remark, when use encode device, it not need to sleep.
...
...
trunk/research/librtmp/srs_bandwidth_check.c
查看文件 @
b3bb2cd
...
...
@@ -81,31 +81,31 @@ int main(int argc, char** argv)
rtmp
=
srs_rtmp_create2
(
argv
[
1
]);
srs_
lib
_trace
(
"bandwidth check/test url: %s"
,
argv
[
1
]);
srs_
human
_trace
(
"bandwidth check/test url: %s"
,
argv
[
1
]);
if
((
ret
=
srs_simple_handshake
(
rtmp
))
!=
0
)
{
srs_
lib
_trace
(
"simple handshake failed."
);
srs_
human
_trace
(
"simple handshake failed."
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"simple handshake success"
);
srs_
human
_trace
(
"simple handshake success"
);
if
((
ret
=
srs_connect_app2
(
rtmp
,
srs_server_ip
,
srs_server
,
srs_primary_authors
,
srs_version
,
&
srs_id
,
&
srs_pid
))
!=
0
)
{
srs_
lib
_trace
(
"connect vhost/app failed."
);
srs_
human
_trace
(
"connect vhost/app failed."
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"connect vhost/app success"
);
srs_
human
_trace
(
"connect vhost/app success"
);
if
((
ret
=
srs_bandwidth_check
(
rtmp
,
&
start_time
,
&
end_time
,
&
play_kbps
,
&
publish_kbps
,
&
play_bytes
,
&
publish_bytes
,
&
play_duration
,
&
publish_duration
))
!=
0
)
{
srs_
lib
_trace
(
"bandwidth check/test failed."
);
srs_
human
_trace
(
"bandwidth check/test failed."
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"bandwidth check/test success"
);
srs_
human
_trace
(
"bandwidth check/test success"
);
srs_
lib
_trace
(
"
\n
%s, %s
\n
"
srs_
human
_trace
(
"
\n
%s, %s
\n
"
"%s, %s, srs_pid=%d, srs_id=%d
\n
"
"duration: %dms(%d+%d)
\n
"
"play: %dkbps
\n
"
...
...
@@ -137,8 +137,8 @@ rtmp_destroy:
(
int
)(
end_time
-
start_time
),
play_duration
,
publish_duration
,
play_kbps
,
publish_kbps
);
srs_lib_trace
(
""
);
srs_lib_trace
(
"completed"
);
srs_human_trace
(
""
);
srs_human_trace
(
"completed"
);
return
ret
;
}
...
...
trunk/research/librtmp/srs_detect_rtmp.c
查看文件 @
b3bb2cd
...
...
@@ -80,56 +80,56 @@ int main(int argc, char** argv)
duration
=
atoi
(
argv
[
2
]);
timeout
=
atoi
(
argv
[
3
]);
srs_lib_trace
(
"rtmp url: %s"
,
rtmp_url
);
srs_lib_trace
(
"duration: %ds, timeout:%ds"
,
duration
,
timeout
);
srs_human_trace
(
"rtmp url: %s"
,
rtmp_url
);
srs_human_trace
(
"duration: %ds, timeout:%ds"
,
duration
,
timeout
);
if
(
duration
<=
0
||
timeout
<=
0
)
{
srs_
lib
_trace
(
"duration and timeout must be positive."
);
srs_
human
_trace
(
"duration and timeout must be positive."
);
exit
(
-
2
);
}
rtmp
=
srs_rtmp_create
(
rtmp_url
);
if
((
ret
=
__srs_dns_resolve
(
rtmp
))
!=
0
)
{
srs_
lib
_trace
(
"dns resolve failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"dns resolve failed. ret=%d"
,
ret
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"dns resolve success"
);
srs_
human
_trace
(
"dns resolve success"
);
time_dns_resolve
=
srs_get_time_ms
();
if
((
ret
=
__srs_connect_server
(
rtmp
))
!=
0
)
{
srs_
lib
_trace
(
"socket connect failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"socket connect failed. ret=%d"
,
ret
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"socket connect success"
);
srs_
human
_trace
(
"socket connect success"
);
time_socket_connect
=
srs_get_time_ms
();
if
((
ret
=
__srs_do_simple_handshake
(
rtmp
))
!=
0
)
{
srs_
lib
_trace
(
"do simple handshake failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"do simple handshake failed. ret=%d"
,
ret
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"do simple handshake success"
);
srs_
human
_trace
(
"do simple handshake success"
);
if
((
ret
=
srs_connect_app
(
rtmp
))
!=
0
)
{
srs_
lib
_trace
(
"connect vhost/app failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"connect vhost/app failed. ret=%d"
,
ret
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"connect vhost/app success"
);
srs_
human
_trace
(
"connect vhost/app success"
);
if
((
ret
=
srs_play_stream
(
rtmp
))
!=
0
)
{
srs_
lib
_trace
(
"play stream failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"play stream failed. ret=%d"
,
ret
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"play stream success"
);
srs_
human
_trace
(
"play stream success"
);
time_play_stream
=
srs_get_time_ms
();
for
(;;)
{
if
((
ret
=
srs_read_packet
(
rtmp
,
&
type
,
&
timestamp
,
&
data
,
&
size
))
!=
0
)
{
srs_
lib
_trace
(
"read packet failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"read packet failed. ret=%d"
,
ret
);
goto
rtmp_destroy
;
}
srs_lib_trace
(
"got packet: type=%s, time=%d, size=%d"
,
srs_type2string
(
type
),
timestamp
,
size
);
srs_human_trace
(
"got packet: type=%s, time=%d, size=%d"
,
srs_human_flv_tag_type2string
(
type
),
timestamp
,
size
);
if
(
SRS_RTMP_TYPE_VIDEO
==
type
||
SRS_RTMP_TYPE_AUDIO
==
type
)
{
if
(
time_first_packet
<=
0
)
{
...
...
@@ -143,12 +143,12 @@ int main(int argc, char** argv)
free
(
data
);
if
(
srs_get_time_ms
()
-
time_startup
>
timeout
*
1000
)
{
srs_
lib
_trace
(
"timeout, terminate."
);
srs_
human
_trace
(
"timeout, terminate."
);
goto
rtmp_destroy
;
}
if
((
timestamp
-
basetime
)
>
duration
*
1000
)
{
srs_
lib
_trace
(
"duration exceed, terminate."
);
srs_
human
_trace
(
"duration exceed, terminate."
);
goto
rtmp_destroy
;
}
}
...
...
@@ -197,8 +197,8 @@ rtmp_destroy:
"
\"
remark2
\"
:
\"
if code is not 0, user must ignore all data
\"
"
);
srs_lib_trace
(
""
);
srs_lib_trace
(
"completed"
);
srs_human_trace
(
""
);
srs_human_trace
(
"completed"
);
return
ret
;
}
...
...
trunk/research/librtmp/srs_flv_injecter.c
查看文件 @
b3bb2cd
...
...
@@ -76,9 +76,9 @@ int main(int argc, char** argv)
tmp_file
=
(
char
*
)
malloc
(
tmp_file_size
);
snprintf
(
tmp_file
,
tmp_file_size
,
"%s.tmp"
,
out_flv_file
);
srs_lib_trace
(
"input: %s"
,
in_flv_file
);
srs_lib_trace
(
"output: %s"
,
out_flv_file
);
srs_lib_trace
(
"tmp_file: %s"
,
tmp_file
);
srs_human_trace
(
"input: %s"
,
in_flv_file
);
srs_human_trace
(
"output: %s"
,
out_flv_file
);
srs_human_trace
(
"tmp_file: %s"
,
tmp_file
);
ret
=
process
(
in_flv_file
,
tmp_file
,
&
ic
,
&
oc
);
...
...
@@ -89,13 +89,13 @@ int main(int argc, char** argv)
unlink
(
tmp_file
);
if
(
ret
==
ERROR_INJECTED
)
{
ret
=
0
;
srs_
lib
_trace
(
"file already injected."
);
srs_
human
_trace
(
"file already injected."
);
}
else
{
srs_
lib
_trace
(
"error, remove tmp file."
);
srs_
human
_trace
(
"error, remove tmp file."
);
}
}
else
{
rename
(
tmp_file
,
out_flv_file
);
srs_
lib
_trace
(
"completed, rename to %s"
,
out_flv_file
);
srs_
human
_trace
(
"completed, rename to %s"
,
out_flv_file
);
}
free
(
tmp_file
);
...
...
@@ -123,14 +123,14 @@ int process(const char* in_flv_file, const char* out_flv_file, srs_flv_t* pic, s
if
((
ic
=
srs_flv_open_read
(
in_flv_file
))
==
NULL
)
{
ret
=
2
;
srs_
lib
_trace
(
"open input flv file failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"open input flv file failed. ret=%d"
,
ret
);
return
ret
;
}
*
pic
=
ic
;
if
((
oc
=
srs_flv_open_write
(
out_flv_file
))
==
NULL
)
{
ret
=
2
;
srs_
lib
_trace
(
"open output flv file failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"open output flv file failed. ret=%d"
,
ret
);
return
ret
;
}
*
poc
=
oc
;
...
...
@@ -164,13 +164,13 @@ int parse_metadata(char* data, int size, srs_amf0_t* pname, srs_amf0_t* pdata)
*
pname
=
srs_amf0_parse
(
data
,
size
,
&
nparsed
);
if
(
*
pname
==
NULL
||
nparsed
>=
size
)
{
srs_
lib
_trace
(
"invalid amf0 name data."
);
srs_
human
_trace
(
"invalid amf0 name data."
);
return
-
1
;
}
*
pdata
=
srs_amf0_parse
(
data
+
nparsed
,
size
-
nparsed
,
&
nparsed
);
if
(
*
pdata
==
NULL
||
nparsed
>
size
)
{
srs_
lib
_trace
(
"invalid amf0 value data"
);
srs_
human
_trace
(
"invalid amf0 value data"
);
return
-
1
;
}
...
...
@@ -206,22 +206,22 @@ int build_keyframes(srs_flv_t ic, srs_amf0_t *pname, srs_amf0_t* pdata, srs_amf0
return
ret
;
}
srs_
lib
_trace
(
"build keyframe infos from flv"
);
srs_
human
_trace
(
"build keyframe infos from flv"
);
for
(;;)
{
offset
=
srs_flv_tellg
(
ic
);
// tag header
if
((
ret
=
srs_flv_read_tag_header
(
ic
,
&
type
,
&
size
,
&
timestamp
))
!=
0
)
{
if
(
srs_flv_is_eof
(
ret
))
{
srs_
lib
_trace
(
"parse completed."
);
srs_
human
_trace
(
"parse completed."
);
return
0
;
}
srs_
lib
_trace
(
"flv get packet failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"flv get packet failed. ret=%d"
,
ret
);
return
ret
;
}
if
(
size
<=
0
)
{
srs_
lib
_trace
(
"invalid size=%d"
,
size
);
srs_
human
_trace
(
"invalid size=%d"
,
size
);
return
ret
;
}
...
...
@@ -343,20 +343,20 @@ int do_inject_flv(srs_flv_t ic, srs_flv_t oc, srs_amf0_t amf0_name, srs_amf0_t a
free
(
data
);
}
srs_
lib
_trace
(
"build keyframe infos from flv"
);
srs_
human
_trace
(
"build keyframe infos from flv"
);
for
(;;)
{
// tag header
if
((
ret
=
srs_flv_read_tag_header
(
ic
,
&
type
,
&
size
,
&
timestamp
))
!=
0
)
{
if
(
srs_flv_is_eof
(
ret
))
{
srs_
lib
_trace
(
"parse completed."
);
srs_
human
_trace
(
"parse completed."
);
return
0
;
}
srs_
lib
_trace
(
"flv get packet failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"flv get packet failed. ret=%d"
,
ret
);
return
ret
;
}
if
(
size
<=
0
)
{
srs_
lib
_trace
(
"invalid size=%d"
,
size
);
srs_
human
_trace
(
"invalid size=%d"
,
size
);
break
;
}
...
...
trunk/research/librtmp/srs_flv_parser.c
查看文件 @
b3bb2cd
...
...
@@ -61,11 +61,11 @@ int main(int argc, char** argv)
}
in_flv_file
=
argv
[
1
];
srs_
lib
_trace
(
"input: %s"
,
in_flv_file
);
srs_
human
_trace
(
"input: %s"
,
in_flv_file
);
if
((
flv
=
srs_flv_open_read
(
in_flv_file
))
==
NULL
)
{
ret
=
2
;
srs_
lib
_trace
(
"open flv file failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"open flv file failed. ret=%d"
,
ret
);
return
ret
;
}
...
...
@@ -141,44 +141,44 @@ int parse_flv(srs_flv_t flv)
return
ret
;
}
srs_
lib
_trace
(
"start parse flv"
);
srs_
human
_trace
(
"start parse flv"
);
for
(;;)
{
offset
=
srs_flv_tellg
(
flv
);
// tag header
if
((
ret
=
srs_flv_read_tag_header
(
flv
,
&
type
,
&
size
,
&
timestamp
))
!=
0
)
{
if
(
srs_flv_is_eof
(
ret
))
{
srs_
lib
_trace
(
"parse completed."
);
srs_
human
_trace
(
"parse completed."
);
return
0
;
}
srs_
lib
_trace
(
"flv get packet failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"flv get packet failed. ret=%d"
,
ret
);
return
ret
;
}
if
(
size
<=
0
)
{
srs_
lib
_trace
(
"invalid size=%d"
,
size
);
srs_
human
_trace
(
"invalid size=%d"
,
size
);
break
;
}
data
=
(
char
*
)
malloc
(
size
);
if
((
ret
=
srs_flv_read_tag_data
(
flv
,
data
,
size
))
==
0
)
{
if
((
ret
=
srs_print_rtmp_packet
(
type
,
timestamp
,
data
,
size
))
==
0
)
{
if
((
ret
=
srs_
human_
print_rtmp_packet
(
type
,
timestamp
,
data
,
size
))
==
0
)
{
char
hbuf
[
48
];
char
tbuf
[
48
];
parse_bytes
(
data
,
size
,
hbuf
,
sizeof
(
hbuf
),
tbuf
,
sizeof
(
tbuf
),
16
);
srs_
raw_trace
(
"offset=%d, first and last 16 bytes:
\n
"
srs_
human_raw
(
"offset=%d, first and last 16 bytes:
\n
"
"[+00, +15] %s
\n
[-15, EOF] %s
\n
"
,
(
int
)
offset
,
hbuf
,
tbuf
);
}
else
{
srs_
lib
_trace
(
"print packet failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"print packet failed. ret=%d"
,
ret
);
}
}
else
{
srs_
lib
_trace
(
"read flv failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"read flv failed. ret=%d"
,
ret
);
}
free
(
data
);
if
(
ret
!=
0
)
{
srs_
lib
_trace
(
"parse failed, ret=%d"
,
ret
);
srs_
human
_trace
(
"parse failed, ret=%d"
,
ret
);
return
ret
;
}
}
...
...
trunk/research/librtmp/srs_h264_raw_publish.c
查看文件 @
b3bb2cd
...
...
@@ -44,7 +44,7 @@ int read_h264_frame(char* data, int size, char** pp, int* pnb_start_code, int fp
// we search the h264 frame from the buffer which cached the h264 data.
// please get h264 raw data from device, it always a encoded frame.
if
(
!
srs_h264_startswith_annexb
(
p
,
size
-
(
p
-
data
),
pnb_start_code
))
{
srs_
lib
_trace
(
"h264 raw data invalid."
);
srs_
human
_trace
(
"h264 raw data invalid."
);
return
-
1
;
}
...
...
@@ -63,7 +63,7 @@ int read_h264_frame(char* data, int size, char** pp, int* pnb_start_code, int fp
*
pp
=
p
;
*
frame_size
=
p
-
*
frame
;
if
(
*
frame_size
<=
0
)
{
srs_
lib
_trace
(
"h264 raw data invalid."
);
srs_
human
_trace
(
"h264 raw data invalid."
);
return
-
1
;
}
...
...
@@ -95,32 +95,32 @@ int main(int argc, char** argv)
const
char
*
raw_file
=
argv
[
1
];
const
char
*
rtmp_url
=
argv
[
2
];
srs_
lib
_trace
(
"raw_file=%s, rtmp_url=%s"
,
raw_file
,
rtmp_url
);
srs_
human
_trace
(
"raw_file=%s, rtmp_url=%s"
,
raw_file
,
rtmp_url
);
// open file
int
raw_fd
=
open
(
raw_file
,
O_RDONLY
);
if
(
raw_fd
<
0
)
{
srs_
lib
_trace
(
"open h264 raw file %s failed."
,
raw_fd
);
srs_
human
_trace
(
"open h264 raw file %s failed."
,
raw_fd
);
goto
rtmp_destroy
;
}
off_t
file_size
=
lseek
(
raw_fd
,
0
,
SEEK_END
);
if
(
file_size
<=
0
)
{
srs_
lib
_trace
(
"h264 raw file %s empty."
,
raw_file
);
srs_
human
_trace
(
"h264 raw file %s empty."
,
raw_file
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"read entirely h264 raw file, size=%dKB"
,
(
int
)(
file_size
/
1024
));
srs_
human
_trace
(
"read entirely h264 raw file, size=%dKB"
,
(
int
)(
file_size
/
1024
));
char
*
h264_raw
=
(
char
*
)
malloc
(
file_size
);
if
(
!
h264_raw
)
{
srs_
lib
_trace
(
"alloc raw buffer failed for file %s."
,
raw_file
);
srs_
human
_trace
(
"alloc raw buffer failed for file %s."
,
raw_file
);
goto
rtmp_destroy
;
}
lseek
(
raw_fd
,
0
,
SEEK_SET
);
ssize_t
nb_read
=
0
;
if
((
nb_read
=
read
(
raw_fd
,
h264_raw
,
file_size
))
!=
file_size
)
{
srs_
lib
_trace
(
"buffer %s failed, expect=%dKB, actual=%dKB."
,
srs_
human
_trace
(
"buffer %s failed, expect=%dKB, actual=%dKB."
,
raw_file
,
(
int
)(
file_size
/
1024
),
(
int
)(
nb_read
/
1024
));
goto
rtmp_destroy
;
}
...
...
@@ -129,22 +129,22 @@ int main(int argc, char** argv)
srs_rtmp_t
rtmp
=
srs_rtmp_create
(
rtmp_url
);
if
(
srs_simple_handshake
(
rtmp
)
!=
0
)
{
srs_
lib
_trace
(
"simple handshake failed."
);
srs_
human
_trace
(
"simple handshake failed."
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"simple handshake success"
);
srs_
human
_trace
(
"simple handshake success"
);
if
(
srs_connect_app
(
rtmp
)
!=
0
)
{
srs_
lib
_trace
(
"connect vhost/app failed."
);
srs_
human
_trace
(
"connect vhost/app failed."
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"connect vhost/app success"
);
srs_
human
_trace
(
"connect vhost/app success"
);
if
(
srs_publish_stream
(
rtmp
)
!=
0
)
{
srs_
lib
_trace
(
"publish stream failed."
);
srs_
human
_trace
(
"publish stream failed."
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"publish stream success"
);
srs_
human
_trace
(
"publish stream success"
);
u_int32_t
dts
=
0
;
u_int32_t
pts
=
0
;
...
...
@@ -161,7 +161,7 @@ int main(int argc, char** argv)
if
(
read_h264_frame
(
h264_raw
,
file_size
,
&
p
,
&
nb_start_code
,
fps
,
&
data
,
&
size
,
&
dts
,
&
pts
)
<
0
)
{
srs_
lib
_trace
(
"read a frame from file buffer failed."
);
srs_
human
_trace
(
"read a frame from file buffer failed."
);
goto
rtmp_destroy
;
}
...
...
@@ -169,13 +169,13 @@ int main(int argc, char** argv)
int
error
=
srs_h264_write_raw_frames
(
rtmp
,
data
,
size
,
dts
,
pts
);
if
(
error
!=
0
)
{
if
(
srs_h264_is_dvbsp_error
(
error
))
{
srs_
lib
_trace
(
"ignore drop video error, code=%d"
,
error
);
srs_
human
_trace
(
"ignore drop video error, code=%d"
,
error
);
}
else
if
(
srs_h264_is_duplicated_sps_error
(
error
))
{
srs_
lib
_trace
(
"ignore duplicated sps, code=%d"
,
error
);
srs_
human
_trace
(
"ignore duplicated sps, code=%d"
,
error
);
}
else
if
(
srs_h264_is_duplicated_pps_error
(
error
))
{
srs_
lib
_trace
(
"ignore duplicated pps, code=%d"
,
error
);
srs_
human
_trace
(
"ignore duplicated pps, code=%d"
,
error
);
}
else
{
srs_
lib
_trace
(
"send h264 raw data failed."
);
srs_
human
_trace
(
"send h264 raw data failed."
);
goto
rtmp_destroy
;
}
}
...
...
@@ -183,14 +183,14 @@ int main(int argc, char** argv)
// 5bits, 7.3.1 NAL unit syntax,
// H.264-AVC-ISO_IEC_14496-10.pdf, page 44.
u_int8_t
nut
=
(
char
)
data
[
nb_start_code
]
&
0x1f
;
srs_lib_trace
(
"sent packet: type=%s, time=%d, size=%d, fps=%d, b[%d]=%#x(%s)"
,
srs_type2string
(
SRS_RTMP_TYPE_VIDEO
),
dts
,
size
,
fps
,
nb_start_code
,
(
char
)
data
[
nb_start_code
],
srs_human_trace
(
"sent packet: type=%s, time=%d, size=%d, fps=%d, b[%d]=%#x(%s)"
,
srs_human_flv_tag_type2string
(
SRS_RTMP_TYPE_VIDEO
),
dts
,
size
,
fps
,
nb_start_code
,
(
char
)
data
[
nb_start_code
],
(
nut
==
7
?
"SPS"
:
(
nut
==
8
?
"PPS"
:
(
nut
==
5
?
"I"
:
(
nut
==
1
?
"P"
:
"Unknown"
)))));
// @remark, when use encode device, it not need to sleep.
usleep
(
1000
/
fps
*
1000
);
}
srs_
lib
_trace
(
"h264 raw data completed"
);
srs_
human
_trace
(
"h264 raw data completed"
);
rtmp_destroy:
srs_rtmp_destroy
(
rtmp
);
...
...
trunk/research/librtmp/srs_ingest_flv.c
查看文件 @
b3bb2cd
...
...
@@ -89,19 +89,19 @@ int main(int argc, char** argv)
}
}
srs_lib_trace
(
"input: %s"
,
in_flv_file
);
srs_lib_trace
(
"output: %s"
,
out_rtmp_url
);
srs_human_trace
(
"input: %s"
,
in_flv_file
);
srs_human_trace
(
"output: %s"
,
out_rtmp_url
);
if
((
flv
=
srs_flv_open_read
(
in_flv_file
))
==
NULL
)
{
ret
=
2
;
srs_
lib
_trace
(
"open flv file failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"open flv file failed. ret=%d"
,
ret
);
return
ret
;
}
ortmp
=
srs_rtmp_create
(
out_rtmp_url
);
ret
=
proxy
(
flv
,
ortmp
);
srs_
lib
_trace
(
"ingest flv to RTMP completed"
);
srs_
human
_trace
(
"ingest flv to RTMP completed"
);
srs_rtmp_destroy
(
ortmp
);
srs_flv_close
(
flv
);
...
...
@@ -118,20 +118,20 @@ int do_proxy(srs_flv_t flv, srs_rtmp_t ortmp, int64_t re, int32_t* pstarttime, u
int
size
;
char
*
data
=
NULL
;
srs_
lib
_trace
(
"start ingest flv to RTMP stream"
);
srs_
human
_trace
(
"start ingest flv to RTMP stream"
);
for
(;;)
{
// tag header
if
((
ret
=
srs_flv_read_tag_header
(
flv
,
&
type
,
&
size
,
ptimestamp
))
!=
0
)
{
if
(
srs_flv_is_eof
(
ret
))
{
srs_
lib
_trace
(
"parse completed."
);
srs_
human
_trace
(
"parse completed."
);
return
0
;
}
srs_
lib
_trace
(
"flv get packet failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"flv get packet failed. ret=%d"
,
ret
);
return
ret
;
}
if
(
size
<=
0
)
{
srs_
lib
_trace
(
"invalid size=%d"
,
size
);
srs_
human
_trace
(
"invalid size=%d"
,
size
);
break
;
}
...
...
@@ -143,13 +143,13 @@ int do_proxy(srs_flv_t flv, srs_rtmp_t ortmp, int64_t re, int32_t* pstarttime, u
u_int32_t
timestamp
=
*
ptimestamp
;
if
((
ret
=
srs_print_rtmp_packet
(
type
,
timestamp
,
data
,
size
))
!=
0
)
{
srs_lib_trace
(
"print packet failed. ret=%d"
,
ret
);
if
((
ret
=
srs_human_print_rtmp_packet
(
type
,
timestamp
,
data
,
size
))
!=
0
)
{
srs_human_trace
(
"print packet failed. ret=%d"
,
ret
);
return
ret
;
}
if
((
ret
=
srs_write_packet
(
ortmp
,
type
,
*
ptimestamp
,
data
,
size
))
!=
0
)
{
srs_
lib
_trace
(
"irtmp get packet failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"irtmp get packet failed. ret=%d"
,
ret
);
return
ret
;
}
...
...
@@ -192,22 +192,22 @@ int connect_oc(srs_rtmp_t ortmp)
int
ret
=
0
;
if
((
ret
=
srs_simple_handshake
(
ortmp
))
!=
0
)
{
srs_
lib
_trace
(
"ortmp simple handshake failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"ortmp simple handshake failed. ret=%d"
,
ret
);
return
ret
;
}
srs_
lib
_trace
(
"ortmp simple handshake success"
);
srs_
human
_trace
(
"ortmp simple handshake success"
);
if
((
ret
=
srs_connect_app
(
ortmp
))
!=
0
)
{
srs_
lib
_trace
(
"ortmp connect vhost/app failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"ortmp connect vhost/app failed. ret=%d"
,
ret
);
return
ret
;
}
srs_
lib
_trace
(
"ortmp connect vhost/app success"
);
srs_
human
_trace
(
"ortmp connect vhost/app success"
);
if
((
ret
=
srs_publish_stream
(
ortmp
))
!=
0
)
{
srs_
lib
_trace
(
"ortmp publish stream failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"ortmp publish stream failed. ret=%d"
,
ret
);
return
ret
;
}
srs_
lib
_trace
(
"ortmp publish stream success"
);
srs_
human
_trace
(
"ortmp publish stream success"
);
return
ret
;
}
...
...
@@ -219,16 +219,16 @@ int64_t re_create()
// use the starttime to get the deviation
int64_t
deviation
=
re
-
tools_main_entrance_startup_time
;
srs_
lib
_trace
(
"deviation is %d ms, pulse is %d ms"
,
(
int
)(
deviation
),
(
int
)(
RE_PULSE_MS
));
srs_
human
_trace
(
"deviation is %d ms, pulse is %d ms"
,
(
int
)(
deviation
),
(
int
)(
RE_PULSE_MS
));
// so, we adjust time to max(0, deviation)
// because the last pulse, we already sleeped
int
adjust
=
(
int
)(
deviation
);
if
(
adjust
>
0
)
{
srs_
lib
_trace
(
"adjust re time for %d ms"
,
adjust
);
srs_
human
_trace
(
"adjust re time for %d ms"
,
adjust
);
re
-=
adjust
;
}
else
{
srs_
lib
_trace
(
"no need to adjust re time"
);
srs_
human
_trace
(
"no need to adjust re time"
);
}
return
re
;
...
...
@@ -249,7 +249,7 @@ void re_cleanup(int64_t re, int32_t starttime, u_int32_t time)
int64_t
now
=
srs_get_time_ms
();
int64_t
diff
=
time
-
starttime
-
(
now
-
re
);
if
(
diff
>
0
)
{
srs_
lib
_trace
(
"re_cleanup, diff=%d, start=%d, last=%d ms"
,
srs_
human
_trace
(
"re_cleanup, diff=%d, start=%d, last=%d ms"
,
(
int
)
diff
,
starttime
,
time
);
usleep
(
diff
*
1000
);
}
...
...
trunk/research/librtmp/srs_ingest_rtmp.c
查看文件 @
b3bb2cd
...
...
@@ -74,14 +74,14 @@ int main(int argc, char** argv)
}
}
srs_lib_trace
(
"input: %s"
,
in_rtmp_url
);
srs_lib_trace
(
"output: %s"
,
out_rtmp_url
);
srs_human_trace
(
"input: %s"
,
in_rtmp_url
);
srs_human_trace
(
"output: %s"
,
out_rtmp_url
);
irtmp
=
srs_rtmp_create
(
in_rtmp_url
);
ortmp
=
srs_rtmp_create
(
out_rtmp_url
);
ret
=
proxy
(
irtmp
,
ortmp
);
srs_
lib
_trace
(
"proxy completed"
);
srs_
human
_trace
(
"proxy completed"
);
srs_rtmp_destroy
(
irtmp
);
srs_rtmp_destroy
(
ortmp
);
...
...
@@ -106,24 +106,24 @@ int proxy(srs_rtmp_t irtmp, srs_rtmp_t ortmp)
return
ret
;
}
srs_
lib
_trace
(
"start proxy RTMP stream"
);
srs_
human
_trace
(
"start proxy RTMP stream"
);
for
(;;)
{
if
((
ret
=
srs_read_packet
(
irtmp
,
&
type
,
&
timestamp
,
&
data
,
&
size
))
!=
0
)
{
srs_
lib
_trace
(
"irtmp get packet failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"irtmp get packet failed. ret=%d"
,
ret
);
return
ret
;
}
if
((
ret
=
srs_print_rtmp_packet
(
type
,
timestamp
,
data
,
size
))
!=
0
)
{
srs_lib_trace
(
"print packet failed. ret=%d"
,
ret
);
if
((
ret
=
srs_human_print_rtmp_packet
(
type
,
timestamp
,
data
,
size
))
!=
0
)
{
srs_human_trace
(
"print packet failed. ret=%d"
,
ret
);
return
ret
;
}
if
((
ret
=
srs_write_packet
(
ortmp
,
type
,
timestamp
,
data
,
size
))
!=
0
)
{
srs_
lib
_trace
(
"irtmp get packet failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"irtmp get packet failed. ret=%d"
,
ret
);
return
ret
;
}
srs_lib_verbose
(
"ortmp sent packet: type=%s, time=%d, size=%d"
,
srs_type2string
(
type
),
timestamp
,
size
);
srs_human_verbose
(
"ortmp sent packet: type=%s, time=%d, size=%d"
,
srs_human_flv_tag_type2string
(
type
),
timestamp
,
size
);
}
return
ret
;
...
...
@@ -134,22 +134,22 @@ int connect_ic(srs_rtmp_t irtmp)
int
ret
=
0
;
if
((
ret
=
srs_simple_handshake
(
irtmp
))
!=
0
)
{
srs_
lib
_trace
(
"irtmp simple handshake failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"irtmp simple handshake failed. ret=%d"
,
ret
);
return
ret
;
}
srs_
lib
_trace
(
"irtmp simple handshake success"
);
srs_
human
_trace
(
"irtmp simple handshake success"
);
if
((
ret
=
srs_connect_app
(
irtmp
))
!=
0
)
{
srs_
lib
_trace
(
"irtmp connect vhost/app failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"irtmp connect vhost/app failed. ret=%d"
,
ret
);
return
ret
;
}
srs_
lib
_trace
(
"irtmp connect vhost/app success"
);
srs_
human
_trace
(
"irtmp connect vhost/app success"
);
if
((
ret
=
srs_play_stream
(
irtmp
))
!=
0
)
{
srs_
lib
_trace
(
"irtmp play stream failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"irtmp play stream failed. ret=%d"
,
ret
);
return
ret
;
}
srs_
lib
_trace
(
"irtmp play stream success"
);
srs_
human
_trace
(
"irtmp play stream success"
);
return
ret
;
}
...
...
@@ -159,22 +159,22 @@ int connect_oc(srs_rtmp_t ortmp)
int
ret
=
0
;
if
((
ret
=
srs_simple_handshake
(
ortmp
))
!=
0
)
{
srs_
lib
_trace
(
"ortmp simple handshake failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"ortmp simple handshake failed. ret=%d"
,
ret
);
return
ret
;
}
srs_
lib
_trace
(
"ortmp simple handshake success"
);
srs_
human
_trace
(
"ortmp simple handshake success"
);
if
((
ret
=
srs_connect_app
(
ortmp
))
!=
0
)
{
srs_
lib
_trace
(
"ortmp connect vhost/app failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"ortmp connect vhost/app failed. ret=%d"
,
ret
);
return
ret
;
}
srs_
lib
_trace
(
"ortmp connect vhost/app success"
);
srs_
human
_trace
(
"ortmp connect vhost/app success"
);
if
((
ret
=
srs_publish_stream
(
ortmp
))
!=
0
)
{
srs_
lib
_trace
(
"ortmp publish stream failed. ret=%d"
,
ret
);
srs_
human
_trace
(
"ortmp publish stream failed. ret=%d"
,
ret
);
return
ret
;
}
srs_
lib
_trace
(
"ortmp publish stream success"
);
srs_
human
_trace
(
"ortmp publish stream success"
);
return
ret
;
}
...
...
trunk/research/librtmp/srs_play.c
查看文件 @
b3bb2cd
...
...
@@ -44,26 +44,26 @@ int main(int argc, char** argv)
exit
(
-
1
);
}
srs_
lib
_trace
(
"rtmp url: %s"
,
argv
[
1
]);
srs_
human
_trace
(
"rtmp url: %s"
,
argv
[
1
]);
srs_rtmp_t
rtmp
=
srs_rtmp_create
(
argv
[
1
]);
if
(
srs_simple_handshake
(
rtmp
)
!=
0
)
{
srs_
lib
_trace
(
"simple handshake failed."
);
srs_
human
_trace
(
"simple handshake failed."
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"simple handshake success"
);
srs_
human
_trace
(
"simple handshake success"
);
if
(
srs_connect_app
(
rtmp
)
!=
0
)
{
srs_
lib
_trace
(
"connect vhost/app failed."
);
srs_
human
_trace
(
"connect vhost/app failed."
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"connect vhost/app success"
);
srs_
human
_trace
(
"connect vhost/app success"
);
if
(
srs_play_stream
(
rtmp
)
!=
0
)
{
srs_
lib
_trace
(
"play stream failed."
);
srs_
human
_trace
(
"play stream failed."
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"play stream success"
);
srs_
human
_trace
(
"play stream success"
);
for
(;;)
{
int
size
;
...
...
@@ -75,7 +75,7 @@ int main(int argc, char** argv)
goto
rtmp_destroy
;
}
if
(
srs_print_rtmp_packet
(
type
,
timestamp
,
data
,
size
)
!=
0
)
{
if
(
srs_
human_
print_rtmp_packet
(
type
,
timestamp
,
data
,
size
)
!=
0
)
{
goto
rtmp_destroy
;
}
...
...
trunk/research/librtmp/srs_publish.c
查看文件 @
b3bb2cd
...
...
@@ -47,31 +47,31 @@ int main(int argc, char** argv)
// warn it .
// @see: https://github.com/winlinvip/simple-rtmp-server/issues/126
srs_
lib
_trace
(
"
\033
[33m%s
\033
[0m"
,
srs_
human
_trace
(
"
\033
[33m%s
\033
[0m"
,
"[warning] it's only a sample to use librtmp. "
"please never use it to publish and test forward/transcode/edge/HLS whatever. "
"you should refer to this tool to use the srs-librtmp to publish the real media stream."
"read about: https://github.com/winlinvip/simple-rtmp-server/issues/126"
);
srs_
lib
_trace
(
"rtmp url: %s"
,
argv
[
1
]);
srs_
human
_trace
(
"rtmp url: %s"
,
argv
[
1
]);
srs_rtmp_t
rtmp
=
srs_rtmp_create
(
argv
[
1
]);
if
(
srs_simple_handshake
(
rtmp
)
!=
0
)
{
srs_
lib
_trace
(
"simple handshake failed."
);
srs_
human
_trace
(
"simple handshake failed."
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"simple handshake success"
);
srs_
human
_trace
(
"simple handshake success"
);
if
(
srs_connect_app
(
rtmp
)
!=
0
)
{
srs_
lib
_trace
(
"connect vhost/app failed."
);
srs_
human
_trace
(
"connect vhost/app failed."
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"connect vhost/app success"
);
srs_
human
_trace
(
"connect vhost/app success"
);
if
(
srs_publish_stream
(
rtmp
)
!=
0
)
{
srs_
lib
_trace
(
"publish stream failed."
);
srs_
human
_trace
(
"publish stream failed."
);
goto
rtmp_destroy
;
}
srs_
lib
_trace
(
"publish stream success"
);
srs_
human
_trace
(
"publish stream success"
);
u_int32_t
timestamp
=
0
;
for
(;;)
{
...
...
@@ -84,8 +84,8 @@ int main(int argc, char** argv)
if
(
srs_write_packet
(
rtmp
,
type
,
timestamp
,
data
,
size
)
!=
0
)
{
goto
rtmp_destroy
;
}
srs_lib_trace
(
"sent packet: type=%s, time=%d, size=%d"
,
srs_type2string
(
type
),
timestamp
,
size
);
srs_human_trace
(
"sent packet: type=%s, time=%d, size=%d"
,
srs_human_flv_tag_type2string
(
type
),
timestamp
,
size
);
usleep
(
40
*
1000
);
}
...
...
trunk/src/libs/srs_librtmp.cpp
查看文件 @
b3bb2cd
...
...
@@ -1432,7 +1432,7 @@ void srs_amf0_strict_array_append(srs_amf0_t amf0, srs_amf0_t value)
obj
->
append
(
any
);
}
char
*
srs_
amf0_human
_print
(
srs_amf0_t
amf0
,
char
**
pdata
,
int
*
psize
)
char
*
srs_
human_amf0
_print
(
srs_amf0_t
amf0
,
char
**
pdata
,
int
*
psize
)
{
if
(
!
amf0
)
{
return
NULL
;
...
...
@@ -1443,7 +1443,7 @@ char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize)
return
any
->
human_print
(
pdata
,
psize
);
}
const
char
*
srs_type2string
(
char
type
)
const
char
*
srs_
human_flv_tag_
type2string
(
char
type
)
{
static
const
char
*
audio
=
"Audio"
;
static
const
char
*
video
=
"Video"
;
...
...
@@ -1460,7 +1460,7 @@ const char* srs_type2string(char type)
return
unknown
;
}
const
char
*
srs_
code
_id2string
(
char
codec_id
)
const
char
*
srs_
human_flv_video_codec
_id2string
(
char
codec_id
)
{
static
const
char
*
h263
=
"H.263"
;
static
const
char
*
screen
=
"Screen"
;
...
...
@@ -1483,7 +1483,7 @@ const char* srs_code_id2string(char codec_id)
return
unknown
;
}
const
char
*
srs_
avc_packet
2string
(
char
avc_packet_type
)
const
char
*
srs_
human_flv_video_avc_packet_type
2string
(
char
avc_packet_type
)
{
static
const
char
*
sps_pps
=
"SpsPps"
;
static
const
char
*
nalu
=
"Nalu"
;
...
...
@@ -1500,7 +1500,7 @@ const char* srs_avc_packet2string(char avc_packet_type)
return
unknown
;
}
const
char
*
srs_frame_type2string
(
char
frame_type
)
const
char
*
srs_
human_flv_video_
frame_type2string
(
char
frame_type
)
{
static
const
char
*
keyframe
=
"I"
;
static
const
char
*
interframe
=
"P/B"
;
...
...
@@ -1521,7 +1521,7 @@ const char* srs_frame_type2string(char frame_type)
return
unknown
;
}
int
srs_print_rtmp_packet
(
char
type
,
u_int32_t
timestamp
,
char
*
data
,
int
size
)
int
srs_
human_
print_rtmp_packet
(
char
type
,
u_int32_t
timestamp
,
char
*
data
,
int
size
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -1531,18 +1531,18 @@ int srs_print_rtmp_packet(char type, u_int32_t timestamp, char* data, int size)
}
if
(
type
==
SRS_RTMP_TYPE_VIDEO
)
{
srs_lib_trace
(
"Video packet type=%s, dts=%d, pts=%d, size=%d, %s(%s,%s)"
,
srs_type2string
(
type
),
timestamp
,
pts
,
size
,
srs_code_id2string
(
srs_get_codec_id
(
data
,
size
)),
srs_avc_packet2string
(
srs_get_avc_packet_type
(
data
,
size
)),
srs_frame_type2string
(
srs_get_frame_type
(
data
,
size
))
srs_human_trace
(
"Video packet type=%s, dts=%d, pts=%d, size=%d, %s(%s,%s)"
,
srs_human_flv_tag_type2string
(
type
),
timestamp
,
pts
,
size
,
srs_human_flv_video_codec_id2string
(
srs_get_codec_id
(
data
,
size
)),
srs_human_flv_video_avc_packet_type2string
(
srs_get_avc_packet_type
(
data
,
size
)),
srs_human_flv_video_frame_type2string
(
srs_get_frame_type
(
data
,
size
))
);
}
else
if
(
type
==
SRS_RTMP_TYPE_AUDIO
)
{
srs_lib_trace
(
"Audio packet type=%s, dts=%d, pts=%d, size=%d"
,
srs_type2string
(
type
),
timestamp
,
pts
,
size
);
srs_human_trace
(
"Audio packet type=%s, dts=%d, pts=%d, size=%d"
,
srs_human_flv_tag_type2string
(
type
),
timestamp
,
pts
,
size
);
}
else
if
(
type
==
SRS_RTMP_TYPE_SCRIPT
)
{
srs_lib_verbose
(
"Data packet type=%s, time=%d, size=%d"
,
srs_type2string
(
type
),
timestamp
,
size
);
srs_human_verbose
(
"Data packet type=%s, time=%d, size=%d"
,
srs_human_flv_tag_type2string
(
type
),
timestamp
,
size
);
int
nparsed
=
0
;
while
(
nparsed
<
size
)
{
int
nb_parsed_this
=
0
;
...
...
@@ -1554,18 +1554,18 @@ int srs_print_rtmp_packet(char type, u_int32_t timestamp, char* data, int size)
nparsed
+=
nb_parsed_this
;
char
*
amf0_str
=
NULL
;
srs_
raw_trace
(
"%s"
,
srs_amf0_human
_print
(
amf0
,
&
amf0_str
,
NULL
));
srs_
human_raw
(
"%s"
,
srs_human_amf0
_print
(
amf0
,
&
amf0_str
,
NULL
));
srs_amf0_free_bytes
(
amf0_str
);
}
}
else
{
srs_lib_trace
(
"Unknown packet type=%s, dts=%d, pts=%d, size=%d"
,
srs_type2string
(
type
),
timestamp
,
pts
,
size
);
srs_human_trace
(
"Unknown packet type=%s, dts=%d, pts=%d, size=%d"
,
srs_human_flv_tag_type2string
(
type
),
timestamp
,
pts
,
size
);
}
return
ret
;
}
const
char
*
srs_format_time
()
const
char
*
srs_
human_
format_time
()
{
struct
timeval
tv
;
static
char
buf
[
23
];
...
...
trunk/src/libs/srs_librtmp.hpp
查看文件 @
b3bb2cd
...
...
@@ -504,7 +504,7 @@ extern void srs_amf0_strict_array_append(srs_amf0_t amf0, srs_amf0_t value);
* user must use srs_amf0_free_bytes to free it.
* @return return the *pdata for print. NULL to ignore.
*/
extern
char
*
srs_
amf0_human
_print
(
srs_amf0_t
amf0
,
char
**
pdata
,
int
*
psize
);
extern
char
*
srs_
human_amf0
_print
(
srs_amf0_t
amf0
,
char
**
pdata
,
int
*
psize
);
/**
* convert the flv tag type to string.
* SRS_RTMP_TYPE_AUDIO to "Audio"
...
...
@@ -514,7 +514,7 @@ extern char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize);
* @remark user never free the return char*,
* it's static shared const string.
*/
extern
const
char
*
srs_type2string
(
char
type
);
extern
const
char
*
srs_
human_flv_tag_
type2string
(
char
type
);
/**
* get the codec id string.
...
...
@@ -528,7 +528,7 @@ extern const char* srs_type2string(char type);
* @remark user never free the return char*,
* it's static shared const string.
*/
extern
const
char
*
srs_
code
_id2string
(
char
codec_id
);
extern
const
char
*
srs_
human_flv_video_codec
_id2string
(
char
codec_id
);
/**
* get the avc packet type string.
...
...
@@ -539,7 +539,7 @@ extern const char* srs_code_id2string(char codec_id);
* @remark user never free the return char*,
* it's static shared const string.
*/
extern
const
char
*
srs_
avc_packet
2string
(
char
avc_packet_type
);
extern
const
char
*
srs_
human_flv_video_avc_packet_type
2string
(
char
avc_packet_type
);
/**
* get the frame type string.
...
...
@@ -552,20 +552,20 @@ extern const char* srs_avc_packet2string(char avc_packet_type);
* @remark user never free the return char*,
* it's static shared const string.
*/
extern
const
char
*
srs_frame_type2string
(
char
frame_type
);
extern
const
char
*
srs_
human_flv_video_
frame_type2string
(
char
frame_type
);
/**
* print the rtmp packet, use srs_lib_trace/srs_lib_verbose for packet,
* and use srs_raw_trace for script data body.
* print the rtmp packet, use srs_human_trace/srs_human_verbose for packet,
* and use srs_human_raw for script data body.
* @return an error code for parse the timetstamp to dts and pts.
*/
extern
int
srs_print_rtmp_packet
(
char
type
,
u_int32_t
timestamp
,
char
*
data
,
int
size
);
extern
int
srs_
human_
print_rtmp_packet
(
char
type
,
u_int32_t
timestamp
,
char
*
data
,
int
size
);
// log to console, for use srs-librtmp application.
extern
const
char
*
srs_format_time
();
#define srs_lib_trace(msg, ...) printf("[%s] ", srs_format_time());printf(msg, ##__VA_ARGS__);printf("\n")
#define srs_lib_verbose(msg, ...) printf("[%s] ", srs_format_time());printf(msg, ##__VA_ARGS__);printf("\n")
#define srs_raw_trace(msg, ...) printf(msg, ##__VA_ARGS__)
extern
const
char
*
srs_human_format_time
();
#define srs_human_trace(msg, ...) printf("[%s] ", srs_human_format_time());printf(msg, ##__VA_ARGS__);printf("\n")
#define srs_human_verbose(msg, ...) printf("[%s] ", srs_human_format_time());printf(msg, ##__VA_ARGS__);printf("\n")
#define srs_human_raw(msg, ...) printf(msg, ##__VA_ARGS__)
/*************************************************************
**************************************************************
...
...
请
注册
或
登录
后发表评论