android_StreamPlayer.h revision d158d31a6bbb06426b71c3d097b7768bc3fb79a3
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 <binder/IServiceManager.h> 18 19 20//-------------------------------------------------------------------------------------------------- 21namespace android { 22 23typedef void (*cb_buffAvailable_t)(const void* user, bool userIsAudioPlayer, 24 size_t bufferId, void* bufferLoc, size_t buffSize); 25 26//-------------------------------------------------------------------------------------------------- 27class StreamSourceAppProxy : public BnStreamSource { 28public: 29 StreamSourceAppProxy(slAndroidBufferQueueCallback callback, 30 cb_buffAvailable_t notify, 31 const void* user, bool userIsAudioPlayer, 32 void *appContext, 33 const void *caller); 34 virtual ~StreamSourceAppProxy(); 35 36 // IStreamSource implementation 37 virtual void setListener(const sp<IStreamListener> &listener); 38 virtual void setBuffers(const Vector<sp<IMemory> > &buffers); 39 virtual void onBufferAvailable(size_t index); 40 41 void receivedFromAppCommand(IStreamListener::Command cmd); 42 void receivedFromAppBuffer(size_t buffIndex, size_t buffLength); 43 44private: 45 Mutex mListenerLock; 46 sp<IStreamListener> mListener; 47 Vector<sp<IMemory> > mBuffers; 48 49 slAndroidBufferQueueCallback mCallback; // FIXME remove 50 cb_buffAvailable_t mCbNotifyBufferAvailable; 51 const void* mUser; 52 bool mUserIsAudioPlayer; 53 54 void *mAppContext; 55 const void *mCaller; 56 57 DISALLOW_EVIL_CONSTRUCTORS(StreamSourceAppProxy); 58}; 59 60 61//-------------------------------------------------------------------------------------------------- 62class StreamPlayer : public GenericMediaPlayer 63{ 64public: 65 StreamPlayer(AudioPlayback_Parameters* params, bool hasVideo); 66 virtual ~StreamPlayer(); 67 68 void registerQueueCallback(slAndroidBufferQueueCallback callback, 69 cb_buffAvailable_t notify, 70 const void* user, bool userIsAudioPlayer, 71 void *context, 72 const void *caller); 73 void appEnqueue(SLuint32 bufferId, SLuint32 length, SLuint32 event, void *pData); 74 void appClear(); 75 76protected: 77 sp<StreamSourceAppProxy> mAppProxy; // application proxy for the android buffer queue source 78 79 // overridden from GenericMediaPlayer 80 virtual void onPrepare(); 81 82 Mutex mAppProxyLock; 83 84private: 85 DISALLOW_EVIL_CONSTRUCTORS(StreamPlayer); 86}; 87 88} // namespace android 89 90 91//-------------------------------------------------------------------------------------------------- 92/* 93 * xxx_l functions are called with a lock on the CAudioPlayer mObject 94 */ 95extern void android_StreamPlayer_realize_l(CAudioPlayer *ap, const notif_cbf_t cbf, 96 void* notifUser); 97extern void android_StreamPlayer_enqueue_l(CAudioPlayer *ap, 98 SLuint32 bufferId, SLuint32 length, SLuint32 event, void *pData); 99extern void android_StreamPlayer_clear_l(CAudioPlayer *ap); 100