[FFmpeg-devel] [PATCH v2 1/2] avcodec/dca_exss: prepare to be called from parser context

foo86 foobaz86 at gmail.com
Mon May 23 16:58:41 CEST 2016


---
Updated version of the patch: don't print error or warning messages when called
from parser context to avoid duplicating messages from decoder context.

 libavcodec/dca_exss.c | 31 ++++++++++++++++++++-----------
 libavcodec/dca_exss.h |  2 +-
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/libavcodec/dca_exss.c b/libavcodec/dca_exss.c
index 87b2f42..adeb6e6 100644
--- a/libavcodec/dca_exss.c
+++ b/libavcodec/dca_exss.c
@@ -130,7 +130,8 @@ static int parse_descriptor(DCAExssParser *s, DCAExssAsset *asset)
 
             // Number of speaker remapping sets
             if ((spkr_remap_nsets = get_bits(&s->gb, 3)) && !spkr_mask_nbits) {
-                av_log(s->avctx, AV_LOG_ERROR, "Speaker mask disabled yet there are remapping sets\n");
+                if (s->avctx)
+                    av_log(s->avctx, AV_LOG_ERROR, "Speaker mask disabled yet there are remapping sets\n");
                 return AVERROR_INVALIDDATA;
             }
 
@@ -215,7 +216,8 @@ static int parse_descriptor(DCAExssParser *s, DCAExssAsset *asset)
 
         for (i = 0; i < s->nmixoutconfigs; i++) {
             if (!s->nmixoutchs[i]) {
-                av_log(s->avctx, AV_LOG_ERROR, "Invalid speaker layout mask for mixing configuration\n");
+                if (s->avctx)
+                    av_log(s->avctx, AV_LOG_ERROR, "Invalid speaker layout mask for mixing configuration\n");
                 return AVERROR_INVALIDDATA;
             }
             for (j = 0; j < nchannels_dmix; j++) {
@@ -312,7 +314,8 @@ static int parse_descriptor(DCAExssParser *s, DCAExssAsset *asset)
     // Reserved
     // Zero pad
     if (ff_dca_seek_bits(&s->gb, descr_pos + descr_size * 8)) {
-        av_log(s->avctx, AV_LOG_ERROR, "Read past end of EXSS asset descriptor\n");
+        if (s->avctx)
+            av_log(s->avctx, AV_LOG_ERROR, "Read past end of EXSS asset descriptor\n");
         return AVERROR_INVALIDDATA;
     }
 
@@ -375,7 +378,7 @@ static int set_exss_offsets(DCAExssAsset *asset)
     return 0;
 }
 
-int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size)
+int ff_dca_exss_parse(DCAExssParser *s, const uint8_t *data, int size)
 {
     int i, ret, offset, wide_hdr, header_size;
 
@@ -398,7 +401,7 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size)
     header_size = get_bits(&s->gb, 8 + 4 * wide_hdr) + 1;
 
     // Check CRC
-    if (ff_dca_check_crc(s->avctx, &s->gb, 32 + 8, header_size * 8)) {
+    if (s->avctx && ff_dca_check_crc(s->avctx, &s->gb, 32 + 8, header_size * 8)) {
         av_log(s->avctx, AV_LOG_ERROR, "Invalid EXSS header checksum\n");
         return AVERROR_INVALIDDATA;
     }
@@ -408,7 +411,8 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size)
     // Number of bytes of extension substream
     s->exss_size = get_bits(&s->gb, s->exss_size_nbits) + 1;
     if (s->exss_size > size) {
-        av_log(s->avctx, AV_LOG_ERROR, "Packet too short for EXSS frame\n");
+        if (s->avctx)
+            av_log(s->avctx, AV_LOG_ERROR, "Packet too short for EXSS frame\n");
         return AVERROR_INVALIDDATA;
     }
 
@@ -430,14 +434,16 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size)
         // Number of defined audio presentations
         s->npresents = get_bits(&s->gb, 3) + 1;
         if (s->npresents > 1) {
-            avpriv_request_sample(s->avctx, "%d audio presentations", s->npresents);
+            if (s->avctx)
+                avpriv_request_sample(s->avctx, "%d audio presentations", s->npresents);
             return AVERROR_PATCHWELCOME;
         }
 
         // Number of audio assets in extension substream
         s->nassets = get_bits(&s->gb, 3) + 1;
         if (s->nassets > 1) {
-            avpriv_request_sample(s->avctx, "%d audio assets", s->nassets);
+            if (s->avctx)
+                avpriv_request_sample(s->avctx, "%d audio assets", s->nassets);
             return AVERROR_PATCHWELCOME;
         }
 
@@ -478,7 +484,8 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size)
         s->assets[i].asset_size = get_bits(&s->gb, s->exss_size_nbits) + 1;
         offset += s->assets[i].asset_size;
         if (offset > s->exss_size) {
-            av_log(s->avctx, AV_LOG_ERROR, "EXSS asset out of bounds\n");
+            if (s->avctx)
+                av_log(s->avctx, AV_LOG_ERROR, "EXSS asset out of bounds\n");
             return AVERROR_INVALIDDATA;
         }
     }
@@ -488,7 +495,8 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size)
         if ((ret = parse_descriptor(s, &s->assets[i])) < 0)
             return ret;
         if ((ret = set_exss_offsets(&s->assets[i])) < 0) {
-            av_log(s->avctx, AV_LOG_ERROR, "Invalid extension size in EXSS asset descriptor\n");
+            if (s->avctx)
+                av_log(s->avctx, AV_LOG_ERROR, "Invalid extension size in EXSS asset descriptor\n");
             return ret;
         }
     }
@@ -500,7 +508,8 @@ int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size)
     // Byte align
     // CRC16 of extension substream header
     if (ff_dca_seek_bits(&s->gb, header_size * 8)) {
-        av_log(s->avctx, AV_LOG_ERROR, "Read past end of EXSS header\n");
+        if (s->avctx)
+            av_log(s->avctx, AV_LOG_ERROR, "Read past end of EXSS header\n");
         return AVERROR_INVALIDDATA;
     }
 
diff --git a/libavcodec/dca_exss.h b/libavcodec/dca_exss.h
index 323063a..208fae1 100644
--- a/libavcodec/dca_exss.h
+++ b/libavcodec/dca_exss.h
@@ -87,6 +87,6 @@ typedef struct DCAExssParser {
     DCAExssAsset   assets[1];    ///< Audio asset descriptors
 } DCAExssParser;
 
-int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size);
+int ff_dca_exss_parse(DCAExssParser *s, const uint8_t *data, int size);
 
 #endif
-- 
2.8.1



More information about the ffmpeg-devel mailing list