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