diff --git a/README.md b/README.md index c674ad2b8..c6285d058 100755 --- a/README.md +++ b/README.md @@ -485,6 +485,7 @@ Supported operating systems and hardware: * 2013-10-17, Created.
## History +* v2.0, 2014-11-28, fix [#215](https://github.com/winlinvip/simple-rtmp-server/issues/215), for bug #215, add srs_rtmp_dump tool. 2.0.37. * v2.0, 2014-11-25, update PRIMARY, AUTHORS, CONTRIBUTORS rule. 2.0.32. * v2.0, 2014-11-24, fix [#212](https://github.com/winlinvip/simple-rtmp-server/issues/212), support publish aac adts raw stream. 2.0.31. * v2.0, 2014-11-22, fix [#217](https://github.com/winlinvip/simple-rtmp-server/issues/217), remove timeout recv, support 7.5k+ 250kbps clients. 2.0.30. diff --git a/trunk/research/librtmp/Makefile b/trunk/research/librtmp/Makefile index f8e9db4f9..d9a470997 100755 --- a/trunk/research/librtmp/Makefile +++ b/trunk/research/librtmp/Makefile @@ -7,7 +7,8 @@ else objs/srs_flv_injecter objs/srs_publish objs/srs_play \ objs/srs_ingest_flv objs/srs_ingest_rtmp objs/srs_detect_rtmp \ objs/srs_bandwidth_check objs/srs_h264_raw_publish \ - objs/srs_audio_raw_publish objs/srs_aac_raw_publish + objs/srs_audio_raw_publish objs/srs_aac_raw_publish \ + objs/srs_rtmp_dump endif .PHONY: default clean help ssl nossl @@ -32,6 +33,7 @@ help: @echo " srs_ingest_rtmp ingest RTMP and publish to RTMP server." @echo " srs_detect_rtmp detect RTMP stream info." @echo " srs_bandwidth_check bandwidth check/test tool." + @echo " srs_rtmp_dump dump rtmp stream to flv file." @echo "Remark: about simple/complex handshake, see: http://blog.csdn.net/win_lin/article/details/13006803" @echo "Remark: srs Makefile will auto invoke this by --with/without-ssl, " @echo " that is, if user specified ssl(by --with-ssl), srs will make this by 'make ssl'" @@ -108,3 +110,6 @@ objs/srs_detect_rtmp: srs_detect_rtmp.c $(SRS_RESEARCH_DEPS) $(SRS_LIBRTMP_I) $( objs/srs_bandwidth_check: srs_bandwidth_check.c $(SRS_RESEARCH_DEPS) $(SRS_LIBRTMP_I) $(SRS_LIBRTMP_L) $(SRS_LIBSSL_L) $(GCC) srs_bandwidth_check.c $(SRS_LIBRTMP_L) $(SRS_LIBSSL_L) $(EXTRA_CXX_FLAG) -o objs/srs_bandwidth_check + +objs/srs_rtmp_dump: srs_rtmp_dump.c $(SRS_RESEARCH_DEPS) $(SRS_LIBRTMP_I) $(SRS_LIBRTMP_L) $(SRS_LIBSSL_L) + $(GCC) srs_rtmp_dump.c $(SRS_LIBRTMP_L) $(SRS_LIBSSL_L) $(EXTRA_CXX_FLAG) -o objs/srs_rtmp_dump diff --git a/trunk/research/librtmp/srs_rtmp_dump.c b/trunk/research/librtmp/srs_rtmp_dump.c new file mode 100644 index 000000000..00f8d1fd6 --- /dev/null +++ b/trunk/research/librtmp/srs_rtmp_dump.c @@ -0,0 +1,122 @@ +/* +The MIT License (MIT) + +Copyright (c) 2013-2014 winlin + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +/** +gcc srs_rtmp_dump.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_rtmp_dump +*/ + +#include +#include + +#include "../../objs/include/srs_librtmp.h" + +int main(int argc, char** argv) +{ + printf("dump rtmp stream to flv file\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("Usage: %s \n" + " rtmp_url RTMP stream url to play\n" + " flv_path The flv file path to save\n" + "For example:\n" + " %s rtmp://127.0.0.1:1935/live/livestream output.flv\n", + argv[0], argv[0]); + exit(-1); + } + + srs_human_trace("rtmp url: %s", argv[1]); + srs_human_trace("flv path: %s", argv[2]); + srs_rtmp_t rtmp = srs_rtmp_create(argv[1]); + + if (srs_rtmp_handshake(rtmp) != 0) { + srs_human_trace("simple handshake failed."); + goto rtmp_destroy; + } + srs_human_trace("simple handshake success"); + + if (srs_rtmp_connect_app(rtmp) != 0) { + srs_human_trace("connect vhost/app failed."); + goto rtmp_destroy; + } + srs_human_trace("connect vhost/app success"); + + if (srs_rtmp_play_stream(rtmp) != 0) { + srs_human_trace("play stream failed."); + goto rtmp_destroy; + } + srs_human_trace("play stream success"); + + srs_flv_t flv = srs_flv_open_write(argv[2]); + + // flv header + char header[9]; + // 3bytes, signature, "FLV", + header[0] = 'F'; + header[1] = 'L'; + header[2] = 'V'; + // 1bytes, version, 0x01, + header[3] = 0x01; + // 1bytes, flags, UB[5] 0, UB[1] audio present, UB[1] 0, UB[1] video present. + header[4] = 0x03; // audio + video. + // 4bytes, dataoffset + header[5] = 0x00; + header[6] = 0x00; + header[7] = 0x00; + header[8] = 0x09; + if (srs_flv_write_header(flv, header) != 0) { + srs_human_trace("write flv header failed."); + goto rtmp_destroy; + } + + for (;;) { + int size; + char type; + char* data; + u_int32_t timestamp; + + if (srs_rtmp_read_packet(rtmp, &type, ×tamp, &data, &size) != 0) { + srs_human_trace("read rtmp packet failed."); + goto rtmp_destroy; + } + + if (srs_human_print_rtmp_packet(type, timestamp, data, size) != 0) { + srs_human_trace("print rtmp packet failed."); + goto rtmp_destroy; + } + + if (srs_flv_write_tag(flv, type, timestamp, data, size) != 0) { + srs_human_trace("dump rtmp packet failed."); + goto rtmp_destroy; + } + + free(data); + } + +rtmp_destroy: + srs_rtmp_destroy(rtmp); + srs_flv_close(flv); + srs_human_trace("completed"); + + return 0; +} diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 94d5287cd..e7333f98e 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR 2 #define VERSION_MINOR 0 -#define VERSION_REVISION 36 +#define VERSION_REVISION 37 // server info. #define RTMP_SIG_SRS_KEY "SRS" #define RTMP_SIG_SRS_ROLE "origin/edge server" diff --git a/trunk/src/srs/srs.upp b/trunk/src/srs/srs.upp index 94f0fd339..8e3d6ff11 100755 --- a/trunk/src/srs/srs.upp +++ b/trunk/src/srs/srs.upp @@ -141,6 +141,7 @@ file ..\..\research\librtmp\srs_ingest_rtmp.c, ..\..\research\librtmp\srs_play.c, ..\..\research\librtmp\srs_publish.c, + ..\..\research\librtmp\srs_rtmp_dump.c, ..\..\research\hls\ts_info.cc; mainconfig