android_GenericPlayer.h revision 70c49ae2867094072a4365423417ea452bf82231
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//-------------------------------------------------------------------------------------------------- 19namespace android { 20 21class GenericPlayer : public AHandler 22{ 23public: 24 25 enum { 26 kEventPrepared = 'prep' 27 }; 28 29 GenericPlayer(const AudioPlayback_Parameters* params); 30 virtual ~GenericPlayer(); 31 32 virtual void init(const notif_cbf_t cbf, void* notifUser); 33 34 virtual void setDataSource(const char *uri); 35 virtual void setDataSource(int fd, int64_t offset, int64_t length); 36 37 virtual void prepare(); 38 virtual void play(); 39 virtual void pause(); 40 virtual void stop(); 41 virtual void seek(int64_t timeMsec); 42 virtual void loop(bool loop); 43 44 virtual void getDurationMsec(int* msec); // -1 if unknown 45 46protected: 47 48 void resetDataLocator(); 49 DataLocator2 mDataLocator; 50 int mDataLocatorType; 51 52 enum { 53 kWhatPrepare = 'prep', 54 kWhatNotif = 'noti', 55 kWhatPlay = 'play', 56 kWhatPause = 'paus', 57 kWhatSeek = 'seek', 58 kWhatLoop = 'loop', 59 }; 60 61 // Send a notification to one of the event listeners 62 virtual void notify(const char* event, int data, bool async); 63 64 // AHandler implementation 65 virtual void onMessageReceived(const sp<AMessage> &msg); 66 67 // Async event handlers (called from GenericPlayer's event loop) 68 virtual void onPrepare(); 69 virtual void onNotify(const sp<AMessage> &msg); 70 virtual void onPlay(); 71 virtual void onPause(); 72 virtual void onSeek(const sp<AMessage> &msg); 73 virtual void onLoop(const sp<AMessage> &msg); 74 75 // Event notification from GenericPlayer to OpenSL ES / OpenMAX AL framework 76 notif_cbf_t mNotifyClient; 77 void* mNotifyUser; 78 79 enum { 80 kFlagPrepared = 1 <<0, 81 kFlagPreparing = 1 <<1, 82 kFlagPlaying = 1 <<2, 83 kFlagBuffering = 1 <<3, 84 kFlagSeeking = 1 <<4, 85 kFlagLooping = 1 <<5, 86 }; 87 88 uint32_t mStateFlags; 89 90 sp<ALooper> mLooper; 91 int32_t mLooperPriority; 92 93 AudioPlayback_Parameters mPlaybackParams; 94 95private: 96 DISALLOW_EVIL_CONSTRUCTORS(GenericPlayer); 97}; 98 99} // namespace android 100