StreamSourceAppProxy::StreamSourceAppProxy(
const void* user, bool userIsAudioPlayer,
- void *context, const void *caller, const sp<CallbackProtector> &callbackProtector) :
+ void *context, const void *caller, const sp<CallbackProtector> &callbackProtector,
+ const sp<StreamPlayer> &player) :
mUser(user),
mUserIsAudioPlayer(userIsAudioPlayer),
mAndroidBufferQueue(NULL),
mAppContext(context),
mCaller(caller),
- mCallbackProtector(callbackProtector)
+ mCallbackProtector(callbackProtector),
+ mPlayer(player)
{
SL_LOGV("StreamSourceAppProxy::StreamSourceAppProxy()");
}
//--------------------------------------------------
-// consumption from ABQ
+// consumption from ABQ: pull from the ABQ, and push to shared memory (media server)
void StreamSourceAppProxy::pullFromBuffQueue() {
if (android::CallbackProtector::enterCbIfOk(mCallbackProtector)) {
//dataUsed = oldFront->mDataSizeConsumed;
}
}
- //SL_LOGD("onBufferAvailable() %d buffers available after enqueue",
- // mAvailableBuffers.size());
+ //SL_LOGD("%d buffers available after enqueue", mAvailableBuffers.size());
+ if (!mAvailableBuffers.empty()) {
+ // there is still room in the shared memory, recheck later if we can pull
+ // data from the buffer queue and write it to shared memory
+ mPlayer->queueRefilled();
+ }
}
}
void StreamPlayer::onMessageReceived(const sp<AMessage> &msg) {
switch (msg->what()) {
- case kWhatQueueRefilled:
- onQueueRefilled();
+ case kWhatPullFromAbq:
+ onPullFromAndroidBufferQueue();
break;
default:
mAppProxy = new StreamSourceAppProxy(
user, userIsAudioPlayer,
- context, caller, mCallbackProtector);
+ context, caller, mCallbackProtector, this);
CHECK(mAppProxy != 0);
SL_LOGD("StreamPlayer::registerQueueCallback end");
/**
- * Called with a lock on ABQ
+ * Asynchronously notify the player that the queue is ready to be pulled from.
*/
-void StreamPlayer::queueRefilled_l() {
- // async notification that the ABQ was refilled
- (new AMessage(kWhatQueueRefilled, id()))->post();
+void StreamPlayer::queueRefilled() {
+ // async notification that the ABQ was refilled: the player should pull from the ABQ, and
+ // and push to shared memory (to the media server)
+ (new AMessage(kWhatPullFromAbq, id()))->post();
}
SL_LOGD("StreamPlayer::onPlay()");
// enqueue a message that will cause StreamAppProxy to consume from the queue (again if the
// player had starved the shared memory)
- queueRefilled_l();
+ queueRefilled();
GenericMediaPlayer::onPlay();
}
-void StreamPlayer::onQueueRefilled() {
+void StreamPlayer::onPullFromAndroidBufferQueue() {
//SL_LOGD("StreamPlayer::onQueueRefilled()");
Mutex::Autolock _l(mAppProxyLock);
if (mAppProxy != 0) {
namespace android {
//--------------------------------------------------------------------------------------------------
+class StreamPlayer;
+
class StreamSourceAppProxy : public BnStreamSource {
public:
StreamSourceAppProxy(
const void* user, bool userIsAudioPlayer,
void *appContext,
const void *caller,
- const sp<CallbackProtector> &callbackProtector);
+ const sp<CallbackProtector> &callbackProtector,
+ const sp<StreamPlayer> &player);
virtual ~StreamSourceAppProxy();
// store an item structure to indicate a processed buffer
const void *mCaller;
sp<CallbackProtector> mCallbackProtector;
+ const sp<StreamPlayer> mPlayer;
DISALLOW_EVIL_CONSTRUCTORS(StreamSourceAppProxy);
};
const void* user, bool userIsAudioPlayer,
void *context,
const void *caller);
- void queueRefilled_l();
+ void queueRefilled();
void appClear_l();
protected:
enum {
- // message to asynchronously notify mAppProxy the Android Buffer Queue was refilled
- kWhatQueueRefilled = 'qrfi'
+ // message to asynchronously notify mAppProxy it should try to pull from the Android
+ // Buffer Queue and push to shared memory (media server), either because the buffer queue
+ // was refilled, or because during playback, the shared memory buffers should remain
+ // filled to prevent it from draining (this can happen if the ABQ is not ready
+ // whenever a shared memory buffer becomes available)
+ kWhatPullFromAbq = 'plfq'
};
sp<StreamSourceAppProxy> mAppProxy; // application proxy for the android buffer queue source
virtual void onPrepare();
virtual void onPlay();
- void onQueueRefilled();
+ void onPullFromAndroidBufferQueue();
Mutex mAppProxyLock;