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