From 431f852e05c9dae1b2debb9af352437e667ecba5 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 13 May 2020 15:23:43 +0800 Subject: [PATCH] RTC: Remove dead code --- trunk/configure | 2 +- trunk/src/app/srs_app_rtc.cpp | 204 --------------------------- trunk/src/app/srs_app_rtc.hpp | 86 ----------- trunk/src/app/srs_app_rtc_source.cpp | 20 --- trunk/src/app/srs_app_rtc_source.hpp | 2 - 5 files changed, 1 insertion(+), 313 deletions(-) delete mode 100644 trunk/src/app/srs_app_rtc.cpp delete mode 100644 trunk/src/app/srs_app_rtc.hpp diff --git a/trunk/configure b/trunk/configure index 648911fb1..210107426 100755 --- a/trunk/configure +++ b/trunk/configure @@ -279,7 +279,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then "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" "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_codec" "srs_app_rtc_sdp" "srs_app_rtc_queue" "srs_app_rtc_server" "srs_app_rtc_source") fi if [[ $SRS_GB28181 == YES ]]; then diff --git a/trunk/src/app/srs_app_rtc.cpp b/trunk/src/app/srs_app_rtc.cpp deleted file mode 100644 index 253129edc..000000000 --- a/trunk/src/app/srs_app_rtc.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2013-2020 John - * - * 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. - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// TODO: Add this function into SrsRtpMux class. -extern srs_error_t aac_raw_append_adts_header(SrsSharedPtrMessage* shared_audio, SrsFormat* format, char** pbuf, int* pnn_buf); - -SrsRtpH264Muxer::SrsRtpH264Muxer() -{ - discard_bframe = false; -} - -SrsRtpH264Muxer::~SrsRtpH264Muxer() -{ -} - -srs_error_t SrsRtpH264Muxer::filter(SrsSharedPtrMessage* shared_frame, SrsFormat* format) -{ - srs_error_t err = srs_success; - - // If IDR, we will insert SPS/PPS before IDR frame. - if (format->video && format->video->has_idr) { - shared_frame->set_has_idr(true); - } - - // Update samples to shared frame. - for (int i = 0; i < format->video->nb_samples; ++i) { - SrsSample* sample = &format->video->samples[i]; - - // Because RTC does not support B-frame, so we will drop them. - // TODO: Drop B-frame in better way, which not cause picture corruption. - if (discard_bframe) { - if ((err = sample->parse_bframe()) != srs_success) { - return srs_error_wrap(err, "parse bframe"); - } - if (sample->bframe) { - continue; - } - } - } - - if (format->video->nb_samples <= 0) { - return err; - } - - shared_frame->set_samples(format->video->samples, format->video->nb_samples); - - return err; -} - -SrsRtc::SrsRtc() -{ - req = NULL; - - enabled = false; - disposable = false; - last_update_time = 0; - - discard_aac = false; -} - -SrsRtc::~SrsRtc() -{ - srs_freep(rtp_h264_muxer); -} - -void SrsRtc::dispose() -{ - if (enabled) { - on_unpublish(); - } -} - -// TODO: FIXME: Dead code? -srs_error_t SrsRtc::cycle() -{ - srs_error_t err = srs_success; - - return err; -} - -srs_error_t SrsRtc::initialize(SrsRequest* r) -{ - srs_error_t err = srs_success; - - req = r; - - rtp_h264_muxer = new SrsRtpH264Muxer(); - rtp_h264_muxer->discard_bframe = _srs_config->get_rtc_bframe_discard(req->vhost); - // TODO: FIXME: Support reload and log it. - discard_aac = _srs_config->get_rtc_aac_discard(req->vhost); - - return err; -} - -srs_error_t SrsRtc::on_publish() -{ - srs_error_t err = srs_success; - - // update the hls time, for hls_dispose. - last_update_time = srs_get_system_time(); - - // support multiple publish. - if (enabled) { - return err; - } - - if (!_srs_config->get_rtc_enabled(req->vhost)) { - return err; - } - - // if enabled, open the muxer. - enabled = true; - - // ok, the hls can be dispose, or need to be dispose. - disposable = true; - - return err; -} - -void SrsRtc::on_unpublish() -{ - // support multiple unpublish. - if (!enabled) { - return; - } - - enabled = false; -} - -srs_error_t SrsRtc::on_video(SrsSharedPtrMessage* shared_video, SrsFormat* format) -{ - srs_error_t err = srs_success; - - // TODO: FIXME: Maybe it should config on vhost level. - if (!enabled) { - return err; - } - - // Ignore if no format->vcodec, it means the codec is not parsed, or unknown codec. - // @issue https://github.com/ossrs/srs/issues/1506#issuecomment-562079474 - if (!format->vcodec) { - return err; - } - - // update the hls time, for hls_dispose. - last_update_time = srs_get_system_time(); - - // ignore info frame, - // @see https://github.com/ossrs/srs/issues/288#issuecomment-69863909 - srs_assert(format->video); - return rtp_h264_muxer->filter(shared_video, format); -} diff --git a/trunk/src/app/srs_app_rtc.hpp b/trunk/src/app/srs_app_rtc.hpp deleted file mode 100644 index c5c6a01b0..000000000 --- a/trunk/src/app/srs_app_rtc.hpp +++ /dev/null @@ -1,86 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (c) 2013-2020 John - * - * 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. - */ - -#ifndef SRS_APP_RTC_HPP -#define SRS_APP_RTC_HPP - -#include - -#include -#include -#include - -class SrsFormat; -class SrsSample; -class SrsSharedPtrMessage; -class SrsRequest; -class SrsOriginHub; -class SrsAudioRecode; -class SrsBuffer; - -// The RTP packet max size, should never exceed this size. -const int kRtpPacketSize = 1500; - -// Payload type will rewrite in srs_app_rtc_conn.cpp when send to client. -const uint8_t kOpusPayloadType = 111; -const uint8_t kH264PayloadType = 102; - -// SSRC will rewrite in srs_app_rtc_conn.cpp when send to client. -const uint32_t kAudioSSRC = 1; -const uint32_t kVideoSSRC = 2; - -// TODO: Define interface class like ISrsRtpMuxer -class SrsRtpH264Muxer -{ -public: - bool discard_bframe; -public: - SrsRtpH264Muxer(); - virtual ~SrsRtpH264Muxer(); -public: - srs_error_t filter(SrsSharedPtrMessage* shared_video, SrsFormat* format); -}; - -class SrsRtc -{ -private: - SrsRequest* req; - bool enabled; - bool disposable; - bool discard_aac; - srs_utime_t last_update_time; - SrsRtpH264Muxer* rtp_h264_muxer; -public: - SrsRtc(); - virtual ~SrsRtc(); -public: - virtual void dispose(); - virtual srs_error_t cycle(); -public: - virtual srs_error_t initialize(SrsRequest* r); - virtual srs_error_t on_publish(); - virtual void on_unpublish(); - virtual srs_error_t on_video(SrsSharedPtrMessage* shared_video, SrsFormat* format); -}; - -#endif diff --git a/trunk/src/app/srs_app_rtc_source.cpp b/trunk/src/app/srs_app_rtc_source.cpp index a6614e319..f98d48d2d 100644 --- a/trunk/src/app/srs_app_rtc_source.cpp +++ b/trunk/src/app/srs_app_rtc_source.cpp @@ -473,7 +473,6 @@ SrsRtcFromRtmpBridger::SrsRtcFromRtmpBridger(SrsRtcSource* source) source_ = source; meta = new SrsMetaCache(); format = new SrsRtmpFormat(); - rtc = new SrsRtc(); codec = new SrsAudioRecode(kChannel, kSamplerate); discard_aac = false; discard_bframe = false; @@ -483,7 +482,6 @@ SrsRtcFromRtmpBridger::~SrsRtcFromRtmpBridger() { srs_freep(meta); srs_freep(format); - srs_freep(rtc); srs_freep(codec); } @@ -497,10 +495,6 @@ srs_error_t SrsRtcFromRtmpBridger::initialize(SrsRequest* r) return srs_error_wrap(err, "format initialize"); } - if ((err = rtc->initialize(r)) != srs_success) { - return srs_error_wrap(err, "rtc initialize"); - } - if ((err = codec->initialize()) != srs_success) { return srs_error_wrap(err, "init codec"); } @@ -522,10 +516,6 @@ srs_error_t SrsRtcFromRtmpBridger::on_publish() { srs_error_t err = srs_success; - if ((err = rtc->on_publish()) != srs_success) { - return srs_error_wrap(err, "rtc publish"); - } - // TODO: FIXME: Should sync with bridger? if ((err = source_->on_publish()) != srs_success) { return srs_error_wrap(err, "source publish"); @@ -543,8 +533,6 @@ void SrsRtcFromRtmpBridger::on_unpublish() // TODO: FIXME: Should sync with bridger? source_->on_unpublish(); - rtc->on_unpublish(); - // Reset the metadata cache, to make VLC happy when disable/enable stream. // @see https://github.com/ossrs/srs/issues/1630#issuecomment-597979448 meta->update_previous_vsh(); @@ -667,14 +655,6 @@ srs_error_t SrsRtcFromRtmpBridger::on_video(SrsSharedPtrMessage* msg) return srs_error_wrap(err, "format consume video"); } - // Parse RTMP message to RTP packets, in FU-A if too large. - if ((err = rtc->on_video(msg, format)) != srs_success) { - // TODO: We should support more strategies. - srs_warn("rtc: ignore video error %s", srs_error_desc(err).c_str()); - srs_error_reset(err); - rtc->on_unpublish(); - } - return source_->on_video_imp(msg); } diff --git a/trunk/src/app/srs_app_rtc_source.hpp b/trunk/src/app/srs_app_rtc_source.hpp index 7a61ae469..f55764f90 100644 --- a/trunk/src/app/srs_app_rtc_source.hpp +++ b/trunk/src/app/srs_app_rtc_source.hpp @@ -180,8 +180,6 @@ private: bool discard_aac; SrsAudioRecode* codec; bool discard_bframe; - // rtc handler - SrsRtc* rtc; public: SrsRtcFromRtmpBridger(SrsRtcSource* source); virtual ~SrsRtcFromRtmpBridger();