This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 277f9cb5d8f1b1de4839ea729fa7fa39569c312f
Author:     James Almer <[email protected]>
AuthorDate: Sat Jan 24 21:48:17 2026 -0300
Commit:     James Almer <[email protected]>
CommitDate: Thu Jan 29 21:09:03 2026 -0300

    avformat/cafenc: add init and deinit callbacks
    
    Signed-off-by: James Almer <[email protected]>
---
 libavformat/cafenc.c | 45 +++++++++++++++++++++++++++++++++------------
 1 file changed, 33 insertions(+), 12 deletions(-)

diff --git a/libavformat/cafenc.c b/libavformat/cafenc.c
index ada03836bc..5bee5f74bb 100644
--- a/libavformat/cafenc.c
+++ b/libavformat/cafenc.c
@@ -116,16 +116,11 @@ static uint32_t samples_per_packet(const 
AVCodecParameters *par) {
     }
 }
 
-static int caf_write_header(AVFormatContext *s)
+static int caf_write_init(struct AVFormatContext *s)
 {
-    AVIOContext *pb = s->pb;
     AVStream *const st = s->streams[0];
     AVCodecParameters *par = s->streams[0]->codecpar;
-    CAFContext *caf = s->priv_data;
-    const AVDictionaryEntry *t = NULL;
     unsigned int codec_tag = ff_codec_get_tag(ff_codec_caf_tags, 
par->codec_id);
-    int64_t chunk_size = 0;
-    int sample_rate = par->sample_rate;
 
     switch (par->codec_id) {
     case AV_CODEC_ID_AAC:
@@ -143,6 +138,28 @@ static int caf_write_header(AVFormatContext *s)
         return AVERROR_INVALIDDATA;
     }
 
+    st->priv_data = av_mallocz(sizeof(CAFStreamContext));
+    if (!st->priv_data)
+        return AVERROR(ENOMEM);
+
+    // if either block_align or frame_size are 0, we need to check that the 
output
+    // is seekable. Postpone reporting init as complete until 
caf_write_header()
+    if (!par->block_align || !par->frame_size)
+        return 1;
+
+    return 0;
+}
+
+static int caf_write_header(AVFormatContext *s)
+{
+    AVIOContext *pb = s->pb;
+    AVCodecParameters *par = s->streams[0]->codecpar;
+    CAFContext *caf = s->priv_data;
+    const AVDictionaryEntry *t = NULL;
+    unsigned int codec_tag = ff_codec_get_tag(ff_codec_caf_tags, 
par->codec_id);
+    int64_t chunk_size = 0;
+    int sample_rate = par->sample_rate;
+
     if (!par->block_align && !(pb->seekable & AVIO_SEEKABLE_NORMAL)) {
         av_log(s, AV_LOG_ERROR, "Muxing variable packet size not supported on 
non seekable output\n");
         return AVERROR_INVALIDDATA;
@@ -160,10 +177,6 @@ static int caf_write_header(AVFormatContext *s)
     if (par->codec_id == AV_CODEC_ID_OPUS)
         sample_rate = 48000;
 
-    st->priv_data = av_mallocz(sizeof(CAFStreamContext));
-    if (!st->priv_data)
-        return AVERROR(ENOMEM);
-
     ffio_wfourcc(pb, "caff"); //< mFileType
     avio_wb16(pb, 1);         //< mFileVersion
     avio_wb16(pb, 0);         //< mFileFlags
@@ -334,10 +347,16 @@ static int caf_write_trailer(AVFormatContext *s)
         }
     }
 
+    return 0;
+}
+
+static void caf_write_deinit(AVFormatContext *s)
+{
+    AVStream *st = s->streams[0];
+    CAFStreamContext *caf_st = st->priv_data;
+
     av_freep(&caf_st->byte_size_buffer);
     av_freep(&caf_st->frame_size_buffer);
-
-    return 0;
 }
 
 const FFOutputFormat ff_caf_muxer = {
@@ -350,8 +369,10 @@ const FFOutputFormat ff_caf_muxer = {
     .p.video_codec  = AV_CODEC_ID_NONE,
     .p.subtitle_codec = AV_CODEC_ID_NONE,
     .flags_internal   = FF_OFMT_FLAG_MAX_ONE_OF_EACH,
+    .init           = caf_write_init,
     .write_header   = caf_write_header,
     .write_packet   = caf_write_packet,
     .write_trailer  = caf_write_trailer,
+    .deinit         = caf_write_deinit,
     .p.codec_tag    = ff_caf_codec_tags_list,
 };

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to