[FFmpeg-devel] [PATCH 19/25] avformat/mux, mxfenc, utils: Use dedicated pointer for AVFormatInternal

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Fri Aug 27 17:27:19 EEST 2021


This gets rid of ugly "->internal" and is in preparation for removing
AVFormatInternal altogether.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavformat/mux.c    |  80 +++++++++++++-------------
 libavformat/mxfenc.c |  15 ++---
 libavformat/utils.c  | 133 ++++++++++++++++++++++++-------------------
 3 files changed, 124 insertions(+), 104 deletions(-)

diff --git a/libavformat/mux.c b/libavformat/mux.c
index a05deb3f0b..036a1956f6 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -433,10 +433,11 @@ static void flush_if_needed(AVFormatContext *s)
 
 static void deinit_muxer(AVFormatContext *s)
 {
-    if (s->oformat && s->oformat->deinit && s->internal->initialized)
+    AVFormatInternal *const si = s->internal;
+    if (s->oformat && s->oformat->deinit && si->initialized)
         s->oformat->deinit(s);
-    s->internal->initialized =
-    s->internal->streams_initialized = 0;
+    si->initialized =
+    si->streams_initialized = 0;
 }
 
 int avformat_init_output(AVFormatContext *s, AVDictionary **options)
@@ -462,8 +463,9 @@ int avformat_init_output(AVFormatContext *s, AVDictionary **options)
 int avformat_write_header(AVFormatContext *s, AVDictionary **options)
 {
     int ret = 0;
-    int already_initialized = s->internal->initialized;
-    int streams_already_initialized = s->internal->streams_initialized;
+    AVFormatInternal *const si = s->internal;
+    int already_initialized = si->initialized;
+    int streams_already_initialized = si->streams_initialized;
 
     if (!already_initialized)
         if ((ret = avformat_init_output(s, options)) < 0)
@@ -482,7 +484,7 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options)
     if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
         avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_UNKNOWN);
 
