avformat/movenc: let avpriv_ac3_parse_header() allocate the AC3HeaderInfo struct

This removes sizeof(AC3HeaderInfo) from the ABI.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
pull/272/head
James Almer 8 years ago
parent 40d635e8c3
commit 502050cb4c
  1. 72
      libavformat/movenc.c

@ -345,9 +345,9 @@ struct eac3_info {
#if CONFIG_AC3_PARSER #if CONFIG_AC3_PARSER
static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track) static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track)
{ {
AC3HeaderInfo tmp, *hdr = &tmp; AC3HeaderInfo *hdr = NULL;
struct eac3_info *info; struct eac3_info *info;
int num_blocks; int num_blocks, ret;
if (!track->eac3_priv && !(track->eac3_priv = av_mallocz(sizeof(*info)))) if (!track->eac3_priv && !(track->eac3_priv = av_mallocz(sizeof(*info))))
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -357,9 +357,10 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track)
/* drop the packets until we see a good one */ /* drop the packets until we see a good one */
if (!track->entry) { if (!track->entry) {
av_log(mov, AV_LOG_WARNING, "Dropping invalid packet from start of the stream\n"); av_log(mov, AV_LOG_WARNING, "Dropping invalid packet from start of the stream\n");
return 0; ret = 0;
} } else
return AVERROR_INVALIDDATA; ret = AVERROR_INVALIDDATA;
goto end;
} }
info->data_rate = FFMAX(info->data_rate, hdr->bit_rate / 1000); info->data_rate = FFMAX(info->data_rate, hdr->bit_rate / 1000);
@ -367,20 +368,25 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track)
if (!info->ec3_done) { if (!info->ec3_done) {
/* AC-3 substream must be the first one */ /* AC-3 substream must be the first one */
if (hdr->bitstream_id <= 10 && hdr->substreamid != 0) if (hdr->bitstream_id <= 10 && hdr->substreamid != 0) {
return AVERROR(EINVAL); ret = AVERROR(EINVAL);
goto end;
}
/* this should always be the case, given that our AC-3 parser /* this should always be the case, given that our AC-3 parser
* concatenates dependent frames to their independent parent */ * concatenates dependent frames to their independent parent */
if (hdr->frame_type == EAC3_FRAME_TYPE_INDEPENDENT) { if (hdr->frame_type == EAC3_FRAME_TYPE_INDEPENDENT) {
/* substream ids must be incremental */ /* substream ids must be incremental */
if (hdr->substreamid > info->num_ind_sub + 1) if (hdr->substreamid > info->num_ind_sub + 1) {
return AVERROR(EINVAL); ret = AVERROR(EINVAL);
goto end;
}
if (hdr->substreamid == info->num_ind_sub + 1) { if (hdr->substreamid == info->num_ind_sub + 1) {
//info->num_ind_sub++; //info->num_ind_sub++;
avpriv_request_sample(track->par, "Multiple independent substreams"); avpriv_request_sample(track->par, "Multiple independent substreams");
return AVERROR_PATCHWELCOME; ret = AVERROR_PATCHWELCOME;
goto end;
} else if (hdr->substreamid < info->num_ind_sub || } else if (hdr->substreamid < info->num_ind_sub ||
hdr->substreamid == 0 && info->substream[0].bsid) { hdr->substreamid == 0 && info->substream[0].bsid) {
info->ec3_done = 1; info->ec3_done = 1;
@ -402,12 +408,14 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track)
while (cumul_size != pkt->size) { while (cumul_size != pkt->size) {
GetBitContext gbc; GetBitContext gbc;
int i, ret; int i;
ret = avpriv_ac3_parse_header(&hdr, pkt->data + cumul_size, pkt->size - cumul_size); ret = avpriv_ac3_parse_header(&hdr, pkt->data + cumul_size, pkt->size - cumul_size);
if (ret < 0) if (ret < 0)
return AVERROR_INVALIDDATA; goto end;
if (hdr->frame_type != EAC3_FRAME_TYPE_DEPENDENT) if (hdr->frame_type != EAC3_FRAME_TYPE_DEPENDENT) {
return AVERROR(EINVAL); ret = AVERROR(EINVAL);
goto end;
}
info->substream[parent].num_dep_sub++; info->substream[parent].num_dep_sub++;
ret /= 8; ret /= 8;
@ -433,37 +441,43 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track)
} }
concatenate: concatenate:
if (!info->num_blocks && num_blocks == 6) if (!info->num_blocks && num_blocks == 6) {
return pkt->size; ret = pkt->size;
else if (info->num_blocks + num_blocks > 6) goto end;
return AVERROR_INVALIDDATA; }
else if (info->num_blocks + num_blocks > 6) {
ret = AVERROR_INVALIDDATA;
goto end;
}
if (!info->num_blocks) { if (!info->num_blocks) {
int ret = av_packet_ref(&info->pkt, pkt); ret = av_packet_ref(&info->pkt, pkt);
if (ret < 0) if (!ret)
return ret; info->num_blocks = num_blocks;
info->num_blocks = num_blocks; goto end;
return 0;
} else { } else {
int ret;
if ((ret = av_grow_packet(&info->pkt, pkt->size)) < 0) if ((ret = av_grow_packet(&info->pkt, pkt->size)) < 0)
return ret; goto end;
memcpy(info->pkt.data + info->pkt.size - pkt->size, pkt->data, pkt->size); memcpy(info->pkt.data + info->pkt.size - pkt->size, pkt->data, pkt->size);
info->num_blocks += num_blocks; info->num_blocks += num_blocks;
info->pkt.duration += pkt->duration; info->pkt.duration += pkt->duration;
if ((ret = av_copy_packet_side_data(&info->pkt, pkt)) < 0) if ((ret = av_copy_packet_side_data(&info->pkt, pkt)) < 0)
return ret; goto end;
if (info->num_blocks != 6) if (info->num_blocks != 6)
return 0; goto end;
av_packet_unref(pkt); av_packet_unref(pkt);
ret = av_packet_ref(pkt, &info->pkt); ret = av_packet_ref(pkt, &info->pkt);
if (ret < 0) if (ret < 0)
return ret; goto end;
av_packet_unref(&info->pkt); av_packet_unref(&info->pkt);
info->num_blocks = 0; info->num_blocks = 0;
} }
ret = pkt->size;
end:
av_free(hdr);
return pkt->size; return ret;
} }
#endif #endif

Loading…
Cancel
Save