xref: /aosp_15_r20/frameworks/wilhelm/src/itf/IVideoDecoderCapabilities.cpp (revision bebae9c0e76121f8312ccb50385c080b3a0b023c)
1*bebae9c0SAndroid Build Coastguard Worker /*
2*bebae9c0SAndroid Build Coastguard Worker  * Copyright (C) 2011 The Android Open Source Project
3*bebae9c0SAndroid Build Coastguard Worker  *
4*bebae9c0SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*bebae9c0SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*bebae9c0SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*bebae9c0SAndroid Build Coastguard Worker  *
8*bebae9c0SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*bebae9c0SAndroid Build Coastguard Worker  *
10*bebae9c0SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*bebae9c0SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*bebae9c0SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*bebae9c0SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*bebae9c0SAndroid Build Coastguard Worker  * limitations under the License.
15*bebae9c0SAndroid Build Coastguard Worker  */
16*bebae9c0SAndroid Build Coastguard Worker 
17*bebae9c0SAndroid Build Coastguard Worker /* VideoDecoderCapabilities implementation */
18*bebae9c0SAndroid Build Coastguard Worker 
19*bebae9c0SAndroid Build Coastguard Worker #include "sles_allinclusive.h"
20*bebae9c0SAndroid Build Coastguard Worker #ifdef ANDROID
21*bebae9c0SAndroid Build Coastguard Worker #include "android/VideoCodec_to_android.h"
22*bebae9c0SAndroid Build Coastguard Worker #endif
23*bebae9c0SAndroid Build Coastguard Worker 
24*bebae9c0SAndroid Build Coastguard Worker 
IVideoDecoderCapabilities_GetVideoDecoders(XAVideoDecoderCapabilitiesItf self,XAuint32 * pNumDecoders,XAuint32 * pDecoderIds)25*bebae9c0SAndroid Build Coastguard Worker static XAresult IVideoDecoderCapabilities_GetVideoDecoders(XAVideoDecoderCapabilitiesItf self,
26*bebae9c0SAndroid Build Coastguard Worker     XAuint32 *pNumDecoders, XAuint32 *pDecoderIds)
27*bebae9c0SAndroid Build Coastguard Worker {
28*bebae9c0SAndroid Build Coastguard Worker     XA_ENTER_INTERFACE
29*bebae9c0SAndroid Build Coastguard Worker 
30*bebae9c0SAndroid Build Coastguard Worker     if (NULL == pNumDecoders) {
31*bebae9c0SAndroid Build Coastguard Worker         result = XA_RESULT_PARAMETER_INVALID;
32*bebae9c0SAndroid Build Coastguard Worker     } else {
33*bebae9c0SAndroid Build Coastguard Worker         if (NULL == pDecoderIds) {
34*bebae9c0SAndroid Build Coastguard Worker             // If pDecoderIds is NULL, pNumDecoders returns the number of decoders available.
35*bebae9c0SAndroid Build Coastguard Worker #ifdef ANDROID
36*bebae9c0SAndroid Build Coastguard Worker             *pNumDecoders = android::android_videoCodec_getNbDecoders();
37*bebae9c0SAndroid Build Coastguard Worker #else
38*bebae9c0SAndroid Build Coastguard Worker             *pNumDecoders = kMaxVideoDecoders;
39*bebae9c0SAndroid Build Coastguard Worker #endif
40*bebae9c0SAndroid Build Coastguard Worker 
41*bebae9c0SAndroid Build Coastguard Worker         } else {
42*bebae9c0SAndroid Build Coastguard Worker             // If pDecodersIds is non-NULL, as an input pNumDecoders specifies the size of the
43*bebae9c0SAndroid Build Coastguard Worker             // pDecoderIds array and as an output it specifies the number of decoder IDs available
44*bebae9c0SAndroid Build Coastguard Worker             // within the pDecoderIds array.
45*bebae9c0SAndroid Build Coastguard Worker             XAuint32 numDecoders = *pNumDecoders;
46*bebae9c0SAndroid Build Coastguard Worker #ifdef ANDROID
47*bebae9c0SAndroid Build Coastguard Worker             const XAuint32 androidNbDecoders = android::android_videoCodec_getNbDecoders();
48*bebae9c0SAndroid Build Coastguard Worker             if (androidNbDecoders < numDecoders) {
49*bebae9c0SAndroid Build Coastguard Worker                 *pNumDecoders = numDecoders = androidNbDecoders;
50*bebae9c0SAndroid Build Coastguard Worker             }
51*bebae9c0SAndroid Build Coastguard Worker             android::android_videoCodec_getDecoderIds(numDecoders, pDecoderIds);
52*bebae9c0SAndroid Build Coastguard Worker #else
53*bebae9c0SAndroid Build Coastguard Worker             if (kMaxVideoDecoders < numDecoders) {
54*bebae9c0SAndroid Build Coastguard Worker                 *pNumDecoders = numDecoders = kMaxVideoDecoders;
55*bebae9c0SAndroid Build Coastguard Worker             }
56*bebae9c0SAndroid Build Coastguard Worker             memcpy(pDecoderIds, VideoDecoderIds, numDecoders * sizeof(XAuint32));
57*bebae9c0SAndroid Build Coastguard Worker #endif
58*bebae9c0SAndroid Build Coastguard Worker         }
59*bebae9c0SAndroid Build Coastguard Worker         result = XA_RESULT_SUCCESS;
60*bebae9c0SAndroid Build Coastguard Worker     }
61*bebae9c0SAndroid Build Coastguard Worker 
62*bebae9c0SAndroid Build Coastguard Worker     XA_LEAVE_INTERFACE
63*bebae9c0SAndroid Build Coastguard Worker }
64*bebae9c0SAndroid Build Coastguard Worker 
65*bebae9c0SAndroid Build Coastguard Worker 
IVideoDecoderCapabilities_GetVideoDecoderCapabilities(XAVideoDecoderCapabilitiesItf self,XAuint32 decoderId,XAuint32 * pIndex,XAVideoCodecDescriptor * pDescriptor)66*bebae9c0SAndroid Build Coastguard Worker static XAresult IVideoDecoderCapabilities_GetVideoDecoderCapabilities(
67*bebae9c0SAndroid Build Coastguard Worker     XAVideoDecoderCapabilitiesItf self, XAuint32 decoderId, XAuint32 *pIndex,
68*bebae9c0SAndroid Build Coastguard Worker     XAVideoCodecDescriptor *pDescriptor)
69*bebae9c0SAndroid Build Coastguard Worker {
70*bebae9c0SAndroid Build Coastguard Worker     XA_ENTER_INTERFACE
71*bebae9c0SAndroid Build Coastguard Worker 
72*bebae9c0SAndroid Build Coastguard Worker     if (NULL == pIndex) {
73*bebae9c0SAndroid Build Coastguard Worker         result = XA_RESULT_PARAMETER_INVALID;
74*bebae9c0SAndroid Build Coastguard Worker     } else {
75*bebae9c0SAndroid Build Coastguard Worker         if (NULL == pDescriptor) {
76*bebae9c0SAndroid Build Coastguard Worker             // pIndex returns the number of video decoders capability descriptions.
77*bebae9c0SAndroid Build Coastguard Worker #ifdef ANDROID
78*bebae9c0SAndroid Build Coastguard Worker             result = android::android_videoCodec_getProfileLevelCombinationNb(decoderId, pIndex);
79*bebae9c0SAndroid Build Coastguard Worker #else
80*bebae9c0SAndroid Build Coastguard Worker             // Generic implementation has zero profile/level combinations for all codecs,
81*bebae9c0SAndroid Build Coastguard Worker             // but this is not allowed per spec:
82*bebae9c0SAndroid Build Coastguard Worker             //    "Each decoder must support at least one profile/mode pair
83*bebae9c0SAndroid Build Coastguard Worker             //    and therefore have at least one Codec Descriptor."
84*bebae9c0SAndroid Build Coastguard Worker             *pIndex = 0;
85*bebae9c0SAndroid Build Coastguard Worker             SL_LOGE("Generic implementation has no video decoder capabilities");
86*bebae9c0SAndroid Build Coastguard Worker             result = XA_RESULT_PARAMETER_INVALID;
87*bebae9c0SAndroid Build Coastguard Worker #endif
88*bebae9c0SAndroid Build Coastguard Worker         } else {
89*bebae9c0SAndroid Build Coastguard Worker             // pIndex is an incrementing value used to enumerate capability descriptions.
90*bebae9c0SAndroid Build Coastguard Worker #ifdef ANDROID
91*bebae9c0SAndroid Build Coastguard Worker             result = android::android_videoCodec_getProfileLevelCombination(decoderId, *pIndex,
92*bebae9c0SAndroid Build Coastguard Worker                     pDescriptor);
93*bebae9c0SAndroid Build Coastguard Worker #else
94*bebae9c0SAndroid Build Coastguard Worker             // For the generic implementation, any index >= 0 is out of range
95*bebae9c0SAndroid Build Coastguard Worker #if 1   // not sure if this is needed, it's not being done for the Android case
96*bebae9c0SAndroid Build Coastguard Worker             pDescriptor->codecId = decoderId;
97*bebae9c0SAndroid Build Coastguard Worker #endif
98*bebae9c0SAndroid Build Coastguard Worker             SL_LOGE("Generic implementation has no video decoder capabilities");
99*bebae9c0SAndroid Build Coastguard Worker             result = XA_RESULT_PARAMETER_INVALID;
100*bebae9c0SAndroid Build Coastguard Worker #endif
101*bebae9c0SAndroid Build Coastguard Worker         }
102*bebae9c0SAndroid Build Coastguard Worker     }
103*bebae9c0SAndroid Build Coastguard Worker 
104*bebae9c0SAndroid Build Coastguard Worker     XA_LEAVE_INTERFACE
105*bebae9c0SAndroid Build Coastguard Worker }
106*bebae9c0SAndroid Build Coastguard Worker 
107*bebae9c0SAndroid Build Coastguard Worker 
108*bebae9c0SAndroid Build Coastguard Worker static const struct XAVideoDecoderCapabilitiesItf_ IVideoDecoderCapabilities_Itf = {
109*bebae9c0SAndroid Build Coastguard Worker     IVideoDecoderCapabilities_GetVideoDecoders,
110*bebae9c0SAndroid Build Coastguard Worker     IVideoDecoderCapabilities_GetVideoDecoderCapabilities
111*bebae9c0SAndroid Build Coastguard Worker };
112*bebae9c0SAndroid Build Coastguard Worker 
IVideoDecoderCapabilities_init(void * self)113*bebae9c0SAndroid Build Coastguard Worker void IVideoDecoderCapabilities_init(void *self)
114*bebae9c0SAndroid Build Coastguard Worker {
115*bebae9c0SAndroid Build Coastguard Worker     IVideoDecoderCapabilities *thiz = (IVideoDecoderCapabilities *) self;
116*bebae9c0SAndroid Build Coastguard Worker     thiz->mItf = &IVideoDecoderCapabilities_Itf;
117*bebae9c0SAndroid Build Coastguard Worker }
118*bebae9c0SAndroid Build Coastguard Worker 
119*bebae9c0SAndroid Build Coastguard Worker 
IVideoDecoderCapabilities_expose(void * self)120*bebae9c0SAndroid Build Coastguard Worker bool IVideoDecoderCapabilities_expose(void *self)
121*bebae9c0SAndroid Build Coastguard Worker {
122*bebae9c0SAndroid Build Coastguard Worker #ifdef ANDROID
123*bebae9c0SAndroid Build Coastguard Worker     // This is an Engine object interface, so we allocate the associated resources every time
124*bebae9c0SAndroid Build Coastguard Worker     //   the interface is exposed on the Engine object and free them when the object is about
125*bebae9c0SAndroid Build Coastguard Worker     //   to be destroyed (see IVideoDecoderCapabilities_deinit), not just once during the
126*bebae9c0SAndroid Build Coastguard Worker     //   lifetime of the process.
127*bebae9c0SAndroid Build Coastguard Worker     return android::android_videoCodec_expose();
128*bebae9c0SAndroid Build Coastguard Worker #else
129*bebae9c0SAndroid Build Coastguard Worker     return false;
130*bebae9c0SAndroid Build Coastguard Worker #endif
131*bebae9c0SAndroid Build Coastguard Worker }
132*bebae9c0SAndroid Build Coastguard Worker 
133*bebae9c0SAndroid Build Coastguard Worker 
IVideoDecoderCapabilities_deinit(void * self)134*bebae9c0SAndroid Build Coastguard Worker void IVideoDecoderCapabilities_deinit(void *self)
135*bebae9c0SAndroid Build Coastguard Worker {
136*bebae9c0SAndroid Build Coastguard Worker     SL_LOGV("IVideoDecoderCapabilities_deinit()");
137*bebae9c0SAndroid Build Coastguard Worker #ifdef ANDROID
138*bebae9c0SAndroid Build Coastguard Worker     android::android_videoCodec_deinit();
139*bebae9c0SAndroid Build Coastguard Worker #endif
140*bebae9c0SAndroid Build Coastguard Worker }
141