2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <media/IStreamSource.h>
18 #include <binder/IServiceManager.h>
19 #include "android/android_GenericMediaPlayer.h"
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
25 //--------------------------------------------------------------------------------------------------
28 //--------------------------------------------------------------------------------------------------
29 class StreamSourceAppProxy : public BnStreamSource {
32 const void* user, bool userIsAudioPlayer,
35 const sp<CallbackProtector> &callbackProtector);
36 virtual ~StreamSourceAppProxy();
38 // store an item structure to indicate a processed buffer
39 static const SLuint32 kItemProcessed[NB_BUFFEREVENT_ITEM_FIELDS];
41 // IStreamSource implementation
42 virtual void setListener(const sp<IStreamListener> &listener);
43 virtual void setBuffers(const Vector<sp<IMemory> > &buffers);
44 virtual void onBufferAvailable(size_t index);
46 // Consumption from ABQ
47 void pullFromBuffQueue();
49 void receivedCmd_l(IStreamListener::Command cmd, const sp<AMessage> &msg = NULL);
50 void receivedBuffer_l(size_t buffIndex, size_t buffLength);
53 // for mListener and mAvailableBuffers
55 sp<IStreamListener> mListener;
56 // array of shared memory buffers
57 Vector<sp<IMemory> > mBuffers;
58 // list of available buffers in shared memory, identified by their index
59 List<size_t> mAvailableBuffers;
62 bool mUserIsAudioPlayer;
63 // the Android Buffer Queue from which data is consumed and written to shared memory
64 IAndroidBufferQueue* mAndroidBufferQueue;
69 sp<CallbackProtector> mCallbackProtector;
71 DISALLOW_EVIL_CONSTRUCTORS(StreamSourceAppProxy);
75 //--------------------------------------------------------------------------------------------------
76 class StreamPlayer : public GenericMediaPlayer
79 StreamPlayer(AudioPlayback_Parameters* params, bool hasVideo);
80 virtual ~StreamPlayer();
82 // overridden from GenericPlayer
83 virtual void onMessageReceived(const sp<AMessage> &msg);
85 void registerQueueCallback(
86 const void* user, bool userIsAudioPlayer,
89 void queueRefilled_l();
95 // message to asynchronously notify mAppProxy the Android Buffer Queue was refilled
96 kWhatQueueRefilled = 'qrfi'
99 sp<StreamSourceAppProxy> mAppProxy; // application proxy for the android buffer queue source
101 // overridden from GenericMediaPlayer
102 virtual void onPrepare();
103 virtual void onPlay();
105 void onQueueRefilled();
111 DISALLOW_EVIL_CONSTRUCTORS(StreamPlayer);
114 } // namespace android
117 //--------------------------------------------------------------------------------------------------
119 * xxx_l functions are called with a lock on the CAudioPlayer mObject
121 extern void android_StreamPlayer_realize_l(CAudioPlayer *ap, const notif_cbf_t cbf,