ref: 91c3d6d0e3f82f9ffddd3fd2e95ea7fafb403111
dir: /plugins/in_mp4/mp4av_audio.cpp/
/* * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is MPEG4IP. * * The Initial Developer of the Original Code is Cisco Systems Inc. * Portions created by Cisco Systems Inc. are * Copyright (C) Cisco Systems Inc. 2000-2002. All Rights Reserved. * * Contributor(s): * Dave Mackie [email protected] */ /* * Notes: * - file formatted with tabstops == 4 spaces */ #include "mp4av_common.h" extern "C" u_int8_t MP4AV_AudioGetChannels( MP4FileHandle mp4File, MP4TrackId audioTrackId) { u_int8_t audioType = MP4GetTrackAudioType(mp4File, audioTrackId); if (audioType == MP4_INVALID_AUDIO_TYPE) { return 0; } if (MP4_IS_MP3_AUDIO_TYPE(audioType)) { return 0; } else if (MP4_IS_AAC_AUDIO_TYPE(audioType)) { u_int8_t* pAacConfig = NULL; u_int32_t aacConfigLength; MP4GetTrackESConfiguration( mp4File, audioTrackId, &pAacConfig, &aacConfigLength); if (pAacConfig == NULL || aacConfigLength < 2) { return 0; } u_int8_t channels = MP4AV_AacConfigGetChannels(pAacConfig); free(pAacConfig); return channels; } else if (audioType == MP4_PCM16_AUDIO_TYPE) { u_int32_t samplesPerFrame = MP4GetSampleSize(mp4File, audioTrackId, 1) / 2; MP4Duration frameDuration = MP4GetSampleDuration(mp4File, audioTrackId, 1); if (frameDuration == 0) { return 0; } // assumes track time scale == sampling rate return samplesPerFrame / frameDuration; } return 0; } extern "C" u_int32_t MP4AV_AudioGetSamplingRate( MP4FileHandle mp4File, MP4TrackId audioTrackId) { u_int8_t audioType = MP4GetTrackAudioType(mp4File, audioTrackId); if (audioType == MP4_INVALID_AUDIO_TYPE) { return 0; } if (MP4_IS_MP3_AUDIO_TYPE(audioType)) { return 0; } else if (MP4_IS_AAC_AUDIO_TYPE(audioType)) { u_int8_t* pAacConfig = NULL; u_int32_t aacConfigLength; MP4GetTrackESConfiguration( mp4File, audioTrackId, &pAacConfig, &aacConfigLength); if (pAacConfig == NULL || aacConfigLength < 2) { return 0; } u_int32_t samplingRate = MP4AV_AacConfigGetSamplingRate(pAacConfig); free(pAacConfig); return samplingRate; } else if (audioType == MP4_PCM16_AUDIO_TYPE) { return MP4GetTrackTimeScale(mp4File, audioTrackId); } return 0; } extern "C" u_int16_t MP4AV_AudioGetSamplingWindow( MP4FileHandle mp4File, MP4TrackId audioTrackId) { u_int8_t audioType = MP4GetTrackAudioType(mp4File, audioTrackId); if (audioType == MP4_INVALID_AUDIO_TYPE) { return 0; } if (MP4_IS_MP3_AUDIO_TYPE(audioType)) { return 0; } else if (MP4_IS_AAC_AUDIO_TYPE(audioType)) { u_int8_t* pAacConfig = NULL; u_int32_t aacConfigLength; MP4GetTrackESConfiguration( mp4File, audioTrackId, &pAacConfig, &aacConfigLength); if (pAacConfig == NULL || aacConfigLength < 2) { return 0; } u_int32_t samplingWindow = MP4AV_AacConfigGetSamplingWindow(pAacConfig); free(pAacConfig); return samplingWindow; } else if (audioType == MP4_PCM16_AUDIO_TYPE) { MP4Duration frameDuration = MP4GetSampleDuration(mp4File, audioTrackId, 1); // assumes track time scale == sampling rate // and constant frame size was used return frameDuration; } return 0; }