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 "sles_allinclusive.h"
18 #include "utils/RefBase.h"
19 #include "android_prompts.h"
20 // LocAVPlayer and StreamPlayer derive from GenericMediaPlayer,
21 // so no need to #include "android_GenericMediaPlayer.h"
22 #include "android_LocAVPlayer.h"
23 #include "android_StreamPlayer.h"
26 //-----------------------------------------------------------------------------
27 static void player_handleMediaPlayerEventNotifications(int event, int data1, int data2, void* user)
30 // FIXME This code is derived from similar code in sfplayer_handlePrefetchEvent. The two
31 // versions are quite similar, but still different enough that they need to be separate.
32 // At some point they should be re-factored and merged if feasible.
33 // As with other OpenMAX AL implementation code, this copy mostly uses SL_ symbols
34 // rather than XA_ unless the difference is significant.
40 CMediaPlayer* mp = (CMediaPlayer*) user;
46 SL_LOGV("player_handleMediaPlayerEventNotifications(event='%c%c%c%c' (%d), data1=%d, data2=%d, "
47 "user=%p) from AVPlayer", u.c[3], u.c[2], u.c[1], u.c[0], event, data1, data2, user);
50 case android::GenericPlayer::kEventPrepared: {
52 SL_LOGV("Received AVPlayer::kEventPrepared for CMediaPlayer %p", mp);
55 slPrefetchCallback callback = NULL;
56 void* callbackPContext = NULL;
58 object_lock_exclusive(&mp->mObject);
59 // mark object as prepared; same state is used for successfully or unsuccessful prepare
60 mp->mAndroidObjState = ANDROID_READY;
62 // AVPlayer prepare() failed prefetching, there is no event in XAPrefetchStatus to
63 // indicate a prefetch error, so we signal it by sending simulataneously two events:
64 // - SL_PREFETCHEVENT_FILLLEVELCHANGE with a level of 0
65 // - SL_PREFETCHEVENT_STATUSCHANGE with a status of SL_PREFETCHSTATUS_UNDERFLOW
66 if (PLAYER_SUCCESS != data1 && IsInterfaceInitialized(&mp->mObject, MPH_XAPREFETCHSTATUS)) {
67 mp->mPrefetchStatus.mLevel = 0;
68 mp->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_UNDERFLOW;
69 if (!(~mp->mPrefetchStatus.mCallbackEventsMask &
70 (SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE))) {
71 callback = mp->mPrefetchStatus.mCallback;
72 callbackPContext = mp->mPrefetchStatus.mContext;
75 object_unlock_exclusive(&mp->mObject);
77 // callback with no lock held
78 if (NULL != callback) {
79 (*callback)(&mp->mPrefetchStatus.mItf, callbackPContext,
80 SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE);
86 case android::GenericPlayer::kEventHasVideoSize: {
87 SL_LOGV("Received AVPlayer::kEventHasVideoSize (%d,%d) for CMediaPlayer %p",
90 object_lock_exclusive(&mp->mObject);
92 // remove an existing video info entry (here we only have one video stream)
93 for(size_t i=0 ; i < mp->mStreamInfo.mStreamInfoTable.size() ; i++) {
94 if (XA_DOMAINTYPE_VIDEO == mp->mStreamInfo.mStreamInfoTable.itemAt(i).domain) {
95 mp->mStreamInfo.mStreamInfoTable.removeAt(i);
99 // update the stream information with a new video info entry
100 StreamInfo streamInfo;
101 streamInfo.domain = XA_DOMAINTYPE_VIDEO;
102 streamInfo.videoInfo.codecId = 0;// unknown, we don't have that info FIXME
103 streamInfo.videoInfo.width = (XAuint32)data1;
104 streamInfo.videoInfo.height = (XAuint32)data2;
105 streamInfo.videoInfo.bitRate = 0;// unknown, we don't have that info FIXME
106 streamInfo.videoInfo.frameRate = 0;
107 streamInfo.videoInfo.duration = XA_TIME_UNKNOWN;
108 StreamInfo &contInfo = mp->mStreamInfo.mStreamInfoTable.editItemAt(0);
109 contInfo.containerInfo.numStreams = 1;
110 ssize_t index = mp->mStreamInfo.mStreamInfoTable.add(streamInfo);
112 xaStreamEventChangeCallback callback = mp->mStreamInfo.mCallback;
113 void* callbackPContext = mp->mStreamInfo.mContext;
115 object_unlock_exclusive(&mp->mObject);
117 // enqueue notification (outside of lock) that the stream information has been updated
118 if ((NULL != callback) && (index >= 0)) {
119 #ifndef USE_ASYNCHRONOUS_STREAMCBEVENT_PROPERTYCHANGE_CALLBACK
120 (*callback)(&mp->mStreamInfo.mItf, XA_STREAMCBEVENT_PROPERTYCHANGE /*eventId*/,
121 1 /*streamIndex, only one stream supported here, 0 is reserved*/,
122 NULL /*pEventData, always NULL in OpenMAX AL 1.0.1*/,
123 callbackPContext /*pContext*/);
125 SLresult res = EnqueueAsyncCallback_piipp(mp, callback,
126 /*p1*/ &mp->mStreamInfo.mItf,
127 /*i1*/ XA_STREAMCBEVENT_PROPERTYCHANGE /*eventId*/,
128 /*i2*/ 1 /*streamIndex, only one stream supported here, 0 is reserved*/,
129 /*p2*/ NULL /*pEventData, always NULL in OpenMAX AL 1.0.1*/,
130 /*p3*/ callbackPContext /*pContext*/);
131 LOGW_IF(SL_RESULT_SUCCESS != res,
132 "Callback %p(%p, XA_STREAMCBEVENT_PROPERTYCHANGE, 1, NULL, %p) dropped",
133 callback, &mp->mStreamInfo.mItf, callbackPContext);
139 case android::GenericPlayer::kEventEndOfStream: {
140 SL_LOGV("Received AVPlayer::kEventEndOfStream for CMediaPlayer %p", mp);
142 object_lock_exclusive(&mp->mObject);
143 // should be xaPlayCallback but we're sharing the itf between SL and AL
144 slPlayCallback playCallback = NULL;
145 void * playContext = NULL;
146 // XAPlayItf callback or no callback?
147 if (mp->mPlay.mEventFlags & XA_PLAYEVENT_HEADATEND) {
148 playCallback = mp->mPlay.mCallback;
149 playContext = mp->mPlay.mContext;
151 mp->mPlay.mState = XA_PLAYSTATE_PAUSED;
152 object_unlock_exclusive(&mp->mObject);
154 // enqueue callback with no lock held
155 if (NULL != playCallback) {
156 #ifndef USE_ASYNCHRONOUS_PLAY_CALLBACK
157 (*playCallback)(&mp->mPlay.mItf, playContext, XA_PLAYEVENT_HEADATEND);
159 SLresult res = EnqueueAsyncCallback_ppi(mp, playCallback, &mp->mPlay.mItf, playContext,
160 XA_PLAYEVENT_HEADATEND);
161 LOGW_IF(SL_RESULT_SUCCESS != res,
162 "Callback %p(%p, %p, SL_PLAYEVENT_HEADATEND) dropped", playCallback,
163 &mp->mPlay.mItf, playContext);
169 case android::GenericPlayer::kEventChannelCount: {
170 SL_LOGV("kEventChannelCount channels = %d", data1);
171 object_lock_exclusive(&mp->mObject);
172 if (UNKNOWN_NUMCHANNELS == mp->mNumChannels && UNKNOWN_NUMCHANNELS != data1) {
173 mp->mNumChannels = data1;
174 android_Player_volumeUpdate(mp);
176 object_unlock_exclusive(&mp->mObject);
180 case android::GenericPlayer::kEventPrefetchFillLevelUpdate: {
181 SL_LOGV("kEventPrefetchFillLevelUpdate");
182 if (!IsInterfaceInitialized(&mp->mObject, MPH_XAPREFETCHSTATUS)) {
185 slPrefetchCallback callback = NULL;
186 void* callbackPContext = NULL;
188 // SLPrefetchStatusItf callback or no callback?
189 interface_lock_exclusive(&mp->mPrefetchStatus);
190 if (mp->mPrefetchStatus.mCallbackEventsMask & SL_PREFETCHEVENT_FILLLEVELCHANGE) {
191 callback = mp->mPrefetchStatus.mCallback;
192 callbackPContext = mp->mPrefetchStatus.mContext;
194 mp->mPrefetchStatus.mLevel = (SLpermille)data1;
195 interface_unlock_exclusive(&mp->mPrefetchStatus);
197 // callback with no lock held
198 if (NULL != callback) {
199 (*callback)(&mp->mPrefetchStatus.mItf, callbackPContext,
200 SL_PREFETCHEVENT_FILLLEVELCHANGE);
205 case android::GenericPlayer::kEventPrefetchStatusChange: {
206 SL_LOGV("kEventPrefetchStatusChange");
207 if (!IsInterfaceInitialized(&mp->mObject, MPH_XAPREFETCHSTATUS)) {
210 slPrefetchCallback callback = NULL;
211 void* callbackPContext = NULL;
213 // SLPrefetchStatusItf callback or no callback?
214 object_lock_exclusive(&mp->mObject);
215 if (mp->mPrefetchStatus.mCallbackEventsMask & SL_PREFETCHEVENT_STATUSCHANGE) {
216 callback = mp->mPrefetchStatus.mCallback;
217 callbackPContext = mp->mPrefetchStatus.mContext;
219 if (data1 >= android::kStatusIntermediate) {
220 mp->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_SUFFICIENTDATA;
221 // FIXME copied from AudioPlayer, but probably wrong
222 mp->mAndroidObjState = ANDROID_READY;
223 } else if (data1 < android::kStatusIntermediate) {
224 mp->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_UNDERFLOW;
226 object_unlock_exclusive(&mp->mObject);
228 // callback with no lock held
229 if (NULL != callback) {
230 (*callback)(&mp->mPrefetchStatus.mItf, callbackPContext, SL_PREFETCHEVENT_STATUSCHANGE);
235 case android::GenericPlayer::kEventPlay: {
236 SL_LOGV("kEventPlay");
238 interface_lock_shared(&mp->mPlay);
239 slPlayCallback callback = mp->mPlay.mCallback;
240 void* callbackPContext = mp->mPlay.mContext;
241 interface_unlock_shared(&mp->mPlay);
243 if (NULL != callback) {
244 (*callback)(&mp->mPlay.mItf, callbackPContext, (SLuint32) data1); // SL_PLAYEVENT_HEAD*
250 SL_LOGE("Received unknown event %d, data %d from AVPlayer", event, data1);
256 //-----------------------------------------------------------------------------
257 XAresult android_Player_checkSourceSink(CMediaPlayer *mp) {
259 XAresult result = XA_RESULT_SUCCESS;
261 const SLDataSource *pSrc = &mp->mDataSource.u.mSource;
262 const SLDataSink *pAudioSnk = &mp->mAudioSink.u.mSink;
265 const SLuint32 sourceLocatorType = *(SLuint32 *)pSrc->pLocator;
266 const SLuint32 sourceFormatType = *(SLuint32 *)pSrc->pFormat;
267 const SLuint32 audioSinkLocatorType = *(SLuint32 *)pAudioSnk->pLocator;
268 //const SLuint32 sinkFormatType = *(SLuint32 *)pAudioSnk->pFormat;
271 switch(sourceLocatorType) {
273 case XA_DATALOCATOR_ANDROIDBUFFERQUEUE: {
274 switch (sourceFormatType) {
275 case XA_DATAFORMAT_MIME: {
276 SLDataFormat_MIME *df_mime = (SLDataFormat_MIME *) pSrc->pFormat;
277 if (SL_CONTAINERTYPE_MPEG_TS != df_mime->containerType) {
278 SL_LOGE("Cannot create player with XA_DATALOCATOR_ANDROIDBUFFERQUEUE data source "
279 "that is not fed MPEG-2 TS data");
280 return SL_RESULT_CONTENT_UNSUPPORTED;
284 SL_LOGE("Cannot create player with XA_DATALOCATOR_ANDROIDBUFFERQUEUE data source "
285 "without SL_DATAFORMAT_MIME format");
286 return XA_RESULT_CONTENT_UNSUPPORTED;
290 case XA_DATALOCATOR_URI: // intended fall-through
291 case XA_DATALOCATOR_ANDROIDFD:
295 SL_LOGE("Cannot create media player with data locator type 0x%x",
296 (unsigned) sourceLocatorType);
297 return SL_RESULT_PARAMETER_INVALID;
298 }// switch (locatorType)
300 // Audio sink check: only playback is supported here
301 switch(audioSinkLocatorType) {
303 case XA_DATALOCATOR_OUTPUTMIX:
307 SL_LOGE("Cannot create media player with audio sink data locator of type 0x%x",
308 (unsigned) audioSinkLocatorType);
309 return XA_RESULT_PARAMETER_INVALID;
310 }// switch (locaaudioSinkLocatorTypeorType)
316 //-----------------------------------------------------------------------------
317 XAresult android_Player_create(CMediaPlayer *mp) {
319 XAresult result = XA_RESULT_SUCCESS;
321 // FIXME verify data source
322 const SLDataSource *pDataSrc = &mp->mDataSource.u.mSource;
323 // FIXME verify audio data sink
324 const SLDataSink *pAudioSnk = &mp->mAudioSink.u.mSink;
325 // FIXME verify image data sink
326 const SLDataSink *pVideoSnk = &mp->mImageVideoSink.u.mSink;
328 XAuint32 sourceLocator = *(XAuint32 *)pDataSrc->pLocator;
329 switch(sourceLocator) {
330 // FIXME support Android simple buffer queue as well
331 case XA_DATALOCATOR_ANDROIDBUFFERQUEUE:
332 mp->mAndroidObjType = AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE;
334 case XA_DATALOCATOR_URI: // intended fall-through
335 case SL_DATALOCATOR_ANDROIDFD:
336 mp->mAndroidObjType = AUDIOVIDEOPLAYER_FROM_URIFD;
338 case XA_DATALOCATOR_ADDRESS: // intended fall-through
340 SL_LOGE("Unable to create MediaPlayer for data source locator 0x%x", sourceLocator);
341 result = XA_RESULT_PARAMETER_INVALID;
345 // FIXME duplicates an initialization also done by higher level
346 mp->mAndroidObjState = ANDROID_UNINITIALIZED;
347 mp->mStreamType = ANDROID_DEFAULT_OUTPUT_STREAM_TYPE;
348 mp->mSessionId = android::AudioSystem::newAudioSessionId();
350 mp->mCallbackProtector = new android::CallbackProtector();
356 //-----------------------------------------------------------------------------
357 // FIXME abstract out the diff between CMediaPlayer and CAudioPlayer
358 XAresult android_Player_realize(CMediaPlayer *mp, SLboolean async) {
359 SL_LOGV("android_Player_realize_l(%p)", mp);
360 XAresult result = XA_RESULT_SUCCESS;
362 const SLDataSource *pDataSrc = &mp->mDataSource.u.mSource;
363 const SLuint32 sourceLocator = *(SLuint32 *)pDataSrc->pLocator;
365 AudioPlayback_Parameters ap_params;
366 ap_params.sessionId = mp->mSessionId;
367 ap_params.streamType = mp->mStreamType;
368 ap_params.trackcb = NULL;
369 ap_params.trackcbUser = NULL;
371 switch(mp->mAndroidObjType) {
372 case AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: {
373 mp->mAVPlayer = new android::StreamPlayer(&ap_params, true /*hasVideo*/);
374 mp->mAVPlayer->init(player_handleMediaPlayerEventNotifications, (void*)mp);
377 case AUDIOVIDEOPLAYER_FROM_URIFD: {
378 mp->mAVPlayer = new android::LocAVPlayer(&ap_params, true /*hasVideo*/);
379 mp->mAVPlayer->init(player_handleMediaPlayerEventNotifications, (void*)mp);
380 switch (mp->mDataSource.mLocator.mLocatorType) {
381 case XA_DATALOCATOR_URI:
382 ((android::LocAVPlayer*)mp->mAVPlayer.get())->setDataSource(
383 (const char*)mp->mDataSource.mLocator.mURI.URI);
385 case XA_DATALOCATOR_ANDROIDFD: {
386 int64_t offset = (int64_t)mp->mDataSource.mLocator.mFD.offset;
387 ((android::LocAVPlayer*)mp->mAVPlayer.get())->setDataSource(
388 (int)mp->mDataSource.mLocator.mFD.fd,
389 offset == SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE ?
390 (int64_t)PLAYER_FD_FIND_FILE_SIZE : offset,
391 (int64_t)mp->mDataSource.mLocator.mFD.length);
395 SL_LOGE("Invalid or unsupported data locator type %u for data source",
396 mp->mDataSource.mLocator.mLocatorType);
397 result = XA_RESULT_PARAMETER_INVALID;
401 case INVALID_TYPE: // intended fall-through
403 SL_LOGE("Unable to realize MediaPlayer, invalid internal Android object type");
404 result = XA_RESULT_PARAMETER_INVALID;
408 if (XA_RESULT_SUCCESS == result) {
410 // inform GenericPlayer of the associated callback protector
411 mp->mAVPlayer->setCallbackProtector(mp->mCallbackProtector);
413 // if there is a video sink
414 if (XA_DATALOCATOR_NATIVEDISPLAY ==
415 mp->mImageVideoSink.mLocator.mLocatorType) {
416 ANativeWindow *nativeWindow = (ANativeWindow *)
417 mp->mImageVideoSink.mLocator.mNativeDisplay.hWindow;
418 // we already verified earlier that hWindow is non-NULL
419 assert(nativeWindow != NULL);
420 result = android_Player_setNativeWindow(mp, nativeWindow);
428 // Called with a lock on MediaPlayer, and blocks until safe to destroy
429 XAresult android_Player_preDestroy(CMediaPlayer *mp) {
430 SL_LOGV("android_Player_preDestroy(%p)", mp);
431 if (mp->mAVPlayer != 0) {
432 mp->mAVPlayer->preDestroy();
434 SL_LOGV("android_Player_preDestroy(%p) after mAVPlayer->preDestroy()", mp);
436 object_unlock_exclusive(&mp->mObject);
437 if (mp->mCallbackProtector != 0) {
438 mp->mCallbackProtector->requestCbExitAndWait();
440 object_lock_exclusive(&mp->mObject);
442 return XA_RESULT_SUCCESS;
445 //-----------------------------------------------------------------------------
446 XAresult android_Player_destroy(CMediaPlayer *mp) {
447 SL_LOGV("android_Player_destroy(%p)", mp);
449 mp->mAVPlayer.clear();
450 mp->mCallbackProtector.clear();
452 // explicit destructor
454 mp->mCallbackProtector.~sp();
456 return XA_RESULT_SUCCESS;
460 void android_Player_usePlayEventMask(CMediaPlayer *mp) {
461 if (mp->mAVPlayer != 0) {
462 IPlay *pPlayItf = &mp->mPlay;
463 mp->mAVPlayer->setPlayEvents((int32_t) pPlayItf->mEventFlags,
464 (int32_t) pPlayItf->mMarkerPosition, (int32_t) pPlayItf->mPositionUpdatePeriod);
469 XAresult android_Player_getDuration(IPlay *pPlayItf, XAmillisecond *pDurMsec) {
470 CMediaPlayer *avp = (CMediaPlayer *)pPlayItf->mThis;
472 switch (avp->mAndroidObjType) {
474 case AUDIOVIDEOPLAYER_FROM_URIFD: {
475 int dur = ANDROID_UNKNOWN_TIME;
476 if (avp->mAVPlayer != 0) {
477 avp->mAVPlayer->getDurationMsec(&dur);
479 if (dur == ANDROID_UNKNOWN_TIME) {
480 *pDurMsec = XA_TIME_UNKNOWN;
482 *pDurMsec = (XAmillisecond)dur;
486 case AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: // intended fall-through
488 *pDurMsec = XA_TIME_UNKNOWN;
492 return XA_RESULT_SUCCESS;
496 XAresult android_Player_getPosition(IPlay *pPlayItf, XAmillisecond *pPosMsec) {
497 SL_LOGD("android_Player_getPosition()");
498 XAresult result = XA_RESULT_SUCCESS;
499 CMediaPlayer *avp = (CMediaPlayer *)pPlayItf->mThis;
501 switch (avp->mAndroidObjType) {
503 case AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: // intended fall-through
504 case AUDIOVIDEOPLAYER_FROM_URIFD: {
505 int pos = ANDROID_UNKNOWN_TIME;
506 if (avp->mAVPlayer != 0) {
507 avp->mAVPlayer->getPositionMsec(&pos);
509 if (pos == ANDROID_UNKNOWN_TIME) {
512 *pPosMsec = (XAmillisecond)pos;
517 // we shouldn't be here
526 //-----------------------------------------------------------------------------
528 * pre-condition: mp != NULL
530 void android_Player_volumeUpdate(CMediaPlayer* mp)
532 android::GenericPlayer* avp = mp->mAVPlayer.get();
535 // MediaPlayer does not currently support EffectSend or MuteSolo
536 android_player_volumeUpdate(volumes, &mp->mVolume, mp->mNumChannels, 1.0f, NULL);
537 float leftVol = volumes[0], rightVol = volumes[1];
538 avp->setVolume(leftVol, rightVol);
542 //-----------------------------------------------------------------------------
544 * pre-condition: gp != 0
546 XAresult android_Player_setPlayState(const android::sp<android::GenericPlayer> &gp,
548 AndroidObjectState* pObjState)
550 XAresult result = XA_RESULT_SUCCESS;
551 AndroidObjectState objState = *pObjState;
554 case SL_PLAYSTATE_STOPPED: {
555 SL_LOGV("setting AVPlayer to SL_PLAYSTATE_STOPPED");
559 case SL_PLAYSTATE_PAUSED: {
560 SL_LOGV("setting AVPlayer to SL_PLAYSTATE_PAUSED");
562 case ANDROID_UNINITIALIZED:
563 *pObjState = ANDROID_PREPARING;
566 case ANDROID_PREPARING:
572 SL_LOGE("Android object in invalid state");
577 case SL_PLAYSTATE_PLAYING: {
578 SL_LOGV("setting AVPlayer to SL_PLAYSTATE_PLAYING");
580 case ANDROID_UNINITIALIZED:
581 *pObjState = ANDROID_PREPARING;
583 // intended fall through
584 case ANDROID_PREPARING:
585 // intended fall through
590 SL_LOGE("Android object in invalid state");
596 // checked by caller, should not happen
605 * pre-condition: mp != NULL
607 XAresult android_Player_seek(CMediaPlayer *mp, SLmillisecond posMsec) {
608 XAresult result = XA_RESULT_SUCCESS;
609 switch (mp->mAndroidObjType) {
610 case AUDIOVIDEOPLAYER_FROM_URIFD:
611 if (mp->mAVPlayer !=0) {
612 mp->mAVPlayer->seek(posMsec);
615 case AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: // intended fall-through
617 result = XA_RESULT_FEATURE_UNSUPPORTED;
625 * pre-condition: mp != NULL
627 XAresult android_Player_loop(CMediaPlayer *mp, SLboolean loopEnable) {
628 XAresult result = XA_RESULT_SUCCESS;
629 switch (mp->mAndroidObjType) {
630 case AUDIOVIDEOPLAYER_FROM_URIFD:
631 if (mp->mAVPlayer !=0) {
632 mp->mAVPlayer->loop(loopEnable);
635 case AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: // intended fall-through
637 result = XA_RESULT_FEATURE_UNSUPPORTED;
644 //-----------------------------------------------------------------------------
645 void android_Player_androidBufferQueue_registerCallback_l(CMediaPlayer *mp) {
646 if ((mp->mAndroidObjType == AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE)
647 && (mp->mAVPlayer != 0)) {
648 SL_LOGD("android_Player_androidBufferQueue_registerCallback_l");
649 android::StreamPlayer* splr = static_cast<android::StreamPlayer*>(mp->mAVPlayer.get());
650 splr->registerQueueCallback(
651 (const void*)mp, false /*userIsAudioPlayer*/,
652 mp->mAndroidBufferQueue.mContext, (const void*)&(mp->mAndroidBufferQueue.mItf));
658 void android_Player_androidBufferQueue_clear_l(CMediaPlayer *mp) {
659 if ((mp->mAndroidObjType == AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE)
660 && (mp->mAVPlayer != 0)) {
661 android::StreamPlayer* splr = static_cast<android::StreamPlayer*>(mp->mAVPlayer.get());
667 void android_Player_androidBufferQueue_onRefilled_l(CMediaPlayer *mp) {
668 if ((mp->mAndroidObjType == AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE)
669 && (mp->mAVPlayer != 0)) {
670 android::StreamPlayer* splr = static_cast<android::StreamPlayer*>(mp->mAVPlayer.get());
671 splr->queueRefilled();
679 * mp->mAVPlayer != 0 (player is realized)
680 * nativeWindow can be NULL, but if NULL it is treated as an error
682 SLresult android_Player_setNativeWindow(CMediaPlayer *mp, ANativeWindow *nativeWindow)
685 assert(mp->mAVPlayer != 0);
686 if (nativeWindow == NULL) {
687 SL_LOGE("ANativeWindow is NULL");
688 return SL_RESULT_PARAMETER_INVALID;
693 // this could crash if app passes in a bad parameter, but that's OK
694 err = (*nativeWindow->query)(nativeWindow, NATIVE_WINDOW_CONCRETE_TYPE, &value);
696 SL_LOGE("Query NATIVE_WINDOW_CONCRETE_TYPE on ANativeWindow * %p failed; "
697 "errno %d", nativeWindow, err);
698 result = SL_RESULT_PARAMETER_INVALID;
701 case NATIVE_WINDOW_SURFACE: { // Surface
702 SL_LOGV("Displaying on ANativeWindow of type NATIVE_WINDOW_SURFACE");
703 android::sp<android::Surface> nativeSurface(
704 static_cast<android::Surface *>(nativeWindow));
705 mp->mAVPlayer->setVideoSurface(nativeSurface);
706 result = SL_RESULT_SUCCESS;
708 case NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT: { // SurfaceTextureClient
709 SL_LOGV("Displaying on ANativeWindow of type NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT");
710 android::sp<android::SurfaceTextureClient> surfaceTextureClient(
711 static_cast<android::SurfaceTextureClient *>(nativeWindow));
712 android::sp<android::ISurfaceTexture> nativeSurfaceTexture(
713 surfaceTextureClient->getISurfaceTexture());
714 mp->mAVPlayer->setVideoSurfaceTexture(nativeSurfaceTexture);
715 result = SL_RESULT_SUCCESS;
717 case NATIVE_WINDOW_FRAMEBUFFER: // FramebufferNativeWindow
720 SL_LOGE("ANativeWindow * %p has unknown or unsupported concrete type %d",
721 nativeWindow, value);
722 result = SL_RESULT_PARAMETER_INVALID;