diff mbox

[FFmpeg-devel] avformat/oggenc: add ogg_init() and ogg_free()

Message ID 20170528200944.6852-1-jamrial@gmail.com
State Accepted
Commit 3c5a53cdfa099bba8bd951f95b85727b4b3b5d68
Headers show

Commit Message

James Almer May 28, 2017, 8:09 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/oggenc.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

Comments

James Almer June 3, 2017, 5:39 p.m. UTC | #1
On 5/28/2017 5:09 PM, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/oggenc.c | 32 ++++++++++++++++++++++++++++----
>  1 file changed, 28 insertions(+), 4 deletions(-)
> 

Ping for this and the aiff one.

I have a set of about 50 patches to do the same with almost every other
muxer, but i want to know if the approach is correct or not before
sending it.
The idea is making avformat_init_output() more useful and eventually
adapting ffmpeg.c to use it to initialize the muxers and do its thing
before the need to actually write the header comes up.
James Almer June 16, 2017, 10:17 p.m. UTC | #2
On 6/3/2017 2:39 PM, James Almer wrote:
> On 5/28/2017 5:09 PM, James Almer wrote:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  libavformat/oggenc.c | 32 ++++++++++++++++++++++++++++----
>>  1 file changed, 28 insertions(+), 4 deletions(-)
>>
> 
> Ping for this and the aiff one.
> 
> I have a set of about 50 patches to do the same with almost every other
> muxer, but i want to know if the approach is correct or not before
> sending it.
> The idea is making avformat_init_output() more useful and eventually
> adapting ffmpeg.c to use it to initialize the muxers and do its thing
> before the need to actually write the header comes up.

No comments? I don't really feel like risking pushing 50+ patches
without at least someone commenting on it.
Michael Niedermayer June 18, 2017, 9:22 p.m. UTC | #3
On Sun, May 28, 2017 at 05:09:44PM -0300, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/oggenc.c | 32 ++++++++++++++++++++++++++++----
>  1 file changed, 28 insertions(+), 4 deletions(-)

LGTM

thx

[...]
James Almer June 19, 2017, 12:02 a.m. UTC | #4
On 6/18/2017 6:22 PM, Michael Niedermayer wrote:
> On Sun, May 28, 2017 at 05:09:44PM -0300, James Almer wrote:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  libavformat/oggenc.c | 32 ++++++++++++++++++++++++++++----
>>  1 file changed, 28 insertions(+), 4 deletions(-)
> 
> LGTM
> 
> thx

Pushed, thanks.
diff mbox

Patch

diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c
index 0713a13a70..7c1115afd6 100644
--- a/libavformat/oggenc.c
+++ b/libavformat/oggenc.c
@@ -483,7 +483,7 @@  static void ogg_write_pages(AVFormatContext *s, int flush)
     ogg->page_list = p;
 }
 
-static int ogg_write_header(AVFormatContext *s)
+static int ogg_init(AVFormatContext *s)
 {
     OGGContext *ogg = s->priv_data;
     OGGStreamContext *oggstream = NULL;
@@ -617,8 +617,16 @@  static int ogg_write_header(AVFormatContext *s)
         }
     }
 
