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-08 14:01:14 +0800
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
f492175a6d862605ace4a184bb4e93ec25787a72
f492175a
2 parents
aac6de69
cf5c24af
Merge branch 'srs.master'
显示空白字符变更
内嵌
并排对比
正在显示
8 个修改的文件
包含
95 行增加
和
97 行删除
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_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.hpp
trunk/research/librtmp/srs_detect_rtmp.c
查看文件 @
f492175
...
...
@@ -59,8 +59,12 @@ int main(int argc, char** argv)
int
duration
=
0
;
int
timeout
=
0
;
printf
(
"detect rtmp stream
\n
"
);
printf
(
"srs(simple-rtmp-server) client librtmp library.
\n
"
);
printf
(
"version: %d.%d.%d
\n
"
,
srs_version_major
(),
srs_version_minor
(),
srs_version_revision
());
if
(
argc
<=
3
)
{
printf
(
"detect stream on RTMP server
\n
"
printf
(
"detect stream on RTMP server
, print result to stderr.
\n
"
"Usage: %s <rtmp_url> <duration> <timeout>
\n
"
" rtmp_url RTMP stream url to play
\n
"
" duration how long to play, in seconds, stream time.
\n
"
...
...
@@ -68,69 +72,63 @@ int main(int argc, char** argv)
"For example:
\n
"
" %s rtmp://127.0.0.1:1935/live/livestream 3 10
\n
"
,
argv
[
0
],
argv
[
0
]);
ret
=
1
;
exit
(
ret
);
return
ret
;
exit
(
-
1
);
}
rtmp_url
=
argv
[
1
];
duration
=
atoi
(
argv
[
2
]);
timeout
=
atoi
(
argv
[
3
]);
printf
(
"detect rtmp stream
\n
"
);
printf
(
"srs(simple-rtmp-server) client librtmp library.
\n
"
);
printf
(
"version: %d.%d.%d
\n
"
,
srs_version_major
(),
srs_version_minor
(),
srs_version_revision
());
printf
(
"rtmp url: %s
\n
"
,
rtmp_url
);
printf
(
"duration: %ds, timeout:%ds
\n
"
,
duration
,
timeout
);
srs_trace
(
"rtmp url: %s"
,
rtmp_url
);
srs_trace
(
"duration: %ds, timeout:%ds"
,
duration
,
timeout
);
if
(
duration
<=
0
||
timeout
<=
0
)
{
ret
=
1
;
fprintf
(
stderr
,
"duration and timeout must be positive. ret=%d
\n
"
,
ret
);
exit
(
ret
);
return
ret
;
srs_trace
(
"duration and timeout must be positive."
);
exit
(
-
1
);
}
rtmp
=
srs_rtmp_create
(
rtmp_url
);
if
((
ret
=
__srs_dns_resolve
(
rtmp
))
!=
0
)
{
fprintf
(
stderr
,
"dns resolve failed. ret=%d
\n
"
,
ret
);
srs_trace
(
"dns resolve failed. ret=%d
"
,
ret
);
goto
rtmp_destroy
;
}
printf
(
"dns resolve success
\n
"
);
srs_trace
(
"dns resolve success
"
);
time_dns_resolve
=
srs_get_time_ms
();
if
((
ret
=
__srs_connect_server
(
rtmp
))
!=
0
)
{
fprintf
(
stderr
,
"socket connect failed. ret=%d
\n
"
,
ret
);
srs_trace
(
"socket connect failed. ret=%d
"
,
ret
);
goto
rtmp_destroy
;
}
printf
(
"socket connect success
\n
"
);
srs_trace
(
"socket connect success
"
);
time_socket_connect
=
srs_get_time_ms
();
if
((
ret
=
__srs_do_simple_handshake
(
rtmp
))
!=
0
)
{
fprintf
(
stderr
,
"do simple handshake failed. ret=%d
\n
"
,
ret
);
srs_trace
(
"do simple handshake failed. ret=%d
"
,
ret
);
goto
rtmp_destroy
;
}
printf
(
"do simple handshake success
\n
"
);
srs_trace
(
"do simple handshake success
"
);
if
((
ret
=
srs_connect_app
(
rtmp
))
!=
0
)
{
fprintf
(
stderr
,
"connect vhost/app failed. ret=%d
\n
"
,
ret
);
srs_trace
(
"connect vhost/app failed. ret=%d
"
,
ret
);
goto
rtmp_destroy
;
}
printf
(
"connect vhost/app success
\n
"
);
srs_trace
(
"connect vhost/app success
"
);
if
((
ret
=
srs_play_stream
(
rtmp
))
!=
0
)
{
fprintf
(
stderr
,
"play stream failed. ret=%d
\n
"
,
ret
);
srs_trace
(
"play stream failed. ret=%d
"
,
ret
);
goto
rtmp_destroy
;
}
printf
(
"play stream success
\n
"
);
srs_trace
(
"play stream success
"
);
time_play_stream
=
srs_get_time_ms
();
for
(;;)
{
if
((
ret
=
srs_read_packet
(
rtmp
,
&
type
,
&
timestamp
,
&
data
,
&
size
))
!=
0
)
{
fprintf
(
stderr
,
"read packet failed. ret=%d
\n
"
,
ret
);
srs_trace
(
"read packet failed. ret=%d
"
,
ret
);
goto
rtmp_destroy
;
}
printf
(
"got packet: type=%s, time=%d, size=%d
\n
"
,
srs_type2string
(
type
),
timestamp
,
size
);
srs_trace
(
"got packet: type=%s, time=%d, size=%d"
,
srs_type2string
(
type
),
timestamp
,
size
);
if
(
SRS_RTMP_TYPE_VIDEO
==
type
||
SRS_RTMP_TYPE_AUDIO
==
type
)
{
if
(
time_first_packet
<=
0
)
{
...
...
@@ -144,12 +142,12 @@ int main(int argc, char** argv)
free
(
data
);
if
(
srs_get_time_ms
()
-
time_startup
>
timeout
*
1000
)
{
printf
(
"timeout, terminate.
\n
"
);
srs_trace
(
"timeout, terminate.
"
);
goto
rtmp_destroy
;
}
if
((
timestamp
-
basetime
)
>
duration
*
1000
)
{
printf
(
"duration exceed, terminate.
\n
"
);
srs_trace
(
"duration exceed, terminate.
"
);
goto
rtmp_destroy
;
}
}
...
...
@@ -197,7 +195,9 @@ rtmp_destroy:
"
\"
remark1
\"
:
\"
delay = stream - (time_cleanup - time_first_packet)
\"
"
,
"
\"
remark2
\"
:
\"
if code is not 0, user must ignore all data
\"
"
);
printf
(
"
\n
"
);
srs_trace
(
""
);
srs_trace
(
"completed"
);
return
ret
;
}
...
...
trunk/research/librtmp/srs_flv_injecter.c
查看文件 @
f492175
...
...
@@ -53,17 +53,20 @@ int main(int argc, char** argv)
int
tmp_file_size
=
0
;
char
*
tmp_file
;
printf
(
"inject flv file keyframes to metadata.
\n
"
);
printf
(
"srs(simple-rtmp-server) client librtmp library.
\n
"
);
printf
(
"version: %d.%d.%d
\n
"
,
srs_version_major
(),
srs_version_minor
(),
srs_version_revision
());
if
(
argc
<=
2
)
{
printf
(
"inject flv file keyframes to metadata
\n
"
"Usage: %s in_flv_file out_flv_file
\n
"
" in_flv_file input flv file to inject.
\n
"
" out_flv_file the inject output file, can be in_flv_file.
\n
"
"For example:
\n
"
" %s doc/source.200kbps.768x320.flv injected.flv
\n
"
" %s ../../doc/source.200kbps.768x320.flv injected.flv
\n
"
,
argv
[
0
],
argv
[
0
]);
ret
=
1
;
exit
(
ret
);
return
ret
;
argv
[
0
],
argv
[
0
],
argv
[
0
]);
exit
(
-
1
);
}
in_flv_file
=
argv
[
1
];
...
...
@@ -73,9 +76,6 @@ 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_trace
(
"inject flv file keyframes to metadata."
);
srs_trace
(
"srs(simple-rtmp-server) client librtmp library."
);
srs_trace
(
"version: %d.%d.%d"
,
srs_version_major
(),
srs_version_minor
(),
srs_version_revision
());
srs_trace
(
"input: %s"
,
in_flv_file
);
srs_trace
(
"output: %s"
,
out_flv_file
);
srs_trace
(
"tmp_file: %s"
,
tmp_file
);
...
...
trunk/research/librtmp/srs_flv_parser.c
查看文件 @
f492175
...
...
@@ -45,23 +45,22 @@ int main(int argc, char** argv)
// flv handler
srs_flv_t
flv
;
printf
(
"parse and show flv file detail.
\n
"
);
printf
(
"srs(simple-rtmp-server) client librtmp library.
\n
"
);
printf
(
"version: %d.%d.%d
\n
"
,
srs_version_major
(),
srs_version_minor
(),
srs_version_revision
());
if
(
argc
<=
1
)
{
printf
(
"parse and show flv file detail
\n
"
"Usage: %s in_flv_file
\n
"
" in_flv_file flv file to parse and show.
\n
"
"For example:
\n
"
" %s doc/source.200kbps.768x320.flv
\n
"
" %s ../../doc/source.200kbps.768x320.flv
\n
"
,
argv
[
0
],
argv
[
0
]);
ret
=
1
;
exit
(
ret
);
return
ret
;
argv
[
0
],
argv
[
0
],
argv
[
0
]);
exit
(
-
1
);
}
in_flv_file
=
argv
[
1
];
srs_trace
(
"parse and show flv file detail."
);
srs_trace
(
"srs(simple-rtmp-server) client librtmp library."
);
srs_trace
(
"version: %d.%d.%d"
,
srs_version_major
(),
srs_version_minor
(),
srs_version_revision
());
srs_trace
(
"input: %s"
,
in_flv_file
);
if
((
flv
=
srs_flv_open_read
(
in_flv_file
))
==
NULL
)
{
...
...
trunk/research/librtmp/srs_ingest_flv.c
查看文件 @
f492175
...
...
@@ -59,17 +59,20 @@ int main(int argc, char** argv)
// flv handler
srs_flv_t
flv
;
printf
(
"ingest flv file and publish to RTMP server like FFMPEG.
\n
"
);
printf
(
"srs(simple-rtmp-server) client librtmp library.
\n
"
);
printf
(
"version: %d.%d.%d
\n
"
,
srs_version_major
(),
srs_version_minor
(),
srs_version_revision
());
if
(
argc
<=
2
)
{
printf
(
"ingest flv file and publish to RTMP server
\n
"
"Usage: %s <-i in_flv_file> <-y out_rtmp_url>
\n
"
" in_flv_file input flv file, ingest from this file.
\n
"
" out_rtmp_url output rtmp url, publish to this url.
\n
"
"For example:
\n
"
" %s -i ../../doc/source.200kbps.768x320.flv -y rtmp://127.0.0.1/live/demo
\n
"
,
argv
[
0
],
argv
[
0
]);
ret
=
1
;
exit
(
ret
);
return
ret
;
" %s -i doc/source.200kbps.768x320.flv -y rtmp://127.0.0.1/live/livestream
\n
"
" %s -i ../../doc/source.200kbps.768x320.flv -y rtmp://127.0.0.1/live/livestream
\n
"
,
argv
[
0
],
argv
[
0
],
argv
[
0
]);
exit
(
-
1
);
}
// parse options in FFMPEG format.
...
...
@@ -86,9 +89,6 @@ int main(int argc, char** argv)
}
}
srs_trace
(
"ingest flv file and publish to RTMP server like FFMPEG."
);
srs_trace
(
"srs(simple-rtmp-server) client librtmp library."
);
srs_trace
(
"version: %d.%d.%d"
,
srs_version_major
(),
srs_version_minor
(),
srs_version_revision
());
srs_trace
(
"input: %s"
,
in_flv_file
);
srs_trace
(
"output: %s"
,
out_rtmp_url
);
...
...
trunk/research/librtmp/srs_ingest_rtmp.c
查看文件 @
f492175
...
...
@@ -45,6 +45,10 @@ int main(int argc, char** argv)
// rtmp handler
srs_rtmp_t
irtmp
,
ortmp
;
printf
(
"ingest RTMP and publish to RTMP server like edge.
\n
"
);
printf
(
"srs(simple-rtmp-server) client librtmp library.
\n
"
);
printf
(
"version: %d.%d.%d
\n
"
,
srs_version_major
(),
srs_version_minor
(),
srs_version_revision
());
if
(
argc
<=
2
)
{
printf
(
"ingest RTMP and publish to RTMP server
\n
"
"Usage: %s <-i in_rtmp_url> <-y out_rtmp_url>
\n
"
...
...
@@ -53,9 +57,7 @@ int main(int argc, char** argv)
"For example:
\n
"
" %s -i rtmp://127.0.0.1/live/livestream -y rtmp://127.0.0.1/live/demo
\n
"
,
argv
[
0
],
argv
[
0
]);
ret
=
1
;
exit
(
ret
);
return
ret
;
exit
(
-
1
);
}
// parse options in FFMPEG format.
...
...
@@ -72,9 +74,6 @@ int main(int argc, char** argv)
}
}
srs_trace
(
"ingest RTMP and publish to RTMP server like edge."
);
srs_trace
(
"srs(simple-rtmp-server) client librtmp library."
);
srs_trace
(
"version: %d.%d.%d"
,
srs_version_major
(),
srs_version_minor
(),
srs_version_revision
());
srs_trace
(
"input: %s"
,
in_rtmp_url
);
srs_trace
(
"output: %s"
,
out_rtmp_url
);
...
...
trunk/research/librtmp/srs_play.c
查看文件 @
f492175
...
...
@@ -31,31 +31,21 @@ gcc srs_play.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_play
int
main
(
int
argc
,
char
**
argv
)
{
srs_rtmp_t
rtmp
;
// packet data
int
type
,
size
;
u_int32_t
timestamp
=
0
;
char
*
data
;
printf
(
"suck rtmp stream like rtmpdump
\n
"
);
printf
(
"srs(simple-rtmp-server) client librtmp library.
\n
"
);
printf
(
"version: %d.%d.%d
\n
"
,
srs_version_major
(),
srs_version_minor
(),
srs_version_revision
());
if
(
argc
<=
1
)
{
printf
(
"play stream on RTMP server
\n
"
"Usage: %s <rtmp_url>
\n
"
printf
(
"Usage: %s <rtmp_url>
\n
"
" rtmp_url RTMP stream url to play
\n
"
"For example:
\n
"
" %s rtmp://127.0.0.1:1935/live/livestream
\n
"
,
argv
[
0
],
argv
[
0
]);
int
ret
=
1
;
exit
(
ret
);
return
ret
;
exit
(
-
1
);
}
rtmp
=
srs_rtmp_create
(
argv
[
1
]);
srs_trace
(
"suck rtmp stream like rtmpdump"
);
srs_trace
(
"srs(simple-rtmp-server) client librtmp library."
);
srs_trace
(
"version: %d.%d.%d"
,
srs_version_major
(),
srs_version_minor
(),
srs_version_revision
());
srs_trace
(
"rtmp url: %s"
,
argv
[
1
]);
srs_rtmp_t
rtmp
=
srs_rtmp_create
(
argv
[
1
]);
if
(
srs_simple_handshake
(
rtmp
)
!=
0
)
{
srs_trace
(
"simple handshake failed."
);
...
...
@@ -76,6 +66,10 @@ int main(int argc, char** argv)
srs_trace
(
"play stream success"
);
for
(;;)
{
int
type
,
size
;
u_int32_t
timestamp
=
0
;
char
*
data
;
if
(
srs_read_packet
(
rtmp
,
&
type
,
&
timestamp
,
&
data
,
&
size
)
!=
0
)
{
goto
rtmp_destroy
;
}
...
...
trunk/research/librtmp/srs_publish.c
查看文件 @
f492175
...
...
@@ -32,54 +32,60 @@ gcc srs_publish.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_publish
int
main
(
int
argc
,
char
**
argv
)
{
srs_rtmp_t
rtmp
;
// packet data
int
type
,
size
;
u_int32_t
timestamp
=
0
;
char
*
data
;
printf
(
"publish rtmp stream to server like FMLE/FFMPEG/Encoder
\n
"
);
printf
(
"srs(simple-rtmp-server) client librtmp library.
\n
"
);
printf
(
"version: %d.%d.%d
\n
"
,
srs_version_major
(),
srs_version_minor
(),
srs_version_revision
());
if
(
argc
<=
1
)
{
printf
(
"Usage: %s <rtmp_url>
\n
"
" rtmp_url RTMP stream url to publish
\n
"
"For example:
\n
"
" %s rtmp://127.0.0.1:1935/live/livestream
\n
"
,
argv
[
0
],
argv
[
0
]);
exit
(
-
1
);
}
// warn it .
// @see: https://github.com/winlinvip/simple-rtmp-server/issues/126
printf
(
"
\033
[33m%s
\033
[0m"
,
srs_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."
);
printf
(
"
\n
"
);
rtmp
=
srs_rtmp_create
(
"rtmp://127.0.0.1:1935/live/livestream"
);
"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_trace
(
"rtmp url: %s"
,
argv
[
1
]);
srs_rtmp_t
rtmp
=
srs_rtmp_create
(
argv
[
1
]);
if
(
srs_simple_handshake
(
rtmp
)
!=
0
)
{
printf
(
"simple handshake failed.
\n
"
);
srs_trace
(
"simple handshake failed.
"
);
goto
rtmp_destroy
;
}
printf
(
"simple handshake success
\n
"
);
srs_trace
(
"simple handshake success
"
);
if
(
srs_connect_app
(
rtmp
)
!=
0
)
{
printf
(
"connect vhost/app failed.
\n
"
);
srs_trace
(
"connect vhost/app failed.
"
);
goto
rtmp_destroy
;
}
printf
(
"connect vhost/app success
\n
"
);
srs_trace
(
"connect vhost/app success
"
);
if
(
srs_publish_stream
(
rtmp
)
!=
0
)
{
printf
(
"publish stream failed.
\n
"
);
srs_trace
(
"publish stream failed.
"
);
goto
rtmp_destroy
;
}
printf
(
"publish stream success
\n
"
);
srs_trace
(
"publish stream success
"
);
u_int32_t
timestamp
=
0
;
for
(;;)
{
type
=
SRS_RTMP_TYPE_VIDEO
;
int
type
=
SRS_RTMP_TYPE_VIDEO
;
int
size
=
4096
;
char
*
data
=
(
char
*
)
malloc
(
4096
);
timestamp
+=
40
;
size
=
4096
;
data
=
(
char
*
)
malloc
(
4096
);
if
(
srs_write_packet
(
rtmp
,
type
,
timestamp
,
data
,
size
)
!=
0
)
{
goto
rtmp_destroy
;
}
printf
(
"sent packet: type=%s, time=%d, size=%d
\n
"
,
srs_type2string
(
type
),
timestamp
,
size
);
srs_trace
(
"sent packet: type=%s, time=%d, size=%d"
,
srs_type2string
(
type
),
timestamp
,
size
);
usleep
(
40
*
1000
);
}
...
...
trunk/src/libs/srs_librtmp.hpp
查看文件 @
f492175
...
...
@@ -237,8 +237,8 @@ extern int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp);
// log to console, for use srs-librtmp application.
extern
const
char
*
srs_format_time
();
#define srs_trace(msg, ...) printf("[%s]", srs_format_time());printf(msg, ##__VA_ARGS__);printf("\n")
#define srs_verbose(msg, ...) printf("[%s]", srs_format_time());printf(msg, ##__VA_ARGS__);printf("\n")
#define srs_trace(msg, ...) printf("[%s] ", srs_format_time());printf(msg, ##__VA_ARGS__);printf("\n")
#define srs_verbose(msg, ...) printf("[%s] ", srs_format_time());printf(msg, ##__VA_ARGS__);printf("\n")
/*************************************************************
**************************************************************
...
...
请
注册
或
登录
后发表评论