android_GenericPlayer.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_GENERICPLAYER_H__ 18#define __ANDROID_GENERICPLAYER_H__ 19 20#include <media/stagefright/foundation/AHandler.h> 21#include <media/stagefright/foundation/ALooper.h> 22#include <media/stagefright/foundation/AMessage.h> 23 24//-------------------------------------------------------------------------------------------------- 25/** 26 * Message parameters for AHandler messages, see list in GenericPlayer::kWhatxxx 27 */ 28#define WHATPARAM_SEEK_SEEKTIME_MS "seekTimeMs" 29#define WHATPARAM_LOOP_LOOPING "looping" 30#define WHATPARAM_BUFFERING_UPDATE "bufferingUpdate" 31#define WHATPARAM_BUFFERING_UPDATETHRESHOLD_PERCENT "buffUpdateThreshold" 32 33namespace android { 34 35class GenericPlayer : public AHandler 36{ 37public: 38 39 enum { 40 kEventPrepared = 'prep', 41 kEventHasVideoSize = 'vsiz', 42 kEventPrefetchStatusChange = 'pfsc', 43 kEventPrefetchFillLevelUpdate = 'pflu', 44 kEventEndOfStream = 'eos' 45 }; 46 47 48 GenericPlayer(const AudioPlayback_Parameters* params); 49 virtual ~GenericPlayer(); 50 51 virtual void init(const notif_cbf_t cbf, void* notifUser); 52 53 virtual void setDataSource(const char *uri); 54 virtual void setDataSource(int fd, int64_t offset, int64_t length); 55 56 virtual void prepare(); 57 virtual void play(); 58 virtual void pause(); 59 virtual void stop(); 60 virtual void seek(int64_t timeMsec); 61 virtual void loop(bool loop); 62 virtual void setBufferingUpdateThreshold(int16_t thresholdPercent); 63 64 virtual void getDurationMsec(int* msec); // ANDROID_UNKNOWN_TIME if unknown 65 virtual void getPositionMsec(int* msec); // ANDROID_UNKNOWN_TIME if unknown 66 67 void setVolume(bool mute, bool useStereoPos, XApermille stereoPos, XAmillibel volume); 68 69protected: 70 Mutex mSettingsLock; 71 72 void resetDataLocator(); 73 DataLocator2 mDataLocator; 74 int mDataLocatorType; 75 76 // Constants used to identify the messages in this player's AHandler message loop 77 // in onMessageReceived() 78 enum { 79 kWhatPrepare = 'prep', 80 kWhatNotif = 'noti', 81 kWhatPlay = 'play', 82 kWhatPause = 'paus', 83 kWhatSeek = 'seek', 84 kWhatSeekComplete = 'skcp', 85 kWhatLoop = 'loop', 86 kWhatVolumeUpdate = 'volu', 87 kWhatBufferingUpdate = 'bufu', 88 kWhatBuffUpdateThres = 'buut', 89 }; 90 91 // Send a notification to one of the event listeners 92 virtual void notify(const char* event, int data1, bool async); 93 virtual void notify(const char* event, int data1, int data2, bool async); 94 95 // AHandler implementation 96 virtual void onMessageReceived(const sp<AMessage> &msg); 97 98 // Async event handlers (called from GenericPlayer's event loop) 99 virtual void onPrepare(); 100 virtual void onNotify(const sp<AMessage> &msg); 101 virtual void onPlay(); 102 virtual void onPause(); 103 virtual void onSeek(const sp<AMessage> &msg); 104 virtual void onLoop(const sp<AMessage> &msg); 105 virtual void onVolumeUpdate(); 106 virtual void onSeekComplete(); 107 virtual void onBufferingUpdate(const sp<AMessage> &msg); 108 virtual void onSetBufferingUpdateThreshold(const sp<AMessage> &msg); 109 110 // Convenience methods 111 // for async notifications of prefetch status and cache fill level, needs to be called 112 // with mSettingsLock locked 113 void notifyStatus(); 114 void notifyCacheFill(); 115 // for internal async notification to update state that the player is no longer seeking 116 void seekComplete(); 117 void bufferingUpdate(int16_t fillLevelPerMille); 118 119 // Event notification from GenericPlayer to OpenSL ES / OpenMAX AL framework 120 notif_cbf_t mNotifyClient; 121 void* mNotifyUser; 122 123 enum { 124 kFlagPrepared = 1 <<0, 125 kFlagPreparing = 1 <<1, 126 kFlagPlaying = 1 <<2, 127 kFlagBuffering = 1 <<3, 128 kFlagSeeking = 1 <<4, 129 kFlagLooping = 1 <<5, 130 }; 131 132 uint32_t mStateFlags; 133 134 sp<ALooper> mLooper; 135 int32_t mLooperPriority; 136 137 AudioPlayback_Parameters mPlaybackParams; 138 139 AndroidAudioLevels mAndroidAudioLevels; 140 int mChannelCount; // this is used for the panning law, and is not exposed outside of the object 141 int32_t mDurationMsec; 142 int32_t mPositionMsec; 143 144 CacheStatus_t mCacheStatus; 145 int16_t mCacheFill; // cache fill level + played back level in permille 146 int16_t mLastNotifiedCacheFill; // last cache fill level communicated to the listener 147 int16_t mCacheFillNotifThreshold; // threshold in cache fill level for cache fill to be reported 148 149 150private: 151 DISALLOW_EVIL_CONSTRUCTORS(GenericPlayer); 152}; 153 154} // namespace android 155 156#endif /* __ANDROID_GENERICPLAYER_H__ */ 157