OSDN Git Service

Merge commit '4b7f1a7ced0e98f2cc698d896f7ebab8d30eaa09'
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 5 Jan 2014 21:53:13 +0000 (22:53 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 5 Jan 2014 21:53:13 +0000 (22:53 +0100)
* commit '4b7f1a7ced0e98f2cc698d896f7ebab8d30eaa09':
  mlp: Parse TrueHD decoder channel modifiers and set the AVMatrixEncoding for each substream.

Conflicts:
libavcodec/mlp_parser.h
libavcodec/mlpdec.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/mlp.h
libavcodec/mlp_parser.c
libavcodec/mlp_parser.h
libavcodec/mlpdec.c

Simple merge
@@@ -170,14 -169,16 +170,17 @@@ int ff_mlp_read_major_sync(void *log, M
          mh->group1_samplerate = mlp_samplerate(ratebits);
          mh->group2_samplerate = 0;
  
-         skip_bits(gb, 8);
+         skip_bits(gb, 4);
+         mh->channel_modifier_thd_stream0 = get_bits(gb, 2);
+         mh->channel_modifier_thd_stream1 = get_bits(gb, 2);
  
 +        mh->channel_arrangement=
          channel_arrangement            = get_bits(gb, 5);
          mh->channels_thd_stream1       = truehd_channels(channel_arrangement);
 -        mh->channel_layout_thd_stream1 = truehd_layout(channel_arrangement);
 +        mh->channel_layout_thd_stream1 = ff_truehd_layout(channel_arrangement);
  
-         skip_bits(gb, 2);
+         mh->channel_modifier_thd_stream2 = get_bits(gb, 2);
  
          channel_arrangement            = get_bits(gb, 13);
          mh->channels_thd_stream2       = truehd_channels(channel_arrangement);
@@@ -39,7 -39,10 +39,12 @@@ typedef struct MLPHeaderInf
      int group1_samplerate;                  ///< Sample rate of first substream
      int group2_samplerate;                  ///< Sample rate of second substream (MLP only)
  
 +    int channel_arrangement;
++
+     int channel_modifier_thd_stream0;       ///< Channel modifier for substream 0 of TrueHD sreams ("2-channel presentation")
+     int channel_modifier_thd_stream1;       ///< Channel modifier for substream 1 of TrueHD sreams ("6-channel presentation")
+     int channel_modifier_thd_stream2;       ///< Channel modifier for substream 2 of TrueHD sreams ("8-channel presentation")
      int channels_mlp;                       ///< Channel count for MLP streams
      int channels_thd_stream1;               ///< Channel count for substream 1 of TrueHD streams ("6-channel presentation")
      int channels_thd_stream2;               ///< Channel count for substream 2 of TrueHD streams ("8-channel presentation")
@@@ -387,17 -374,48 +389,57 @@@ static int read_major_sync(MLPDecodeCon
              else
                  m->substream[2].ch_layout = mh.channel_layout_thd_stream1;
          m->substream[substr].ch_layout = mh.channel_layout_thd_stream1;
 +
 +        if (m->avctx->channels<=2 && m->substream[substr].ch_layout == AV_CH_LAYOUT_MONO && m->max_decoded_substream == 1) {
 +            av_log(m->avctx, AV_LOG_DEBUG, "Mono stream with 2 substreams, ignoring 2nd\n");
 +            m->max_decoded_substream = 0;
 +            if (m->avctx->channels==2)
 +                m->avctx->channel_layout = AV_CH_LAYOUT_STEREO;
 +        }
      }
  
 +    m->needs_reordering = mh.channel_arrangement >= 18 && mh.channel_arrangement <= 20;
 +
+     /* Parse the TrueHD decoder channel modifiers and set each substream's
+      * AVMatrixEncoding accordingly.
+      *
+      * The meaning of the modifiers depends on the channel layout:
+      *
+      * - THD_CH_MODIFIER_LTRT, THD_CH_MODIFIER_LBINRBIN only apply to 2-channel
+      *
+      * - THD_CH_MODIFIER_MONO applies to 1-channel or 2-channel (dual mono)
+      *
+      * - THD_CH_MODIFIER_SURROUNDEX, THD_CH_MODIFIER_NOTSURROUNDEX only apply to
+      *   layouts with an Ls/Rs channel pair
+      */
+     for (substr = 0; substr < MAX_SUBSTREAMS; substr++)
+         m->substream[substr].matrix_encoding = AV_MATRIX_ENCODING_NONE;
+     if (m->avctx->codec_id == AV_CODEC_ID_TRUEHD) {
+         if (mh.num_substreams > 2 &&
+             mh.channel_layout_thd_stream2 & AV_CH_SIDE_LEFT &&
+             mh.channel_layout_thd_stream2 & AV_CH_SIDE_RIGHT &&
+             mh.channel_modifier_thd_stream2 == THD_CH_MODIFIER_SURROUNDEX)
+             m->substream[2].matrix_encoding = AV_MATRIX_ENCODING_DOLBYEX;
+         if (mh.num_substreams > 1 &&
+             mh.channel_layout_thd_stream1 & AV_CH_SIDE_LEFT &&
+             mh.channel_layout_thd_stream1 & AV_CH_SIDE_RIGHT &&
+             mh.channel_modifier_thd_stream1 == THD_CH_MODIFIER_SURROUNDEX)
+             m->substream[1].matrix_encoding = AV_MATRIX_ENCODING_DOLBYEX;
+         if (mh.num_substreams > 0)
+             switch (mh.channel_modifier_thd_stream0) {
+             case THD_CH_MODIFIER_LTRT:
+                 m->substream[0].matrix_encoding = AV_MATRIX_ENCODING_DOLBY;
+                 break;
+             case THD_CH_MODIFIER_LBINRBIN:
+                 m->substream[0].matrix_encoding = AV_MATRIX_ENCODING_DOLBYHEADPHONE;
+                 break;
+             default:
+                 break;
+             }
+     }
      return 0;
  }