From 28350c0d057e444eaae2da380debadcf7626e9fb Mon Sep 17 00:00:00 2001 From: CharleyWangHZ <57120416+CharleyWangHZ@users.noreply.github.com> Date: Wed, 29 Jun 2022 11:01:16 +0800 Subject: [PATCH] Optimize Decoder inheritance relationship (#1760) --- src/Rtp/Decoder.cpp | 9 +++++++++ src/Rtp/Decoder.h | 8 ++++++-- src/Rtp/PSDecoder.cpp | 10 +--------- src/Rtp/PSDecoder.h | 4 ---- src/Rtp/TSDecoder.cpp | 8 -------- src/Rtp/TSDecoder.h | 4 ---- 6 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/Rtp/Decoder.cpp b/src/Rtp/Decoder.cpp index 596c59cf..02b6e98c 100644 --- a/src/Rtp/Decoder.cpp +++ b/src/Rtp/Decoder.cpp @@ -24,6 +24,15 @@ using namespace toolkit; namespace mediakit { + +void Decoder::setOnDecode(Decoder::onDecode cb) { + _on_decode = std::move(cb); +} + +void Decoder::setOnStream(Decoder::onStream cb) { + _on_stream = std::move(cb); +} + static Decoder::Ptr createDecoder_l(DecoderImp::Type type) { switch (type){ case DecoderImp::decoder_ps: diff --git a/src/Rtp/Decoder.h b/src/Rtp/Decoder.h index 66271b8e..44fecfee 100644 --- a/src/Rtp/Decoder.h +++ b/src/Rtp/Decoder.h @@ -25,12 +25,16 @@ public: typedef std::function onStream; virtual ssize_t input(const uint8_t *data, size_t bytes) = 0; - virtual void setOnDecode(onDecode cb) = 0; - virtual void setOnStream(onStream cb) = 0; + void setOnDecode(onDecode cb); + void setOnStream(onStream cb); protected: Decoder() = default; virtual ~Decoder() = default; + +protected: + onDecode _on_decode; + onStream _on_stream; }; class DecoderImp{ diff --git a/src/Rtp/PSDecoder.cpp b/src/Rtp/PSDecoder.cpp index 4f3249b1..ecad9e88 100644 --- a/src/Rtp/PSDecoder.cpp +++ b/src/Rtp/PSDecoder.cpp @@ -53,14 +53,6 @@ ssize_t PSDecoder::input(const uint8_t *data, size_t bytes) { return bytes; } -void PSDecoder::setOnDecode(Decoder::onDecode cb) { - _on_decode = std::move(cb); -} - -void PSDecoder::setOnStream(Decoder::onStream cb) { - _on_stream = std::move(cb); -} - const char *PSDecoder::onSearchPacketTail(const char *data, size_t len) { try { auto ret = ps_demuxer_input(static_cast(_ps_demuxer), reinterpret_cast(data), len); @@ -81,4 +73,4 @@ const char *PSDecoder::onSearchPacketTail(const char *data, size_t len) { } }//namespace mediakit -#endif//#if defined(ENABLE_RTPPROXY) \ No newline at end of file +#endif//#if defined(ENABLE_RTPPROXY) diff --git a/src/Rtp/PSDecoder.h b/src/Rtp/PSDecoder.h index 6cb5b40e..c56475ab 100644 --- a/src/Rtp/PSDecoder.h +++ b/src/Rtp/PSDecoder.h @@ -25,8 +25,6 @@ public: ~PSDecoder(); ssize_t input(const uint8_t* data, size_t bytes) override; - void setOnDecode(onDecode cb) override; - void setOnStream(onStream cb) override; // HttpRequestSplitter interface private: @@ -36,8 +34,6 @@ private: private: void *_ps_demuxer = nullptr; - onDecode _on_decode; - onStream _on_stream; }; }//namespace mediakit diff --git a/src/Rtp/TSDecoder.cpp b/src/Rtp/TSDecoder.cpp index 0f86c10e..c31ddc9b 100644 --- a/src/Rtp/TSDecoder.cpp +++ b/src/Rtp/TSDecoder.cpp @@ -101,14 +101,6 @@ ssize_t TSDecoder::input(const uint8_t *data, size_t bytes) { return bytes; } -void TSDecoder::setOnDecode(Decoder::onDecode cb) { - _on_decode = std::move(cb); -} - -void TSDecoder::setOnStream(Decoder::onStream cb) { - _on_stream = std::move(cb); -} - #endif//defined(ENABLE_HLS) }//namespace mediakit diff --git a/src/Rtp/TSDecoder.h b/src/Rtp/TSDecoder.h index 25a68412..d693827e 100644 --- a/src/Rtp/TSDecoder.h +++ b/src/Rtp/TSDecoder.h @@ -45,14 +45,10 @@ public: TSDecoder(); ~TSDecoder(); ssize_t input(const uint8_t* data, size_t bytes) override ; - void setOnDecode(onDecode cb) override; - void setOnStream(onStream cb) override; private: TSSegment _ts_segment; struct ts_demuxer_t* _demuxer_ctx = nullptr; - onDecode _on_decode; - onStream _on_stream; }; #endif//defined(ENABLE_HLS)