113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi/* 213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * Copyright (C) 2011 The Android Open Source Project 313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * 413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * Licensed under the Apache License, Version 2.0 (the "License"); 513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * you may not use this file except in compliance with the License. 613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * You may obtain a copy of the License at 713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * 813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * http://www.apache.org/licenses/LICENSE-2.0 913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * 1013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * Unless required by applicable law or agreed to in writing, software 1113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * distributed under the License is distributed on an "AS IS" BASIS, 1213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * See the License for the specific language governing permissions and 1413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi * limitations under the License. 1513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi */ 1613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 17bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#ifndef AUDIO_SF_DECODER_H_ 18bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#define AUDIO_SF_DECODER_H_ 19bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 204ee246c55533bdab8ab5fa0f0581744fe58e7c91Jean-Michel Trivi#include <media/stagefright/DataSource.h> 214ee246c55533bdab8ab5fa0f0581744fe58e7c91Jean-Michel Trivi#include <media/stagefright/MediaSource.h> 224ee246c55533bdab8ab5fa0f0581744fe58e7c91Jean-Michel Trivi#include <media/stagefright/FileSource.h> 234ee246c55533bdab8ab5fa0f0581744fe58e7c91Jean-Michel Trivi#include <media/stagefright/MediaDefs.h> 244ee246c55533bdab8ab5fa0f0581744fe58e7c91Jean-Michel Trivi#include <media/stagefright/MediaExtractor.h> 254ee246c55533bdab8ab5fa0f0581744fe58e7c91Jean-Michel Trivi#include <media/stagefright/MetaData.h> 264ee246c55533bdab8ab5fa0f0581744fe58e7c91Jean-Michel Trivi#include <media/stagefright/OMXClient.h> 274ee246c55533bdab8ab5fa0f0581744fe58e7c91Jean-Michel Trivi#include <media/stagefright/OMXCodec.h> 284ee246c55533bdab8ab5fa0f0581744fe58e7c91Jean-Michel Trivi#include "NuCachedSource2.h" 294ee246c55533bdab8ab5fa0f0581744fe58e7c91Jean-Michel Trivi#include "ThrottledSource.h" 304ee246c55533bdab8ab5fa0f0581744fe58e7c91Jean-Michel Trivi 314ee246c55533bdab8ab5fa0f0581744fe58e7c91Jean-Michel Trivi#include "android_GenericPlayer.h" 3213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 3313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi//-------------------------------------------------------------------------------------------------- 3413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivinamespace android { 3513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 36bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi// keep in sync with the entries of kPcmDecodeMetadataKeys[] 37bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#define ANDROID_KEY_INDEX_PCMFORMAT_NUMCHANNELS 0 380f92f48017588949daf7d24a339423e149bb2555Glenn Kasten#define ANDROID_KEY_INDEX_PCMFORMAT_SAMPLERATE 1 39bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#define ANDROID_KEY_INDEX_PCMFORMAT_BITSPERSAMPLE 2 40bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#define ANDROID_KEY_INDEX_PCMFORMAT_CONTAINERSIZE 3 41bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#define ANDROID_KEY_INDEX_PCMFORMAT_CHANNELMASK 4 42bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#define ANDROID_KEY_INDEX_PCMFORMAT_ENDIANNESS 5 43bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 447f5cc1afe49395fefaad9b2bbd728a45d1bfda6aJean-Michel Trivi// to keep in sync with the ANDROID_KEY_INDEX_PCMFORMAT_* constants in android_AudioSfDecoder.cpp 457f5cc1afe49395fefaad9b2bbd728a45d1bfda6aJean-Michel Trivistatic const char* const kPcmDecodeMetadataKeys[] = { 460f92f48017588949daf7d24a339423e149bb2555Glenn Kasten ANDROID_KEY_PCMFORMAT_NUMCHANNELS, ANDROID_KEY_PCMFORMAT_SAMPLERATE, 477f5cc1afe49395fefaad9b2bbd728a45d1bfda6aJean-Michel Trivi ANDROID_KEY_PCMFORMAT_BITSPERSAMPLE, ANDROID_KEY_PCMFORMAT_CONTAINERSIZE, 487f5cc1afe49395fefaad9b2bbd728a45d1bfda6aJean-Michel Trivi ANDROID_KEY_PCMFORMAT_CHANNELMASK, ANDROID_KEY_PCMFORMAT_ENDIANNESS }; 497f5cc1afe49395fefaad9b2bbd728a45d1bfda6aJean-Michel Trivi#define NB_PCMMETADATA_KEYS (sizeof(kPcmDecodeMetadataKeys)/sizeof(kPcmDecodeMetadataKeys[0])) 507f5cc1afe49395fefaad9b2bbd728a45d1bfda6aJean-Michel Trivi 517349b2e742b2cedc6d149fac62ed661ad7d47decGlenn Kasten// abstract base class for AudioToCbRenderer and it's subclasses 5213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Triviclass AudioSfDecoder : public GenericPlayer 5313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi{ 5413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivipublic: 5513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 5613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi AudioSfDecoder(const AudioPlayback_Parameters* params); 5713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual ~AudioSfDecoder(); 5813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 59e6ded5c61944a87fa9e472dec3a6929855d42aebJean-Michel Trivi virtual void preDestroy(); 60e6ded5c61944a87fa9e472dec3a6929855d42aebJean-Michel Trivi 6113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi // overridden from GenericPlayer 6213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void play(); 635050a75e342ce45794d56666cddde3d46472acc7Jean-Michel Trivi virtual void getPositionMsec(int* msec); //msec != NULL, ANDROID_UNKNOWN_TIME if unknown 6413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 6591540f92d7f1bcda423859af6bd82df083c2afabGlenn Kasten uint32_t getPcmFormatKeyCount() const; 667f5cc1afe49395fefaad9b2bbd728a45d1bfda6aJean-Michel Trivi bool getPcmFormatKeySize(uint32_t index, uint32_t* pKeySize); 677f5cc1afe49395fefaad9b2bbd728a45d1bfda6aJean-Michel Trivi bool getPcmFormatKeyName(uint32_t index, uint32_t keySize, char* keyName); 687f5cc1afe49395fefaad9b2bbd728a45d1bfda6aJean-Michel Trivi bool getPcmFormatValueSize(uint32_t index, uint32_t* pValueSize); 697f5cc1afe49395fefaad9b2bbd728a45d1bfda6aJean-Michel Trivi bool getPcmFormatKeyValue(uint32_t index, uint32_t size, uint32_t* pValue); 707f5cc1afe49395fefaad9b2bbd728a45d1bfda6aJean-Michel Trivi 7113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Triviprotected: 7213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 7313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi enum { 747f5cc1afe49395fefaad9b2bbd728a45d1bfda6aJean-Michel Trivi kWhatDecode = 'deco', 757f5cc1afe49395fefaad9b2bbd728a45d1bfda6aJean-Michel Trivi kWhatRender = 'rend', 7654cad4f35a090a06e655fcc9e072e1d38f9e7689Jean-Michel Trivi kWhatCheckCache = 'cach' 7713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi }; 7813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 7913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi // Async event handlers (called from the AudioSfDecoder's event loop) 8013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi void onDecode(); 8113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi void onCheckCache(const sp<AMessage> &msg); 827349b2e742b2cedc6d149fac62ed661ad7d47decGlenn Kasten virtual void onRender() = 0; 8313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 8413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi // Async event handlers (called from GenericPlayer's event loop) 8513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void onPrepare(); 8613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void onPlay(); 8713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void onPause(); 8813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void onSeek(const sp<AMessage> &msg); 8913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void onLoop(const sp<AMessage> &msg); 9013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 9113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi // overridden from GenericPlayer 9213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void onNotify(const sp<AMessage> &msg); 9313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void onMessageReceived(const sp<AMessage> &msg); 9413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 9513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi // to be implemented by subclasses of AudioSfDecoder to do something with the audio samples 9654cad4f35a090a06e655fcc9e072e1d38f9e7689Jean-Michel Trivi // (called from GenericPlayer's event loop) 9713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void createAudioSink() = 0; 9854cad4f35a090a06e655fcc9e072e1d38f9e7689Jean-Michel Trivi virtual void updateAudioSink() = 0; // called with mBufferSourceLock held 9913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void startAudioSink() = 0; 10013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void pauseAudioSink() = 0; 10113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 102e6ded5c61944a87fa9e472dec3a6929855d42aebJean-Michel Trivi sp<DataSource> mDataSource; // where the raw data comes from 103e6ded5c61944a87fa9e472dec3a6929855d42aebJean-Michel Trivi sp<MediaSource> mAudioSource;// the decoder reading from the data source 104e6ded5c61944a87fa9e472dec3a6929855d42aebJean-Michel Trivi // used to indicate mAudioSource was successfully started, but wasn't stopped 105e6ded5c61944a87fa9e472dec3a6929855d42aebJean-Michel Trivi bool mAudioSourceStarted; 10613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 10713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi // negative values indicate invalid value 10813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi int64_t mBitrate; // in bits/sec 1095050a75e342ce45794d56666cddde3d46472acc7Jean-Michel Trivi int64_t mDurationUsec; // ANDROID_UNKNOWN_TIME if unknown 11013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 11113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi // buffer passed from decoder to renderer 11213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi MediaBuffer *mDecodeBuffer; 113e6ded5c61944a87fa9e472dec3a6929855d42aebJean-Michel Trivi 114e6ded5c61944a87fa9e472dec3a6929855d42aebJean-Michel Trivi // mutex used to protect the decode buffer, the audio source and its running state 115e6ded5c61944a87fa9e472dec3a6929855d42aebJean-Michel Trivi Mutex mBufferSourceLock; 11613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 11713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi void notifyPrepared(status_t prepareRes); 11813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 11913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi int64_t mSeekTimeMsec; 1205050a75e342ce45794d56666cddde3d46472acc7Jean-Michel Trivi int64_t mLastDecodedPositionUs; // ANDROID_UNKNOWN_TIME if unknown 1215050a75e342ce45794d56666cddde3d46472acc7Jean-Michel Trivi // mutex used for seek flag, seek time (mSeekTimeMsec), 1225050a75e342ce45794d56666cddde3d46472acc7Jean-Michel Trivi // and last decoded position (mLastDecodedPositionUs) 1235050a75e342ce45794d56666cddde3d46472acc7Jean-Michel Trivi Mutex mTimeLock; 12413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 1257f5cc1afe49395fefaad9b2bbd728a45d1bfda6aJean-Michel Trivi // informations that can be retrieved in the PCM format queries 1267f5cc1afe49395fefaad9b2bbd728a45d1bfda6aJean-Michel Trivi // these values are only written in the event loop 1277f5cc1afe49395fefaad9b2bbd728a45d1bfda6aJean-Michel Trivi uint32_t mPcmFormatValues[NB_PCMMETADATA_KEYS]; 12891540f92d7f1bcda423859af6bd82df083c2afabGlenn Kasten // protects mPcmFormatValues 12954cad4f35a090a06e655fcc9e072e1d38f9e7689Jean-Michel Trivi Mutex mPcmFormatLock; 1307f5cc1afe49395fefaad9b2bbd728a45d1bfda6aJean-Michel Trivi 1317349b2e742b2cedc6d149fac62ed661ad7d47decGlenn Kasten virtual bool advancesPositionInRealTime() const { return false; } 1327349b2e742b2cedc6d149fac62ed661ad7d47decGlenn Kasten 133bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Triviprivate: 13413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi bool wantPrefetch(); 1354ee246c55533bdab8ab5fa0f0581744fe58e7c91Jean-Michel Trivi CacheStatus_t getCacheRemaining(bool *eos); 1365050a75e342ce45794d56666cddde3d46472acc7Jean-Michel Trivi int64_t getPositionUsec(); // ANDROID_UNKNOWN_TIME if unknown 13713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 13854cad4f35a090a06e655fcc9e072e1d38f9e7689Jean-Michel Trivi // convenience function to update internal state when decoding parameters have changed, 13954cad4f35a090a06e655fcc9e072e1d38f9e7689Jean-Michel Trivi // called with a lock on mBufferSourceLock 14054cad4f35a090a06e655fcc9e072e1d38f9e7689Jean-Michel Trivi void hasNewDecodeParams(); 14154cad4f35a090a06e655fcc9e072e1d38f9e7689Jean-Michel Trivi 1423597268c2bf4ff71521e3cbe522d7ee02c41f175Jean-Michel Trivi static bool isSupportedCodec(const char* mime); 1433597268c2bf4ff71521e3cbe522d7ee02c41f175Jean-Michel Trivi 14413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Triviprivate: 14513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi DISALLOW_EVIL_CONSTRUCTORS(AudioSfDecoder); 14613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 14713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi}; 14813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 14913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} // namespace android 150bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi 151bb832e853d4afb11b0a3287b2eb0cad87696d631Jean-Michel Trivi#endif // AUDIO_SF_DECODER_H_ 152