android_GenericPlayer.h revision 37dc2fccf3f122b79ebd554de209d0a3c94ae161
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//--------------------------------------------------------------------------------------------------
19namespace android {
20
21class GenericPlayer : public AHandler
22{
23public:
24
25    enum {
26        kEventPrepared      = 'prep',
27        kEventHasVideoSize  = 'vsiz',
28    };
29
30    GenericPlayer(const AudioPlayback_Parameters* params);
31    virtual ~GenericPlayer();
32
33    virtual void init(const notif_cbf_t cbf, void* notifUser);
34
35    virtual void setDataSource(const char *uri);
36    virtual void setDataSource(int fd, int64_t offset, int64_t length);
37
38    virtual void prepare();
39    virtual void play();
40    virtual void pause();
41    virtual void stop();
42    virtual void seek(int64_t timeMsec);
43    virtual void loop(bool loop);
44
45    virtual void getDurationMsec(int* msec); // -1 if unknown
46
47    void updateVolume(bool mute, bool useStereoPos, XApermille stereoPos, XAmillibel volume);
48
49protected:
50    Mutex mSettingsLock;
51
52    void resetDataLocator();
53    DataLocator2 mDataLocator;
54    int          mDataLocatorType;
55
56    enum {
57        kWhatPrepare      = 'prep',
58        kWhatNotif        = 'noti',
59        kWhatPlay         = 'play',
60        kWhatPause        = 'paus',
61        kWhatSeek         = 'seek',
62        kWhatLoop         = 'loop',
63        kWhatVolumeUpdate = 'volu'
64    };
65
66    // Send a notification to one of the event listeners
67    virtual void notify(const char* event, int data1, bool async);
68    virtual void notify(const char* event, int data1, int data2, bool async);
69
70    // AHandler implementation
71    virtual void onMessageReceived(const sp<AMessage> &msg);
72
73    // Async event handlers (called from GenericPlayer's event loop)
74    virtual void onPrepare();
75    virtual void onNotify(const sp<AMessage> &msg);
76    virtual void onPlay();
77    virtual void onPause();
78    virtual void onSeek(const sp<AMessage> &msg);
79    virtual void onLoop(const sp<AMessage> &msg);
80    virtual void onVolumeUpdate();
81
82    // Event notification from GenericPlayer to OpenSL ES / OpenMAX AL framework
83    notif_cbf_t mNotifyClient;
84    void*       mNotifyUser;
85
86    enum {
87        kFlagPrepared  = 1 <<0,
88        kFlagPreparing = 1 <<1,
89        kFlagPlaying   = 1 <<2,
90        kFlagBuffering = 1 <<3,
91        kFlagSeeking   = 1 <<4,
92        kFlagLooping   = 1 <<5,
93    };
94
95    uint32_t mStateFlags;
96
97    sp<ALooper> mLooper;
98    int32_t mLooperPriority;
99
100    AudioPlayback_Parameters mPlaybackParams;
101
102    AndroidAudioLevels mAndroidAudioLevels;
103    int mChannelCount; // this is used for the panning law, and is not exposed outside of the object
104
105private:
106    DISALLOW_EVIL_CONSTRUCTORS(GenericPlayer);
107};
108
109} // namespace android
110