2 * Copyright (C) 2011 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 //--------------------------------------------------------------------------------------------------
21 class AudioSfDecoder : public GenericPlayer
25 AudioSfDecoder(const AudioPlayback_Parameters* params);
26 virtual ~AudioSfDecoder();
28 // overridden from GenericPlayer
31 void startPrefetch_async();
45 kEventPrefetchStatusChange = 'prsc',
46 kEventPrefetchFillLevelUpdate = 'pflu',
47 kEventEndOfStream = 'eos',
53 kWhatCheckCache = 'cach',
56 // Async event handlers (called from the AudioSfDecoder's event loop)
58 void onCheckCache(const sp<AMessage> &msg);
59 virtual void onRender();
61 // Async event handlers (called from GenericPlayer's event loop)
62 virtual void onPrepare();
63 virtual void onPlay();
64 virtual void onPause();
65 virtual void onSeek(const sp<AMessage> &msg);
66 virtual void onLoop(const sp<AMessage> &msg);
68 // overridden from GenericPlayer
69 virtual void onNotify(const sp<AMessage> &msg);
70 virtual void onMessageReceived(const sp<AMessage> &msg);
72 // to be implemented by subclasses of AudioSfDecoder to do something with the audio samples
73 virtual void createAudioSink() = 0;
74 virtual void updateAudioSink() = 0;
75 virtual void startAudioSink() = 0;
76 virtual void pauseAudioSink() = 0;
78 sp<DataSource> mDataSource;
79 sp<MediaSource> mAudioSource;
81 // negative values indicate invalid value
82 int64_t mBitrate; // in bits/sec
84 int32_t mSampleRateHz;
85 int64_t mDurationUsec;
87 // buffer passed from decoder to renderer
88 MediaBuffer *mDecodeBuffer;
89 // mutex used to protect the decode buffer
90 Mutex mDecodeBufferLock;
96 void notifyCacheFill();
97 void notifyPrepared(status_t prepareRes);
99 CacheStatus mCacheStatus;
100 int16_t mCacheFill; // cache fill level in permille, signed per OpenSL ES
101 int16_t mLastNotifiedCacheFill; // last cache fill level communicated to the listener
102 int16_t mCacheFillNotifThreshold; // threshold in cache fill level for cache fill to be reported
105 int64_t mSeekTimeMsec;
106 int64_t mLastDecodedPositionUs;
108 // mutex used for seek flag and seek time read/write
112 sp<ALooper> mRenderLooper;
116 CacheStatus getCacheRemaining(bool *eos);
117 int64_t getPositionUsec();
120 DISALLOW_EVIL_CONSTRUCTORS(AudioSfDecoder);
124 } // namespace android