The branch, release/7.1 has been updated
       via  bd4191a5670563c1062a7b357058cba5f726abc6 (commit)
      from  8f77695e65a69c8009804e9d457762d2d394403d (commit)


- Log -----------------------------------------------------------------
commit bd4191a5670563c1062a7b357058cba5f726abc6
Author:     James Almer <[email protected]>
AuthorDate: Mon Oct 27 16:18:17 2025 -0300
Commit:     James Almer <[email protected]>
CommitDate: Tue Oct 28 11:45:26 2025 -0300

    avformat/demux: pass new extradata to the parser
    
    The parser API doesn't work with packets, only raw data, so in order for it 
to
    be made aware of new extradata propagated through packet side data we need 
to
    pass it in some other form, namely, replacing the main extradata and 
ensuring
    it will be parsed by restarting the parser.
    
    Signed-off-by: James Almer <[email protected]>

diff --git a/libavformat/demux.c b/libavformat/demux.c
index 4fd22c4934..2796209239 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -1159,7 +1159,10 @@ static int parse_packet(AVFormatContext *s, AVPacket 
*pkt,
     AVPacket *out_pkt = si->parse_pkt;
     AVStream *st = s->streams[stream_index];
     FFStream *const sti = ffstream(st);
+    const AVPacketSideData *sd = NULL;
     const uint8_t *data = pkt->data;
+    uint8_t *extradata = sti->avctx->extradata;
+    int extradata_size = sti->avctx->extradata_size;
     int size = pkt->size;
     int ret = 0, got_output = flush;
 
@@ -1168,6 +1171,16 @@ static int parse_packet(AVFormatContext *s, AVPacket 
*pkt,
         compute_pkt_fields(s, st, sti->parser, pkt, AV_NOPTS_VALUE, 
AV_NOPTS_VALUE);
     }
 
+    if (pkt->side_data_elems)
+        sd = av_packet_side_data_get(pkt->side_data, pkt->side_data_elems,
+                                     AV_PKT_DATA_NEW_EXTRADATA);
+    if (sd) {
+        av_assert1(size && !flush);
+
+        sti->avctx->extradata      = sd->data;
+        sti->avctx->extradata_size = sd->size;
+    }
+
     while (size > 0 || (flush && got_output)) {
         int64_t next_pts = pkt->pts;
         int64_t next_dts = pkt->dts;
@@ -1261,6 +1274,11 @@ static int parse_packet(AVFormatContext *s, AVPacket 
*pkt,
     }
 
 fail:
+    if (sd) {
+        sti->avctx->extradata      = extradata;
+        sti->avctx->extradata_size = extradata_size;
+    }
+
     if (ret < 0)
         av_packet_unref(out_pkt);
     av_packet_unref(pkt);
@@ -1353,6 +1371,11 @@ static int read_frame_internal(AVFormatContext *s, 
AVPacket *pkt)
 
         st->event_flags |= AVSTREAM_EVENT_FLAG_NEW_PACKETS;
 
+        int new_extradata = !!av_packet_side_data_get(pkt->side_data, 
pkt->side_data_elems,
+                                                      
AV_PKT_DATA_NEW_EXTRADATA);
+        if (new_extradata)
+            sti->need_context_update = 1;
+
         /* update context if required */
         if (sti->need_context_update) {
             if (avcodec_is_open(sti->avctx)) {
@@ -1363,8 +1386,9 @@ static int read_frame_internal(AVFormatContext *s, 
AVPacket *pkt)
                     return ret;
             }
 
-            /* close parser, because it depends on the codec */
-            if (sti->parser && sti->avctx->codec_id != st->codecpar->codec_id) 
{
+            /* close parser, because it depends on the codec and extradata */
+            if (sti->parser &&
+                (sti->avctx->codec_id != st->codecpar->codec_id || 
new_extradata)) {
                 av_parser_close(sti->parser);
                 sti->parser = NULL;
             }

-----------------------------------------------------------------------

Summary of changes:
 libavformat/demux.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)


hooks/post-receive
-- 

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

Reply via email to