Commit 57c5d296 by xiongziliang

优化DevChannel内存拷贝问题

parent 9cdbe4c4
...@@ -104,7 +104,13 @@ void DevChannel::inputH264(const char* pcData, int iDataLen, uint32_t dts,uint32 ...@@ -104,7 +104,13 @@ void DevChannel::inputH264(const char* pcData, int iDataLen, uint32_t dts,uint32
} else { } else {
prefixeSize = 0; prefixeSize = 0;
} }
inputFrame(std::make_shared<H264FrameNoCacheAble>((char *)pcData,iDataLen,dts,pts,prefixeSize));
H264Frame::Ptr frame = std::make_shared<H264Frame>();
frame->timeStamp = dts;
frame->ptsStamp = pts;
frame->buffer.assign("\x00\x00\x00\x01",4);
frame->buffer.append(pcData + prefixeSize, iDataLen - prefixeSize);
inputFrame(frame);
} }
void DevChannel::inputH265(const char* pcData, int iDataLen, uint32_t dts,uint32_t pts) { void DevChannel::inputH265(const char* pcData, int iDataLen, uint32_t dts,uint32_t pts) {
...@@ -122,7 +128,13 @@ void DevChannel::inputH265(const char* pcData, int iDataLen, uint32_t dts,uint32 ...@@ -122,7 +128,13 @@ void DevChannel::inputH265(const char* pcData, int iDataLen, uint32_t dts,uint32
} else { } else {
prefixeSize = 0; prefixeSize = 0;
} }
inputFrame(std::make_shared<H265FrameNoCacheAble>((char *)pcData,iDataLen,dts,pts,prefixeSize));
H265Frame::Ptr frame = std::make_shared<H265Frame>();
frame->timeStamp = dts;
frame->ptsStamp = pts;
frame->buffer.assign("\x00\x00\x00\x01",4);
frame->buffer.append(pcData + prefixeSize, iDataLen - prefixeSize);
inputFrame(frame);
} }
void DevChannel::inputAAC(const char* pcData, int iDataLen, uint32_t uiStamp,bool withAdtsHeader) { void DevChannel::inputAAC(const char* pcData, int iDataLen, uint32_t uiStamp,bool withAdtsHeader) {
......
...@@ -104,7 +104,6 @@ public: ...@@ -104,7 +104,6 @@ public:
//表示说ADTS帧中有一个AAC数据块并不是说没有。(一个AAC原始帧包含一段时间内1024个采样及相关数据) //表示说ADTS帧中有一个AAC数据块并不是说没有。(一个AAC原始帧包含一段时间内1024个采样及相关数据)
unsigned int no_raw_data_blocks_in_frame; //2 uimsfb unsigned int no_raw_data_blocks_in_frame; //2 uimsfb
unsigned char buffer[2 * 1024 + 7]; unsigned char buffer[2 * 1024 + 7];
uint16_t sequence;
uint32_t timeStamp; uint32_t timeStamp;
uint32_t iPrefixSize = 7; uint32_t iPrefixSize = 7;
} ; } ;
......
...@@ -149,7 +149,6 @@ bool AACRtpDecoder::inputRtp(const RtpPacket::Ptr &rtppack, bool key_pos) { ...@@ -149,7 +149,6 @@ bool AACRtpDecoder::inputRtp(const RtpPacket::Ptr &rtppack, bool key_pos) {
memcpy(_adts->buffer + _adts->aac_frame_length, rtp_packet_payload + next_aac_payload_offset, cur_aac_payload_len); memcpy(_adts->buffer + _adts->aac_frame_length, rtp_packet_payload + next_aac_payload_offset, cur_aac_payload_len);
_adts->aac_frame_length += (cur_aac_payload_len); _adts->aac_frame_length += (cur_aac_payload_len);
if (rtppack->mark == true) { if (rtppack->mark == true) {
_adts->sequence = rtppack->sequence;
_adts->timeStamp = rtppack->timeStamp; _adts->timeStamp = rtppack->timeStamp;
writeAdtsHeader(*_adts, _adts->buffer); writeAdtsHeader(*_adts, _adts->buffer);
onGetAAC(_adts); onGetAAC(_adts);
......
...@@ -222,13 +222,23 @@ public: ...@@ -222,13 +222,23 @@ public:
auto iAudioIndex = frame->stamp() / MUTE_ADTS_DATA_MS; auto iAudioIndex = frame->stamp() / MUTE_ADTS_DATA_MS;
if(_iAudioIndex != iAudioIndex){ if(_iAudioIndex != iAudioIndex){
_iAudioIndex = iAudioIndex; _iAudioIndex = iAudioIndex;
auto aacFrame = std::make_shared<AACFrameNoCacheAble>((char *)MUTE_ADTS_DATA, auto aacFrame = std::make_shared<AACFrameCacheAble>((char *)MUTE_ADTS_DATA, MUTE_ADTS_DATA_LEN, _iAudioIndex * MUTE_ADTS_DATA_MS);
MUTE_ADTS_DATA_LEN,
_iAudioIndex * MUTE_ADTS_DATA_MS);
FrameDispatcher::inputFrame(aacFrame); FrameDispatcher::inputFrame(aacFrame);
} }
} }
} }
private:
class AACFrameCacheAble : public AACFrameNoCacheAble{
public:
template <typename ... ARGS>
AACFrameCacheAble(ARGS && ...args) : AACFrameNoCacheAble(std::forward<ARGS>(args)...){};
virtual ~AACFrameCacheAble() = default;
bool cacheAble() const override {
return true;
}
};
private: private:
int _iAudioIndex = 0; int _iAudioIndex = 0;
}; };
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论