mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-29 14:45:55 +08:00
Merge branch 'feature/ps-decoder-cache-buffer' of https://github.com/xia-chu/ZLMediaKit
This commit is contained in:
commit
49f59fb993
@ -150,27 +150,6 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) {
|
||||
return ref->inputRtp(TrackVideo, (unsigned char *) data, data_len);
|
||||
}
|
||||
|
||||
const char *GB28181Process::onSearchPacketTail(const char *packet,size_t bytes){
|
||||
try {
|
||||
auto ret = _decoder->input((uint8_t *) packet, bytes);
|
||||
if (ret >= 0) {
|
||||
//解析成功全部或部分
|
||||
return packet + ret;
|
||||
}
|
||||
//解析失败,丢弃所有数据
|
||||
return packet + bytes;
|
||||
} catch (std::exception &ex) {
|
||||
InfoL << "解析ps或ts异常: bytes=" << bytes
|
||||
<< " ,exception=" << ex.what()
|
||||
<< " ,hex=" << hexdump((uint8_t *) packet, MIN(bytes,32));
|
||||
if (remainDataSize() > 256 * 1024) {
|
||||
//缓存太多数据无法处理则上抛异常
|
||||
throw;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void GB28181Process::onRtpDecode(const Frame::Ptr &frame) {
|
||||
if (frame->getCodecId() != CodecInvalid) {
|
||||
//这里不是ps或ts
|
||||
@ -197,7 +176,7 @@ void GB28181Process::onRtpDecode(const Frame::Ptr &frame) {
|
||||
}
|
||||
|
||||
if (_decoder) {
|
||||
HttpRequestSplitter::input(frame->data(), frame->size());
|
||||
_decoder->input(reinterpret_cast<const uint8_t *>(frame->data()), frame->size());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
namespace mediakit{
|
||||
|
||||
class RtpReceiverImp;
|
||||
class GB28181Process : public HttpRequestSplitter, public ProcessInterface{
|
||||
class GB28181Process : public ProcessInterface {
|
||||
public:
|
||||
typedef std::shared_ptr<GB28181Process> Ptr;
|
||||
GB28181Process(const MediaInfo &media_info, MediaSinkInterface *interface);
|
||||
@ -38,8 +38,6 @@ public:
|
||||
|
||||
protected:
|
||||
void onRtpSorted(RtpPacket::Ptr rtp);
|
||||
const char *onSearchPacketTail(const char *data,size_t len) override;
|
||||
ssize_t onRecvHeader(const char *data,size_t len) override { return 0; };
|
||||
|
||||
private:
|
||||
void onRtpDecode(const Frame::Ptr &frame);
|
||||
|
@ -45,7 +45,8 @@ PSDecoder::~PSDecoder() {
|
||||
}
|
||||
|
||||
ssize_t PSDecoder::input(const uint8_t *data, size_t bytes) {
|
||||
return ps_demuxer_input((struct ps_demuxer_t*)_ps_demuxer,data,bytes);
|
||||
HttpRequestSplitter::input(reinterpret_cast<const char *>(data), bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
void PSDecoder::setOnDecode(Decoder::onDecode cb) {
|
||||
@ -56,5 +57,28 @@ 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);
|
||||
if (ret >= 0) {
|
||||
//解析成功全部或部分
|
||||
return data + ret;
|
||||
}
|
||||
|
||||
//解析失败,丢弃所有数据
|
||||
return data + len;
|
||||
} catch (std::exception &ex) {
|
||||
InfoL << "解析 ps 异常: bytes=" << len
|
||||
<< ", exception=" << ex.what()
|
||||
<< ", hex=" << hexdump(data, MIN(len, 32));
|
||||
if (remainDataSize() > 256 * 1024) {
|
||||
//缓存太多数据无法处理则上抛异常
|
||||
throw;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
}//namespace mediakit
|
||||
#endif//#if defined(ENABLE_RTPPROXY)
|
@ -14,17 +14,26 @@
|
||||
#if defined(ENABLE_RTPPROXY)
|
||||
#include <stdint.h>
|
||||
#include "Decoder.h"
|
||||
#include "Http/HttpRequestSplitter.h"
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
//ps解析器
|
||||
class PSDecoder : public Decoder {
|
||||
class PSDecoder : public Decoder, private HttpRequestSplitter {
|
||||
public:
|
||||
PSDecoder();
|
||||
~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:
|
||||
using HttpRequestSplitter::input;
|
||||
const char *onSearchPacketTail(const char *data, size_t len) override;
|
||||
ssize_t onRecvHeader(const char *, size_t) override { return 0; };
|
||||
|
||||
private:
|
||||
void *_ps_demuxer = nullptr;
|
||||
onDecode _on_decode;
|
||||
|
Loading…
Reference in New Issue
Block a user