Home | History | Annotate | Download | only in itf
      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 #ifdef ANDROID
     46             XAuint32 numDecoders = *pNumDecoders;
     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             XAuint32 numDecoders = *pNumDecoders;
     54             if (kMaxVideoDecoders <= numDecoders) {
     55                 *pNumDecoders = numDecoders = kMaxVideoDecoders;
     56             }
     57             memcpy(pDecoderIds, VideoDecoderIds, numDecoders * sizeof(XAuint32));
     58 #endif
     59         }
     60         result = XA_RESULT_SUCCESS;
     61     }
     62 
     63     XA_LEAVE_INTERFACE
     64 }
     65 
     66 
     67 static XAresult IVideoDecoderCapabilities_GetVideoDecoderCapabilities(
     68     XAVideoDecoderCapabilitiesItf self, XAuint32 decoderId, XAuint32 *pIndex,
     69     XAVideoCodecDescriptor *pDescriptor)
     70 {
     71     XA_ENTER_INTERFACE
     72 
     73     if (NULL == pIndex) {
     74         result = XA_RESULT_PARAMETER_INVALID;
     75     } else {
     76         if (NULL == pDescriptor) {
     77             // pIndex returns the number of video decoders capability descriptions.
     78 #ifdef ANDROID
     79             result = android::android_videoCodec_getProfileLevelCombinationNb(decoderId, pIndex);
     80 #else
     81             SL_LOGE("Generic implementation has no video decoder capabilities");
     82             result = XA_RESULT_PARAMETER_INVALID;
     83 #endif
     84         } else {
     85             // pIndex is an incrementing value used to enumerate capability descriptions.
     86 #ifdef ANDROID
     87             result = android::android_videoCodec_getProfileLevelCombination(decoderId, *pIndex,
     88                     pDescriptor);
     89 #else
     90             pDescriptor->codecId = decoderId;
     91             SL_LOGE("Generic implementation has no video decoder capabilities");
     92             result = XA_RESULT_PARAMETER_INVALID;
     93 #endif
     94         }
     95     }
     96 
     97     XA_LEAVE_INTERFACE
     98 }
     99 
    100 
    101 static const struct XAVideoDecoderCapabilitiesItf_ IVideoDecoderCapabilities_Itf = {
    102     IVideoDecoderCapabilities_GetVideoDecoders,
    103     IVideoDecoderCapabilities_GetVideoDecoderCapabilities
    104 };
    105 
    106 void IVideoDecoderCapabilities_init(void *self)
    107 {
    108     IVideoDecoderCapabilities *thiz = (IVideoDecoderCapabilities *) self;
    109     thiz->mItf = &IVideoDecoderCapabilities_Itf;
    110 }
    111 
    112 
    113 bool IVideoDecoderCapabilities_expose(void *self)
    114 {
    115 #ifdef ANDROID
    116     // This is an Engine object interface, so we allocate the associated resources every time
    117     //   the interface is exposed on the Engine object and free them when the object is about
    118     //   to be destroyed (see IVideoDecoderCapabilities_deinit), not just once during the
    119     //   lifetime of the process.
    120     return android::android_videoCodec_expose();
    121 #else
    122     return false;
    123 #endif
    124 }
    125 
    126 
    127 void IVideoDecoderCapabilities_deinit(void *self)
    128 {
    129     SL_LOGV("IVideoDecoderCapabilities_deinit()");
    130 #ifdef ANDROID
    131     android::android_videoCodec_deinit();
    132 #endif
    133 }
    134