android_AudioSfDecoder.h revision 13837cf3f7be0eb8b1a9552bd99a89f98c987720
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 1713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 1813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi//-------------------------------------------------------------------------------------------------- 1913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivinamespace android { 2013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 2113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Triviclass AudioSfDecoder : public GenericPlayer 2213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi{ 2313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivipublic: 2413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 2513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi AudioSfDecoder(const AudioPlayback_Parameters* params); 2613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual ~AudioSfDecoder(); 2713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 2813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi // overridden from GenericPlayer 2913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void play(); 3013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 3113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi void startPrefetch_async(); 3213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 3313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Triviprotected: 3413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 3513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi enum CacheStatus { 3613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi kStatusUnknown = -1, 3713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi kStatusEmpty = 0, 3813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi kStatusLow, 3913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi kStatusIntermediate, 4013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi kStatusEnough, 4113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi kStatusHigh 4213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi }; 4313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 4413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi enum { 4513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi kEventPrefetchStatusChange = 'prsc', 4613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi kEventPrefetchFillLevelUpdate = 'pflu', 4713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi kEventEndOfStream = 'eos', 4813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi }; 4913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 5013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi enum { 5113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi kWhatDecode = 'deco', 5213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi kWhatRender = 'rend', 5313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi kWhatCheckCache = 'cach', 5413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi }; 5513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 5613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi // Async event handlers (called from the AudioSfDecoder's event loop) 5713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi void onDecode(); 5813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi void onCheckCache(const sp<AMessage> &msg); 5913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void onRender(); 6013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 6113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi // Async event handlers (called from GenericPlayer's event loop) 6213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void onPrepare(); 6313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void onPlay(); 6413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void onPause(); 6513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void onSeek(const sp<AMessage> &msg); 6613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void onLoop(const sp<AMessage> &msg); 6713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 6813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi // overridden from GenericPlayer 6913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void onNotify(const sp<AMessage> &msg); 7013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void onMessageReceived(const sp<AMessage> &msg); 7113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 7213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi // to be implemented by subclasses of AudioSfDecoder to do something with the audio samples 7313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void createAudioSink() = 0; 7413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void updateAudioSink() = 0; 7513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void startAudioSink() = 0; 7613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi virtual void pauseAudioSink() = 0; 7713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 7813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi sp<DataSource> mDataSource; 7913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi sp<MediaSource> mAudioSource; 8013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 8113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi // negative values indicate invalid value 8213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi int64_t mBitrate; // in bits/sec 8313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi int32_t mNumChannels; 8413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi int32_t mSampleRateHz; 8513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi int64_t mDurationUsec; 8613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 8713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi // buffer passed from decoder to renderer 8813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi MediaBuffer *mDecodeBuffer; 8913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi // mutex used to protect the decode buffer 9013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi Mutex mDecodeBufferLock; 9113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 9213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 9313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Triviprivate: 9413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 9513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi void notifyStatus(); 9613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi void notifyCacheFill(); 9713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi void notifyPrepared(status_t prepareRes); 9813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 9913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi CacheStatus mCacheStatus; 10013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi int16_t mCacheFill; // cache fill level in permille, signed per OpenSL ES 10113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi int16_t mLastNotifiedCacheFill; // last cache fill level communicated to the listener 10213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi int16_t mCacheFillNotifThreshold; // threshold in cache fill level for cache fill to be reported 10313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 10413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi int64_t mTimeDelta; 10513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi int64_t mSeekTimeMsec; 10613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi int64_t mLastDecodedPositionUs; 10713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 10813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi // mutex used for seek flag and seek time read/write 10913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi Mutex mSeekLock; 11013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 11113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi/* 11213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi sp<ALooper> mRenderLooper; 11313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi*/ 11413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 11513837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi bool wantPrefetch(); 11613837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi CacheStatus getCacheRemaining(bool *eos); 11713837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi int64_t getPositionUsec(); 11813837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 11913837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Triviprivate: 12013837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi DISALLOW_EVIL_CONSTRUCTORS(AudioSfDecoder); 12113837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 12213837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi}; 12313837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi 12413837cf3f7be0eb8b1a9552bd99a89f98c987720Jean-Michel Trivi} // namespace android 125