android_StreamPlayer.h revision 2b06e20ae32388f6e1dfd088d9773c34e6b1cb45
1/* 2 * Copyright (C) 2010 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#include <media/IStreamSource.h> 18#include <binder/IServiceManager.h> 19#include "android/android_GenericMediaPlayer.h" 20 21// number of SLuint32 fields to store a buffer event message in an item, by mapping each 22// to the item key (SLuint32), the item size (SLuint32), and the item data (mask on SLuint32) 23#define NB_BUFFEREVENT_ITEM_FIELDS 3 24 25//-------------------------------------------------------------------------------------------------- 26namespace android { 27 28//-------------------------------------------------------------------------------------------------- 29class StreamSourceAppProxy : public BnStreamSource { 30public: 31 StreamSourceAppProxy( 32 const void* user, bool userIsAudioPlayer, 33 void *appContext, 34 const void *caller); 35 virtual ~StreamSourceAppProxy(); 36 37 // store an item structure to indicate a processed buffer 38 static const SLuint32 kItemProcessed[NB_BUFFEREVENT_ITEM_FIELDS]; 39 40 // IStreamSource implementation 41 virtual void setListener(const sp<IStreamListener> &listener); 42 virtual void setBuffers(const Vector<sp<IMemory> > &buffers); 43 virtual void onBufferAvailable(size_t index); 44 45 // Consumption from ABQ 46 void pullFromBuffQueue(); 47 48 void receivedCmd_l(IStreamListener::Command cmd, const sp<AMessage> &msg = NULL); 49 void receivedBuffer_l(size_t buffIndex, size_t buffLength); 50 51private: 52 // for mListener and mAvailableBuffers 53 Mutex mLock; 54 sp<IStreamListener> mListener; 55 // array of shared memory buffers 56 Vector<sp<IMemory> > mBuffers; 57 // list of available buffers in shared memory, identified by their index 58 List<size_t> mAvailableBuffers; 59 60 const void* mUser; 61 bool mUserIsAudioPlayer; 62 // the Android Buffer Queue from which data is consumed and written to shared memory 63 IAndroidBufferQueue* mAndroidBufferQueue; 64 65 void *mAppContext; 66 const void *mCaller; 67 68 DISALLOW_EVIL_CONSTRUCTORS(StreamSourceAppProxy); 69}; 70 71 72//-------------------------------------------------------------------------------------------------- 73class StreamPlayer : public GenericMediaPlayer 74{ 75public: 76 StreamPlayer(AudioPlayback_Parameters* params, bool hasVideo); 77 virtual ~StreamPlayer(); 78 79 // overridden from GenericPlayer 80 virtual void onMessageReceived(const sp<AMessage> &msg); 81 82 void registerQueueCallback( 83 const void* user, bool userIsAudioPlayer, 84 void *context, 85 const void *caller); 86 void queueRefilled_l(); 87 void appClear_l(); 88 89protected: 90 91 enum { 92 // message to asynchronously notify mAppProxy the Android Buffer Queue was refilled 93 kWhatQueueRefilled = 'qrfi' 94 }; 95 96 sp<StreamSourceAppProxy> mAppProxy; // application proxy for the android buffer queue source 97 98 // overridden from GenericMediaPlayer 99 virtual void onPrepare(); 100 101 void onQueueRefilled(); 102 103 Mutex mAppProxyLock; 104 105 106private: 107 DISALLOW_EVIL_CONSTRUCTORS(StreamPlayer); 108}; 109 110} // namespace android 111 112 113//-------------------------------------------------------------------------------------------------- 114/* 115 * xxx_l functions are called with a lock on the CAudioPlayer mObject 116 */ 117extern void android_StreamPlayer_realize_l(CAudioPlayer *ap, const notif_cbf_t cbf, 118 void* notifUser); 119