2
* The contents of this file are subject to the Mozilla Public
3
* License Version 1.1 (the "License"); you may not use this file
4
* except in compliance with the License. You may obtain a copy of
5
* the License at http://www.mozilla.org/MPL/
7
* Software distributed under the License is distributed on an "AS
8
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9
* implied. See the License for the specific language governing
10
* rights and limitations under the License.
12
* The Original Code is MPEG4IP.
14
* The Initial Developer of the Original Code is Cisco Systems Inc.
15
* Portions created by Cisco Systems Inc. are
16
* Copyright (C) Cisco Systems Inc. 2000-2002. All Rights Reserved.
19
* Dave Mackie dmackie@cisco.com
24
* - file formatted with tabstops == 4 spaces
27
#include <mp4av_common.h>
29
static MP4AV_Mp3Header GetMp3Header(
30
MP4FileHandle mp4File,
31
MP4TrackId audioTrackId)
33
u_int8_t* pMp3Frame = NULL;
34
u_int32_t mp3FrameLength = 0;
36
bool rc = MP4ReadSample(
43
if (!rc || mp3FrameLength < 4) {
47
MP4AV_Mp3Header mp3Hdr =
48
MP4AV_Mp3HeaderFromBytes(pMp3Frame);
54
extern "C" u_int8_t MP4AV_AudioGetChannels(
55
MP4FileHandle mp4File,
56
MP4TrackId audioTrackId)
59
MP4GetTrackEsdsObjectTypeId(mp4File, audioTrackId);
61
if (audioType == MP4_INVALID_AUDIO_TYPE) {
65
if (MP4_IS_MP3_AUDIO_TYPE(audioType)) {
66
MP4AV_Mp3Header mp3Hdr =
67
GetMp3Header(mp4File, audioTrackId);
72
return MP4AV_Mp3GetChannels(mp3Hdr);
74
} else if (MP4_IS_AAC_AUDIO_TYPE(audioType)) {
75
u_int8_t* pAacConfig = NULL;
76
u_int32_t aacConfigLength;
78
MP4GetTrackESConfiguration(
84
if (pAacConfig == NULL || aacConfigLength < 2) {
89
MP4AV_AacConfigGetChannels(pAacConfig);
95
} else if ((audioType == MP4_PCM16_LITTLE_ENDIAN_AUDIO_TYPE) ||
96
(audioType == MP4_PCM16_BIG_ENDIAN_AUDIO_TYPE)) {
97
u_int32_t samplesPerFrame =
98
MP4GetSampleSize(mp4File, audioTrackId, 1) / 2;
100
MP4Duration frameDuration =
101
MP4GetSampleDuration(mp4File, audioTrackId, 1);
103
if (frameDuration == 0) {
107
// assumes track time scale == sampling rate
108
return samplesPerFrame / frameDuration;
114
extern "C" u_int32_t MP4AV_AudioGetSamplingRate(
115
MP4FileHandle mp4File,
116
MP4TrackId audioTrackId)
119
MP4GetTrackEsdsObjectTypeId(mp4File, audioTrackId);
121
if (audioType == MP4_INVALID_AUDIO_TYPE) {
125
if (MP4_IS_MP3_AUDIO_TYPE(audioType)) {
126
MP4AV_Mp3Header mp3Hdr =
127
GetMp3Header(mp4File, audioTrackId);
132
return MP4AV_Mp3GetHdrSamplingRate(mp3Hdr);
134
} else if (MP4_IS_AAC_AUDIO_TYPE(audioType)) {
135
u_int8_t* pAacConfig = NULL;
136
u_int32_t aacConfigLength;
138
MP4GetTrackESConfiguration(
144
if (pAacConfig == NULL || aacConfigLength < 2) {
148
u_int32_t samplingRate =
149
MP4AV_AacConfigGetSamplingRate(pAacConfig);
155
} else if ((audioType == MP4_PCM16_LITTLE_ENDIAN_AUDIO_TYPE)||
156
(audioType == MP4_PCM16_BIG_ENDIAN_AUDIO_TYPE)) {
157
return MP4GetTrackTimeScale(mp4File, audioTrackId);
163
extern "C" u_int16_t MP4AV_AudioGetSamplingWindow(
164
MP4FileHandle mp4File,
165
MP4TrackId audioTrackId)
168
MP4GetTrackEsdsObjectTypeId(mp4File, audioTrackId);
170
if (audioType == MP4_INVALID_AUDIO_TYPE) {
174
if (MP4_IS_MP3_AUDIO_TYPE(audioType)) {
175
MP4AV_Mp3Header mp3Hdr =
176
GetMp3Header(mp4File, audioTrackId);
178
return MP4AV_Mp3GetHdrSamplingWindow(mp3Hdr);
180
} else if (MP4_IS_AAC_AUDIO_TYPE(audioType)) {
181
u_int8_t* pAacConfig = NULL;
182
u_int32_t aacConfigLength;
184
MP4GetTrackESConfiguration(
190
if (pAacConfig == NULL || aacConfigLength < 2) {
194
u_int32_t samplingWindow =
195
MP4AV_AacConfigGetSamplingWindow(pAacConfig);
199
return samplingWindow;
201
} else if ((audioType == MP4_PCM16_LITTLE_ENDIAN_AUDIO_TYPE)||
202
(audioType == MP4_PCM16_BIG_ENDIAN_AUDIO_TYPE)) {
203
MP4Duration frameDuration =
204
MP4GetSampleDuration(mp4File, audioTrackId, 1);
206
// assumes track time scale == sampling rate
207
// and constant frame size was used
208
return frameDuration;