aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/movenc.c
diff options
context:
space:
mode:
authorBenoit Fouet <benoit.fouet@free.fr>2014-10-13 09:35:11 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-10-13 19:24:06 +0200
commitf87134c7a13f96f40160831e5b72e271e66a9730 (patch)
tree301d5d0b77eca67bd1ea85bcd4146e51e350d7ab /libavformat/movenc.c
parent4da7111eb8382c9fa5b464c0a62d12d497f7018a (diff)
downloadffmpeg-f87134c7a13f96f40160831e5b72e271e66a9730.tar.gz
avformat/movenc: add support for syncframes concatenation for E-AC-3.
E-AC-3 samples should contain 6 audio blocks, so concatenate syncframes in order to achieve this. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/movenc.c')
-rw-r--r--libavformat/movenc.c43
1 files changed, 37 insertions, 6 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 7b1554ed8f..d8b8517920 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -295,7 +295,9 @@ static int mov_write_ac3_tag(AVIOContext *pb, MOVTrack *track)
}
struct eac3_info {
+ AVPacket pkt;
uint8_t ec3_done;
+ uint8_t num_blocks;
/* Layout of the EC3SpecificBox */
/* maximum bitrate */
@@ -412,11 +414,34 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track)
}
}
-/* TODO: concatenate syncframes to have 6 blocks per entry */
concatenate:
- if (num_blocks != 6) {
- avpriv_request_sample(track->enc, "%d block(s) in syncframe", num_blocks);
- return AVERROR_PATCHWELCOME;
+ if (!info->num_blocks && num_blocks == 6)
+ return pkt->size;
+ else if (info->num_blocks + num_blocks > 6)
+ return AVERROR_INVALIDDATA;
+
+ if (!info->num_blocks) {
+ int ret;
+ if ((ret = av_copy_packet(&info->pkt, pkt)) < 0)
+ return ret;
+ info->num_blocks = num_blocks;
+ return 0;
+ } else {
+ int ret;
+ if ((ret = av_grow_packet(&info->pkt, pkt->size)) < 0)
+ return ret;
+ memcpy(info->pkt.data + info->pkt.size - pkt->size, pkt->data, pkt->size);
+ info->num_blocks += num_blocks;
+ info->pkt.duration += pkt->duration;
+ if ((ret = av_copy_packet_side_data(&info->pkt, pkt)) < 0)
+ return ret;
+ if (info->num_blocks != 6)
+ return 0;
+ av_free_packet(pkt);
+ if ((ret = av_copy_packet(pkt, &info->pkt)) < 0)
+ return ret;
+ av_free_packet(&info->pkt);
+ info->num_blocks = 0;
}
return pkt->size;
@@ -436,8 +461,8 @@ static int mov_write_eac3_tag(AVIOContext *pb, MOVTrack *track)
size = 2 + 4 * (info->num_ind_sub + 1);
buf = av_malloc(size);
if (!buf) {
- av_freep(&track->eac3_priv);
- return AVERROR(ENOMEM);
+ size = AVERROR(ENOMEM);
+ goto end;
}
init_put_bits(&pbc, buf, size);
@@ -467,6 +492,9 @@ static int mov_write_eac3_tag(AVIOContext *pb, MOVTrack *track)
avio_write(pb, buf, size);
av_free(buf);
+
+end:
+ av_free_packet(&info->pkt);
av_freep(&track->eac3_priv);
return size;
@@ -3810,6 +3838,8 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
size = handle_eac3(mov, pkt, trk);
if (size < 0)
return size;
+ else if (!size)
+ goto end;
avio_write(pb, pkt->data, size);
} else {
avio_write(pb, pkt->data, size);
@@ -3889,6 +3919,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams)
ff_mov_add_hinted_packet(s, pkt, trk->hint_track, trk->entry,
reformatted_data, size);
+end:
av_free(reformatted_data);
return 0;
}