修复rtmp注册时还未生成完整config包的bug

This commit is contained in:
xiongziliang 2020-01-15 11:46:15 +08:00
parent 444137e5b7
commit 2610ba7c8b
8 changed files with 61 additions and 30 deletions

View File

@ -76,17 +76,24 @@ AACRtmpEncoder::AACRtmpEncoder(const Track::Ptr &track) {
_track = dynamic_pointer_cast<AACTrack>(track); _track = dynamic_pointer_cast<AACTrack>(track);
} }
void AACRtmpEncoder::inputFrame(const Frame::Ptr &frame) { void AACRtmpEncoder::makeConfigPacket() {
if(_aac_cfg.empty()){ if (_track && _track->ready()) {
if(frame->prefixSize() >= 7){
//包含adts头,从adts头获取aac配置信息
_aac_cfg = makeAdtsConfig(reinterpret_cast<const uint8_t *>(frame->data()));
makeAudioConfigPkt();
} else if(_track && _track->ready()){
//从track中和获取aac配置信息 //从track中和获取aac配置信息
_aac_cfg = _track->getAacCfg(); _aac_cfg = _track->getAacCfg();
}
if (!_aac_cfg.empty()) {
makeAudioConfigPkt(); makeAudioConfigPkt();
} }
}
void AACRtmpEncoder::inputFrame(const Frame::Ptr &frame) {
if (_aac_cfg.empty()) {
if (frame->prefixSize() >= 7) {
//包含adts头,从adts头获取aac配置信息
_aac_cfg = makeAdtsConfig(reinterpret_cast<const uint8_t *>(frame->data()));
}
makeConfigPacket();
} }
if(!_aac_cfg.empty()){ if(!_aac_cfg.empty()){

View File

@ -88,6 +88,10 @@ public:
*/ */
void inputFrame(const Frame::Ptr &frame) override; void inputFrame(const Frame::Ptr &frame) override;
/**
* config包
*/
void makeConfigPacket() override;
private: private:
void makeAudioConfigPkt(); void makeAudioConfigPkt();
private: private:

View File

@ -99,7 +99,20 @@ inline void H264RtmpDecoder::onGetH264(const char* pcData, int iLen, uint32_t dt
H264RtmpEncoder::H264RtmpEncoder(const Track::Ptr &track) { H264RtmpEncoder::H264RtmpEncoder(const Track::Ptr &track) {
_track = dynamic_pointer_cast<H264Track>(track); _track = dynamic_pointer_cast<H264Track>(track);
}
void H264RtmpEncoder::makeConfigPacket(){
if (_track && _track->ready()) {
//尝试从track中获取sps pps信息
_sps = _track->getSps();
_pps = _track->getPps();
}
if (!_sps.empty() && !_pps.empty()) {
//获取到sps/pps
makeVideoConfigPkt();
_gotSpsPps = true;
}
} }
void H264RtmpEncoder::inputFrame(const Frame::Ptr &frame) { void H264RtmpEncoder::inputFrame(const Frame::Ptr &frame) {
@ -107,37 +120,24 @@ void H264RtmpEncoder::inputFrame(const Frame::Ptr &frame) {
auto iLen = frame->size() - frame->prefixSize(); auto iLen = frame->size() - frame->prefixSize();
auto type = H264_TYPE(((uint8_t*)pcData)[0]); auto type = H264_TYPE(((uint8_t*)pcData)[0]);
if(!_gotSpsPps){ if (!_gotSpsPps) {
//尝试从frame中获取sps pps //尝试从frame中获取sps pps
switch (type){ switch (type) {
case H264Frame::NAL_SPS:{ case H264Frame::NAL_SPS: {
//sps //sps
if(_sps.empty()){ _sps = string(pcData, iLen);
_sps = string(pcData,iLen); makeConfigPacket();
}
}
break; break;
case H264Frame::NAL_PPS:{ }
case H264Frame::NAL_PPS: {
//pps //pps
if(_pps.empty()){ _pps = string(pcData, iLen);
_pps = string(pcData,iLen); makeConfigPacket();
}
}
break; break;
}
default: default:
break; break;
} }
if(_track && _track->ready()){
//尝试从track中获取sps pps信息
_sps = _track->getSps();
_pps = _track->getPps();
}
if(!_sps.empty() && !_pps.empty()){
_gotSpsPps = true;
makeVideoConfigPkt();
}
} }
if(type == H264Frame::NAL_SEI){ if(type == H264Frame::NAL_SEI){

View File

@ -90,6 +90,11 @@ public:
* @param frame * @param frame
*/ */
void inputFrame(const Frame::Ptr &frame) override; void inputFrame(const Frame::Ptr &frame) override;
/**
* config包
*/
void makeConfigPacket() override;
private: private:
void makeVideoConfigPkt(); void makeVideoConfigPkt();
private: private:

View File

@ -80,6 +80,7 @@ public:
typedef std::shared_ptr<RtmpCodec> Ptr; typedef std::shared_ptr<RtmpCodec> Ptr;
RtmpCodec(){} RtmpCodec(){}
virtual ~RtmpCodec(){} virtual ~RtmpCodec(){}
virtual void makeConfigPacket() {};
}; };

View File

@ -58,6 +58,7 @@ public:
} }
void onAllTrackReady(){ void onAllTrackReady(){
makeConfigPacket();
_mediaSouce->setMetaData(getMetadata()); _mediaSouce->setMetaData(getMetadata());
} }

View File

@ -78,6 +78,14 @@ void RtmpMuxer::inputFrame(const Frame::Ptr &frame) {
} }
} }
void RtmpMuxer::makeConfigPacket(){
for(auto &encoder : _encoder){
if(encoder){
encoder->makeConfigPacket();
}
}
}
const AMFValue &RtmpMuxer::getMetadata() const { const AMFValue &RtmpMuxer::getMetadata() const {
return _metadata; return _metadata;
} }

View File

@ -71,6 +71,11 @@ public:
* track * track
*/ */
void resetTracks() override ; void resetTracks() override ;
/**
* config包
*/
void makeConfigPacket();
private: private:
RtmpRing::RingType::Ptr _rtmpRing; RtmpRing::RingType::Ptr _rtmpRing;
AMFValue _metadata; AMFValue _metadata;