android_GenericMediaPlayer.h revision 7ef5526a7bd12eccfa777cc8bc167794634f405a
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    int32_t mSeekTimeMsec;
75
76    sp<Surface> mVideoSurface;
77    sp<ISurfaceTexture> mVideoSurfaceTexture;
78
79    sp<IMediaPlayer> mPlayer;
80    // Receives Android MediaPlayer events from mPlayer
81    sp<MediaPlayerNotificationClient> mPlayerClient;
82
83    sp<IServiceManager> mServiceManager;
84    sp<IBinder> mBinder;
85    sp<IMediaPlayerService> mMediaPlayerService;
86
87    Parcel metadatafilter;
88
89private:
90    DISALLOW_EVIL_CONSTRUCTORS(GenericMediaPlayer);
91    void onAfterMediaPlayerPrepared();
92};
93
94} // namespace android
95
96#endif /* __ANDROID_GENERICMEDIAPLAYER_H__ */
97