1 /* 2 * Copyright (C) 2011 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 /* VideoDecoderCapabilities implementation */ 18 19 #include "sles_allinclusive.h" 20 #ifdef ANDROID 21 #include "android/VideoCodec_to_android.h" 22 #endif 23 24 25 static XAresult IVideoDecoderCapabilities_GetVideoDecoders(XAVideoDecoderCapabilitiesItf self, 26 XAuint32 *pNumDecoders, XAuint32 *pDecoderIds) 27 { 28 XA_ENTER_INTERFACE 29 30 if (NULL == pNumDecoders) { 31 result = XA_RESULT_PARAMETER_INVALID; 32 } else { 33 if (NULL == pDecoderIds) { 34 // If pDecoderIds is NULL, pNumDecoders returns the number of decoders available. 35 #ifdef ANDROID 36 *pNumDecoders = android::android_videoCodec_getNbDecoders(); 37 #else 38 *pNumDecoders = kMaxVideoDecoders; 39 #endif 40 41 } else { 42 // If pDecodersIds is non-NULL, as an input pNumDecoders specifies the size of the 43 // pDecoderIds array and as an output it specifies the number of decoder IDs available 44 // within the pDecoderIds array. 45 XAuint32 numDecoders = *pNumDecoders; 46 #ifdef ANDROID 47 const XAuint32 androidNbDecoders = android::android_videoCodec_getNbDecoders(); 48 if (androidNbDecoders < numDecoders) { 49 *pNumDecoders = numDecoders = androidNbDecoders; 50 } 51 android::android_videoCodec_getDecoderIds(numDecoders, pDecoderIds); 52 #else 53 if (kMaxVideoDecoders < numDecoders) { 54 *pNumDecoders = numDecoders = kMaxVideoDecoders; 55 } 56 memcpy(pDecoderIds, VideoDecoderIds, numDecoders * sizeof(XAuint32)); 57 #endif 58 } 59 result = XA_RESULT_SUCCESS; 60 } 61 62 XA_LEAVE_INTERFACE 63 } 64 65 66 static XAresult IVideoDecoderCapabilities_GetVideoDecoderCapabilities( 67 XAVideoDecoderCapabilitiesItf self, XAuint32 decoderId, XAuint32 *pIndex, 68 XAVideoCodecDescriptor *pDescriptor) 69 { 70 XA_ENTER_INTERFACE 71 72 if (NULL == pIndex) { 73 result = XA_RESULT_PARAMETER_INVALID; 74 } else { 75 if (NULL == pDescriptor) { 76 // pIndex returns the number of video decoders capability descriptions. 77 #ifdef ANDROID 78 result = android::android_videoCodec_getProfileLevelCombinationNb(decoderId, pIndex); 79 #else 80 // Generic implementation has zero profile/level combinations for all codecs, 81 // but this is not allowed per spec: 82 // "Each decoder must support at least one profile/mode pair 83 // and therefore have at least one Codec Descriptor." 84 *pIndex = 0; 85 SL_LOGE("Generic implementation has no video decoder capabilities"); 86 result = XA_RESULT_PARAMETER_INVALID; 87 #endif 88 } else { 89 // pIndex is an incrementing value used to enumerate capability descriptions. 90 #ifdef ANDROID 91 result = android::android_videoCodec_getProfileLevelCombination(decoderId, *pIndex, 92 pDescriptor); 93 #else 94 // For the generic implementation, any index >= 0 is out of range 95 #if 1 // not sure if this is needed, it's not being done for the Android case 96 pDescriptor->codecId = decoderId; 97 #endif 98 SL_LOGE("Generic implementation has no video decoder capabilities"); 99 result = XA_RESULT_PARAMETER_INVALID; 100 #endif 101 } 102 } 103 104 XA_LEAVE_INTERFACE 105 } 106 107 108 static const struct XAVideoDecoderCapabilitiesItf_ IVideoDecoderCapabilities_Itf = { 109 IVideoDecoderCapabilities_GetVideoDecoders, 110 IVideoDecoderCapabilities_GetVideoDecoderCapabilities 111 }; 112 113 void IVideoDecoderCapabilities_init(void *self) 114 { 115 IVideoDecoderCapabilities *thiz = (IVideoDecoderCapabilities *) self; 116 thiz->mItf = &IVideoDecoderCapabilities_Itf; 117 } 118 119 120 bool IVideoDecoderCapabilities_expose(void *self) 121 { 122 #ifdef ANDROID 123 // This is an Engine object interface, so we allocate the associated resources every time 124 // the interface is exposed on the Engine object and free them when the object is about 125 // to be destroyed (see IVideoDecoderCapabilities_deinit), not just once during the 126 // lifetime of the process. 127 return android::android_videoCodec_expose(); 128 #else 129 return false; 130 #endif 131 } 132 133 134 void IVideoDecoderCapabilities_deinit(void *self) 135 { 136 SL_LOGV("IVideoDecoderCapabilities_deinit()"); 137 #ifdef ANDROID 138 android::android_videoCodec_deinit(); 139 #endif 140 } 141