Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "MediaInfo.h"
8 :
9 : namespace mozilla {
10 :
11 : const char*
12 0 : TrackTypeToStr(TrackInfo::TrackType aTrack)
13 : {
14 0 : switch (aTrack) {
15 : case TrackInfo::kUndefinedTrack:
16 0 : return "Undefined";
17 : case TrackInfo::kAudioTrack:
18 0 : return "Audio";
19 : case TrackInfo::kVideoTrack:
20 0 : return "Video";
21 : case TrackInfo::kTextTrack:
22 0 : return "Text";
23 : default:
24 0 : return "Unknown";
25 : }
26 : }
27 :
28 : typedef AudioConfig::ChannelLayout ChannelLayout;
29 :
30 : /**
31 : * AudioConfig::ChannelLayout
32 : */
33 :
34 : /*
35 : SMPTE channel layout (also known as wave order)
36 : DUAL-MONO L R
37 : DUAL-MONO-LFE L R LFE
38 : MONO M
39 : MONO-LFE M LFE
40 : STEREO L R
41 : STEREO-LFE L R LFE
42 : 3F L R C
43 : 3F-LFE L R C LFE
44 : 2F1 L R S
45 : 2F1-LFE L R LFE S
46 : 3F1 L R C S
47 : 3F1-LFE L R C LFE S
48 : 2F2 L R LS RS
49 : 2F2-LFE L R LFE LS RS
50 : 3F2 L R C LS RS
51 : 3F2-LFE L R C LFE LS RS
52 : 3F3R-LFE L R C LFE BC LS RS
53 : 3F4-LFE L R C LFE Rls Rrs LS RS
54 : */
55 :
56 : void
57 0 : AudioConfig::ChannelLayout::UpdateChannelMap()
58 : {
59 0 : mChannelMap = 0;
60 0 : mValid = mChannels.Length() <= MAX_AUDIO_CHANNELS;
61 0 : for (size_t i = 0; i < mChannels.Length() && i <= MAX_AUDIO_CHANNELS; i++) {
62 0 : uint32_t mask = 1 << mChannels[i];
63 0 : if (mChannels[i] == CHANNEL_INVALID || (mChannelMap & mask)) {
64 0 : mValid = false;
65 : }
66 0 : mChannelMap |= mask;
67 : }
68 0 : }
69 :
70 : /* static */ const AudioConfig::Channel*
71 0 : AudioConfig::ChannelLayout::SMPTEDefault(uint32_t aChannels) const
72 : {
73 0 : switch (aChannels) {
74 : case 1: // MONO
75 : {
76 : static const Channel config[] = { CHANNEL_MONO };
77 0 : return config;
78 : }
79 : case 2: // STEREO
80 : {
81 : static const Channel config[] = { CHANNEL_LEFT, CHANNEL_RIGHT };
82 0 : return config;
83 : }
84 : case 3: // 3F
85 : {
86 : static const Channel config[] = { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER };
87 0 : return config;
88 : }
89 : case 4: // 2F2
90 : {
91 : static const Channel config[] = { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_LS, CHANNEL_RS };
92 0 : return config;
93 : }
94 : case 5: // 3F2
95 : {
96 : static const Channel config[] = { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER, CHANNEL_LS, CHANNEL_RS };
97 0 : return config;
98 : }
99 : case 6: // 3F2-LFE
100 : {
101 : static const Channel config[] = { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER, CHANNEL_LFE, CHANNEL_LS, CHANNEL_RS };
102 0 : return config;
103 : }
104 : case 7: // 3F3R-LFE
105 : {
106 : static const Channel config[] = { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER, CHANNEL_LFE, CHANNEL_RCENTER, CHANNEL_LS, CHANNEL_RS };
107 0 : return config;
108 : }
109 : case 8: // 3F4-LFE
110 : {
111 : static const Channel config[] = { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER, CHANNEL_LFE, CHANNEL_RLS, CHANNEL_RRS, CHANNEL_LS, CHANNEL_RS };
112 0 : return config;
113 : }
114 : default:
115 0 : return nullptr;
116 : }
117 : }
118 :
119 : bool
120 0 : AudioConfig::ChannelLayout::MappingTable(const ChannelLayout& aOther,
121 : uint8_t* aMap) const
122 : {
123 0 : if (!IsValid() || !aOther.IsValid() ||
124 0 : Map() != aOther.Map()) {
125 0 : return false;
126 : }
127 0 : if (!aMap) {
128 0 : return true;
129 : }
130 0 : for (uint32_t i = 0; i < Count(); i++) {
131 0 : for (uint32_t j = 0; j < Count(); j++) {
132 0 : if (aOther[j] == mChannels[i]) {
133 0 : aMap[j] = i;
134 0 : break;
135 : }
136 : }
137 : }
138 0 : return true;
139 : }
140 :
141 : /**
142 : * AudioConfig::ChannelConfig
143 : */
144 :
145 : /* static */ const char*
146 0 : AudioConfig::FormatToString(AudioConfig::SampleFormat aFormat)
147 : {
148 0 : switch (aFormat) {
149 0 : case FORMAT_U8: return "unsigned 8 bit";
150 0 : case FORMAT_S16: return "signed 16 bit";
151 0 : case FORMAT_S24: return "signed 24 bit MSB";
152 0 : case FORMAT_S24LSB: return "signed 24 bit LSB";
153 0 : case FORMAT_S32: return "signed 32 bit";
154 0 : case FORMAT_FLT: return "32 bit floating point";
155 0 : case FORMAT_NONE: return "none";
156 0 : default: return "unknown";
157 : }
158 : }
159 : /* static */ uint32_t
160 0 : AudioConfig::SampleSize(AudioConfig::SampleFormat aFormat)
161 : {
162 0 : switch (aFormat) {
163 0 : case FORMAT_U8: return 1;
164 0 : case FORMAT_S16: return 2;
165 : case FORMAT_S24: MOZ_FALLTHROUGH;
166 : case FORMAT_S24LSB: MOZ_FALLTHROUGH;
167 : case FORMAT_S32: MOZ_FALLTHROUGH;
168 0 : case FORMAT_FLT: return 4;
169 : case FORMAT_NONE:
170 0 : default: return 0;
171 : }
172 : }
173 :
174 : /* static */ uint32_t
175 0 : AudioConfig::FormatToBits(AudioConfig::SampleFormat aFormat)
176 : {
177 0 : switch (aFormat) {
178 0 : case FORMAT_U8: return 8;
179 0 : case FORMAT_S16: return 16;
180 : case FORMAT_S24LSB: MOZ_FALLTHROUGH;
181 0 : case FORMAT_S24: return 24;
182 : case FORMAT_S32: MOZ_FALLTHROUGH;
183 0 : case FORMAT_FLT: return 32;
184 : case FORMAT_NONE: MOZ_FALLTHROUGH;
185 0 : default: return 0;
186 : }
187 : }
188 :
189 0 : AudioConfig::AudioConfig(const ChannelLayout& aChannelLayout, uint32_t aRate,
190 0 : AudioConfig::SampleFormat aFormat, bool aInterleaved)
191 : : mChannelLayout(aChannelLayout)
192 0 : , mChannels(aChannelLayout.Count())
193 : , mRate(aRate)
194 : , mFormat(aFormat)
195 0 : , mInterleaved(aInterleaved)
196 0 : {}
197 :
198 0 : AudioConfig::AudioConfig(uint32_t aChannels, uint32_t aRate,
199 0 : AudioConfig::SampleFormat aFormat, bool aInterleaved)
200 : : mChannelLayout(aChannels)
201 : , mChannels(aChannels)
202 : , mRate(aRate)
203 : , mFormat(aFormat)
204 0 : , mInterleaved(aInterleaved)
205 0 : {}
206 :
207 : } // namespace mozilla
|