-    if (!s->internal->streams_initialized) {
+    if (!si->streams_initialized) {
         if ((ret = init_pts(s)) < 0)
             goto fail;
     }
@@ -650,20 +652,21 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
     }
 
     if (s->avoid_negative_ts > 0) {
+        AVFormatInternal *const si = s->internal;
         AVStream *st = s->streams[pkt->stream_index];
         int64_t offset = st->internal->mux_ts_offset;
-        int64_t ts = s->internal->avoid_negative_ts_use_pts ? pkt->pts : pkt->dts;
+        int64_t ts = si->avoid_negative_ts_use_pts ? pkt->pts : pkt->dts;
 
-        if (s->internal->offset == AV_NOPTS_VALUE && ts != AV_NOPTS_VALUE &&
+        if (si->offset == AV_NOPTS_VALUE && ts != AV_NOPTS_VALUE &&
             (ts < 0 || s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO)) {
-            s->internal->offset = -ts;
-            s->internal->offset_timebase = st->time_base;
+            si->offset = -ts;
+            si->offset_timebase = st->time_base;
         }
 
-        if (s->internal->offset != AV_NOPTS_VALUE && !offset) {
+        if (si->offset != AV_NOPTS_VALUE && !offset) {
             offset = st->internal->mux_ts_offset =
-                av_rescale_q_rnd(s->internal->offset,
-                                 s->internal->offset_timebase,
+                av_rescale_q_rnd(si->offset,
+                                 si->offset_timebase,
                                  st->time_base,
                                  AV_ROUND_UP);
         }
@@ -673,7 +676,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
         if (pkt->pts != AV_NOPTS_VALUE)
             pkt->pts += offset;
 
-        if (s->internal->avoid_negative_ts_use_pts) {
+        if (si->avoid_negative_ts_use_pts) {
             if (pkt->pts != AV_NOPTS_VALUE && pkt->pts < 0) {
                 av_log(s, AV_LOG_WARNING, "failed to avoid negative "
                     "pts %s in stream %d.\n"
@@ -786,6 +789,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
                              int (*compare)(AVFormatContext *, const AVPacket *, const AVPacket *))
 {
     int ret;
+    AVFormatInternal *const si = s->internal;
     PacketList **next_point, *this_pktl;
     AVStream *st = s->streams[pkt->stream_index];
     int chunked  = s->max_chunk_size || s->max_chunk_duration;
@@ -807,7 +811,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
     if (st->internal->last_in_packet_buffer) {
         next_point = &(st->internal->last_in_packet_buffer->next);
     } else {
-        next_point = &s->internal->packet_buffer;
+        next_point = &si->packet_buffer;
     }
 
     if (chunked) {
@@ -831,7 +835,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
         if (chunked && !(pkt->flags & CHUNK_START))
             goto next_non_null;
 
-        if (compare(s, &s->internal->packet_buffer_end->pkt, pkt)) {
+        if (compare(s, &si->packet_buffer_end->pkt, pkt)) {
             while (   *next_point
                    && ((chunked && !((*next_point)->pkt.flags&CHUNK_START))
                        || !compare(s, &(*next_point)->pkt, pkt)))
@@ -839,12 +843,12 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
             if (*next_point)
                 goto next_non_null;
         } else {
-            next_point = &(s->internal->packet_buffer_end->next);
+            next_point = &(si->packet_buffer_end->next);
         }
     }
     av_assert1(!*next_point);
 
-    s->internal->packet_buffer_end = this_pktl;
+    si->packet_buffer_end = this_pktl;
 next_non_null:
 
     this_pktl->next = *next_point;
@@ -887,6 +891,7 @@ static int interleave_compare_dts(AVFormatContext *s, const AVPacket *next,
 int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
                                  AVPacket *pkt, int flush)
 {
+    AVFormatInternal *const si = s->internal;
     int stream_count = 0;
     int noninterleaved_count = 0;
     int ret;
@@ -907,15 +912,15 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
         }
     }
 
-    if (s->internal->nb_interleaved_streams == stream_count)
+    if (si->nb_interleaved_streams == stream_count)
         flush = 1;
 
     if (s->max_interleave_delta > 0 &&
-        s->internal->packet_buffer &&
+        si->packet_buffer &&
         !flush &&
-        s->internal->nb_interleaved_streams == stream_count+noninterleaved_count
+        si->nb_interleaved_streams == stream_count+noninterleaved_count
     ) {
-        AVPacket *top_pkt = &s->internal->packet_buffer->pkt;
+        AVPacket *const top_pkt = &si->packet_buffer->pkt;
         int64_t delta_dts = INT64_MIN;
         int64_t top_dts = av_rescale_q(top_pkt->dts,
                                        s->streams[top_pkt->stream_index]->time_base,
@@ -943,31 +948,31 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
         }
     }
 
-    if (s->internal->packet_buffer &&
+    if (si->packet_buffer &&
         eof &&
         (s->flags & AVFMT_FLAG_SHORTEST) &&
-        s->internal->shortest_end == AV_NOPTS_VALUE) {
-        AVPacket *top_pkt = &s->internal->packet_buffer->pkt;
+        si->shortest_end == AV_NOPTS_VALUE) {
+        AVPacket *const top_pkt = &si->packet_buffer->pkt;
 
-        s->internal->shortest_end = av_rescale_q(top_pkt->dts,
+        si->shortest_end = av_rescale_q(top_pkt->dts,
                                        s->streams[top_pkt->stream_index]->time_base,
                                        AV_TIME_BASE_Q);
     }
 
-    if (s->internal->shortest_end != AV_NOPTS_VALUE) {
-        while (s->internal->packet_buffer) {
-            PacketList *pktl = s->internal->packet_buffer;
+    if (si->shortest_end != AV_NOPTS_VALUE) {
+        while (si->packet_buffer) {
+            PacketList *pktl = si->packet_buffer;
             AVPacket *const top_pkt = &pktl->pkt;
             AVStream *const st = s->streams[top_pkt->stream_index];
             int64_t top_dts = av_rescale_q(top_pkt->dts, st->time_base,
                                         AV_TIME_BASE_Q);
 
-            if (s->internal->shortest_end + 1 >= top_dts)
+            if (si->shortest_end + 1 >= top_dts)
                 break;
 
-            s->internal->packet_buffer = pktl->next;
-            if (!s->internal->packet_buffer)
-                s->internal->packet_buffer_end = NULL;
+            si->packet_buffer = pktl->next;
+            if (!si->packet_buffer)
+                si->packet_buffer_end = NULL;
 
             if (st->internal->last_in_packet_buffer == pktl)
                 st->internal->last_in_packet_buffer = NULL;
@@ -979,14 +984,13 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
     }
 
     if (stream_count && flush) {
-        PacketList *pktl = s->internal->packet_buffer;
+        PacketList *pktl = si->packet_buffer;
         AVStream *const st = s->streams[pktl->pkt.stream_index];
-
         *out = pktl->pkt;
 
-        s->internal->packet_buffer = pktl->next;
-        if (!s->internal->packet_buffer)
-            s->internal->packet_buffer_end = NULL;
+        si->packet_buffer = pktl->next;
+        if (!si->packet_buffer)
+            si->packet_buffer_end = NULL;
 
         if (st->internal->last_in_packet_buffer == pktl)
             st->internal->last_in_packet_buffer = NULL;
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 229817dba6..36f334adbf 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -3100,13 +3100,14 @@ static void mxf_deinit(AVFormatContext *s)
 
 static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)
 {
+    AVFormatInternal *const si = s->internal;
     int i, stream_count = 0;
 
     for (i = 0; i < s->nb_streams; i++)
         stream_count += !!s->streams[i]->internal->last_in_packet_buffer;
 
     if (stream_count && (s->nb_streams == stream_count || flush)) {
-        PacketList *pktl = s->internal->packet_buffer;
+        PacketList *pktl = si->packet_buffer;
         if (s->nb_streams != stream_count) {
             PacketList *last = NULL;
             // find last packet in edit unit
@@ -3130,20 +3131,20 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket
             if (last)
                 last->next = NULL;
             else {
-                s->internal->packet_buffer = NULL;
-                s->internal->packet_buffer_end= NULL;
+                si->packet_buffer     = NULL;
+                si->packet_buffer_end = NULL;
                 goto out;
             }
-            pktl = s->internal->packet_buffer;
+            pktl = si->packet_buffer;
         }
 
         *out = pktl->pkt;
         av_log(s, AV_LOG_TRACE, "out st:%d dts:%"PRId64"\n", (*out).stream_index, (*out).dts);
-        s->internal->packet_buffer = pktl->next;
+        si->packet_buffer = pktl->next;
         if(s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer == pktl)
             s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer= NULL;
-        if(!s->internal->packet_buffer)
-            s->internal->packet_buffer_end= NULL;
+        if (!si->packet_buffer)
+            si->packet_buffer_end = NULL;
         av_freep(&pktl);
         return 1;
     } else {
diff --git a/libavformat/utils.c b/libavformat/utils.c
index df11dc2517..67ec3384d0 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -457,12 +457,14 @@ int avformat_open_input(AVFormatContext **ps, const char *filename,
                         const AVInputFormat *fmt, AVDictionary **options)
 {
     AVFormatContext *s = *ps;
+    AVFormatInternal *si;
     int ret = 0;
     AVDictionary *tmp = NULL;
     ID3v2ExtraMeta *id3v2_extra_meta = NULL;
 
     if (!s && !(s = avformat_alloc_context()))
         return AVERROR(ENOMEM);
+    si = s->internal;
     if (!s->av_class) {
         av_log(NULL, AV_LOG_ERROR, "Input context has not been properly allocated by avformat_alloc_context() and is not NULL either\n");
         return AVERROR(EINVAL);
@@ -538,7 +540,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename,
 
     /* e.g. AVFMT_NOFILE formats will not have a AVIOContext */
     if (s->pb)
-        ff_id3v2_read_dict(s->pb, &s->internal->id3v2_meta, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta);
+        ff_id3v2_read_dict(s->pb, &si->id3v2_meta, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta);
 
     if (s->iformat->read_header)
         if ((ret = s->iformat->read_header(s)) < 0) {
@@ -548,11 +550,11 @@ int avformat_open_input(AVFormatContext **ps, const char *filename,
         }
 
     if (!s->metadata) {
-        s->metadata = s->internal->id3v2_meta;
-        s->internal->id3v2_meta = NULL;
-    } else if (s->internal->id3v2_meta) {
+        s->metadata    = si->id3v2_meta;
+        si->id3v2_meta = NULL;
+    } else if (si->id3v2_meta) {
         av_log(s, AV_LOG_WARNING, "Discarding ID3 tags because more suitable tags were found.\n");
-        av_dict_free(&s->internal->id3v2_meta);
+        av_dict_free(&si->id3v2_meta);
     }
 
     if (id3v2_extra_meta) {
@@ -572,10 +574,10 @@ int avformat_open_input(AVFormatContext **ps, const char *filename,
     if ((ret = avformat_queue_attached_pictures(s)) < 0)
         goto close;
 
-    if (s->pb && !s->internal->data_offset)
-        s->internal->data_offset = avio_tell(s->pb);
+    if (s->pb && !si->data_offset)
+        si->data_offset = avio_tell(s->pb);
 
-    s->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
+    si->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
 
     update_stream_avctx(s);
 
@@ -741,6 +743,7 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in
 
 int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
+    AVFormatInternal *const si = s->internal;
     AVStream *st;
     int err;
 
@@ -755,18 +758,18 @@ FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
     for (;;) {
-        PacketList *pktl = s->internal->raw_packet_buffer;
+        PacketList *pktl = si->raw_packet_buffer;
         const AVPacket *pkt1;
 
         if (pktl) {
             st = s->streams[pktl->pkt.stream_index];
-            if (s->internal->raw_packet_buffer_remaining_size <= 0)
+            if (si->raw_packet_buffer_remaining_size <= 0)
                 if ((err = probe_codec(s, st, NULL)) < 0)
                     return err;
             if (st->internal->request_probe <= 0) {
-                avpriv_packet_list_get(&s->internal->raw_packet_buffer,
-                                   &s->internal->raw_packet_buffer_end, pkt);
-                s->internal->raw_packet_buffer_remaining_size += pkt->size;
+                avpriv_packet_list_get(&si->raw_packet_buffer,
+                                       &si->raw_packet_buffer_end, pkt);
+                si->raw_packet_buffer_remaining_size += pkt->size;
                 return 0;
             }
         }
@@ -837,15 +840,15 @@ FF_ENABLE_DEPRECATION_WARNINGS
         if (!pktl && st->internal->request_probe <= 0)
             return 0;
 
-        err = avpriv_packet_list_put(&s->internal->raw_packet_buffer,
-                                 &s->internal->raw_packet_buffer_end,
+        err = avpriv_packet_list_put(&si->raw_packet_buffer,
+                                     &si->raw_packet_buffer_end,
                                  pkt, NULL, 0);
         if (err < 0) {
             av_packet_unref(pkt);
             return err;
         }
-        pkt1 = &s->internal->raw_packet_buffer_end->pkt;
-        s->internal->raw_packet_buffer_remaining_size -= pkt1->size;
+        pkt1 = &si->raw_packet_buffer_end->pkt;
+        si->raw_packet_buffer_remaining_size -= pkt1->size;
 
         if ((err = probe_codec(s, st, pkt1)) < 0)
             return err;
@@ -957,10 +960,11 @@ static int has_decode_delay_been_guessed(AVStream *st)
 
 static PacketList *get_next_pkt(AVFormatContext *s, AVStream *st, PacketList *pktl)
 {
+    AVFormatInternal *const si = s->internal;
     if (pktl->next)
         return pktl->next;
-    if (pktl == s->internal->packet_buffer_end)
-        return s->internal->parse_queue;
+    if (pktl == si->packet_buffer_end)
+        return si->parse_queue;
     return NULL;
 }
 
@@ -1038,8 +1042,9 @@ static void update_dts_from_pts(AVFormatContext *s, int stream_index,
 static void update_initial_timestamps(AVFormatContext *s, int stream_index,
                                       int64_t dts, int64_t pts, AVPacket *pkt)
 {
+    AVFormatInternal *const si = s->internal;
     AVStream *st       = s->streams[stream_index];
-    PacketList *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue;
+    PacketList *pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue;
     PacketList *pktl_it;
 
     uint64_t shift;
@@ -1091,7 +1096,8 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index,
 static void update_initial_durations(AVFormatContext *s, AVStream *st,
                                      int stream_index, int64_t duration)
 {
-    PacketList *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue;
+    AVFormatInternal *const si = s->internal;
+    PacketList *pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue;
     int64_t cur_dts    = RELATIVE_TS_BASE;
 
     if (st->internal->first_dts != AV_NOPTS_VALUE) {
@@ -1117,7 +1123,7 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st,
             av_log(s, AV_LOG_DEBUG, "first_dts %s but no packet with dts in the queue\n", av_ts2str(st->internal->first_dts));
             return;
         }
-        pktl          = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue;
+        pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue;
         st->internal->first_dts = cur_dts;
     } else if (st->internal->cur_dts != RELATIVE_TS_BASE)
         return;
@@ -1339,7 +1345,8 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
 static int parse_packet(AVFormatContext *s, AVPacket *pkt,
                         int stream_index, int flush)
 {
-    AVPacket *out_pkt = s->internal->parse_pkt;
+    AVFormatInternal *const si = s->internal;
+    AVPacket *out_pkt = si->parse_pkt;
     AVStream *st = s->streams[stream_index];
     uint8_t *data = pkt->data;
     int size      = pkt->size;
@@ -1425,8 +1432,8 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt,
 
         compute_pkt_fields(s, st, st->internal->parser, out_pkt, next_dts, next_pts);
 
-        ret = avpriv_packet_list_put(&s->internal->parse_queue,
-                                 &s->internal->parse_queue_end,
+        ret = avpriv_packet_list_put(&si->parse_queue,
+                                     &si->parse_queue_end,
                                  out_pkt, NULL, 0);
         if (ret < 0)
             goto fail;
@@ -1452,10 +1459,11 @@ static int64_t ts_to_samples(AVStream *st, int64_t ts)
 
 static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
 {
+    AVFormatInternal *const si = s->internal;
     int ret, got_packet = 0;
     AVDictionary *metadata = NULL;
 
-    while (!got_packet && !s->internal->parse_queue) {
+    while (!got_packet && !si->parse_queue) {
         AVStream *st;
 
         /* read next packet */
@@ -1565,8 +1573,8 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
         }
     }
 
-    if (!got_packet && s->internal->parse_queue)
-        ret = avpriv_packet_list_get(&s->internal->parse_queue, &s->internal->parse_queue_end, pkt);
+    if (!got_packet && si->parse_queue)
+        ret = avpriv_packet_list_get(&si->parse_queue, &si->parse_queue_end, pkt);
 
     if (ret >= 0) {
         AVStream *st = s->streams[pkt->stream_index];
@@ -1639,15 +1647,16 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
 
 int av_read_frame(AVFormatContext *s, AVPacket *pkt)
 {
+    AVFormatInternal *const si = s->internal;
     const int genpts = s->flags & AVFMT_FLAG_GENPTS;
     int eof = 0;
     int ret;
     AVStream *st;
 
     if (!genpts) {
-        ret = s->internal->packet_buffer
-              ? avpriv_packet_list_get(&s->internal->packet_buffer,
-                                        &s->internal->packet_buffer_end, pkt)
+        ret = si->packet_buffer
+              ? avpriv_packet_list_get(&si->packet_buffer,
+                                       &si->packet_buffer_end, pkt)
               : read_frame_internal(s, pkt);
         if (ret < 0)
             return ret;
@@ -1655,7 +1664,7 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt)
     }
 
     for (;;) {
-        PacketList *pktl = s->internal->packet_buffer;
+        PacketList *pktl = si->packet_buffer;
 
         if (pktl) {
             AVPacket *next_pkt = &pktl->pkt;
@@ -1688,15 +1697,15 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt)
                     // 3. the packets for this stream at the end of the files had valid dts.
                     next_pkt->pts = last_dts + next_pkt->duration;
                 }
-                pktl = s->internal->packet_buffer;
+                pktl = si->packet_buffer;
             }
 
             /* read packet from packet buffer, if there is data */
             st = s->streams[next_pkt->stream_index];
             if (!(next_pkt->pts == AV_NOPTS_VALUE && st->discard < AVDISCARD_ALL &&
                   next_pkt->dts != AV_NOPTS_VALUE && !eof)) {
-                ret = avpriv_packet_list_get(&s->internal->packet_buffer,
-                                               &s->internal->packet_buffer_end, pkt);
+                ret = avpriv_packet_list_get(&si->packet_buffer,
+                                             &si->packet_buffer_end, pkt);
                 goto return_packet;
             }
         }
@@ -1710,8 +1719,8 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt)
                 return ret;
         }
 
-        ret = avpriv_packet_list_put(&s->internal->packet_buffer,
-                                 &s->internal->packet_buffer_end,
+        ret = avpriv_packet_list_put(&si->packet_buffer,
+                                     &si->packet_buffer_end,
                                  pkt, NULL, 0);
         if (ret < 0) {
             av_packet_unref(pkt);
@@ -1738,11 +1747,12 @@ return_packet:
 /* XXX: suppress the packet queue */
 static void flush_packet_queue(AVFormatContext *s)
 {
-    avpriv_packet_list_free(&s->internal->parse_queue,       &s->internal->parse_queue_end);
-    avpriv_packet_list_free(&s->internal->packet_buffer,     &s->internal->packet_buffer_end);
-    avpriv_packet_list_free(&s->internal->raw_packet_buffer, &s->internal->raw_packet_buffer_end);
+    AVFormatInternal *const si = s->internal;
+    avpriv_packet_list_free(&si->parse_queue,       &si->parse_queue_end);
+    avpriv_packet_list_free(&si->packet_buffer,     &si->packet_buffer_end);
+    avpriv_packet_list_free(&si->raw_packet_buffer, &si->raw_packet_buffer_end);
 
-    s->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
+    si->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
 }
 
 /*******************************************************/
@@ -3434,10 +3444,10 @@ fail:
     return ret;
 }
 
-static int extract_extradata(AVFormatContext *s, AVStream *st, const AVPacket *pkt)
+static int extract_extradata(AVFormatInternal *si, AVStream *st, const AVPacket *pkt)
 {
     AVStreamInternal *sti = st->internal;
-    AVPacket *pkt_ref = s->internal->parse_pkt;
+    AVPacket *pkt_ref = si->parse_pkt;
     int ret;
 
     if (!sti->extract_extradata.inited) {
@@ -3498,9 +3508,10 @@ static int add_coded_side_data(AVStream *st, AVCodecContext *avctx)
 
 int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
 {
+    AVFormatInternal *const si = ic->internal;
     int count = 0, ret = 0;
     int64_t read_size;
-    AVPacket *pkt1 = ic->internal->pkt;
+    AVPacket *pkt1 = si->pkt;
     int64_t old_offset  = avio_tell(ic->pb);
     // new streams might appear, no options for those
     int orig_nb_streams = ic->nb_streams;
@@ -3698,13 +3709,13 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
         }
 
         if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) {
-            ret = avpriv_packet_list_put(&ic->internal->packet_buffer,
-                                     &ic->internal->packet_buffer_end,
+            ret = avpriv_packet_list_put(&si->packet_buffer,
+                                         &si->packet_buffer_end,
                                      pkt1, NULL, 0);
             if (ret < 0)
                 goto unref_then_goto_end;
 
-            pkt = &ic->internal->packet_buffer_end->pkt;
+            pkt = &si->packet_buffer_end->pkt;
         } else {
             pkt = pkt1;
         }
@@ -3808,7 +3819,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
                 st->internal->info->frame_delay_evidence = 1;
         }
         if (!st->internal->avctx->extradata) {
-            ret = extract_extradata(ic, st, pkt);
+            ret = extract_extradata(si, st, pkt);
             if (ret < 0)
                 goto unref_then_goto_end;
         }
@@ -3851,14 +3862,14 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
 
             // EOF already reached while reading the stream above.
             // So continue with reoordering DTS with whatever delay we have.
-            if (ic->internal->packet_buffer && !has_decode_delay_been_guessed(st)) {
-                update_dts_from_pts(ic, stream_index, ic->internal->packet_buffer);
+            if (si->packet_buffer && !has_decode_delay_been_guessed(st)) {
+                update_dts_from_pts(ic, stream_index, si->packet_buffer);
             }
         }
     }
 
     if (flush_codecs) {
-        AVPacket *empty_pkt = ic->internal->pkt;
+        AVPacket *empty_pkt = si->pkt;
         int err = 0;
         av_packet_unref(empty_pkt);
 
@@ -3923,7 +3934,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
                         best_fps   = std_fps.num;
                     }
 
-                    if (ic->internal->prefer_codec_framerate && codec_frame_rate.num > 0 && codec_frame_rate.den > 0) {
+                    if (si->prefer_codec_framerate && codec_frame_rate.num > 0 && codec_frame_rate.den > 0) {
                         error       = fabs(av_q2d(codec_frame_rate) /
                                            av_q2d(std_fps) - 1);
                         if (error < best_error) {
@@ -4248,10 +4259,13 @@ void ff_free_stream(AVFormatContext *s, AVStream *st)
 
 void avformat_free_context(AVFormatContext *s)
 {
+    AVFormatInternal *si;
+
     if (!s)
         return;
+    si = s->internal;
 
-    if (s->oformat && s->oformat->deinit && s->internal->initialized)
+    if (s->oformat && s->oformat->deinit && si->initialized)
         s->oformat->deinit(s);
 
     av_opt_free(s);
@@ -4279,9 +4293,9 @@ void avformat_free_context(AVFormatContext *s)
     }
     av_freep(&s->chapters);
     av_dict_free(&s->metadata);
-    av_dict_free(&s->internal->id3v2_meta);
-    av_packet_free(&s->internal->pkt);
-    av_packet_free(&s->internal->parse_pkt);
+    av_dict_free(&si->id3v2_meta);
+    av_packet_free(&si->pkt);
+    av_packet_free(&si->parse_pkt);
     av_freep(&s->streams);
     flush_packet_queue(s);
     av_freep(&s->internal);
@@ -4430,6 +4444,7 @@ AVProgram *av_new_program(AVFormatContext *ac, int id)
 AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base,
                               int64_t start, int64_t end, const char *title)
 {
+    AVFormatInternal *const si = s->internal;
     AVChapter *chapter = NULL;
     int ret;
 
@@ -4439,9 +4454,9 @@ AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_ba
     }
 
     if (!s->nb_chapters) {
-        s->internal->chapter_ids_monotonic = 1;
-    } else if (!s->internal->chapter_ids_monotonic || s->chapters[s->nb_chapters-1]->id >= id) {
-        s->internal->chapter_ids_monotonic = 0;
+        si->chapter_ids_monotonic = 1;
+    } else if (!si->chapter_ids_monotonic || s->chapters[s->nb_chapters-1]->id >= id) {
+        si->chapter_ids_monotonic = 0;
         for (unsigned i = 0; i < s->nb_chapters; i++)
             if (s->chapters[i]->id == id)
                 chapter = s->chapters[i];
-- 
2.30.2



More information about the ffmpeg-devel mailing list