[FFmpeg-cvslog] Merge commit '94c54d97e7f4fe90570c323803f2bdf6246c1010'

James Almer git at videolan.org
Mon Oct 30 21:56:08 EET 2017


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Mon Oct 30 16:52:36 2017 -0300| [e3ebc293c624ff4cb9e225c269a466290788bb55] | committer: James Almer

Merge commit '94c54d97e7f4fe90570c323803f2bdf6246c1010'

* commit '94c54d97e7f4fe90570c323803f2bdf6246c1010':
  mlp: Factor out channel layout subset checks

Merged-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e3ebc293c624ff4cb9e225c269a466290788bb55
---

 libavcodec/mlp_parser.c | 22 +++++++++++-----------
 libavcodec/mlp_parser.h |  2 ++
 libavcodec/mlpdec.c     |  4 ++--
 3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/libavcodec/mlp_parser.c b/libavcodec/mlp_parser.c
index d131106cfc..379c644e36 100644
--- a/libavcodec/mlp_parser.c
+++ b/libavcodec/mlp_parser.c
@@ -119,6 +119,11 @@ uint64_t ff_truehd_layout(int chanmap)
     return layout;
 }
 
+int ff_mlp_channel_layout_subset(uint64_t channel_layout, uint64_t mask)
+{
+    return channel_layout && ((channel_layout & mask) == channel_layout);
+}
+
 static int mlp_get_major_sync_size(const uint8_t * buf, int bufsize)
 {
     int has_extension, extensions = 0;
@@ -341,6 +346,8 @@ static int mlp_parse(AVCodecParserContext *s,
     } else {
         GetBitContext gb;
         MLPHeaderInfo mh;
+        int stereo_requested = ff_mlp_channel_layout_subset(avctx->request_channel_layout,
+                                                            AV_CH_LAYOUT_STEREO);
 
         init_get_bits(&gb, buf + 4, (buf_size - 4) << 3);
         if (ff_mlp_read_major_sync(avctx, &mh, &gb) < 0)
@@ -357,10 +364,7 @@ static int mlp_parse(AVCodecParserContext *s,
         if(!avctx->channels || !avctx->channel_layout) {
         if (mh.stream_type == 0xbb) {
             /* MLP stream */
-            if (avctx->request_channel_layout &&
-                (avctx->request_channel_layout & AV_CH_LAYOUT_STEREO) ==
-                avctx->request_channel_layout &&
-                mh.num_substreams > 1) {
+            if (stereo_requested && mh.num_substreams > 1) {
                 avctx->channels       = 2;
                 avctx->channel_layout = AV_CH_LAYOUT_STEREO;
             } else {
@@ -369,16 +373,12 @@ static int mlp_parse(AVCodecParserContext *s,
             }
         } else { /* mh.stream_type == 0xba */
             /* TrueHD stream */
-            if (avctx->request_channel_layout &&
-                    (avctx->request_channel_layout & AV_CH_LAYOUT_STEREO) ==
-                    avctx->request_channel_layout &&
-                    mh.num_substreams > 1) {
+            if (stereo_requested && mh.num_substreams > 1) {
                 avctx->channels       = 2;
                 avctx->channel_layout = AV_CH_LAYOUT_STEREO;
             } else if (!mh.channels_thd_stream2 ||
-                       (avctx->request_channel_layout &&
-                        (avctx->request_channel_layout & mh.channel_layout_thd_stream1) ==
-                        avctx->request_channel_layout)) {
+                       ff_mlp_channel_layout_subset(avctx->request_channel_layout,
+                                                    mh.channel_layout_thd_stream1)) {
                 avctx->channels       = mh.channels_thd_stream1;
                 avctx->channel_layout = mh.channel_layout_thd_stream1;
             } else {
diff --git a/libavcodec/mlp_parser.h b/libavcodec/mlp_parser.h
index c5a2883920..79c4efdb9a 100644
--- a/libavcodec/mlp_parser.h
+++ b/libavcodec/mlp_parser.h
@@ -68,4 +68,6 @@ uint64_t ff_truehd_layout(int chanmap);
 
 extern const uint64_t ff_mlp_layout[32];
 
+int ff_mlp_channel_layout_subset(uint64_t channel_layout, uint64_t mask);
+
 #endif /* AVCODEC_MLP_PARSER_H */
diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
index 0a6b0feb97..4d40e18f6e 100644
--- a/libavcodec/mlpdec.c
+++ b/libavcodec/mlpdec.c
@@ -533,8 +533,8 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp,
     s->max_channel        = max_channel;
     s->max_matrix_channel = max_matrix_channel;
 
-    if (m->avctx->request_channel_layout && (s->mask & m->avctx->request_channel_layout) ==
-        m->avctx->request_channel_layout && m->max_decoded_substream > substr) {
+    if (ff_mlp_channel_layout_subset(m->avctx->request_channel_layout, s->mask) &&
+        m->max_decoded_substream > substr) {
         av_log(m->avctx, AV_LOG_DEBUG,
                "Extracting %d-channel downmix (0x%"PRIx64") from substream %d. "
                "Further substreams will be skipped.\n",


======================================================================

diff --cc libavcodec/mlp_parser.c
index d131106cfc,7d73058e4c..379c644e36
--- a/libavcodec/mlp_parser.c
+++ b/libavcodec/mlp_parser.c
@@@ -339,11 -334,13 +344,13 @@@ static int mlp_parse(AVCodecParserConte
              goto lost_sync;
          }
      } else {
 -        BitstreamContext bc;
 +        GetBitContext gb;
          MLPHeaderInfo mh;
+         int stereo_requested = ff_mlp_channel_layout_subset(avctx->request_channel_layout,
+                                                             AV_CH_LAYOUT_STEREO);
  
 -        bitstream_init8(&bc, buf + 4, buf_size - 4);
 -        if (ff_mlp_read_major_sync(avctx, &mh, &bc) < 0)
 +        init_get_bits(&gb, buf + 4, (buf_size - 4) << 3);
 +        if (ff_mlp_read_major_sync(avctx, &mh, &gb) < 0)
              goto lost_sync;
  
          avctx->bits_per_raw_sample = mh.group1_bits;
@@@ -354,13 -351,9 +361,10 @@@
          avctx->sample_rate = mh.group1_samplerate;
          s->duration = mh.access_unit_size;
  
 +        if(!avctx->channels || !avctx->channel_layout) {
          if (mh.stream_type == 0xbb) {
              /* MLP stream */
-             if (avctx->request_channel_layout &&
-                 (avctx->request_channel_layout & AV_CH_LAYOUT_STEREO) ==
-                 avctx->request_channel_layout &&
-                 mh.num_substreams > 1) {
+             if (stereo_requested && mh.num_substreams > 1) {
                  avctx->channels       = 2;
                  avctx->channel_layout = AV_CH_LAYOUT_STEREO;
              } else {
diff --cc libavcodec/mlp_parser.h
index c5a2883920,946f4d240c..79c4efdb9a
--- a/libavcodec/mlp_parser.h
+++ b/libavcodec/mlp_parser.h
@@@ -63,9 -61,8 +63,11 @@@ typedef struct MLPHeaderInf
  } MLPHeaderInfo;
  
  
 -int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, BitstreamContext *bc);
 +int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb);
 +uint64_t ff_truehd_layout(int chanmap);
 +
 +extern const uint64_t ff_mlp_layout[32];
  
+ int ff_mlp_channel_layout_subset(uint64_t channel_layout, uint64_t mask);
+ 
  #endif /* AVCODEC_MLP_PARSER_H */



More information about the ffmpeg-cvslog mailing list