android_AudioSfDecoder.h revision 4ee246c55533bdab8ab5fa0f0581744fe58e7c91
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#include <media/stagefright/DataSource.h>
18#include <media/stagefright/MediaSource.h>
19#include <media/stagefright/FileSource.h>
20#include <media/stagefright/MediaDefs.h>
21#include <media/stagefright/MediaExtractor.h>
22#include <media/stagefright/MetaData.h>
23#include <media/stagefright/OMXClient.h>
24#include <media/stagefright/OMXCodec.h>
25#include "NuCachedSource2.h"
26#include "NuHTTPDataSource.h"
27#include "ThrottledSource.h"
28
29#include "android_GenericPlayer.h"
30
31//--------------------------------------------------------------------------------------------------
32namespace android {
33
34class AudioSfDecoder : public GenericPlayer
35{
36public:
37
38    AudioSfDecoder(const AudioPlayback_Parameters* params);
39    virtual ~AudioSfDecoder();
40
41    // overridden from GenericPlayer
42    virtual void play();
43
44    void startPrefetch_async();
45
46protected:
47
48    enum {
49        kWhatDecode     = 'deco',
50        kWhatRender     = 'rend',
51        kWhatCheckCache = 'cach',
52    };
53
54    // Async event handlers (called from the AudioSfDecoder's event loop)
55    void onDecode();
56    void onCheckCache(const sp<AMessage> &msg);
57    virtual void onRender();
58
59    // Async event handlers (called from GenericPlayer's event loop)
60    virtual void onPrepare();
61    virtual void onPlay();
62    virtual void onPause();
63    virtual void onSeek(const sp<AMessage> &msg);
64    virtual void onLoop(const sp<AMessage> &msg);
65
66    // overridden from GenericPlayer
67    virtual void onNotify(const sp<AMessage> &msg);
68    virtual void onMessageReceived(const sp<AMessage> &msg);
69
70    // to be implemented by subclasses of AudioSfDecoder to do something with the audio samples
71    virtual void createAudioSink() = 0;
72    virtual void updateAudioSink() = 0;
73    virtual void startAudioSink() = 0;
74    virtual void pauseAudioSink() = 0;
75
76    sp<DataSource> mDataSource;
77    sp<MediaSource> mAudioSource;
78
79    // negative values indicate invalid value
80    int64_t mBitrate;  // in bits/sec
81    int32_t mNumChannels;
82    int32_t mSampleRateHz;
83    int64_t mDurationUsec;
84
85    // buffer passed from decoder to renderer
86    MediaBuffer *mDecodeBuffer;
87    // mutex used to protect the decode buffer
88    Mutex       mDecodeBufferLock;
89
90
91private:
92
93    void notifyPrepared(status_t prepareRes);
94
95    int64_t mTimeDelta;
96    int64_t mSeekTimeMsec;
97    int64_t mLastDecodedPositionUs;
98
99    // mutex used for seek flag and seek time read/write
100    Mutex mSeekLock;
101
102    bool wantPrefetch();
103    CacheStatus_t getCacheRemaining(bool *eos);
104    int64_t getPositionUsec();
105
106private:
107    DISALLOW_EVIL_CONSTRUCTORS(AudioSfDecoder);
108
109};
110
111} // namespace android
112