diff --git a/trunk/auto/auto_headers.sh b/trunk/auto/auto_headers.sh index fd4bf322d..60c00db9a 100755 --- a/trunk/auto/auto_headers.sh +++ b/trunk/auto/auto_headers.sh @@ -87,6 +87,12 @@ else srs_undefine_macro "SRS_RTC" $SRS_AUTO_HEADERS_H fi +if [ $SRS_FFMPEG_FIT = YES ]; then + srs_define_macro "SRS_FFMPEG_FIT" $SRS_AUTO_HEADERS_H +else + srs_undefine_macro "SRS_FFMPEG_FIT" $SRS_AUTO_HEADERS_H +fi + if [ $SRS_SIMULATOR = YES ]; then srs_define_macro "SRS_SIMULATOR" $SRS_AUTO_HEADERS_H else diff --git a/trunk/auto/depends.sh b/trunk/auto/depends.sh index b0863bdab..406349885 100755 --- a/trunk/auto/depends.sh +++ b/trunk/auto/depends.sh @@ -595,7 +595,7 @@ fi ##################################################################################### # ffmpeg-fix, for WebRTC to transcode AAC with Opus. ##################################################################################### -if [[ $SRS_RTC == YES ]]; then +if [[ $SRS_FFMPEG_FIT == YES ]]; then FFMPEG_OPTIONS="" # If disable nasm, disable all ASMs. diff --git a/trunk/auto/options.sh b/trunk/auto/options.sh index 58cb2af27..f0b9e56c0 100755 --- a/trunk/auto/options.sh +++ b/trunk/auto/options.sh @@ -22,7 +22,6 @@ SRS_GB28181=NO SRS_CXX11=NO SRS_CXX14=NO SRS_NGINX=NO -SRS_FFMPEG_TOOL=NO SRS_LIBRTMP=NO SRS_RESEARCH=NO SRS_UTEST=NO @@ -46,8 +45,12 @@ SRS_HLS=YES SRS_DVR=YES # ################################################################ -# libraries +# FFmpeg stub is the stub code in SRS for ingester or encoder. SRS_FFMPEG_STUB=NO +# FFmpeg tool is the binary for FFmpeg tool, to exec ingest or transcode. +SRS_FFMPEG_TOOL=NO +# FFmpeg fit is the source code for RTC, to transcode audio or video in SRS. +SRS_FFMPEG_FIT=RESERVED # arguments SRS_PREFIX=/usr/local/srs SRS_JOBS=1 @@ -153,6 +156,7 @@ Features: --gb28181=on|off Whether build the GB28181 support for SRS. --cxx11=on|off Whether enable the C++11 support for SRS. --cxx14=on|off Whether enable the C++14 support for SRS. + --ffmpeg-fit=on|off Whether enable the FFmpeg fit(source code) for SRS. --prefix= The absolute installation path for srs. Default: $SRS_PREFIX --gcov=on|off Whether enable the GCOV compiler options. @@ -282,7 +286,7 @@ function parse_user_option() { --with-ffmpeg) SRS_FFMPEG_TOOL=YES ;; --without-ffmpeg) SRS_FFMPEG_TOOL=NO ;; - --ffmpeg) if [[ $value == off ]]; then SRS_FFMPEG_TOOL=NO; else SRS_FFMPEG_TOOL=YES; fi ;; + --ffmpeg-tool) if [[ $value == off ]]; then SRS_FFMPEG_TOOL=NO; else SRS_FFMPEG_TOOL=YES; fi ;; --with-transcode) SRS_TRANSCODE=YES ;; --without-transcode) echo "ignore option \"$option\"" ;; @@ -327,6 +331,7 @@ function parse_user_option() { --cxx11) if [[ $value == off ]]; then SRS_CXX11=NO; else SRS_CXX11=YES; fi ;; --cxx14) if [[ $value == off ]]; then SRS_CXX14=NO; else SRS_CXX14=YES; fi ;; + --ffmpeg-fit) if [[ $value == off ]]; then SRS_FFMPEG_FIT=NO; else SRS_FFMPEG_FIT=YES; fi ;; --with-clean) SRS_CLEAN=YES ;; --without-clean) SRS_CLEAN=NO ;; @@ -526,6 +531,11 @@ function apply_user_presets() { if [[ $SRS_SRT == YES ]]; then SRS_CXX11=YES fi + + # Enable FFmpeg fit for RTC to trancode audio from AAC to OPUS, if user has't disabled it. + if [[ $SRS_RTC == YES && $SRS_FFMPEG_FIT == RESERVED ]]; then + SRS_FFMPEG_FIT=YES + fi } apply_user_presets @@ -625,8 +635,9 @@ function regenerate_options() { if [ $SRS_RTC = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --rtc=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --rtc=off"; fi if [ $SRS_SIMULATOR = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --simulator=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --simulator=off"; fi if [ $SRS_GB28181 = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --gb28181=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --gb28181=off"; fi - if [ $SRS_CXX11 = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cxx11=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cxx11=off"; fi - if [ $SRS_CXX14 = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cxx14=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cxx14=off"; fi + if [ $SRS_CXX11 = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cxx11=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cxx11=off"; fi + if [ $SRS_CXX14 = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cxx14=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cxx14=off"; fi + if [ $SRS_FFMPEG_FIT = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --ffmpeg-fit=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --ffmpeg-fit=off"; fi if [ $SRS_NASM = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --nasm=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --nasm=off"; fi if [ $SRS_SRTP_ASM = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --srtp-nasm=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --srtp-nasm=off"; fi if [ $SRS_SENDMMSG = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --sendmmsg=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --sendmmsg=off"; fi diff --git a/trunk/configure b/trunk/configure index a66a8cdf7..95e9cb874 100755 --- a/trunk/configure +++ b/trunk/configure @@ -141,7 +141,7 @@ if [[ $SRS_RTC == YES ]]; then LibSrtpRoot="${SRS_OBJS_DIR}/srtp2/include"; LibSrtpFile="${SRS_OBJS_DIR}/srtp2/lib/libsrtp2.a" fi # FFMPEG for WebRTC transcoding, such as aac to opus. -if [[ $SRS_RTC == YES ]]; then +if [[ $SRS_FFMPEG_FIT == YES ]]; then LibFfmpegRoot="${SRS_OBJS_DIR}/ffmpeg/include"; LibFfmpegFile="${SRS_OBJS_DIR}/ffmpeg/lib/libavcodec.a ${SRS_OBJS_DIR}/ffmpeg/lib/libswresample.a ${SRS_OBJS_DIR}/ffmpeg/lib/libavutil.a" LibFfmpegRoot="${LibFfmpegRoot} ${SRS_OBJS_DIR}/opus/include"; LibFfmpegFile="${LibFfmpegFile} ${SRS_OBJS_DIR}/opus/lib/libopus.a" fi @@ -222,7 +222,10 @@ MODULE_FILES=("srs_protocol_amf0" "srs_protocol_io" "srs_rtmp_stack" "srs_service_rtmp_conn" "srs_service_utility" "srs_service_conn") if [[ $SRS_RTC == YES ]]; then MODULE_FILES+=("srs_rtc_stun_stack") - ModuleLibIncs+=("${LibFfmpegRoot[*]}" ${LibSrtpRoot}) + ModuleLibIncs+=(${LibSrtpRoot}) +fi +if [[ $SRS_FFMPEG_FIT == YES ]]; then + ModuleLibIncs+=("${LibFfmpegRoot[*]}") fi PROTOCOL_INCS="src/protocol"; MODULE_DIR=${PROTOCOL_INCS} . auto/modules.sh PROTOCOL_OBJS="${MODULE_OBJS[@]}" @@ -246,7 +249,10 @@ if [ $SRS_GPERF = YES ]; then ModuleLibIncs+=(${LibGperfRoot}) fi if [[ $SRS_RTC == YES ]]; then - ModuleLibIncs+=("${LibFfmpegRoot[*]}" ${LibSrtpRoot}) + ModuleLibIncs+=(${LibSrtpRoot}) +fi +if [[ $SRS_FFMPEG_FIT == YES ]]; then + ModuleLibIncs+=("${LibFfmpegRoot[*]}") fi MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_rtmp_conn" "srs_app_source" "srs_app_refer" "srs_app_hls" "srs_app_forward" "srs_app_encoder" "srs_app_http_stream" @@ -260,9 +266,12 @@ MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_rtmp_conn" "srs_app_sourc "srs_app_hourglass" "srs_app_dash" "srs_app_fragment" "srs_app_dvr" "srs_app_coworkers" "srs_app_hybrid") if [[ $SRS_RTC == YES ]]; then - MODULE_FILES+=("srs_app_rtc_conn" "srs_app_rtc_dtls" "srs_app_rtc_codec" "srs_app_rtc_sdp" + MODULE_FILES+=("srs_app_rtc_conn" "srs_app_rtc_dtls" "srs_app_rtc_sdp" "srs_app_rtc_queue" "srs_app_rtc_server" "srs_app_rtc_source" "srs_app_rtc_api") fi +if [[ $SRS_FFMPEG_FIT == YES ]]; then + MODULE_FILES+=("srs_app_rtc_codec") +fi if [[ $SRS_GB28181 == YES ]]; then MODULE_FILES+=("srs_app_gb28181" "srs_app_gb28181_sip" "srs_app_gb28181_jitbuffer") fi @@ -284,7 +293,10 @@ if [[ $SRS_SRT == YES ]]; then fi ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSTRoot} ${LibGperfRoot} ${LibSSLRoot}) if [[ $SRS_RTC == YES ]]; then - ModuleLibIncs+=("${LibFfmpegRoot[*]}" ${LibSrtpRoot}) + ModuleLibIncs+=(${LibSrtpRoot}) +fi +if [[ $SRS_FFMPEG_FIT == YES ]]; then + ModuleLibIncs+=("${LibFfmpegRoot[*]}") fi if [[ $SRS_SRT == YES ]]; then ModuleLibIncs+=("${LibSRTRoot[*]}") @@ -298,7 +310,10 @@ MODULE_ID="MAIN" MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL") ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSTRoot} ${LibGperfRoot} ${LibSSLRoot}) if [[ $SRS_RTC == YES ]]; then - ModuleLibIncs+=("${LibFfmpegRoot[*]}" ${LibSrtpRoot}) + ModuleLibIncs+=(${LibSrtpRoot}) +fi +if [[ $SRS_FFMPEG_FIT == YES ]]; then + ModuleLibIncs+=("${LibFfmpegRoot[*]}") fi MODULE_FILES=() DEFINES="" @@ -325,7 +340,10 @@ done # all depends libraries ModuleLibFiles=(${LibSTfile} ${LibSSLfile} ${LibGperfFile}) if [[ $SRS_RTC == YES ]]; then - ModuleLibFiles+=("${LibFfmpegFile[*]}" ${LibSrtpFile}) + ModuleLibFiles+=(${LibSrtpFile}) +fi +if [[ $SRS_FFMPEG_FIT == YES ]]; then + ModuleLibFiles+=("${LibFfmpegFile[*]}") fi if [[ $SRS_SRT == YES ]]; then ModuleLibFiles+=("${LibSRTfile[*]}") @@ -334,7 +352,10 @@ fi MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${APP_OBJS[@]} ${SERVER_OBJS[@]}" ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSTRoot} ${LibGperfRoot} ${LibSSLRoot}) if [[ $SRS_RTC == YES ]]; then - ModuleLibIncs+=("${LibFfmpegRoot[*]}" ${LibSrtpRoot}) + ModuleLibIncs+=(${LibSrtpRoot}) +fi +if [[ $SRS_FFMPEG_FIT == YES ]]; then + ModuleLibIncs+=("${LibFfmpegRoot[*]}") fi if [[ $SRS_SRT == YES ]]; then MODULE_OBJS="${MODULE_OBJS} ${SRT_OBJS[@]}" @@ -348,7 +369,10 @@ BUILD_KEY="srs" APP_MAIN="srs_main_server" APP_NAME="srs" . auto/apps.sh MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${MAIN_OBJS[@]}" ModuleLibFiles=(${LibSTfile} ${LibSSLfile} ${LibGperfFile}) if [[ $SRS_RTC == YES ]]; then - ModuleLibFiles+=("${LibFfmpegFile[*]}" ${LibSrtpFile}) + ModuleLibFiles+=(${LibSrtpFile}) +fi +if [[ $SRS_FFMPEG_FIT == YES ]]; then + ModuleLibFiles+=("${LibFfmpegFile[*]}") fi # for SRS_MODULE in ${SRS_MODULES[*]}; do @@ -370,14 +394,20 @@ if [ $SRS_UTEST = YES ]; then "srs_utest_mp4" "srs_utest_service" "srs_utest_app" "srs_utest_rtc") ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSTRoot} ${LibSSLRoot}) if [[ $SRS_RTC == YES ]]; then - ModuleLibIncs+=("${LibFfmpegRoot[*]}" ${LibSrtpRoot}) + ModuleLibIncs+=(${LibSrtpRoot}) + fi + if [[ $SRS_FFMPEG_FIT == YES ]]; then + ModuleLibIncs+=("${LibFfmpegRoot[*]}") fi if [[ $SRS_SRT == YES ]]; then ModuleLibIncs+=("${LibSRTRoot[*]}") fi ModuleLibFiles=(${LibSTfile} ${LibSSLfile}) if [[ $SRS_RTC == YES ]]; then - ModuleLibFiles+=("${LibFfmpegFile[*]}" ${LibSrtpFile}) + ModuleLibFiles+=(${LibSrtpFile}) + fi + if [[ $SRS_FFMPEG_FIT == YES ]]; then + ModuleLibFiles+=("${LibFfmpegFile[*]}") fi if [[ $SRS_SRT == YES ]]; then ModuleLibFiles+=("${LibSRTfile[*]}") diff --git a/trunk/src/app/srs_app_rtc_source.cpp b/trunk/src/app/srs_app_rtc_source.cpp index b41d6cb48..e0acd57e1 100644 --- a/trunk/src/app/srs_app_rtc_source.cpp +++ b/trunk/src/app/srs_app_rtc_source.cpp @@ -247,7 +247,11 @@ SrsRtcSource::SrsRtcSource() rtc_publisher_ = NULL; req = NULL; +#ifdef SRS_FFMPEG_FIT bridger_ = new SrsRtcFromRtmpBridger(this); +#else + bridger_ = new SrsRtcDummyBridger(); +#endif } SrsRtcSource::~SrsRtcSource() @@ -266,9 +270,12 @@ srs_error_t SrsRtcSource::initialize(SrsRequest* r) req = r->copy(); - if ((err = bridger_->initialize(req)) != srs_success) { +#ifdef SRS_FFMPEG_FIT + SrsRtcFromRtmpBridger* bridger = dynamic_cast(bridger_); + if ((err = bridger->initialize(req)) != srs_success) { return srs_error_wrap(err, "bridge initialize"); } +#endif return err; } @@ -414,6 +421,7 @@ srs_error_t SrsRtcSource::on_rtp(SrsRtpPacket2* pkt) return err; } +#ifdef SRS_FFMPEG_FIT SrsRtcFromRtmpBridger::SrsRtcFromRtmpBridger(SrsRtcSource* source) { req = NULL; @@ -936,4 +944,32 @@ srs_error_t SrsRtcFromRtmpBridger::consume_packets(vector& pkts) return err; } +#endif + +SrsRtcDummyBridger::SrsRtcDummyBridger() +{ +} + +SrsRtcDummyBridger::~SrsRtcDummyBridger() +{ +} + +srs_error_t SrsRtcDummyBridger::on_publish() +{ + return srs_error_new(ERROR_RTC_DUMMY_BRIDGER, "no FFmpeg fit"); +} + +srs_error_t SrsRtcDummyBridger::on_audio(SrsSharedPtrMessage* /*audio*/) +{ + return srs_error_new(ERROR_RTC_DUMMY_BRIDGER, "no FFmpeg fit"); +} + +srs_error_t SrsRtcDummyBridger::on_video(SrsSharedPtrMessage* /*video*/) +{ + return srs_error_new(ERROR_RTC_DUMMY_BRIDGER, "no FFmpeg fit"); +} + +void SrsRtcDummyBridger::on_unpublish() +{ +} diff --git a/trunk/src/app/srs_app_rtc_source.hpp b/trunk/src/app/srs_app_rtc_source.hpp index 4f370f381..de4bc4daa 100644 --- a/trunk/src/app/srs_app_rtc_source.hpp +++ b/trunk/src/app/srs_app_rtc_source.hpp @@ -115,7 +115,7 @@ private: SrsRequest* req; ISrsRtcPublisher* rtc_publisher_; // Transmux RTMP to RTC. - SrsRtcFromRtmpBridger* bridger_; + ISrsSourceBridger* bridger_; private: // To delivery stream to clients. std::vector consumers; @@ -159,6 +159,7 @@ public: srs_error_t on_rtp(SrsRtpPacket2* pkt); }; +#ifdef SRS_FFMPEG_FIT class SrsRtcFromRtmpBridger : public ISrsSourceBridger { private: @@ -197,6 +198,19 @@ private: srs_error_t package_fu_a(SrsSharedPtrMessage* msg, SrsSample* sample, int fu_payload_size, std::vector& pkts); srs_error_t consume_packets(std::vector& pkts); }; +#endif + +class SrsRtcDummyBridger : public ISrsSourceBridger +{ +public: + SrsRtcDummyBridger(); + virtual ~SrsRtcDummyBridger(); +public: + virtual srs_error_t on_publish(); + virtual srs_error_t on_audio(SrsSharedPtrMessage* audio); + virtual srs_error_t on_video(SrsSharedPtrMessage* video); + virtual void on_unpublish(); +}; #endif diff --git a/trunk/src/kernel/srs_kernel_error.hpp b/trunk/src/kernel/srs_kernel_error.hpp index 9c6bdb17c..6275087ee 100644 --- a/trunk/src/kernel/srs_kernel_error.hpp +++ b/trunk/src/kernel/srs_kernel_error.hpp @@ -352,6 +352,7 @@ #define ERROR_RTC_DISABLED 5021 #define ERROR_RTC_NO_SESSION 5022 #define ERROR_RTC_INVALID_PARAMS 5023 +#define ERROR_RTC_DUMMY_BRIDGER 5024 /////////////////////////////////////////////////////// // GB28181 API error.