content/media/fmp4/demuxer/channel_layout.cc

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include "mp4_demuxer/channel_layout.h"
michael@0 6
michael@0 7 #include "mp4_demuxer/basictypes.h"
michael@0 8
michael@0 9 namespace mp4_demuxer {
michael@0 10
michael@0 11 static const int kLayoutToChannels[] = {
michael@0 12 0, // CHANNEL_LAYOUT_NONE
michael@0 13 0, // CHANNEL_LAYOUT_UNSUPPORTED
michael@0 14 1, // CHANNEL_LAYOUT_MONO
michael@0 15 2, // CHANNEL_LAYOUT_STEREO
michael@0 16 3, // CHANNEL_LAYOUT_2_1
michael@0 17 3, // CHANNEL_LAYOUT_SURROUND
michael@0 18 4, // CHANNEL_LAYOUT_4_0
michael@0 19 4, // CHANNEL_LAYOUT_2_2
michael@0 20 4, // CHANNEL_LAYOUT_QUAD
michael@0 21 5, // CHANNEL_LAYOUT_5_0
michael@0 22 6, // CHANNEL_LAYOUT_5_1
michael@0 23 5, // CHANNEL_LAYOUT_5_0_BACK
michael@0 24 6, // CHANNEL_LAYOUT_5_1_BACK
michael@0 25 7, // CHANNEL_LAYOUT_7_0
michael@0 26 8, // CHANNEL_LAYOUT_7_1
michael@0 27 8, // CHANNEL_LAYOUT_7_1_WIDE
michael@0 28 2, // CHANNEL_LAYOUT_STEREO_DOWNMIX
michael@0 29 3, // CHANNEL_LAYOUT_2POINT1
michael@0 30 4, // CHANNEL_LAYOUT_3_1
michael@0 31 5, // CHANNEL_LAYOUT_4_1
michael@0 32 6, // CHANNEL_LAYOUT_6_0
michael@0 33 6, // CHANNEL_LAYOUT_6_0_FRONT
michael@0 34 6, // CHANNEL_LAYOUT_HEXAGONAL
michael@0 35 7, // CHANNEL_LAYOUT_6_1
michael@0 36 7, // CHANNEL_LAYOUT_6_1_BACK
michael@0 37 7, // CHANNEL_LAYOUT_6_1_FRONT
michael@0 38 7, // CHANNEL_LAYOUT_7_0_FRONT
michael@0 39 8, // CHANNEL_LAYOUT_7_1_WIDE_BACK
michael@0 40 8, // CHANNEL_LAYOUT_OCTAGONAL
michael@0 41 0, // CHANNEL_LAYOUT_DISCRETE
michael@0 42 };
michael@0 43
michael@0 44 // The channel orderings for each layout as specified by FFmpeg. Each value
michael@0 45 // represents the index of each channel in each layout. Values of -1 mean the
michael@0 46 // channel at that index is not used for that layout.For example, the left side
michael@0 47 // surround sound channel in FFmpeg's 5.1 layout is in the 5th position (because
michael@0 48 // the order is L, R, C, LFE, LS, RS), so
michael@0 49 // kChannelOrderings[CHANNEL_LAYOUT_5POINT1][SIDE_LEFT] = 4;
michael@0 50 static const int kChannelOrderings[CHANNEL_LAYOUT_MAX][CHANNELS_MAX] = {
michael@0 51 // FL | FR | FC | LFE | BL | BR | FLofC | FRofC | BC | SL | SR
michael@0 52
michael@0 53 // CHANNEL_LAYOUT_NONE
michael@0 54 { -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },
michael@0 55
michael@0 56 // CHANNEL_LAYOUT_UNSUPPORTED
michael@0 57 { -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },
michael@0 58
michael@0 59 // CHANNEL_LAYOUT_MONO
michael@0 60 { -1 , -1 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },
michael@0 61
michael@0 62 // CHANNEL_LAYOUT_STEREO
michael@0 63 { 0 , 1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },
michael@0 64
michael@0 65 // CHANNEL_LAYOUT_2_1
michael@0 66 { 0 , 1 , -1 , -1 , -1 , -1 , -1 , -1 , 2 , -1 , -1 },
michael@0 67
michael@0 68 // CHANNEL_LAYOUT_SURROUND
michael@0 69 { 0 , 1 , 2 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },
michael@0 70
michael@0 71 // CHANNEL_LAYOUT_4_0
michael@0 72 { 0 , 1 , 2 , -1 , -1 , -1 , -1 , -1 , 3 , -1 , -1 },
michael@0 73
michael@0 74 // CHANNEL_LAYOUT_2_2
michael@0 75 { 0 , 1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 2 , 3 },
michael@0 76
michael@0 77 // CHANNEL_LAYOUT_QUAD
michael@0 78 { 0 , 1 , -1 , -1 , 2 , 3 , -1 , -1 , -1 , -1 , -1 },
michael@0 79
michael@0 80 // CHANNEL_LAYOUT_5_0
michael@0 81 { 0 , 1 , 2 , -1 , -1 , -1 , -1 , -1 , -1 , 3 , 4 },
michael@0 82
michael@0 83 // CHANNEL_LAYOUT_5_1
michael@0 84 { 0 , 1 , 2 , 3 , -1 , -1 , -1 , -1 , -1 , 4 , 5 },
michael@0 85
michael@0 86 // FL | FR | FC | LFE | BL | BR | FLofC | FRofC | BC | SL | SR
michael@0 87
michael@0 88 // CHANNEL_LAYOUT_5_0_BACK
michael@0 89 { 0 , 1 , 2 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 },
michael@0 90
michael@0 91 // CHANNEL_LAYOUT_5_1_BACK
michael@0 92 { 0 , 1 , 2 , 3 , 4 , 5 , -1 , -1 , -1 , -1 , -1 },
michael@0 93
michael@0 94 // CHANNEL_LAYOUT_7_0
michael@0 95 { 0 , 1 , 2 , -1 , 5 , 6 , -1 , -1 , -1 , 3 , 4 },
michael@0 96
michael@0 97 // CHANNEL_LAYOUT_7_1
michael@0 98 { 0 , 1 , 2 , 3 , 6 , 7 , -1 , -1 , -1 , 4 , 5 },
michael@0 99
michael@0 100 // CHANNEL_LAYOUT_7_1_WIDE
michael@0 101 { 0 , 1 , 2 , 3 , -1 , -1 , 6 , 7 , -1 , 4 , 5 },
michael@0 102
michael@0 103 // CHANNEL_LAYOUT_STEREO_DOWNMIX
michael@0 104 { 0 , 1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },
michael@0 105
michael@0 106 // CHANNEL_LAYOUT_2POINT1
michael@0 107 { 0 , 1 , -1 , 2 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },
michael@0 108
michael@0 109 // CHANNEL_LAYOUT_3_1
michael@0 110 { 0 , 1 , 2 , 3 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },
michael@0 111
michael@0 112 // CHANNEL_LAYOUT_4_1
michael@0 113 { 0 , 1 , 2 , 4 , -1 , -1 , -1 , -1 , 3 , -1 , -1 },
michael@0 114
michael@0 115 // CHANNEL_LAYOUT_6_0
michael@0 116 { 0 , 1 , 2 , -1 , -1 , -1 , -1 , -1 , 5 , 3 , 4 },
michael@0 117
michael@0 118 // CHANNEL_LAYOUT_6_0_FRONT
michael@0 119 { 0 , 1 , -1 , -1 , -1 , -1 , 4 , 5 , -1 , 2 , 3 },
michael@0 120
michael@0 121 // FL | FR | FC | LFE | BL | BR | FLofC | FRofC | BC | SL | SR
michael@0 122
michael@0 123 // CHANNEL_LAYOUT_HEXAGONAL
michael@0 124 { 0 , 1 , 2 , -1 , 3 , 4 , -1 , -1 , 5 , -1 , -1 },
michael@0 125
michael@0 126 // CHANNEL_LAYOUT_6_1
michael@0 127 { 0 , 1 , 2 , 3 , -1 , -1 , -1 , -1 , 6 , 4 , 5 },
michael@0 128
michael@0 129 // CHANNEL_LAYOUT_6_1_BACK
michael@0 130 { 0 , 1 , 2 , 3 , 4 , 5 , -1 , -1 , 6 , -1 , -1 },
michael@0 131
michael@0 132 // CHANNEL_LAYOUT_6_1_FRONT
michael@0 133 { 0 , 1 , -1 , 6 , -1 , -1 , 4 , 5 , -1 , 2 , 3 },
michael@0 134
michael@0 135 // CHANNEL_LAYOUT_7_0_FRONT
michael@0 136 { 0 , 1 , 2 , -1 , -1 , -1 , 5 , 6 , -1 , 3 , 4 },
michael@0 137
michael@0 138 // CHANNEL_LAYOUT_7_1_WIDE_BACK
michael@0 139 { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , -1 , -1 , -1 },
michael@0 140
michael@0 141 // CHANNEL_LAYOUT_OCTAGONAL
michael@0 142 { 0 , 1 , 2 , -1 , 5 , 6 , -1 , -1 , 7 , 3 , 4 },
michael@0 143
michael@0 144 // CHANNEL_LAYOUT_DISCRETE
michael@0 145 { -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },
michael@0 146
michael@0 147 // FL | FR | FC | LFE | BL | BR | FLofC | FRofC | BC | SL | SR
michael@0 148 };
michael@0 149
michael@0 150 int ChannelLayoutToChannelCount(ChannelLayout layout) {
michael@0 151 DCHECK_LT(static_cast<size_t>(layout), arraysize(kLayoutToChannels));
michael@0 152 return kLayoutToChannels[layout];
michael@0 153 }
michael@0 154
michael@0 155 // Converts a channel count into a channel layout.
michael@0 156 ChannelLayout GuessChannelLayout(int channels) {
michael@0 157 switch (channels) {
michael@0 158 case 1:
michael@0 159 return CHANNEL_LAYOUT_MONO;
michael@0 160 case 2:
michael@0 161 return CHANNEL_LAYOUT_STEREO;
michael@0 162 case 3:
michael@0 163 return CHANNEL_LAYOUT_SURROUND;
michael@0 164 case 4:
michael@0 165 return CHANNEL_LAYOUT_QUAD;
michael@0 166 case 5:
michael@0 167 return CHANNEL_LAYOUT_5_0;
michael@0 168 case 6:
michael@0 169 return CHANNEL_LAYOUT_5_1;
michael@0 170 case 7:
michael@0 171 return CHANNEL_LAYOUT_6_1;
michael@0 172 case 8:
michael@0 173 return CHANNEL_LAYOUT_7_1;
michael@0 174 default:
michael@0 175 DMX_LOG("Unsupported channel count: %d\n", channels);
michael@0 176 }
michael@0 177 return CHANNEL_LAYOUT_UNSUPPORTED;
michael@0 178 }
michael@0 179
michael@0 180 int ChannelOrder(ChannelLayout layout, Channels channel) {
michael@0 181 DCHECK_LT(static_cast<size_t>(layout), arraysize(kChannelOrderings));
michael@0 182 DCHECK_LT(static_cast<size_t>(channel), arraysize(kChannelOrderings[0]));
michael@0 183 return kChannelOrderings[layout][channel];
michael@0 184 }
michael@0 185
michael@0 186 } // namespace mp4_demuxer

mercurial