mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 20:47:08 +08:00
Frame添加cacheAbel接口
This commit is contained in:
parent
2d460ff83d
commit
f50eaf8648
@ -103,7 +103,7 @@ void DevChannel::inputH264(const char* pcData, int iDataLen, uint32_t dts,uint32
|
||||
} else {
|
||||
prefixeSize = 0;
|
||||
}
|
||||
inputFrame(std::make_shared<H264FrameNoCopyAble>((char *)pcData,iDataLen,dts,pts,prefixeSize));
|
||||
inputFrame(std::make_shared<H264FrameNoCacheAble>((char *)pcData,iDataLen,dts,pts,prefixeSize));
|
||||
}
|
||||
|
||||
void DevChannel::inputAAC(const char* pcData, int iDataLen, uint32_t uiStamp,bool withAdtsHeader) {
|
||||
@ -119,12 +119,12 @@ void DevChannel::inputAAC(const char *pcDataWithoutAdts,int iDataLen, uint32_t u
|
||||
uiStamp = (uint32_t)_aTicker[1].elapsedTime();
|
||||
}
|
||||
if(pcAdtsHeader + 7 == pcDataWithoutAdts){
|
||||
inputFrame(std::make_shared<AACFrameNoCopyAble>((char *)pcDataWithoutAdts - 7,iDataLen + 7,uiStamp,7));
|
||||
inputFrame(std::make_shared<AACFrameNoCacheAble>((char *)pcDataWithoutAdts - 7,iDataLen + 7,uiStamp,7));
|
||||
} else {
|
||||
char *dataWithAdts = new char[iDataLen + 7];
|
||||
memcpy(dataWithAdts,pcAdtsHeader,7);
|
||||
memcpy(dataWithAdts + 7 , pcDataWithoutAdts , iDataLen);
|
||||
inputFrame(std::make_shared<AACFrameNoCopyAble>(dataWithAdts,iDataLen + 7,uiStamp,7));
|
||||
inputFrame(std::make_shared<AACFrameNoCacheAble>(dataWithAdts,iDataLen + 7,uiStamp,7));
|
||||
delete [] dataWithAdts;
|
||||
}
|
||||
}
|
||||
|
@ -105,11 +105,11 @@ public:
|
||||
uint32_t iPrefixSize = 7;
|
||||
} ;
|
||||
|
||||
class AACFrameNoCopyAble : public FrameNoCopyAble {
|
||||
class AACFrameNoCacheAble : public FrameNoCacheAble {
|
||||
public:
|
||||
typedef std::shared_ptr<AACFrameNoCopyAble> Ptr;
|
||||
typedef std::shared_ptr<AACFrameNoCacheAble> Ptr;
|
||||
|
||||
AACFrameNoCopyAble(char *ptr,uint32_t size,uint32_t dts,int prefixeSize = 7){
|
||||
AACFrameNoCacheAble(char *ptr,uint32_t size,uint32_t dts,int prefixeSize = 7){
|
||||
_ptr = ptr;
|
||||
_size = size;
|
||||
_dts = dts;
|
||||
|
@ -116,6 +116,11 @@ public:
|
||||
* @return
|
||||
*/
|
||||
virtual bool keyFrame() const = 0;
|
||||
|
||||
/**
|
||||
* 是否可以缓存
|
||||
*/
|
||||
virtual bool cacheAble() const { return true; }
|
||||
};
|
||||
|
||||
/**
|
||||
@ -281,9 +286,9 @@ private:
|
||||
map<void *,FrameWriterInterface::Ptr> _delegateMap;
|
||||
};
|
||||
|
||||
class FrameNoCopyAble : public Frame{
|
||||
class FrameNoCacheAble : public Frame{
|
||||
public:
|
||||
typedef std::shared_ptr<FrameNoCopyAble> Ptr;
|
||||
typedef std::shared_ptr<FrameNoCacheAble> Ptr;
|
||||
char *data() const override{
|
||||
return _ptr;
|
||||
}
|
||||
@ -306,6 +311,13 @@ public:
|
||||
return _prefixSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 该帧不可缓存
|
||||
* @return
|
||||
*/
|
||||
bool cacheAble() const override {
|
||||
return false;
|
||||
}
|
||||
protected:
|
||||
char *_ptr;
|
||||
uint32_t _size;
|
||||
|
@ -92,11 +92,11 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class H264FrameNoCopyAble : public FrameNoCopyAble {
|
||||
class H264FrameNoCacheAble : public FrameNoCacheAble {
|
||||
public:
|
||||
typedef std::shared_ptr<H264FrameNoCopyAble> Ptr;
|
||||
typedef std::shared_ptr<H264FrameNoCacheAble> Ptr;
|
||||
|
||||
H264FrameNoCopyAble(char *ptr,uint32_t size,uint32_t dts , uint32_t pts ,int prefixeSize = 4){
|
||||
H264FrameNoCacheAble(char *ptr,uint32_t size,uint32_t dts , uint32_t pts ,int prefixeSize = 4){
|
||||
_ptr = ptr;
|
||||
_size = size;
|
||||
_dts = dts;
|
||||
@ -117,13 +117,13 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class H264FrameSubFrame : public H264FrameNoCopyAble{
|
||||
class H264FrameSubFrame : public H264FrameNoCacheAble{
|
||||
public:
|
||||
typedef std::shared_ptr<H264FrameSubFrame> Ptr;
|
||||
H264FrameSubFrame(const Frame::Ptr &strongRef,
|
||||
char *ptr,
|
||||
uint32_t size,
|
||||
int prefixeSize) : H264FrameNoCopyAble(ptr,size,strongRef->dts(),strongRef->pts(),prefixeSize){
|
||||
int prefixeSize) : H264FrameNoCacheAble(ptr,size,strongRef->dts(),strongRef->pts(),prefixeSize){
|
||||
_strongRef = strongRef;
|
||||
}
|
||||
private:
|
||||
|
@ -121,11 +121,11 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class H265FrameNoCopyAble : public FrameNoCopyAble {
|
||||
class H265FrameNoCacheAble : public FrameNoCacheAble {
|
||||
public:
|
||||
typedef std::shared_ptr<H265FrameNoCopyAble> Ptr;
|
||||
typedef std::shared_ptr<H265FrameNoCacheAble> Ptr;
|
||||
|
||||
H265FrameNoCopyAble(char *ptr, uint32_t size, uint32_t dts,uint32_t pts, int prefixeSize = 4) {
|
||||
H265FrameNoCacheAble(char *ptr, uint32_t size, uint32_t dts,uint32_t pts, int prefixeSize = 4) {
|
||||
_ptr = ptr;
|
||||
_size = size;
|
||||
_dts = dts;
|
||||
|
@ -261,11 +261,11 @@ inline bool MediaReader::readAudioSample(int iTimeInc,bool justSeekSyncFrame) {
|
||||
}
|
||||
|
||||
inline void MediaReader::writeH264(uint8_t *pucData,int iLen,uint32_t dts,uint32_t pts) {
|
||||
_mediaMuxer->inputFrame(std::make_shared<H264FrameNoCopyAble>((char*)pucData,iLen,dts,pts));
|
||||
_mediaMuxer->inputFrame(std::make_shared<H264FrameNoCacheAble>((char*)pucData,iLen,dts,pts));
|
||||
}
|
||||
|
||||
inline void MediaReader::writeAAC(uint8_t *pucData,int iLen,uint32_t uiStamp) {
|
||||
_mediaMuxer->inputFrame(std::make_shared<AACFrameNoCopyAble>((char*)pucData,iLen,uiStamp));
|
||||
_mediaMuxer->inputFrame(std::make_shared<AACFrameNoCacheAble>((char*)pucData,iLen,uiStamp));
|
||||
}
|
||||
|
||||
inline MP4SampleId MediaReader::getVideoSampleId(int iTimeInc ) {
|
||||
|
@ -212,7 +212,7 @@ public:
|
||||
auto iAudioIndex = frame->stamp() / MUTE_ADTS_DATA_MS;
|
||||
if(_iAudioIndex != iAudioIndex){
|
||||
_iAudioIndex = iAudioIndex;
|
||||
auto aacFrame = std::make_shared<AACFrameNoCopyAble>((char *)MUTE_ADTS_DATA,
|
||||
auto aacFrame = std::make_shared<AACFrameNoCacheAble>((char *)MUTE_ADTS_DATA,
|
||||
MUTE_ADTS_DATA_LEN,
|
||||
_iAudioIndex * MUTE_ADTS_DATA_MS);
|
||||
FrameRingInterfaceDelegate::inputFrame(aacFrame);
|
||||
|
Loading…
Reference in New Issue
Block a user