android_GenericPlayer.h revision dff1b1fc1f687c544e19df56bef225c45f7256a9
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    };
28
29    GenericPlayer(const AudioPlayback_Parameters* params);
30    virtual ~GenericPlayer();
31
32    virtual void init(const notif_cbf_t cbf, void* notifUser);
33
34    virtual void setDataSource(const char *uri);
35    virtual void setDataSource(int fd, int64_t offset, int64_t length);
36
37    virtual void prepare();
38    virtual void play();
39    virtual void pause();
40    virtual void stop();
41    virtual void seek(int64_t timeMsec);
42    virtual void loop(bool loop);
43
44protected:
45
46    void resetDataLocator();
47    DataLocator2 mDataLocator;
48    int          mDataLocatorType;
49
50    enum {
51        kWhatPrepare    = 'prep',
52        kWhatNotif      = 'noti',
53        kWhatPlay       = 'play',
54        kWhatPause      = 'paus',
55        kWhatSeek       = 'seek',
56        kWhatLoop       = 'loop',
57    };
58
59    // Send a notification to one of the event listeners
60    virtual void notify(const char* event, int data, bool async);
61
62    // AHandler implementation
63    virtual void onMessageReceived(const sp<AMessage> &msg);
64
65    // Async event handlers (called from GenericPlayer's event loop)
66    virtual void onPrepare();
67    virtual void onNotify(const sp<AMessage> &msg);
68    virtual void onPlay();
69    virtual void onPause();
70    virtual void onSeek(const sp<AMessage> &msg);
71    virtual void onLoop(const sp<AMessage> &msg);
72
73    // Event notification from GenericPlayer to OpenSL ES / OpenMAX AL framework
74    notif_cbf_t mNotifyClient;
75    void*       mNotifyUser;
76
77    enum {
78        kFlagPrepared  = 1 <<0,
79        kFlagPreparing = 1 <<1,
80        kFlagPlaying   = 1 <<2,
81        kFlagBuffering = 1 <<3,
82        kFlagSeeking   = 1 <<4,
83        kFlagLooping   = 1 <<5,
84    };
85
86    uint32_t mStateFlags;
87
88    sp<ALooper> mLooper;
89    int32_t mLooperPriority;
90
91    AudioPlayback_Parameters mPlaybackParams;
92
93private:
94    DISALLOW_EVIL_CONSTRUCTORS(GenericPlayer);
95};
96
97} // namespace android
98