mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 04:31:37 +08:00
Optimize Decoder inheritance relationship (#1760)
This commit is contained in:
parent
07982b7243
commit
28350c0d05
@ -24,6 +24,15 @@
|
|||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
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) {
|
static Decoder::Ptr createDecoder_l(DecoderImp::Type type) {
|
||||||
switch (type){
|
switch (type){
|
||||||
case DecoderImp::decoder_ps:
|
case DecoderImp::decoder_ps:
|
||||||
|
@ -25,12 +25,16 @@ public:
|
|||||||
typedef std::function<void(int stream, int codecid, const void *extra, size_t bytes, int finish)> onStream;
|
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 ssize_t input(const uint8_t *data, size_t bytes) = 0;
|
||||||
virtual void setOnDecode(onDecode cb) = 0;
|
void setOnDecode(onDecode cb);
|
||||||
virtual void setOnStream(onStream cb) = 0;
|
void setOnStream(onStream cb);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Decoder() = default;
|
Decoder() = default;
|
||||||
virtual ~Decoder() = default;
|
virtual ~Decoder() = default;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
onDecode _on_decode;
|
||||||
|
onStream _on_stream;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DecoderImp{
|
class DecoderImp{
|
||||||
|
@ -53,14 +53,6 @@ ssize_t PSDecoder::input(const uint8_t *data, size_t bytes) {
|
|||||||
return 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) {
|
const char *PSDecoder::onSearchPacketTail(const char *data, size_t len) {
|
||||||
try {
|
try {
|
||||||
auto ret = ps_demuxer_input(static_cast<struct ps_demuxer_t *>(_ps_demuxer), reinterpret_cast<const uint8_t *>(data), len);
|
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
|
}//namespace mediakit
|
||||||
#endif//#if defined(ENABLE_RTPPROXY)
|
#endif//#if defined(ENABLE_RTPPROXY)
|
||||||
|
@ -25,8 +25,6 @@ public:
|
|||||||
~PSDecoder();
|
~PSDecoder();
|
||||||
|
|
||||||
ssize_t input(const uint8_t* data, size_t bytes) override;
|
ssize_t input(const uint8_t* data, size_t bytes) override;
|
||||||
void setOnDecode(onDecode cb) override;
|
|
||||||
void setOnStream(onStream cb) override;
|
|
||||||
|
|
||||||
// HttpRequestSplitter interface
|
// HttpRequestSplitter interface
|
||||||
private:
|
private:
|
||||||
@ -36,8 +34,6 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void *_ps_demuxer = nullptr;
|
void *_ps_demuxer = nullptr;
|
||||||
onDecode _on_decode;
|
|
||||||
onStream _on_stream;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}//namespace mediakit
|
}//namespace mediakit
|
||||||
|
@ -101,14 +101,6 @@ ssize_t TSDecoder::input(const uint8_t *data, size_t bytes) {
|
|||||||
return 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)
|
#endif//defined(ENABLE_HLS)
|
||||||
|
|
||||||
}//namespace mediakit
|
}//namespace mediakit
|
||||||
|
@ -45,14 +45,10 @@ public:
|
|||||||
TSDecoder();
|
TSDecoder();
|
||||||
~TSDecoder();
|
~TSDecoder();
|
||||||
ssize_t input(const uint8_t* data, size_t bytes) override ;
|
ssize_t input(const uint8_t* data, size_t bytes) override ;
|
||||||
void setOnDecode(onDecode cb) override;
|
|
||||||
void setOnStream(onStream cb) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TSSegment _ts_segment;
|
TSSegment _ts_segment;
|
||||||
struct ts_demuxer_t* _demuxer_ctx = nullptr;
|
struct ts_demuxer_t* _demuxer_ctx = nullptr;
|
||||||
onDecode _on_decode;
|
|
||||||
onStream _on_stream;
|
|
||||||
};
|
};
|
||||||
#endif//defined(ENABLE_HLS)
|
#endif//defined(ENABLE_HLS)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user