CMediaPlayer.c revision 2b06e20ae32388f6e1dfd088d9773c34e6b1cb45
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/** \file CMediaPlayer.c MediaPlayer class */ 18 19#include "sles_allinclusive.h" 20 21#ifdef ANDROID 22#include <gui/SurfaceTextureClient.h> 23#include "android/android_GenericMediaPlayer.h" 24using namespace android; 25#endif 26 27 28XAresult CMediaPlayer_Realize(void *self, XAboolean async) 29{ 30 CMediaPlayer *thiz = (CMediaPlayer *) self; 31 32 XAresult result = XA_RESULT_SUCCESS; 33 34#ifdef ANDROID 35 // realize player 36 result = android_Player_realize(thiz, async); 37 if (XA_RESULT_SUCCESS == result) { 38 39 // if there is a video sink 40 if (XA_DATALOCATOR_NATIVEDISPLAY == 41 thiz->mImageVideoSink.mLocator.mLocatorType) { 42 ANativeWindow *nativeWindow = (ANativeWindow *) 43 thiz->mImageVideoSink.mLocator.mNativeDisplay.hWindow; 44 // we already verified earlier that hWindow is non-NULL 45 assert(nativeWindow != NULL); 46 int err; 47 int value; 48 // this could crash if app passes in a bad parameter, but that's OK 49 err = (*nativeWindow->query)(nativeWindow, NATIVE_WINDOW_CONCRETE_TYPE, &value); 50 if (0 != err) { 51 SL_LOGE("Query NATIVE_WINDOW_CONCRETE_TYPE on ANativeWindow * %p failed; " 52 "errno %d", nativeWindow, err); 53 } else { 54 // thiz->mAVPlayer != 0 is implied by success after android_Player_realize() 55 switch (value) { 56 case NATIVE_WINDOW_SURFACE: { // Surface 57 sp<Surface> nativeSurface(static_cast<Surface *>(nativeWindow)); 58 result = android_Player_setVideoSurface(thiz->mAVPlayer, nativeSurface); 59 } break; 60 case NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT: { // SurfaceTextureClient 61 sp<SurfaceTextureClient> surfaceTextureClient( 62 static_cast<SurfaceTextureClient *>(nativeWindow)); 63 sp<ISurfaceTexture> nativeSurfaceTexture( 64 surfaceTextureClient->getISurfaceTexture()); 65 result = android_Player_setVideoSurfaceTexture(thiz->mAVPlayer, 66 nativeSurfaceTexture); 67 } break; 68 case NATIVE_WINDOW_FRAMEBUFFER: // FramebufferNativeWindow 69 // fall through 70 default: 71 SL_LOGE("ANativeWindow * %p has unknown or unsupported concrete type %d", 72 nativeWindow, value); 73 break; 74 } 75 } 76 } 77 } 78#endif 79 80 return result; 81} 82 83 84XAresult CMediaPlayer_Resume(void *self, XAboolean async) 85{ 86 return XA_RESULT_SUCCESS; 87} 88 89 90/** \brief Hook called by Object::Destroy when a media player is destroyed */ 91 92void CMediaPlayer_Destroy(void *self) 93{ 94 CMediaPlayer *thiz = (CMediaPlayer *) self; 95 freeDataLocatorFormat(&thiz->mDataSource); 96 freeDataLocatorFormat(&thiz->mBankSource); 97 freeDataLocatorFormat(&thiz->mAudioSink); 98 freeDataLocatorFormat(&thiz->mImageVideoSink); 99 freeDataLocatorFormat(&thiz->mVibraSink); 100 freeDataLocatorFormat(&thiz->mLEDArraySink); 101#ifdef ANDROID 102 android_Player_destroy(thiz); 103#endif 104} 105 106 107predestroy_t CMediaPlayer_PreDestroy(void *self) 108{ 109 return predestroy_ok; 110} 111