diff mbox

[FFmpeg-devel,4/6] avformat/matroskadec: Cache whether a track needs to be decoded

Message ID 20191206231622.13672-4-andreas.rheinhardt@gmail.com
State New
Headers show

Commit Message

Andreas Rheinhardt Dec. 6, 2019, 11:16 p.m. UTC
There is no need to recheck this for every frame.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/matroskadec.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index d1a0a07782..a7226ee810 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -249,6 +249,7 @@  typedef struct MatroskaTrack {
     AVStream *stream;
     int64_t end_timecode;
     int ms_compat;
+    int needs_decoding;
     uint64_t max_block_additional_id;
 
     uint32_t palette[AVPALETTE_COUNT];
@@ -2385,6 +2386,11 @@  static int matroska_parse_tracks(AVFormatContext *s)
                 }
             }
         }
+        track->needs_decoding = encodings && !encodings[0].type &&
+                                encodings[0].scope & 1          &&
+                                (encodings[0].compression.algo !=
+                                   MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP ||
+                                 encodings[0].compression.settings.size);
 
         for (j = 0; ff_mkv_codec_tags[j].id != AV_CODEC_ID_NONE; j++) {
             if (!strncmp(ff_mkv_codec_tags[j].str, track->codec_id,
@@ -3381,12 +3387,11 @@  static int matroska_parse_frame(MatroskaDemuxContext *matroska,
                                 uint8_t *additional, uint64_t additional_id, int additional_size,
                                 int64_t discard_padding)
 {
-    MatroskaTrackEncoding *encodings = track->encodings.elem;
     uint8_t *pkt_data = data;
     int res;
     AVPacket pktl, *pkt = &pktl;
 
-    if (encodings && !encodings->type && encodings->scope & 1) {
+    if (track->needs_decoding) {
         res = matroska_decode_buffer(&pkt_data, &pkt_size, track);
         if (res < 0)
             return res;