Re: [FFmpeg-devel] [PATCH 2/2 v2] avformat/flacenc: add flac_init() and flac_deinit()

2017-11-24 Thread James Almer
On 11/24/2017 8:19 AM, Carl Eugen Hoyos wrote:
> 2017-11-24 4:38 GMT+01:00 James Almer :
>> Signed-off-by: James Almer 
>> ---
>> Simpler/smaller diff.
> 
> Sorry if this is obvious:
> What is the advantage of having these new functions?
> 
> Carl Eugen

Muxers with an init() function can be initialized before the header is
written. deinit() is mainly meant to free any allocated buffer in init()
in case the latter fails, but should ideally also be used to free what
would otherwise be freed in write_trailer().
API users can know if muxing is possible and in some cases have the
output streams initialized with container specific parameters by calling
avformat_init_output() before avformat_write_header() with the above
functions.

ffmpeg.c should ideally be doing the above, so we can remove all the
delayed header writing code in libavformat/mux.c (see the patch i sent
for the latter some time ago).
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2 v2] avformat/flacenc: add flac_init() and flac_deinit()

2017-11-24 Thread Carl Eugen Hoyos
2017-11-24 4:38 GMT+01:00 James Almer :
> Signed-off-by: James Almer 
> ---
> Simpler/smaller diff.

Sorry if this is obvious:
What is the advantage of having these new functions?

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/2 v2] avformat/flacenc: add flac_init() and flac_deinit()

2017-11-23 Thread James Almer
Signed-off-by: James Almer 
---
Simpler/smaller diff.

 libavformat/flacenc.c | 50 +-
 1 file changed, 33 insertions(+), 17 deletions(-)

diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index 84da54a1df..d5fcf96b6b 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -197,11 +197,11 @@ static int flac_finish_header(struct AVFormatContext *s)
 return 0;
 }
 
-static int flac_write_header(struct AVFormatContext *s)
+static int flac_init(struct AVFormatContext *s)
 {
 AVCodecParameters *par;
 FlacMuxerContext *c = s->priv_data;
-int ret, i;
+int i;
 
 c->audio_stream_idx = -1;
 for (i = 0; i < s->nb_streams; i++) {
@@ -233,14 +233,6 @@ static int flac_write_header(struct AVFormatContext *s)
 if (c->nb_pics && !(c->pics = av_calloc(c->nb_pics, sizeof(AVPacket
 return AVERROR(ENOMEM);
 
-if (!c->write_header)
-return 0;
-
-ret = ff_flac_write_header(s->pb, par->extradata,
-   par->extradata_size, 0);
-if (ret)
-return ret;
-
 /* add the channel layout tag */
 if (par->channel_layout &&
 !(par->channel_layout & ~0x3ULL) &&
@@ -258,6 +250,23 @@ static int flac_write_header(struct AVFormatContext *s)
 }
 }
 
+return 0;
+}
+
+static int flac_write_header(struct AVFormatContext *s)
+{
+FlacMuxerContext *c = s->priv_data;
+AVCodecParameters *par = s->streams[c->audio_stream_idx]->codecpar;
+int ret;
+
+if (!c->write_header)
+return 0;
+
+ret = ff_flac_write_header(s->pb, par->extradata,
+   par->extradata_size, 0);
+if (ret < 0)
+return ret;
+
 if (!c->waiting_pics)
 ret = flac_finish_header(s);
 
@@ -313,7 +322,6 @@ static int flac_write_trailer(struct AVFormatContext *s)
 FlacMuxerContext *c = s->priv_data;
 uint8_t *streaminfo = c->streaminfo ? c->streaminfo :
   
s->streams[c->audio_stream_idx]->codecpar->extradata;
-int i;
 
 if (c->waiting_pics) {
 av_log(s, AV_LOG_WARNING, "No packets were sent for some of the "
@@ -321,10 +329,6 @@ static int flac_write_trailer(struct AVFormatContext *s)
 flac_queue_flush(s);
 }
 
-for (i = 0; i < c->nb_pics; i++)
-av_packet_unref(>pics[i]);
-av_freep(>pics);
-
 if (!c->write_header || !streaminfo)
 return 0;
 
@@ -339,11 +343,21 @@ static int flac_write_trailer(struct AVFormatContext *s)
 av_log(s, AV_LOG_WARNING, "unable to rewrite FLAC header.\n");
 }
 
-av_freep(>streaminfo);
-
 return 0;
 }
 
+static void flac_deinit(struct AVFormatContext *s)
+{
+FlacMuxerContext *c = s->priv_data;
+int i;
+
+for (i = 0; i < c->nb_pics; i++)
+av_packet_unref(>pics[i]);
+av_freep(>pics);
+
+av_freep(>streaminfo);
+}
+
 static int flac_write_packet(struct AVFormatContext *s, AVPacket *pkt)
 {
 FlacMuxerContext *c = s->priv_data;
@@ -420,9 +434,11 @@ AVOutputFormat ff_flac_muxer = {
 .extensions= "flac",
 .audio_codec   = AV_CODEC_ID_FLAC,
 .video_codec   = AV_CODEC_ID_PNG,
+.init  = flac_init,
 .write_header  = flac_write_header,
 .write_packet  = flac_write_packet,
 .write_trailer = flac_write_trailer,
+.deinit= flac_deinit,
 .flags = AVFMT_NOTIMESTAMPS,
 .priv_class= _muxer_class,
 };
-- 
2.15.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel