android_GenericMediaPlayer.h revision 2b06e20ae32388f6e1dfd088d9773c34e6b1cb45
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#ifndef __ANDROID_GENERICMEDIAPLAYER_H__
18#define __ANDROID_GENERICMEDIAPLAYER_H__
19
20#include <binder/IServiceManager.h>
21#include <surfaceflinger/Surface.h>
22#include <gui/ISurfaceTexture.h>
23
24
25//--------------------------------------------------------------------------------------------------
26namespace android {
27
28class GenericMediaPlayer;
29class MediaPlayerNotificationClient : public BnMediaPlayerClient
30{
31public:
32    MediaPlayerNotificationClient(GenericMediaPlayer* gmp);
33    virtual ~MediaPlayerNotificationClient();
34
35    // IMediaPlayerClient implementation
36    virtual void notify(int msg, int ext1, int ext2);
37
38    void blockUntilPlayerPrepared();
39
40private:
41    Mutex mLock;
42    GenericMediaPlayer* mGenericMediaPlayer;
43    Condition mPlayerPreparedCondition;
44    bool mPlayerPrepared;
45};
46
47
48//--------------------------------------------------------------------------------------------------
49class GenericMediaPlayer : public GenericPlayer
50{
51public:
52
53    GenericMediaPlayer(const AudioPlayback_Parameters* params, bool hasVideo);
54    virtual ~GenericMediaPlayer();
55
56    virtual void setVideoSurface(const sp<Surface> &surface);
57    virtual void setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture);
58
59protected:
60    friend class MediaPlayerNotificationClient;
61
62    // Async event handlers (called from GenericPlayer's event loop)
63    virtual void onPrepare();
64    virtual void onPlay();
65    virtual void onPause();
66    virtual void onVolumeUpdate();
67
68    bool mHasVideo;
69
70    sp<Surface> mVideoSurface;
71    sp<ISurfaceTexture> mVideoSurfaceTexture;
72
73    sp<IMediaPlayer> mPlayer;
74    // Receives Android MediaPlayer events from mPlayer
75    sp<MediaPlayerNotificationClient> mPlayerClient;
76
77    sp<IServiceManager> mServiceManager;
78    sp<IBinder> mBinder;
79    sp<IMediaPlayerService> mMediaPlayerService;
80
81private:
82    DISALLOW_EVIL_CONSTRUCTORS(GenericMediaPlayer);
83};
84
85} // namespace android
86
87#endif /* __ANDROID_GENERICMEDIAPLAYER_H__ */
88