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