+    return 0;
+}
+
+static int ogg_write_header(AVFormatContext *s)
+{
+    OGGStreamContext *oggstream = NULL;
+    int i, j;
+
     for (j = 0; j < s->nb_streams; j++) {
-        OGGStreamContext *oggstream = s->streams[j]->priv_data;
+        oggstream = s->streams[j]->priv_data;
         ogg_buffer_data(s, s->streams[j], oggstream->header[0],
                         oggstream->header_len[0], 0, 1);
         oggstream->page.flags |= 2; // bos
@@ -626,7 +634,7 @@  static int ogg_write_header(AVFormatContext *s)
     }
     for (j = 0; j < s->nb_streams; j++) {
         AVStream *st = s->streams[j];
-        OGGStreamContext *oggstream = st->priv_data;
+        oggstream = st->priv_data;
         for (i = 1; i < 3; i++) {
             if (oggstream->header_len[i])
                 ogg_buffer_data(s, st, oggstream->header[i],
@@ -725,6 +733,13 @@  static int ogg_write_trailer(AVFormatContext *s)
 
     ogg_write_pages(s, 1);
 
+    return 0;
+}
+
+static void ogg_free(AVFormatContext *s)
+{
+    int i;
+
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st = s->streams[i];
         OGGStreamContext *oggstream = st->priv_data;
@@ -737,7 +752,6 @@  static int ogg_write_trailer(AVFormatContext *s)
         av_freep(&oggstream->header[1]);
         av_freep(&st->priv_data);
     }
-    return 0;
 }
 
 #if CONFIG_OGG_MUXER
@@ -761,9 +775,11 @@  AVOutputFormat ff_ogg_muxer = {
     .audio_codec       = CONFIG_LIBVORBIS_ENCODER ?
                          AV_CODEC_ID_VORBIS : AV_CODEC_ID_FLAC,
     .video_codec       = AV_CODEC_ID_THEORA,
+    .init              = ogg_init,
     .write_header      = ogg_write_header,
     .write_packet      = ogg_write_packet,
     .write_trailer     = ogg_write_trailer,
+    .deinit            = ogg_free,
     .flags             = AVFMT_TS_NEGATIVE | AVFMT_TS_NONSTRICT | AVFMT_ALLOW_FLUSH,
     .priv_class        = &ogg_muxer_class,
 };
@@ -778,9 +794,11 @@  AVOutputFormat ff_oga_muxer = {
     .extensions        = "oga",
     .priv_data_size    = sizeof(OGGContext),
     .audio_codec       = AV_CODEC_ID_FLAC,
+    .init              = ogg_init,
     .write_header      = ogg_write_header,
     .write_packet      = ogg_write_packet,
     .write_trailer     = ogg_write_trailer,
+    .deinit            = ogg_free,
     .flags             = AVFMT_TS_NEGATIVE | AVFMT_ALLOW_FLUSH,
     .priv_class        = &oga_muxer_class,
 };
@@ -798,9 +816,11 @@  AVOutputFormat ff_ogv_muxer = {
                          AV_CODEC_ID_VORBIS : AV_CODEC_ID_FLAC,
     .video_codec       = CONFIG_LIBTHEORA_ENCODER ?
                          AV_CODEC_ID_THEORA : AV_CODEC_ID_VP8,
+    .init              = ogg_init,
     .write_header      = ogg_write_header,
     .write_packet      = ogg_write_packet,
     .write_trailer     = ogg_write_trailer,
+    .deinit            = ogg_free,
     .flags             = AVFMT_TS_NEGATIVE | AVFMT_TS_NONSTRICT | AVFMT_ALLOW_FLUSH,
     .priv_class        = &ogv_muxer_class,
 };
@@ -815,9 +835,11 @@  AVOutputFormat ff_spx_muxer = {
     .extensions        = "spx",
     .priv_data_size    = sizeof(OGGContext),
     .audio_codec       = AV_CODEC_ID_SPEEX,
+    .init              = ogg_init,
     .write_header      = ogg_write_header,
     .write_packet      = ogg_write_packet,
     .write_trailer     = ogg_write_trailer,
+    .deinit            = ogg_free,
     .flags             = AVFMT_TS_NEGATIVE | AVFMT_ALLOW_FLUSH,
     .priv_class        = &spx_muxer_class,
 };
@@ -832,9 +854,11 @@  AVOutputFormat ff_opus_muxer = {
     .extensions        = "opus",
     .priv_data_size    = sizeof(OGGContext),
     .audio_codec       = AV_CODEC_ID_OPUS,
+    .init              = ogg_init,
     .write_header      = ogg_write_header,
     .write_packet      = ogg_write_packet,
     .write_trailer     = ogg_write_trailer,
+    .deinit            = ogg_free,
     .flags             = AVFMT_TS_NEGATIVE | AVFMT_ALLOW_FLUSH,
     .priv_class        = &opus_muxer_class,
 };