rtmp播放成功时确保aac track处于ready状态

This commit is contained in:
xiongziliang 2020-06-30 21:00:45 +08:00
parent 41c75fb66a
commit 29077dcef4
2 changed files with 15 additions and 9 deletions

View File

@ -138,15 +138,19 @@ public:
if (_cfg.empty()) { if (_cfg.empty()) {
//未获取到aac_cfg信息 //未获取到aac_cfg信息
if (frame->prefixSize()) { if (frame->prefixSize()) {
//7个字节的adts头 //根据7个字节的adts头生成aac config
_cfg = makeAacConfig((uint8_t *) (frame->data()), frame->prefixSize()); _cfg = makeAacConfig((uint8_t *) (frame->data()), frame->prefixSize());
onReady(); onReady();
} else { } else {
WarnL << "无法获取adts头!"; WarnL << "无法获取adts头!";
} }
} }
if (frame->size() > frame->prefixSize()) {
//除adts头外有实际负载
AudioTrack::inputFrame(frame); AudioTrack::inputFrame(frame);
} }
}
private: private:
/** /**
* 2aac配置 * 2aac配置

View File

@ -32,7 +32,6 @@ static string getAacCfg(const RtmpPacket &thiz) {
bool AACRtmpDecoder::inputRtmp(const RtmpPacket::Ptr &pkt, bool) { bool AACRtmpDecoder::inputRtmp(const RtmpPacket::Ptr &pkt, bool) {
if (pkt->isCfgFrame()) { if (pkt->isCfgFrame()) {
_aac_cfg = getAacCfg(*pkt); _aac_cfg = getAacCfg(*pkt);
return false;
} }
if (!_aac_cfg.empty()) { if (!_aac_cfg.empty()) {
onGetAAC(pkt->strBuf.data() + 2, pkt->strBuf.size() - 2, pkt->timeStamp); onGetAAC(pkt->strBuf.data() + 2, pkt->strBuf.size() - 2, pkt->timeStamp);
@ -42,7 +41,6 @@ bool AACRtmpDecoder::inputRtmp(const RtmpPacket::Ptr &pkt, bool) {
void AACRtmpDecoder::onGetAAC(const char* data, int len, uint32_t stamp) { void AACRtmpDecoder::onGetAAC(const char* data, int len, uint32_t stamp) {
auto frame = ResourcePoolHelper<AACFrame>::obtainObj(); auto frame = ResourcePoolHelper<AACFrame>::obtainObj();
//生成adts头 //生成adts头
char adts_header[32] = {0}; char adts_header[32] = {0};
auto size = dumpAacConfig(_aac_cfg, len, (uint8_t *) adts_header, sizeof(adts_header)); auto size = dumpAacConfig(_aac_cfg, len, (uint8_t *) adts_header, sizeof(adts_header));
@ -54,13 +52,17 @@ void AACRtmpDecoder::onGetAAC(const char* data, int len, uint32_t stamp) {
frame->_prefix_size = 0; frame->_prefix_size = 0;
} }
if(len){
//追加负载数据 //追加负载数据
frame->_buffer.append(data, len); frame->_buffer.append(data, len);
frame->_dts = stamp; frame->_dts = stamp;
}
//写入环形缓存 if(size || len){
//有adts头或者实际aac负载
RtmpCodec::inputFrame(frame); RtmpCodec::inputFrame(frame);
} }
}
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////