diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-06-01 14:16:29 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-06-01 14:16:29 +0200 |
commit | 955b31a7513e924cce36e484dc098581290af9b6 (patch) | |
tree | f063480e25161f2038c50e9106c0a9666beebb50 | |
parent | 855e3b5700fff78bf20f900daade58396b73846d (diff) | |
parent | e19d48dfce52f1417f7f06143b96fed00cbcdc52 (diff) | |
download | ffmpeg-955b31a7513e924cce36e484dc098581290af9b6.tar.gz |
Merge commit 'e19d48dfce52f1417f7f06143b96fed00cbcdc52'
* commit 'e19d48dfce52f1417f7f06143b96fed00cbcdc52':
flac muxer: support reading updated extradata from side data
Conflicts:
libavformat/flacenc.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavformat/flacenc.c | 37 | ||||
-rw-r--r-- | libavformat/flacenc.h | 4 | ||||
-rw-r--r-- | libavformat/flacenc_header.c | 8 | ||||
-rw-r--r-- | libavformat/matroskaenc.c | 3 |
4 files changed, 37 insertions, 15 deletions
diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c index ae8e171fb1..b3695a27ba 100644 --- a/libavformat/flacenc.c +++ b/libavformat/flacenc.c @@ -32,6 +32,9 @@ typedef struct FlacMuxerContext { const AVClass *class; int write_header; + + /* updated streaminfo sent by the encoder at the end */ + uint8_t *streaminfo; } FlacMuxerContext; static int flac_write_block_padding(AVIOContext *pb, unsigned int n_padding_bytes, @@ -94,7 +97,8 @@ static int flac_write_header(struct AVFormatContext *s) * size of a metadata block so we must clip this value to 2^24-1. */ padding = av_clip_c(padding, 0, 16777215); - ret = ff_flac_write_header(s->pb, codec, 0); + ret = ff_flac_write_header(s->pb, codec->extradata, + codec->extradata_size, 0); if (ret) return ret; @@ -133,17 +137,14 @@ static int flac_write_header(struct AVFormatContext *s) static int flac_write_trailer(struct AVFormatContext *s) { AVIOContext *pb = s->pb; - uint8_t *streaminfo; - enum FLACExtradataFormat format; int64_t file_size; FlacMuxerContext *c = s->priv_data; + uint8_t *streaminfo = c->streaminfo ? c->streaminfo : + s->streams[0]->codec->extradata; - if (!c->write_header) + if (!c->write_header || !streaminfo) return 0; - if (!avpriv_flac_is_extradata_valid(s->streams[0]->codec, &format, &streaminfo)) - return -1; - if (pb->seekable) { /* rewrite the STREAMINFO header block data */ file_size = avio_tell(pb); @@ -154,12 +155,32 @@ static int flac_write_trailer(struct AVFormatContext *s) } else { av_log(s, AV_LOG_WARNING, "unable to rewrite FLAC header.\n"); } + + av_freep(&c->streaminfo); + return 0; } static int flac_write_packet(struct AVFormatContext *s, AVPacket *pkt) { - avio_write(s->pb, pkt->data, pkt->size); + FlacMuxerContext *c = s->priv_data; + uint8_t *streaminfo; + int streaminfo_size; + + /* check for updated streaminfo */ + streaminfo = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, + &streaminfo_size); + if (streaminfo && streaminfo_size == FLAC_STREAMINFO_SIZE) { + av_freep(&c->streaminfo); + + c->streaminfo = av_malloc(FLAC_STREAMINFO_SIZE); + if (!c->streaminfo) + return AVERROR(ENOMEM); + memcpy(c->streaminfo, streaminfo, FLAC_STREAMINFO_SIZE); + } + + if (pkt->size) + avio_write(s->pb, pkt->data, pkt->size); return 0; } diff --git a/libavformat/flacenc.h b/libavformat/flacenc.h index 2e9ee37766..d5d53a5dcb 100644 --- a/libavformat/flacenc.h +++ b/libavformat/flacenc.h @@ -26,8 +26,8 @@ #include "libavcodec/bytestream.h" #include "avformat.h" -int ff_flac_write_header(AVIOContext *pb, AVCodecContext *codec, - int last_block); +int ff_flac_write_header(AVIOContext *pb, uint8_t *extradata, + int extradata_size, int last_block); int ff_flac_is_native_layout(uint64_t channel_layout); diff --git a/libavformat/flacenc_header.c b/libavformat/flacenc_header.c index 3fb28c9e3b..61833cc8b9 100644 --- a/libavformat/flacenc_header.c +++ b/libavformat/flacenc_header.c @@ -26,8 +26,8 @@ #include "avformat.h" #include "flacenc.h" -int ff_flac_write_header(AVIOContext *pb, AVCodecContext *codec, - int last_block) +int ff_flac_write_header(AVIOContext *pb, uint8_t *extradata, + int extradata_size, int last_block) { uint8_t header[8] = { 0x66, 0x4C, 0x61, 0x43, 0x00, 0x00, 0x00, 0x22 @@ -35,14 +35,14 @@ int ff_flac_write_header(AVIOContext *pb, AVCodecContext *codec, header[4] = last_block ? 0x80 : 0x00; - if (codec->extradata_size < FLAC_STREAMINFO_SIZE) + if (extradata_size < FLAC_STREAMINFO_SIZE) return AVERROR_INVALIDDATA; /* write "fLaC" stream marker and first metadata block header */ avio_write(pb, header, 8); /* write STREAMINFO */ - avio_write(pb, codec->extradata, FLAC_STREAMINFO_SIZE); + avio_write(pb, extradata, FLAC_STREAMINFO_SIZE); return 0; } diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index fb26d9535b..3f88346e2e 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -514,7 +514,8 @@ static int put_flac_codecpriv(AVFormatContext *s, int write_comment = (codec->channel_layout && !(codec->channel_layout & ~0x3ffffULL) && !ff_flac_is_native_layout(codec->channel_layout)); - int ret = ff_flac_write_header(pb, codec, !write_comment); + int ret = ff_flac_write_header(pb, codec->extradata, codec->extradata_size, + !write_comment); if (ret < 0) return ret; |