Optimize Decoder inheritance relationship (#1760)

This commit is contained in:
CharleyWangHZ 2022-06-29 11:01:16 +08:00 committed by GitHub
parent 07982b7243
commit 28350c0d05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 27 deletions

View File

@ -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:

View File

@ -25,12 +25,16 @@ public:
typedef std::function<void(int stream, int codecid, const void *extra, size_t bytes, int finish)> 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{

View File

@ -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<struct ps_demuxer_t *>(_ps_demuxer), reinterpret_cast<const uint8_t *>(data), len);
@ -81,4 +73,4 @@ const char *PSDecoder::onSearchPacketTail(const char *data, size_t len) {
}
}//namespace mediakit
#endif//#if defined(ENABLE_RTPPROXY)
#endif//#if defined(ENABLE_RTPPROXY)

View File

@ -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

View File

@ -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

View File

@ -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)