MediaPlayer_to_android.cpp revision bcfe680db1e392f3bb29382c2e15e89c3af783ed
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 "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"
24
25
26//-----------------------------------------------------------------------------
27static void player_handleMediaPlayerEventNotifications(int event, int data1, int data2, void* user)
28{
29    if (NULL == user) {
30        return;
31    }
32
33    CMediaPlayer* mp = (CMediaPlayer*) user;
34    SL_LOGV("received event %d, data %d from AVPlayer", event, data1);
35
36    switch(event) {
37
38      case android::GenericPlayer::kEventPrepared: {
39        if (PLAYER_SUCCESS == data1) {
40            object_lock_exclusive(&mp->mObject);
41            SL_LOGV("Received AVPlayer::kEventPrepared from AVPlayer for CMediaPlayer %p", mp);
42            mp->mAndroidObjState = ANDROID_READY;
43            object_unlock_exclusive(&mp->mObject);
44        }
45        break;
46      }
47
48      case android::GenericPlayer::kEventHasVideoSize: {
49        SL_LOGV("Received AVPlayer::kEventHasVideoSize (%d,%d) for CMediaPlayer %p",
50                data1, data2, mp);
51
52        object_lock_exclusive(&mp->mObject);
53
54        // remove an existing video info entry (here we only have one video stream)
55        for(size_t i=0 ; i < mp->mStreamInfo.mStreamInfoTable.size() ; i++) {
56            if (XA_DOMAINTYPE_VIDEO == mp->mStreamInfo.mStreamInfoTable.itemAt(i).domain) {
57                mp->mStreamInfo.mStreamInfoTable.removeAt(i);
58                break;
59            }
60        }
61        // update the stream information with a new video info entry
62        StreamInfo streamInfo;
63        streamInfo.domain = XA_DOMAINTYPE_VIDEO;
64        streamInfo.videoInfo.codecId = 0;// unknown, we don't have that info FIXME
65        streamInfo.videoInfo.width = (XAuint32)data1;
66        streamInfo.videoInfo.height = (XAuint32)data2;
67        streamInfo.videoInfo.bitRate = 0;// unknown, we don't have that info FIXME
68        streamInfo.videoInfo.duration = XA_TIME_UNKNOWN;
69        StreamInfo &contInfo = mp->mStreamInfo.mStreamInfoTable.editItemAt(0);
70        contInfo.containerInfo.numStreams = 1;
71        ssize_t index = mp->mStreamInfo.mStreamInfoTable.add(streamInfo);
72
73        xaStreamEventChangeCallback callback = mp->mStreamInfo.mCallback;
74        void* callbackPContext = mp->mStreamInfo.mContext;
75
76        object_unlock_exclusive(&mp->mObject);
77
78        // enqueue notification (outside of lock) that the stream information has been updated
79        if ((NULL != callback) && (index >= 0)) {
80#ifdef XA_SYNCHRONOUS_STREAMCBEVENT_PROPERTYCHANGE
81            (*callback)(&mp->mStreamInfo.mItf, XA_STREAMCBEVENT_PROPERTYCHANGE /*eventId*/,
82                    1 /*streamIndex, only one stream supported here, 0 is reserved*/,
83                    NULL /*pEventData, always NULL in OpenMAX AL 1.0.1*/,
84                    callbackPContext /*pContext*/);
85#else
86            SLresult res = EnqueueAsyncCallback_piipp(mp, callback,
87                    /*p1*/ &mp->mStreamInfo.mItf,
88                    /*i1*/ XA_STREAMCBEVENT_PROPERTYCHANGE /*eventId*/,
89                    /*i2*/ 1 /*streamIndex, only one stream supported here, 0 is reserved*/,
90                    /*p2*/ NULL /*pEventData, always NULL in OpenMAX AL 1.0.1*/,
91                    /*p3*/ callbackPContext /*pContext*/);
92#endif
93        }
94        break;
95      }
96
97      case android::GenericPlayer::kEventEndOfStream: {
98        SL_LOGV("Received AVPlayer::kEventEndOfStream for CMediaPlayer %p", mp);
99
100        object_lock_exclusive(&mp->mObject);
101        // should be xaPlayCallback but we're sharing the itf between SL and AL
102        slPlayCallback playCallback = NULL;
103        void * playContext = NULL;
104        // XAPlayItf callback or no callback?
105        if (mp->mPlay.mEventFlags & XA_PLAYEVENT_HEADATEND) {
106            playCallback = mp->mPlay.mCallback;
107            playContext = mp->mPlay.mContext;
108        }
109        object_unlock_exclusive(&mp->mObject);
110
111        // enqueue callback with no lock held
112        if (NULL != playCallback) {
113#ifdef XA_SYNCHRONOUS_PLAYEVENT_HEADATEND
114            (*playCallback)(&mp->mPlay.mItf, playContext, XA_PLAYEVENT_HEADATEND);
115#else
116            SLresult res = EnqueueAsyncCallback_ppi(mp, playCallback, &mp->mPlay.mItf, playContext,
117                    XA_PLAYEVENT_HEADATEND);
118            LOGW_IF(SL_RESULT_SUCCESS != res,
119                    "Callback %p(%p, %p, XA_PLAYEVENT_HEADATEND) dropped", playCallback,
120                    &mp->mPlay.mItf, playContext);
121#endif
122        }
123        break;
124      }
125
126      case android::GenericPlayer::kEventChannelCount: {
127        SL_LOGV("kEventChannelCount channels = %d", data1);
128        object_lock_exclusive(&mp->mObject);
129        if (UNKNOWN_NUMCHANNELS == mp->mNumChannels && UNKNOWN_NUMCHANNELS != data1) {
130            mp->mNumChannels = data1;
131            android_Player_volumeUpdate(mp);
132        }
133        object_unlock_exclusive(&mp->mObject);
134      }
135      break;
136
137      case android::GenericPlayer::kEventPrefetchFillLevelUpdate: {
138        SL_LOGV("kEventPrefetchFillLevelUpdate");
139      }
140      break;
141
142      case android::GenericPlayer::kEventPrefetchStatusChange: {
143        SL_LOGV("kEventPrefetchStatusChange");
144      }
145      break;
146
147      case android::GenericPlayer::kEventPlay: {
148        SL_LOGV("kEventPlay");
149
150        interface_lock_shared(&mp->mPlay);
151        slPlayCallback callback = mp->mPlay.mCallback;
152        void* callbackPContext = mp->mPlay.mContext;
153        interface_unlock_shared(&mp->mPlay);
154
155        if (NULL != callback) {
156            (*callback)(&mp->mPlay.mItf, callbackPContext, (SLuint32) data1); // SL_PLAYEVENT_HEAD*
157        }
158      }
159      break;
160
161      default: {
162        SL_LOGE("Received unknown event %d, data %d from AVPlayer", event, data1);
163      }
164    }
165}
166
167
168//-----------------------------------------------------------------------------
169XAresult android_Player_checkSourceSink(CMediaPlayer *mp) {
170
171    XAresult result = XA_RESULT_SUCCESS;
172
173    const SLDataSource *pSrc    = &mp->mDataSource.u.mSource;
174    const SLDataSink *pAudioSnk = &mp->mAudioSink.u.mSink;
175
176    // format check:
177    const SLuint32 sourceLocatorType = *(SLuint32 *)pSrc->pLocator;
178    const SLuint32 sourceFormatType  = *(SLuint32 *)pSrc->pFormat;
179    const SLuint32 audioSinkLocatorType = *(SLuint32 *)pAudioSnk->pLocator;
180    //const SLuint32 sinkFormatType = *(SLuint32 *)pAudioSnk->pFormat;
181
182    // Source check
183    switch(sourceLocatorType) {
184
185    case XA_DATALOCATOR_ANDROIDBUFFERQUEUE: {
186        switch (sourceFormatType) {
187        case XA_DATAFORMAT_MIME: {
188            SLDataFormat_MIME *df_mime = (SLDataFormat_MIME *) pSrc->pFormat;
189            if (SL_CONTAINERTYPE_MPEG_TS != df_mime->containerType) {
190                SL_LOGE("Cannot create player with XA_DATALOCATOR_ANDROIDBUFFERQUEUE data source "
191                        "that is not fed MPEG-2 TS data");
192                return SL_RESULT_CONTENT_UNSUPPORTED;
193            }
194        } break;
195        default:
196            SL_LOGE("Cannot create player with XA_DATALOCATOR_ANDROIDBUFFERQUEUE data source "
197                    "without SL_DATAFORMAT_MIME format");
198            return XA_RESULT_CONTENT_UNSUPPORTED;
199        }
200    } break;
201
202    case XA_DATALOCATOR_URI: // intended fall-through
203    case XA_DATALOCATOR_ANDROIDFD:
204        break;
205
206    default:
207        SL_LOGE("Cannot create media player with data locator type 0x%x",
208                (unsigned) sourceLocatorType);
209        return SL_RESULT_PARAMETER_INVALID;
210    }// switch (locatorType)
211
212    // Audio sink check: only playback is supported here
213    switch(audioSinkLocatorType) {
214
215    case XA_DATALOCATOR_OUTPUTMIX:
216        break;
217
218    default:
219        SL_LOGE("Cannot create media player with audio sink data locator of type 0x%x",
220                (unsigned) audioSinkLocatorType);
221        return XA_RESULT_PARAMETER_INVALID;
222    }// switch (locaaudioSinkLocatorTypeorType)
223
224    return result;
225}
226
227
228//-----------------------------------------------------------------------------
229XAresult android_Player_create(CMediaPlayer *mp) {
230
231    XAresult result = XA_RESULT_SUCCESS;
232
233    // FIXME verify data source
234    const SLDataSource *pDataSrc = &mp->mDataSource.u.mSource;
235    // FIXME verify audio data sink
236    const SLDataSink *pAudioSnk = &mp->mAudioSink.u.mSink;
237    // FIXME verify image data sink
238    const SLDataSink *pVideoSnk = &mp->mImageVideoSink.u.mSink;
239
240    XAuint32 sourceLocator = *(XAuint32 *)pDataSrc->pLocator;
241    switch(sourceLocator) {
242    // FIXME support Android simple buffer queue as well
243    case XA_DATALOCATOR_ANDROIDBUFFERQUEUE:
244        mp->mAndroidObjType = AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE;
245        break;
246    case XA_DATALOCATOR_URI: // intended fall-through
247    case SL_DATALOCATOR_ANDROIDFD:
248        mp->mAndroidObjType = AUDIOVIDEOPLAYER_FROM_URIFD;
249        break;
250    case XA_DATALOCATOR_ADDRESS: // intended fall-through
251    default:
252        SL_LOGE("Unable to create MediaPlayer for data source locator 0x%x", sourceLocator);
253        result = XA_RESULT_PARAMETER_INVALID;
254        break;
255    }
256
257    // FIXME duplicates an initialization also done by higher level
258    mp->mAndroidObjState = ANDROID_UNINITIALIZED;
259    mp->mStreamType = ANDROID_DEFAULT_OUTPUT_STREAM_TYPE;
260    mp->mSessionId = android::AudioSystem::newAudioSessionId();
261
262    return result;
263}
264
265
266//-----------------------------------------------------------------------------
267// FIXME abstract out the diff between CMediaPlayer and CAudioPlayer
268XAresult android_Player_realize(CMediaPlayer *mp, SLboolean async) {
269    SL_LOGV("android_Player_realize_l(%p)", mp);
270    XAresult result = XA_RESULT_SUCCESS;
271
272    const SLDataSource *pDataSrc = &mp->mDataSource.u.mSource;
273    const SLuint32 sourceLocator = *(SLuint32 *)pDataSrc->pLocator;
274
275    AudioPlayback_Parameters ap_params;
276    ap_params.sessionId = mp->mSessionId;
277    ap_params.streamType = mp->mStreamType;
278    ap_params.trackcb = NULL;
279    ap_params.trackcbUser = NULL;
280
281    switch(mp->mAndroidObjType) {
282    case AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: {
283        mp->mAVPlayer = new android::StreamPlayer(&ap_params, true /*hasVideo*/);
284        mp->mAVPlayer->init(player_handleMediaPlayerEventNotifications, (void*)mp);
285        }
286        break;
287    case AUDIOVIDEOPLAYER_FROM_URIFD: {
288        mp->mAVPlayer = new android::LocAVPlayer(&ap_params, true /*hasVideo*/);
289        mp->mAVPlayer->init(player_handleMediaPlayerEventNotifications, (void*)mp);
290        switch (mp->mDataSource.mLocator.mLocatorType) {
291        case XA_DATALOCATOR_URI:
292            ((android::LocAVPlayer*)mp->mAVPlayer.get())->setDataSource(
293                    (const char*)mp->mDataSource.mLocator.mURI.URI);
294            break;
295        case XA_DATALOCATOR_ANDROIDFD: {
296            int64_t offset = (int64_t)mp->mDataSource.mLocator.mFD.offset;
297            ((android::LocAVPlayer*)mp->mAVPlayer.get())->setDataSource(
298                    (int)mp->mDataSource.mLocator.mFD.fd,
299                    offset == SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE ?
300                            (int64_t)PLAYER_FD_FIND_FILE_SIZE : offset,
301                    (int64_t)mp->mDataSource.mLocator.mFD.length);
302            }
303            break;
304        default:
305            SL_LOGE("Invalid or unsupported data locator type %u for data source",
306                    mp->mDataSource.mLocator.mLocatorType);
307            result = XA_RESULT_PARAMETER_INVALID;
308        }
309        }
310        break;
311    case INVALID_TYPE: // intended fall-through
312    default:
313        SL_LOGE("Unable to realize MediaPlayer, invalid internal Android object type");
314        result = XA_RESULT_PARAMETER_INVALID;
315        break;
316    }
317
318    if (XA_RESULT_SUCCESS == result) {
319
320        // if there is a video sink
321        if (XA_DATALOCATOR_NATIVEDISPLAY ==
322                mp->mImageVideoSink.mLocator.mLocatorType) {
323            ANativeWindow *nativeWindow = (ANativeWindow *)
324                    mp->mImageVideoSink.mLocator.mNativeDisplay.hWindow;
325            // we already verified earlier that hWindow is non-NULL
326            assert(nativeWindow != NULL);
327            result = android_Player_setNativeWindow(mp, nativeWindow);
328        }
329
330    }
331
332    return result;
333}
334
335//-----------------------------------------------------------------------------
336XAresult android_Player_destroy(CMediaPlayer *mp) {
337    SL_LOGV("android_Player_destroy(%p)", mp);
338    XAresult result = XA_RESULT_SUCCESS;
339
340    if (mp->mAVPlayer != 0) {
341        mp->mAVPlayer.clear();
342    }
343
344    return result;
345}
346
347
348void android_Player_usePlayEventMask(CMediaPlayer *mp) {
349    if (mp->mAVPlayer != 0) {
350        IPlay *pPlayItf = &mp->mPlay;
351        mp->mAVPlayer->setPlayEvents((int32_t) pPlayItf->mEventFlags,
352                (int32_t) pPlayItf->mMarkerPosition, (int32_t) pPlayItf->mPositionUpdatePeriod);
353    }
354}
355
356
357XAresult android_Player_getDuration(IPlay *pPlayItf, XAmillisecond *pDurMsec) {
358    XAresult result = XA_RESULT_SUCCESS;
359    CMediaPlayer *avp = (CMediaPlayer *)pPlayItf->mThis;
360
361    switch (avp->mAndroidObjType) {
362
363    case AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: // intended fall-through
364    case AUDIOVIDEOPLAYER_FROM_URIFD: {
365        int dur = -1;
366        if (avp->mAVPlayer != 0) {
367            avp->mAVPlayer->getDurationMsec(&dur);
368        }
369        if (dur == ANDROID_UNKNOWN_TIME) {
370            *pDurMsec = XA_TIME_UNKNOWN;
371        } else {
372            *pDurMsec = (XAmillisecond)dur;
373        }
374    } break;
375
376    default:
377        // we shouldn't be here
378        assert(false);
379        break;
380    }
381
382    return result;
383}
384
385
386XAresult android_Player_getPosition(IPlay *pPlayItf, XAmillisecond *pPosMsec) {
387    SL_LOGD("android_Player_getPosition()");
388    XAresult result = XA_RESULT_SUCCESS;
389    CMediaPlayer *avp = (CMediaPlayer *)pPlayItf->mThis;
390
391    switch (avp->mAndroidObjType) {
392
393    case AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: // intended fall-through
394    case AUDIOVIDEOPLAYER_FROM_URIFD: {
395        int pos = -1;
396        if (avp->mAVPlayer != 0) {
397            avp->mAVPlayer->getPositionMsec(&pos);
398        }
399        if (pos == ANDROID_UNKNOWN_TIME) {
400            *pPosMsec = XA_TIME_UNKNOWN;
401        } else {
402            *pPosMsec = (XAmillisecond)pos;
403        }
404    } break;
405
406    default:
407        // we shouldn't be here
408        assert(false);
409        break;
410    }
411
412    return result;
413}
414
415
416//-----------------------------------------------------------------------------
417/**
418 * pre-condition: mp != NULL
419 */
420void android_Player_volumeUpdate(CMediaPlayer* mp)
421{
422    android::GenericPlayer* avp = mp->mAVPlayer.get();
423    if (avp != NULL) {
424        float volumes[2];
425        // MediaPlayer does not currently support EffectSend or MuteSolo
426        android_player_volumeUpdate(volumes, &mp->mVolume, mp->mNumChannels, 1.0f, NULL);
427        float leftVol = volumes[0], rightVol = volumes[1];
428        avp->setVolume(leftVol, rightVol);
429    }
430}
431
432//-----------------------------------------------------------------------------
433/**
434 * pre-condition: gp != 0
435 */
436XAresult android_Player_setPlayState(const android::sp<android::GenericPlayer> &gp,
437        SLuint32 playState,
438        AndroidObjectState* pObjState)
439{
440    XAresult result = XA_RESULT_SUCCESS;
441    AndroidObjectState objState = *pObjState;
442
443    switch (playState) {
444     case SL_PLAYSTATE_STOPPED: {
445         SL_LOGV("setting AVPlayer to SL_PLAYSTATE_STOPPED");
446         gp->stop();
447         }
448         break;
449     case SL_PLAYSTATE_PAUSED: {
450         SL_LOGV("setting AVPlayer to SL_PLAYSTATE_PAUSED");
451         switch(objState) {
452         case ANDROID_UNINITIALIZED:
453             *pObjState = ANDROID_PREPARING;
454             gp->prepare();
455             break;
456         case ANDROID_PREPARING:
457             break;
458         case ANDROID_READY:
459             gp->pause();
460             break;
461         default:
462             SL_LOGE("Android object in invalid state");
463             break;
464         }
465         }
466         break;
467     case SL_PLAYSTATE_PLAYING: {
468         SL_LOGV("setting AVPlayer to SL_PLAYSTATE_PLAYING");
469         switch(objState) {
470         case ANDROID_UNINITIALIZED:
471             *pObjState = ANDROID_PREPARING;
472             gp->prepare();
473             // intended fall through
474         case ANDROID_PREPARING:
475             // intended fall through
476         case ANDROID_READY:
477             gp->play();
478             break;
479         default:
480             SL_LOGE("Android object in invalid state");
481             break;
482         }
483         }
484         break;
485     default:
486         // checked by caller, should not happen
487         break;
488     }
489
490    return result;
491}
492
493
494/**
495 * pre-condition: mp != NULL
496 */
497XAresult android_Player_seek(CMediaPlayer *mp, SLmillisecond posMsec) {
498    XAresult result = XA_RESULT_SUCCESS;
499    switch (mp->mAndroidObjType) {
500      case AUDIOVIDEOPLAYER_FROM_URIFD:
501        if (mp->mAVPlayer !=0) {
502            mp->mAVPlayer->seek(posMsec);
503        }
504        break;
505      case AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: // intended fall-through
506      default: {
507          result = XA_RESULT_PARAMETER_INVALID;
508      }
509    }
510    return result;
511}
512
513
514/**
515 * pre-condition: mp != NULL
516 */
517XAresult android_Player_loop(CMediaPlayer *mp, SLboolean loopEnable) {
518    XAresult result = XA_RESULT_SUCCESS;
519    switch (mp->mAndroidObjType) {
520      case AUDIOVIDEOPLAYER_FROM_URIFD:
521        if (mp->mAVPlayer !=0) {
522            mp->mAVPlayer->loop(loopEnable);
523        }
524        break;
525      case AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: // intended fall-through
526      default: {
527          result = XA_RESULT_PARAMETER_INVALID;
528      }
529    }
530    return result;
531}
532
533
534//-----------------------------------------------------------------------------
535void android_Player_androidBufferQueue_registerCallback_l(CMediaPlayer *mp) {
536    if ((mp->mAndroidObjType == AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE)
537            && (mp->mAVPlayer != 0)) {
538        SL_LOGD("android_Player_androidBufferQueue_registerCallback_l");
539        android::StreamPlayer* splr = static_cast<android::StreamPlayer*>(mp->mAVPlayer.get());
540        splr->registerQueueCallback(
541                (const void*)mp, false /*userIsAudioPlayer*/,
542                mp->mAndroidBufferQueue.mContext, (const void*)&(mp->mAndroidBufferQueue.mItf));
543
544    }
545}
546
547
548void android_Player_androidBufferQueue_clear_l(CMediaPlayer *mp) {
549    if ((mp->mAndroidObjType == AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE)
550            && (mp->mAVPlayer != 0)) {
551        android::StreamPlayer* splr = static_cast<android::StreamPlayer*>(mp->mAVPlayer.get());
552        splr->appClear_l();
553    }
554}
555
556
557void android_Player_androidBufferQueue_onRefilled_l(CMediaPlayer *mp) {
558    if ((mp->mAndroidObjType == AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE)
559            && (mp->mAVPlayer != 0)) {
560        android::StreamPlayer* splr = static_cast<android::StreamPlayer*>(mp->mAVPlayer.get());
561        splr->queueRefilled_l();
562    }
563}
564
565
566/*
567 *  pre-conditions:
568 *      mp != NULL
569 *      mp->mAVPlayer != 0 (player is realized)
570 *      nativeWindow can be NULL, but if NULL it is treated as an error
571 */
572SLresult android_Player_setNativeWindow(CMediaPlayer *mp, ANativeWindow *nativeWindow)
573{
574    assert(mp != NULL);
575    assert(mp->mAVPlayer != 0);
576    if (nativeWindow == NULL) {
577        SL_LOGE("ANativeWindow is NULL");
578        return SL_RESULT_PARAMETER_INVALID;
579    }
580    SLresult result;
581    int err;
582    int value;
583    // this could crash if app passes in a bad parameter, but that's OK
584    err = (*nativeWindow->query)(nativeWindow, NATIVE_WINDOW_CONCRETE_TYPE, &value);
585    if (0 != err) {
586        SL_LOGE("Query NATIVE_WINDOW_CONCRETE_TYPE on ANativeWindow * %p failed; "
587                "errno %d", nativeWindow, err);
588        result = SL_RESULT_PARAMETER_INVALID;
589    } else {
590        switch (value) {
591        case NATIVE_WINDOW_SURFACE: {                // Surface
592            SL_LOGV("Displaying on ANativeWindow of type NATIVE_WINDOW_SURFACE");
593            android::sp<android::Surface> nativeSurface(
594                    static_cast<android::Surface *>(nativeWindow));
595            mp->mAVPlayer->setVideoSurface(nativeSurface);
596            result = SL_RESULT_SUCCESS;
597            } break;
598        case NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT: { // SurfaceTextureClient
599            SL_LOGV("Displaying on ANativeWindow of type NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT");
600            android::sp<android::SurfaceTextureClient> surfaceTextureClient(
601                    static_cast<android::SurfaceTextureClient *>(nativeWindow));
602            android::sp<android::ISurfaceTexture> nativeSurfaceTexture(
603                    surfaceTextureClient->getISurfaceTexture());
604            mp->mAVPlayer->setVideoSurfaceTexture(nativeSurfaceTexture);
605            result = SL_RESULT_SUCCESS;
606            } break;
607        case NATIVE_WINDOW_FRAMEBUFFER:              // FramebufferNativeWindow
608            // fall through
609        default:
610            SL_LOGE("ANativeWindow * %p has unknown or unsupported concrete type %d",
611                    nativeWindow, value);
612            result = SL_RESULT_PARAMETER_INVALID;
613            break;
614        }
615    }
616    return result;
617}
618