1 /*
2  * Copyright (C) 2024 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 /**
18  * @addtogroup Media
19  * @{
20  */
21 
22 /**
23  * @file NdkMediaCodecStore.h
24  */
25 
26 /*
27  * This file defines an NDK API.
28  * Do not remove methods.
29  * Do not change method signatures.
30  * Do not change the value of constants.
31  * Do not change the size of any of the classes defined in here.
32  * Do not reference types that are not part of the NDK.
33  * Do not #include files that aren't part of the NDK.
34  */
35 
36 #ifndef _NDK_MEDIA_CODEC_STORE_H
37 #define _NDK_MEDIA_CODEC_STORE_H
38 
39 #include <stdint.h>
40 
41 #include "NdkMediaCodecInfo.h"
42 #include "NdkMediaError.h"
43 #include "NdkMediaFormat.h"
44 
45 __BEGIN_DECLS
46 
47 /**
48  * The media type definition with bitfeids indicating if it is
49  * supported by decoders/ encoders/ both.
50  */
51 typedef struct AMediaCodecSupportedMediaType {
52     enum Mode : uint32_t {
53         FLAG_DECODER = 1 << 0,
54         FLAG_ENCODER = 1 << 1,
55     };
56 
57     // The media type.
58     const char *mMediaType;
59     // bitfields for modes.
60     uint32_t mMode;
61 } AMediaCodecSupportedMediaType;
62 
63 /**
64  * Get an array of all the supported media types of a device.
65  *
66  * @param outMediaTypes The pointer to the output AMediaCodecSupportedMediaType array.
67  *                      It is owned by the fraework and has an infinite lifetime.
68  *
69  * @param outCount size of the out array.
70  *
71  * Return AMEDIA_OK if successfully made the copy.
72  * Return AMEDIA_ERROR_INVALID_PARAMETER if the @param outMediaTypes is invalid.
73  */
74 media_status_t AMediaCodecStore_getSupportedMediaTypes(
75         const AMediaCodecSupportedMediaType **outMediaTypes, size_t *outCount) __INTRODUCED_IN(36);
76 
77 /**
78  * Get the next decoder info that supports the format.
79  *
80  * @param outCodecInfo  should be set as NULL to start the iteration.
81  *                      Keep the last codecInfo you got from a previous call to get the next one.
82  *                      *outCodecInfo will be set to NULL if reached the end.
83  *                      It is owned by the framework and has an infinite lifetime.
84  *
85  * @param format        If set as NULL, this API will iterate through all available decoders.
86  *                      If NOT NULL, it MUST contain key "mime" implying the media type.
87  *
88  * Return AMEDIA_OK if successfully got the info.
89  * Return AMEDIA_ERROR_INVALID_PARAMETER if @param outCodecInfo or @param format is invalid.
90  * Return AMEDIA_ERROR_UNSUPPORTED if no more decoder supporting the format.
91  *
92  * It is undefined behavior to call this API with a NON NULL @param outCodecInfo
93  * and a different @param format during an iteration.
94  */
95 media_status_t AMediaCodecStore_findNextDecoderForFormat(
96         const AMediaFormat *format, const AMediaCodecInfo **outCodecInfo) __INTRODUCED_IN(36);
97 
98 /**
99  * Get the next encoder info that supports the format.
100  *
101  * @param outCodecInfo  should be set as NULL to start the iteration.
102  *                      Keep the last codecInfo you got from a previous call to get the next one.
103  *                      *outCodecInfo will be set to NULL if reached the end.
104  *                      It is owned by the framework and has an infinite lifetime.
105  *
106  * @param format        If set as NULL, this API will iterate through all available encoders.
107  *                      If NOT NULL, it MUST contain key "mime" implying the media type.
108  *
109  * Return AMEDIA_OK if successfully got the info.
110  * Return AMEDIA_ERROR_INVALID_PARAMETER if @param outCodecInfo is invalid.
111  * Return AMEDIA_ERROR_UNSUPPORTED if no more encoder supporting the format.
112  *
113  * It is undefined behavior to call this API with a NON NULL @param outCodecInfo
114  * and a different @param format during an iteration.
115  *
116  * No secure encoder will show in the output.
117  */
118 media_status_t AMediaCodecStore_findNextEncoderForFormat(
119         const AMediaFormat* format, const AMediaCodecInfo **outCodecInfo) __INTRODUCED_IN(36);
120 
121 /**
122  * Get the codecInfo corresponding to a given codec name.
123  *
124  * @param name          Media codec name.
125  *                      Users can get valid codec names from the AMediaCodecInfo structures
126  *                      returned from findNextDecoder|EncoderForFormat methods.
127  *                      Note that this name may not correspond to the name the same codec used
128  *                      by the SDK API, but will always do for codec names starting with "c2.".
129  *
130  * @param outCodecInfo  Output parameter for the corresponding AMeidaCodecInfo structure.
131  *                      It is owned by the framework and has an infinite lifetime.
132  *
133  * Return AMEDIA_OK if got the codecInfo successfully.
134  * Return AMEDIA_ERROR_UNSUPPORTED if no corresponding codec found.
135  * Return AMEDIA_ERROR_INVALID_PARAMETER if @param outCodecInfo or @param name is invalid.
136  */
137 media_status_t AMediaCodecStore_getCodecInfo(
138         const char *name, const AMediaCodecInfo **outCodecInfo) __INTRODUCED_IN(36);
139 
140 __END_DECLS
141 
142 #endif //_NDK_MEDIA_CODEC_STORE_H
143 
144 /** @} */