完善Frame相关的接口
This commit is contained in:
parent
8930dd099e
commit
452f150f22
|
|
@ -50,13 +50,19 @@ public:
|
||||||
/**
|
/**
|
||||||
* 时间戳
|
* 时间戳
|
||||||
*/
|
*/
|
||||||
virtual uint32_t stamp() = 0;
|
virtual uint32_t stamp() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 前缀长度,譬如264前缀为0x00 00 00 01,那么前缀长度就是4
|
* 前缀长度,譬如264前缀为0x00 00 00 01,那么前缀长度就是4
|
||||||
* aac前缀则为7个字节
|
* aac前缀则为7个字节
|
||||||
*/
|
*/
|
||||||
virtual uint32_t prefixSize() = 0;
|
virtual uint32_t prefixSize() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回是否为关键帧
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual bool keyFrame() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -85,10 +91,8 @@ public:
|
||||||
/**
|
/**
|
||||||
* 写入帧数据
|
* 写入帧数据
|
||||||
* @param frame 帧
|
* @param frame 帧
|
||||||
* @param key_pos 是否为关键帧
|
|
||||||
* @return 是否为关键帧
|
|
||||||
*/
|
*/
|
||||||
virtual bool inputFrame(const Frame::Ptr &frame,bool key_pos) = 0;
|
virtual void inputFrame(const Frame::Ptr &frame) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -120,11 +124,9 @@ public:
|
||||||
/**
|
/**
|
||||||
* 输入数据帧
|
* 输入数据帧
|
||||||
* @param frame
|
* @param frame
|
||||||
* @param key_pos
|
|
||||||
*/
|
*/
|
||||||
bool inputFrame(const Frame::Ptr &frame,bool key_pos) override{
|
void inputFrame(const Frame::Ptr &frame) override{
|
||||||
_frameRing->write(frame,key_pos);
|
_frameRing->write(frame,frame->keyFrame());
|
||||||
return key_pos;
|
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
RingType::Ptr _frameRing;
|
RingType::Ptr _frameRing;
|
||||||
|
|
@ -143,10 +145,10 @@ public:
|
||||||
uint32_t size() const override {
|
uint32_t size() const override {
|
||||||
return buffer.size();
|
return buffer.size();
|
||||||
}
|
}
|
||||||
uint32_t stamp() override {
|
uint32_t stamp() const override {
|
||||||
return timeStamp;
|
return timeStamp;
|
||||||
}
|
}
|
||||||
uint32_t prefixSize() override{
|
uint32_t prefixSize() const override{
|
||||||
return iPrefixSize;
|
return iPrefixSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -157,6 +159,10 @@ public:
|
||||||
CodecId getCodecId() const override{
|
CodecId getCodecId() const override{
|
||||||
return CodecH264;
|
return CodecH264;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool keyFrame() const override {
|
||||||
|
return type == 5;
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
uint16_t sequence;
|
uint16_t sequence;
|
||||||
uint32_t timeStamp;
|
uint32_t timeStamp;
|
||||||
|
|
@ -178,10 +184,10 @@ public:
|
||||||
uint32_t size() const override {
|
uint32_t size() const override {
|
||||||
return aac_frame_length;
|
return aac_frame_length;
|
||||||
}
|
}
|
||||||
uint32_t stamp() override {
|
uint32_t stamp() const override {
|
||||||
return timeStamp;
|
return timeStamp;
|
||||||
}
|
}
|
||||||
uint32_t prefixSize() override{
|
uint32_t prefixSize() const override{
|
||||||
return iPrefixSize;
|
return iPrefixSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -192,6 +198,10 @@ public:
|
||||||
CodecId getCodecId() const override{
|
CodecId getCodecId() const override{
|
||||||
return CodecAAC;
|
return CodecAAC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool keyFrame() const override {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
unsigned int syncword; //12 bslbf 同步字The bit string ‘1111 1111 1111’,说明一个ADTS帧的开始
|
unsigned int syncword; //12 bslbf 同步字The bit string ‘1111 1111 1111’,说明一个ADTS帧的开始
|
||||||
unsigned int id; //1 bslbf MPEG 标示符, 设置为1
|
unsigned int id; //1 bslbf MPEG 标示符, 设置为1
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@ public:
|
||||||
Track(){}
|
Track(){}
|
||||||
virtual ~Track(){}
|
virtual ~Track(){}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据sdp生成Track对象
|
||||||
|
*/
|
||||||
static Ptr getTrackBySdp(const string &sdp);
|
static Ptr getTrackBySdp(const string &sdp);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -165,9 +168,8 @@ public:
|
||||||
/**
|
/**
|
||||||
* 输入数据帧,并获取sps pps
|
* 输入数据帧,并获取sps pps
|
||||||
* @param frame 数据帧
|
* @param frame 数据帧
|
||||||
* @param key_pos 是否为关键帧
|
|
||||||
*/
|
*/
|
||||||
bool inputFrame(const Frame::Ptr &frame,bool key_pos) override{
|
void inputFrame(const Frame::Ptr &frame) override{
|
||||||
int type = (*((uint8_t *)frame->data() + frame->prefixSize())) & 0x1F;
|
int type = (*((uint8_t *)frame->data() + frame->prefixSize())) & 0x1F;
|
||||||
switch (type){
|
switch (type){
|
||||||
case 7:{
|
case 7:{
|
||||||
|
|
@ -193,7 +195,7 @@ public:
|
||||||
insertFrame->type = 7;
|
insertFrame->type = 7;
|
||||||
insertFrame->buffer = _sps;
|
insertFrame->buffer = _sps;
|
||||||
insertFrame->iPrefixSize = 0;
|
insertFrame->iPrefixSize = 0;
|
||||||
VideoTrack::inputFrame(insertFrame, true);
|
VideoTrack::inputFrame(insertFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!_pps.empty()){
|
if(!_pps.empty()){
|
||||||
|
|
@ -202,19 +204,18 @@ public:
|
||||||
insertFrame->type = 8;
|
insertFrame->type = 8;
|
||||||
insertFrame->buffer = _pps;
|
insertFrame->buffer = _pps;
|
||||||
insertFrame->iPrefixSize = 0;
|
insertFrame->iPrefixSize = 0;
|
||||||
VideoTrack::inputFrame(insertFrame, false);
|
VideoTrack::inputFrame(insertFrame);
|
||||||
}
|
}
|
||||||
VideoTrack::inputFrame(frame, false);
|
VideoTrack::inputFrame(frame);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:{
|
case 1:{
|
||||||
//B or P
|
//B or P
|
||||||
VideoTrack::inputFrame(frame, false);
|
VideoTrack::inputFrame(frame);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return type == 5;
|
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@ AACRtpEncoder::AACRtpEncoder(uint32_t ui32Ssrc,
|
||||||
AACRtpDecoder(ui32SampleRate){
|
AACRtpDecoder(ui32SampleRate){
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AACRtpEncoder::inputFrame(const Frame::Ptr &frame, bool key_pos) {
|
void AACRtpEncoder::inputFrame(const Frame::Ptr &frame) {
|
||||||
RtpCodec::inputFrame(frame, false);
|
RtpCodec::inputFrame(frame);
|
||||||
|
|
||||||
GET_CONFIG_AND_REGISTER(uint32_t, cycleMS, Config::Rtp::kCycleMS);
|
GET_CONFIG_AND_REGISTER(uint32_t, cycleMS, Config::Rtp::kCycleMS);
|
||||||
auto uiStamp = frame->stamp();
|
auto uiStamp = frame->stamp();
|
||||||
|
|
@ -47,7 +47,6 @@ bool AACRtpEncoder::inputFrame(const Frame::Ptr &frame, bool key_pos) {
|
||||||
ptr += (m_ui32MtuSize - 20);
|
ptr += (m_ui32MtuSize - 20);
|
||||||
iSize -= (m_ui32MtuSize - 20);
|
iSize -= (m_ui32MtuSize - 20);
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AACRtpEncoder::makeAACRtp(const void *pData, unsigned int uiLen, bool bMark, uint32_t uiStamp) {
|
void AACRtpEncoder::makeAACRtp(const void *pData, unsigned int uiLen, bool bMark, uint32_t uiStamp) {
|
||||||
|
|
@ -122,7 +121,7 @@ bool AACRtpDecoder::inputRtp(const RtpPacket::Ptr &rtppack, bool key_pos) {
|
||||||
|
|
||||||
void AACRtpDecoder::onGetAdts(const AACFrame::Ptr &frame) {
|
void AACRtpDecoder::onGetAdts(const AACFrame::Ptr &frame) {
|
||||||
//写入环形缓存
|
//写入环形缓存
|
||||||
RtpCodec::inputFrame(frame, false);
|
RtpCodec::inputFrame(frame);
|
||||||
m_adts = obtainFrame();
|
m_adts = obtainFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,9 +68,8 @@ public:
|
||||||
/**
|
/**
|
||||||
* 输入aac 数据,必须带dats头
|
* 输入aac 数据,必须带dats头
|
||||||
* @param frame 带dats头的aac数据
|
* @param frame 带dats头的aac数据
|
||||||
* @param key_pos 此参数内部强制转换为false,请忽略之
|
|
||||||
*/
|
*/
|
||||||
bool inputFrame(const Frame::Ptr &frame, bool key_pos = false) override;
|
void inputFrame(const Frame::Ptr &frame) override;
|
||||||
private:
|
private:
|
||||||
void makeAACRtp(const void *pData, unsigned int uiLen, bool bMark, uint32_t uiStamp);
|
void makeAACRtp(const void *pData, unsigned int uiLen, bool bMark, uint32_t uiStamp);
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
|
||||||
|
|
||||||
void H264RtpDecoder::onGetH264(const H264Frame::Ptr &frame) {
|
void H264RtpDecoder::onGetH264(const H264Frame::Ptr &frame) {
|
||||||
//写入环形缓存
|
//写入环形缓存
|
||||||
RtpCodec::inputFrame(frame,frame->type == 5);
|
RtpCodec::inputFrame(frame);
|
||||||
m_h264frame = obtainFrame();
|
m_h264frame = obtainFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,13 +118,11 @@ H264RtpEncoder::H264RtpEncoder(uint32_t ui32Ssrc,
|
||||||
ui8Interleaved) {
|
ui8Interleaved) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool H264RtpEncoder::inputFrame(const Frame::Ptr &frame, bool key_pos) {
|
void H264RtpEncoder::inputFrame(const Frame::Ptr &frame) {
|
||||||
auto pcData = frame->data() + frame->prefixSize();
|
RtpCodec::inputFrame(frame);
|
||||||
|
|
||||||
key_pos = (((uint8_t *) (pcData))[0] & 0x1F) == 5;
|
|
||||||
RtpCodec::inputFrame(frame, key_pos);
|
|
||||||
|
|
||||||
GET_CONFIG_AND_REGISTER(uint32_t,cycleMS,Config::Rtp::kCycleMS);
|
GET_CONFIG_AND_REGISTER(uint32_t,cycleMS,Config::Rtp::kCycleMS);
|
||||||
|
auto pcData = frame->data() + frame->prefixSize();
|
||||||
auto uiStamp = frame->stamp();
|
auto uiStamp = frame->stamp();
|
||||||
auto iLen = frame->size() - frame->prefixSize();
|
auto iLen = frame->size() - frame->prefixSize();
|
||||||
|
|
||||||
|
|
@ -167,8 +165,6 @@ bool H264RtpEncoder::inputFrame(const Frame::Ptr &frame, bool key_pos) {
|
||||||
} else {
|
} else {
|
||||||
makeH264Rtp(pcData, iLen, true, uiStamp);
|
makeH264Rtp(pcData, iLen, true, uiStamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return key_pos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void H264RtpEncoder::makeH264Rtp(const void* data, unsigned int len, bool mark, uint32_t uiStamp) {
|
void H264RtpEncoder::makeH264Rtp(const void* data, unsigned int len, bool mark, uint32_t uiStamp) {
|
||||||
|
|
|
||||||
|
|
@ -67,9 +67,8 @@ public:
|
||||||
/**
|
/**
|
||||||
* 输入264帧
|
* 输入264帧
|
||||||
* @param frame 帧数据,必须
|
* @param frame 帧数据,必须
|
||||||
* @param key_pos
|
|
||||||
*/
|
*/
|
||||||
bool inputFrame(const Frame::Ptr &frame, bool key_pos) override;
|
void inputFrame(const Frame::Ptr &frame) override;
|
||||||
private:
|
private:
|
||||||
void makeH264Rtp(const void *pData, unsigned int uiLen, bool bMark, uint32_t uiStamp);
|
void makeH264Rtp(const void *pData, unsigned int uiLen, bool bMark, uint32_t uiStamp);
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,16 @@ public:
|
||||||
RtpCodec(){}
|
RtpCodec(){}
|
||||||
virtual ~RtpCodec(){}
|
virtual ~RtpCodec(){}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据CodecId生成Rtp打包器
|
||||||
|
* @param codecId
|
||||||
|
* @param ui32Ssrc
|
||||||
|
* @param ui32MtuSize
|
||||||
|
* @param ui32SampleRate
|
||||||
|
* @param ui8PlayloadType
|
||||||
|
* @param ui8Interleaved
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
static Ptr getRtpEncoderById(CodecId codecId,
|
static Ptr getRtpEncoderById(CodecId codecId,
|
||||||
uint32_t ui32Ssrc,
|
uint32_t ui32Ssrc,
|
||||||
uint32_t ui32MtuSize,
|
uint32_t ui32MtuSize,
|
||||||
|
|
@ -169,6 +179,12 @@ public:
|
||||||
uint8_t ui8PlayloadType,
|
uint8_t ui8PlayloadType,
|
||||||
uint8_t ui8Interleaved);
|
uint8_t ui8Interleaved);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据CodecId生成Rtp解包器
|
||||||
|
* @param codecId
|
||||||
|
* @param ui32SampleRate
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
static Ptr getRtpDecoderById(CodecId codecId,uint32_t ui32SampleRate);
|
static Ptr getRtpDecoderById(CodecId codecId,uint32_t ui32SampleRate);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,10 +71,9 @@ public:
|
||||||
/**
|
/**
|
||||||
* 输入帧数据,驱动rtp打包
|
* 输入帧数据,驱动rtp打包
|
||||||
* @param frame 帧数据
|
* @param frame 帧数据
|
||||||
* @param key_pos 是否为关键帧
|
|
||||||
*/
|
*/
|
||||||
bool inputFrame(const Frame::Ptr &frame,bool key_pos) override{
|
void inputFrame(const Frame::Ptr &frame) override{
|
||||||
return _encoder->inputFrame(frame,key_pos);
|
_encoder->inputFrame(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -313,14 +312,13 @@ public:
|
||||||
/**
|
/**
|
||||||
* 写入帧数据然后打包rtp
|
* 写入帧数据然后打包rtp
|
||||||
* @param frame 帧数据
|
* @param frame 帧数据
|
||||||
* @param key_pos 是否为关键帧
|
|
||||||
*/
|
*/
|
||||||
bool inputFrame(const Frame::Ptr &frame,bool key_pos = true) override {
|
void inputFrame(const Frame::Ptr &frame) override {
|
||||||
auto it = _sdp_map.find(frame->getTrackType());
|
auto it = _sdp_map.find(frame->getTrackType());
|
||||||
if(it == _sdp_map.end()){
|
if(it == _sdp_map.end()){
|
||||||
return false;
|
return ;
|
||||||
}
|
}
|
||||||
return it->second->inputFrame(frame,key_pos);
|
it->second->inputFrame(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue