IVideoDecoderCapabilities.cpp revision 6e7e174807fc639c49125ced8962aa369370fbf0
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
25static 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
67static 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            pIndex = 0;
82            SL_LOGE("Generic implementation has no video decoder capabilities");
83            result = XA_RESULT_PARAMETER_INVALID;
84#endif
85        } else {
86            // pIndex is an incrementing value used to enumerate capability descriptions.
87#ifdef ANDROID
88            result = android::android_videoCodec_getProfileLevelCombination(decoderId, *pIndex,
89                    pDescriptor);
90#else
91            pDescriptor->codecId = decoderId;
92            SL_LOGE("Generic implementation has no video decoder capabilities");
93            result = XA_RESULT_PARAMETER_INVALID;
94#endif
95        }
96    }
97
98    XA_LEAVE_INTERFACE
99}
100
101
102static const struct XAVideoDecoderCapabilitiesItf_ IVideoDecoderCapabilities_Itf = {
103    IVideoDecoderCapabilities_GetVideoDecoders,
104    IVideoDecoderCapabilities_GetVideoDecoderCapabilities
105};
106
107void IVideoDecoderCapabilities_init(void *self)
108{
109    IVideoDecoderCapabilities *thiz = (IVideoDecoderCapabilities *) self;
110    thiz->mItf = &IVideoDecoderCapabilities_Itf;
111}
112
113
114bool IVideoDecoderCapabilities_expose(void *self)
115{
116#ifdef ANDROID
117    // This is an Engine object interface, so we allocate the associated resources every time
118    //   the interface is exposed on the Engine object and free them when the object is about
119    //   to be destroyed (see IVideoDecoderCapabilities_deinit), not just once during the
120    //   lifetime of the process.
121    return android::android_videoCodec_expose();
122#else
123    return false;
124#endif
125}
126
127
128void IVideoDecoderCapabilities_deinit(void *self)
129{
130    LOGE("IVideoDecoderCapabilities_deinit()");
131#ifdef ANDROID
132    android::android_videoCodec_deinit();
133#endif
134}
135