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

View File

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