优化rtmp推流时,aac config获取不完整的bug

This commit is contained in:
xiongziliang 2020-06-11 17:40:09 +08:00
parent 0e47dc94f9
commit b9006a90d4
3 changed files with 33 additions and 16 deletions

View File

@ -71,10 +71,17 @@ public:
/**
* aac类型的媒体
* @param aac_cfg aac两个字节的配置信息
* @param aac_cfg aac配置信息
*/
AACTrack(const string &aac_cfg){
if(aac_cfg.size() < 2){
setAacCfg(aac_cfg);
}
/**
* aac
*/
void setAacCfg(const string &aac_cfg){
if (aac_cfg.size() < 2) {
throw std::invalid_argument("adts配置必须最少2个字节");
}
_cfg = aac_cfg;
@ -82,7 +89,7 @@ public:
}
/**
* aac两个字节的配置
* aac
*/
const string &getAacCfg() const{
return _cfg;

View File

@ -13,8 +13,9 @@
namespace mediakit{
AACRtmpDecoder::AACRtmpDecoder() {
_adts = obtainFrame();
AACRtmpDecoder::AACRtmpDecoder(const Track::Ptr &track) {
_frame = obtainFrame();
_track = dynamic_pointer_cast<AACTrack>(track);
}
AACFrame::Ptr AACRtmpDecoder::obtainFrame() {
@ -38,13 +39,19 @@ static string getAacCfg(const RtmpPacket &thiz) {
WarnL << "bad aac cfg!";
return ret;
}
ret = thiz.strBuf.substr(2, 2);
ret = thiz.strBuf.substr(2);
return ret;
}
bool AACRtmpDecoder::inputRtmp(const RtmpPacket::Ptr &pkt, bool) {
if (pkt->isCfgFrame()) {
_aac_cfg = getAacCfg(*pkt);
if (_track) {
//设置aac config
_track->setAacCfg(_aac_cfg);
//不再强引用
_track = nullptr;
}
return false;
}
if (!_aac_cfg.empty()) {
@ -54,20 +61,20 @@ bool AACRtmpDecoder::inputRtmp(const RtmpPacket::Ptr &pkt, bool) {
}
void AACRtmpDecoder::onGetAAC(const char* data, int len, uint32_t stamp) {
_adts->_dts = stamp;
_frame->_dts = stamp;
//先追加数据
_adts->_buffer.append(data, len);
_frame->_buffer.append(data, len);
//覆盖adts头
dumpAacConfig(_aac_cfg, _adts->size(), (uint8_t *) _adts->data());
dumpAacConfig(_aac_cfg, _frame->size(), (uint8_t *) _frame->data());
//写入环形缓存
RtmpCodec::inputFrame(_adts);
_adts = obtainFrame();
RtmpCodec::inputFrame(_frame);
_frame = obtainFrame();
}
/////////////////////////////////////////////////////////////////////////////////////
AACRtmpEncoder::AACRtmpEncoder(const Track::Ptr &track) {
AACRtmpEncoder::AACRtmpEncoder(const Track::Ptr &track): AACRtmpDecoder(track) {
_track = dynamic_pointer_cast<AACTrack>(track);
}

View File

@ -23,7 +23,7 @@ class AACRtmpDecoder : public RtmpCodec , public ResourcePoolHelper<AACFrame> {
public:
typedef std::shared_ptr<AACRtmpDecoder> Ptr;
AACRtmpDecoder();
AACRtmpDecoder(const Track::Ptr &track);
~AACRtmpDecoder() {}
/**
@ -38,10 +38,12 @@ public:
}
protected:
void onGetAAC(const char* data, int len, uint32_t stamp);
void onGetAAC(const char *data, int len, uint32_t stamp);
AACFrame::Ptr obtainFrame();
protected:
AACFrame::Ptr _adts;
AACFrame::Ptr _frame;
AACTrack::Ptr _track;
string _aac_cfg;
};
@ -72,11 +74,12 @@ public:
* config包
*/
void makeConfigPacket() override;
private:
void makeAudioConfigPkt();
private:
uint8_t _audio_flv_flags;
AACTrack::Ptr _track;
};
}//namespace mediakit