android_GenericMediaPlayer.h revision 16ce39d96d41884c7b0d1676553ab8167baaab74
1/*
2 * Copyright (C) 2010 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#include <binder/IServiceManager.h>
19
20
21//--------------------------------------------------------------------------------------------------
22namespace android {
23
24class MediaPlayerNotificationClient : public BnMediaPlayerClient
25{
26public:
27    MediaPlayerNotificationClient();
28    virtual ~MediaPlayerNotificationClient();
29
30    // IMediaPlayerClient implementation
31    virtual void notify(int msg, int ext1, int ext2);
32
33    void blockUntilPlayerPrepared();
34
35private:
36    Mutex mLock;
37    Condition mPlayerPreparedCondition;
38    bool mPlayerPrepared;
39};
40
41//--------------------------------------------------------------------------------------------------
42class AVPlayer : public AHandler
43{
44public:
45    AVPlayer(AudioPlayback_Parameters* params);
46    virtual ~AVPlayer();
47
48    virtual void init();
49
50    virtual void prepare();
51    virtual void play();
52    virtual void pause();
53    virtual void stop();
54
55protected:
56
57    enum {
58        kWhatPrepare    = 'prep',
59        kWhatNotif      = 'noti',
60        kWhatPlay       = 'play',
61        kWhatPause      = 'paus',
62        kWhatStop       = 'stop'
63    };
64
65    // AHandler implementation
66    virtual void onMessageReceived(const sp<AMessage> &msg);
67
68    sp<ALooper> mLooper;
69
70    AudioPlayback_Parameters mPlaybackParams;
71
72    sp<IMediaPlayer> mPlayer;
73    sp<MediaPlayerNotificationClient> mPlayerClient; // receives events from mPlayer
74
75    sp<IServiceManager> mServiceManager;
76    sp<IBinder> mBinder;
77    sp<IMediaPlayerService> mMediaPlayerService;
78
79    Mutex mLock;
80
81    // Event handlers
82    virtual void onPrepare();
83    //virtual void onNotif(const sp<AMessage> &msg);
84    virtual void onPlay();
85    virtual void onPause();
86    virtual void onStop();
87};
88
89} // namespace android
90