• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup Codec
18  * @{
19  *
20  * @brief Defines APIs related to the Codec module.
21  *
22  * The Codec module provides APIs for initializing the custom data and audio and video codecs,
23  * setting codec parameters, and controlling and transferring data.
24  *
25  * @since 3.1
26  */
27 
28 /**
29  * @file codec_component_type.h
30  *
31  * @brief Declares custom data types used in the Codec module APIs, including the codec types,
32  * audio and video parameters, and buffers.
33  *
34  * @since 3.1
35  */
36 
37 #ifndef CODEC_COMPONENT_TYPE_H
38 #define CODEC_COMPONENT_TYPE_H
39 
40 #include <stdint.h>
41 #include <stdbool.h>
42 #include "OMX_Types.h"
43 #include "OMX_Index.h"
44 #include "codec_common_type.h"
45 
46 #ifdef __cplusplus
47 #if __cplusplus
48 extern "C" {
49 #endif
50 #endif /* __cplusplus */
51 
52 /**
53  * @brief Defines the maximum value of the sampling format.
54  */
55 #define SAMPLE_FMT_NUM 32
56 #define UUID_LENGTH 128
57 
58 /**
59  * @brief Enumerates the types of audio and video encoding/decoding components.
60  */
61 typedef enum {
62     /** JPEG image */
63     MEDIA_ROLETYPE_IMAGE_JPEG = 0,
64     /** H.264 video */
65     MEDIA_ROLETYPE_VIDEO_AVC,
66     /** H.265 video */
67     MEDIA_ROLETYPE_VIDEO_HEVC,
68     /** MPEG4 video */
69     MEDIA_ROLETYPE_VIDEO_MPEG4,
70     /** VP9 video */
71     MEDIA_ROLETYPE_VIDEO_VP9,
72     /** Audio codec */
73     MEDIA_ROLETYPE_AUDIO_FIRST = 0x10000,
74     /** Advanced Audio Coding (AAC) */
75     MEDIA_ROLETYPE_AUDIO_AAC = 0x10000,
76     /** G711A audio */
77     MEDIA_ROLETYPE_AUDIO_G711A,
78     /** G711U audio */
79     MEDIA_ROLETYPE_AUDIO_G711U,
80     /** G726 audio */
81     MEDIA_ROLETYPE_AUDIO_G726,
82     /** Pulse-Code Modulation (PCM) audio */
83     MEDIA_ROLETYPE_AUDIO_PCM,
84     /** MP3 */
85     MEDIA_ROLETYPE_AUDIO_MP3,
86     /** Invalid type */
87     MEDIA_ROLETYPE_INVALID,
88 } AvCodecRole;
89 
90 /**
91  * @brief Defines the video encoding and decoding capabilities.
92  */
93 #define PIX_FORMAT_NUM 16 /** Size of the supported pixel format array */
94 #define BIT_RATE_MODE_NUM 5 /* Size of the array bit rate mode. */
95 #define MEASURED_FRAME_RATE_NUM 32 /* Size of the array measured frame rate. */
96 
97 typedef enum {
98     BIT_RATE_MODE_INVALID,
99     /** Variable Bit Rate. */
100     BIT_RATE_MODE_VBR,
101     /* Constant Bit Rate. */
102     BIT_RATE_MODE_CBR,
103     /* Constant Quality. */
104     BIT_RATE_MODE_CQ,
105      /* Constrained VariableBit Rate. */
106     BIT_RATE_MODE_VCBR,
107     /* Average Bit Rate. */
108     BIT_RATE_MODE_ABR,
109 } BitRateMode;
110 
111 typedef struct {
112     Rect minSize;                            /** Minimum resolution supported. */
113     Rect maxSize;                            /** Maximum resolution supported. */
114     Alignment whAlignment;                   /** Values to align with the width and height. */
115     RangeValue blockCount;                   /** Number of blocks supported. */
116     RangeValue blocksPerSecond;              /** Number of blocks processed per second. */
117     Rect blockSize;                          /** Block size supported. */
118     int32_t supportPixFmts[PIX_FORMAT_NUM];  /** Supported pixel format. For details,
119                                                  see {@link OMX_COLOR_FORMATTYPE}. */
120     BitRateMode bitRatemode[BIT_RATE_MODE_NUM]; /* Bit Rate Mode. For details, see {@link BitRateMode}. */
121     RangeValue frameRate;                       /* Frame Rate. */
122     int32_t measuredFrameRate[MEASURED_FRAME_RATE_NUM]; /* Measured Frame Rate.  */
123 } CodecVideoPortCap;
124 
125 /**
126  * @brief Defines the video encoding and decoding capabilities.
127  */
128 #define SAMPLE_FORMAT_NUM 12 /** Size of the audio sampling format array supported. */
129 #define SAMPLE_RATE_NUM 16 /** Size of the audio sampling rate array supported. */
130 #define CHANNEL_NUM 16 /** Size of the audio channel array supported. */
131 typedef struct {
132     int32_t sampleFormats[SAMPLE_FMT_NUM]; /** Supported audio sampling formats. For details,
133                                                see {@link CodecAudioSampleFormat}. */
134     int32_t sampleRate[SAMPLE_RATE_NUM];   /** Supported audio sampling rates. For details,
135                                                see {@link AudioSampleRate}. */
136     int32_t channelLayouts[CHANNEL_NUM];   /** Supported audio channel layouts. */
137     int32_t channelCount[CHANNEL_NUM];     /** Supported audio channels. */
138 } CodecAudioPortCap;
139 
140 /**
141  * @brief Defines the audio and video encoding and decoding capabilities.
142  */
143 typedef union {
144     CodecVideoPortCap video;               /** Video encoding and decoding capabilities */
145     CodecAudioPortCap audio;               /** Audio encoding and decoding capabilities */
146 } PortCap;
147 
148 /**
149  * @brief Defines the codec capabilities.
150  */
151 #define NAME_LENGTH 32  /** Size of the component name. */
152 #define PROFILE_NUM 256  /** Size of the profile array supported. */
153 typedef struct {
154     AvCodecRole role;                     /** Media type. */
155     CodecType type;                       /** Codec type. */
156     char compName[NAME_LENGTH];           /** Codec component name. */
157     int32_t supportProfiles[PROFILE_NUM]; /** Supported profiles. For details, see {@link Profile}. */
158     int32_t maxInst;                      /** Maximum instance. */
159     bool isSoftwareCodec;                 /** Whether it is software codec or hardware codec. */
160     int32_t processModeMask;              /** Codec processing mode mask. For details,
161                                               see {@link CodecProcessMode}. */
162     uint32_t capsMask;                    /** Codec playback capability mask. For details,
163                                               see {@link CodecCapsMask}. */
164     RangeValue bitRate;                   /** Supported bit rate range. */
165     PortCap port;                         /** Supported audio and video encoding/decoding capabilities. */
166     bool canSwapWidthHeight;              /** Whether width and height verification is supported. */
167 } CodecCompCapability;
168 
169 /**
170  * @brief Enumerate the shared memory types.
171  */
172 enum ShareMemTypes {
173     /** Readable and writable shared memory */
174     READ_WRITE_TYPE = 0x1,
175     /** Readable shared memory */
176     READ_ONLY_TYPE = 0x2,
177 };
178 
179 /**
180  * @brief Defines the codec buffer information.
181  */
182 struct OmxCodecBuffer {
183     uint32_t bufferId;               /** Buffer ID. */
184     uint32_t size;                   /** Size of the structure. */
185     union OMX_VERSIONTYPE version;   /** Component version. */
186     uint32_t bufferType;             /** Codec buffer type. For details,
187                                          see {@link CodecBufferType}. */
188     uint8_t *buffer;                 /** Buffer used for encoding or decoding. */
189     uint32_t bufferLen;              /** Size of the buffer. */
190     uint32_t allocLen;               /** Size of the buffer allocated. */
191     uint32_t filledLen;              /** Size of the buffer filled. */
192     uint32_t offset;                 /** Offset to the start position of the valid data in the buffer. */
193     int32_t fenceFd;                 /** Fence file descriptor used to signal when the input or
194                                          output buffer is ready to consume. */
195     enum ShareMemTypes type;         /** Shared memory type. */
196     int64_t pts;                     /** Timestamp. */
197     uint32_t flag;                   /** Flag. */
198 };
199 
200 /**
201  * @brief Defines the <b>CompVerInfo</b>.
202  */
203 struct CompVerInfo {
204     char compName[NAME_LENGTH];         /** The name of the component */
205     uint8_t compUUID[UUID_LENGTH];      /** The UUID of the component */
206     union OMX_VERSIONTYPE compVersion;  /** The version of the component. For details, see {@link OMX_VERSIONTYPE}. */
207     union OMX_VERSIONTYPE specVersion;  /** The spec version of the component. */
208 };
209 
210 /**
211  * @brief Defines the <b>EventInfo</b>.
212  */
213 struct EventInfo {
214     int64_t appData;                /** The pointer to the upper-layer instance passed to the callback */
215     uint32_t data1;                 /** Data 1 carried in the event. */
216     uint32_t data2;                 /** Data 2 carried in the event. */
217     int8_t *eventData;              /** The pointer of data carried in the event. */
218     uint32_t eventDataLen;          /** The length of <b>eventData</b>, in bytes. */
219 };
220 
221 #ifdef __cplusplus
222 #if __cplusplus
223 }
224 #endif
225 #endif /* __cplusplus */
226 
227 #endif /* CODEC_COMPONENT_TYPE_H */
228 /** @} */