OSDN Git Service

OpenSL ES: support decode to PCM buffer queue
[android-x86/system-media.git] / wilhelm / src / android / android_AudioSfDecoder.h
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17
18 //--------------------------------------------------------------------------------------------------
19 namespace android {
20
21 class AudioSfDecoder : public GenericPlayer
22 {
23 public:
24
25     AudioSfDecoder(const AudioPlayback_Parameters* params);
26     virtual ~AudioSfDecoder();
27
28     // overridden from GenericPlayer
29     virtual void play();
30
31     void startPrefetch_async();
32
33 protected:
34
35     enum CacheStatus {
36             kStatusUnknown = -1,
37             kStatusEmpty = 0,
38             kStatusLow,
39             kStatusIntermediate,
40             kStatusEnough,
41             kStatusHigh
42         };
43
44     enum {
45         kEventPrefetchStatusChange    = 'prsc',
46         kEventPrefetchFillLevelUpdate = 'pflu',
47         kEventEndOfStream             = 'eos',
48     };
49
50     enum {
51         kWhatDecode     = 'deco',
52         kWhatRender     = 'rend',
53         kWhatCheckCache = 'cach',
54     };
55
56     // Async event handlers (called from the AudioSfDecoder's event loop)
57     void onDecode();
58     void onCheckCache(const sp<AMessage> &msg);
59     virtual void onRender();
60
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);
67
68     // overridden from GenericPlayer
69     virtual void onNotify(const sp<AMessage> &msg);
70     virtual void onMessageReceived(const sp<AMessage> &msg);
71
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;
77
78     sp<DataSource> mDataSource;
79     sp<MediaSource> mAudioSource;
80
81     // negative values indicate invalid value
82     int64_t mBitrate;  // in bits/sec
83     int32_t mNumChannels;
84     int32_t mSampleRateHz;
85     int64_t mDurationUsec;
86
87     // buffer passed from decoder to renderer
88     MediaBuffer *mDecodeBuffer;
89     // mutex used to protect the decode buffer
90     Mutex       mDecodeBufferLock;
91
92
93 private:
94
95     void notifyStatus();
96     void notifyCacheFill();
97     void notifyPrepared(status_t prepareRes);
98
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
103
104     int64_t mTimeDelta;
105     int64_t mSeekTimeMsec;
106     int64_t mLastDecodedPositionUs;
107
108     // mutex used for seek flag and seek time read/write
109     Mutex mSeekLock;
110
111 /*
112     sp<ALooper> mRenderLooper;
113 */
114
115     bool wantPrefetch();
116     CacheStatus getCacheRemaining(bool *eos);
117     int64_t getPositionUsec();
118
119 private:
120     DISALLOW_EVIL_CONSTRUCTORS(AudioSfDecoder);
121
122 };
123
124 } // namespace android