android_GenericMediaPlayer.h revision 4b0e0b2860ffd5e246b42c8a434833cca2f068b3
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, const Parcel *obj); 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 preDestroy(); 59 60 // overridden from GenericPlayer 61 virtual void getPositionMsec(int* msec); // ANDROID_UNKNOWN_TIME if unknown 62 63 virtual void setVideoSurface(const sp<Surface> &surface); 64 virtual void setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture); 65 66protected: 67 friend class MediaPlayerNotificationClient; 68 69 // overridden from GenericPlayer 70 virtual void onMessageReceived(const sp<AMessage> &msg); 71 72 // Async event handlers (called from GenericPlayer's event loop) 73 virtual void onPrepare(); 74 virtual void onPlay(); 75 virtual void onPause(); 76 virtual void onSeek(const sp<AMessage> &msg); 77 virtual void onLoop(const sp<AMessage> &msg); 78 virtual void onVolumeUpdate(); 79 virtual void onBufferingUpdate(const sp<AMessage> &msg); 80 virtual void onGetMediaPlayerInfo(); 81 82 bool mHasVideo; 83 int32_t mSeekTimeMsec; 84 85 sp<Surface> mVideoSurface; 86 sp<ISurfaceTexture> mVideoSurfaceTexture; 87 88 sp<IMediaPlayer> mPlayer; 89 // Receives Android MediaPlayer events from mPlayer 90 sp<MediaPlayerNotificationClient> mPlayerClient; 91 92 sp<IServiceManager> mServiceManager; 93 sp<IBinder> mBinder; 94 sp<IMediaPlayerService> mMediaPlayerService; 95 96 Parcel metadatafilter; 97 98 // for synchronous "getXXX" calls on misc MediaPlayer settings: currently querying: 99 // - position (time): protects GenericPlayer::mPositionMsec 100 Mutex mGetMediaPlayerInfoLock; 101 Condition mGetMediaPlayerInfoCondition; 102 // marks the current "generation" of MediaPlayer info,any change denotes more recent info, 103 // protected by mGetMediaPlayerInfoLock 104 uint32_t mGetMediaPlayerInfoGenCount; 105 106private: 107 DISALLOW_EVIL_CONSTRUCTORS(GenericMediaPlayer); 108 void onAfterMediaPlayerPrepared(); 109}; 110 111} // namespace android 112 113#endif /* __ANDROID_GENERICMEDIAPLAYER_H__ */ 114