Merge commit '94c54d97e7f4fe90570c323803f2bdf6246c1010'
authorJames Almer <jamrial@gmail.com>
Mon, 30 Oct 2017 19:52:36 +0000 (16:52 -0300)
committerJames Almer <jamrial@gmail.com>
Mon, 30 Oct 2017 19:52:36 +0000 (16:52 -0300)
* commit '94c54d97e7f4fe90570c323803f2bdf6246c1010':
  mlp: Factor out channel layout subset checks

Merged-by: James Almer <jamrial@gmail.com>
libavcodec/mlp_parser.c
libavcodec/mlp_parser.h
libavcodec/mlpdec.c

index d131106..379c644 100644 (file)
@@ -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 {
index c5a2883..79c4efd 100644 (file)
@@ -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 */
index 0a6b0fe..4d40e18 100644 (file)
@@ -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",