• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Obtaining Supported Codecs (C/C++)
2
3Different devices support different codecs. Before invoking or configuring a codec, you need to query the codec specifications supported.
4
5You can call the native APIs provided by the **AVCapability** module to check whether related capabilities are supported.
6
7## Linking the Dynamic Library in the CMake Script
8
9``` cmake
10target_link_libraries(sample PUBLIC libnative_media_codecbase.so)
11```
12
13## How to Develop
14
15Read [AVCapability](../reference/apis-avcodec-kit/_a_v_capability.md) for the API reference.
16
171. Add the header files.
18
19   ```c
20   #include <multimedia/player_framework/native_avcapability.h>
21   #include <multimedia/player_framework/native_avcodec_base.h>
22   ```
23
242. Obtain a codec capability instance.
25
26   ```c
27   // Obtain a codec capability instance based on the MIME type and encoder flag.
28   OH_AVCapability *capability = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_VIDEO_AVC, false);
29
30   // Obtain a codec capability instance based on the MIME type, encoder flag, and software/hardware type.
31   OH_AVCapability *capability = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, false, SOFTWARE);
32   ```
33
343. Query parameters.
35
36   ```c
37    // Check whether the codec capability instance describes a hardware codec.
38   bool isHardware = OH_AVCapability_IsHardware(capability);
39
40   // Obtain the codec name of the codec capability instance.
41   const char *codecName = OH_AVCapability_GetName(capability);
42
43   // Obtain the maximum number of instances supported by the codec capability instance.
44   int32_t maxSupportedInstances = OH_AVCapability_GetMaxSupportedInstances(capability);
45
46   // Obtain the bit rate range supported by the encoder.
47   OH_AVRange bitrateRange;
48   int32_t bitrateRet = OH_AVCapability_GetEncoderBitrateRange(capability, &bitrateRange);
49
50
51   // Check whether the codec capability instance supports a specific bit rate mode.
52   bool isEncoderBitrateModeSupported = OH_AVCapability_IsEncoderBitrateModeSupported(capability, BITRATE_MODE_CBR);
53
54   // Obtain the quality range supported by the encoder.
55   OH_AVRange qualityRange;
56   int32_t qualityRet = OH_AVCapability_GetEncoderQualityRange(capability, &qualityRange);
57
58
59   // Obtain the complexity range supported by the encoder.
60   OH_AVRange complexityRange;
61   int32_t complexityRet = OH_AVCapability_GetEncoderComplexityRange(capability, &complexityRange);
62
63
64   // Obtain the supported audio sampling rates.
65   const int32_t *sampleRates;
66   uint32_t sampleRateNum = 0;
67   int32_t sampleRet = OH_AVCapability_GetAudioSupportedSampleRates(capability, &sampleRates, &sampleRateNum);
68
69
70   // Obtain the number of audio channels supported.
71   OH_AVRange channelCountRange;
72   int32_t channelCountRet = OH_AVCapability_GetAudioChannelCountRange(capability, &channelCountRange);
73
74
75   // Obtain the width alignment value supported.
76   int32_t widthAlignment;
77   int32_t widthRet = OH_AVCapability_GetVideoWidthAlignment(capability, &widthAlignment);
78
79
80   // Obtain the height alignment value supported.
81   int32_t heightAlignment;
82   int32_t heightRet = OH_AVCapability_GetVideoHeightAlignment(capability, &heightAlignment);
83
84
85   // Obtain the width range when the height is 1080.
86   OH_AVRange widthRange;
87   int32_t widthRangeRet = OH_AVCapability_GetVideoWidthRangeForHeight(capability, 1080, &widthRange);
88
89
90   // Obtain the height range when the width is 1920.
91   OH_AVRange heightRange;
92   int32_t heightRangeRet = OH_AVCapability_GetVideoHeightRangeForWidth(capability, 1920, &heightRange);
93
94
95   // Obtain the width range supported.
96   OH_AVRange videoWidthRange;
97   int32_t videoWidthRet = OH_AVCapability_GetVideoWidthRange(capability, &videoWidthRange);
98
99
100   // Obtain the height range supported.
101   OH_AVRange videoHeightRange;
102   int32_t videoHeightRet = OH_AVCapability_GetVideoHeightRange(capability, &videoHeightRange);
103
104
105   // Check whether the codec capability instance supports the 1080p resolution.
106   bool isVideoSizeSupported = OH_AVCapability_IsVideoSizeSupported(capability, 1920, 1080);
107
108   // Obtain the video frame rate range supported.
109   OH_AVRange frameRateRange;
110   int32_t videoFrameRet = OH_AVCapability_GetVideoFrameRateRange(capability, &frameRateRange);
111
112
113   // Obtain the video frame rate range when the resolution is 1920 x 1080.
114   OH_AVRange frameRateRangeForSize;
115   int32_t ret = OH_AVCapability_GetVideoFrameRateRangeForSize(capability, 1920, 1080, &frameRateRangeForSize);
116
117
118   // Check whether the codec capability instance supports the scenario where the resolution is 1080p and the frame rate is 30 fps.
119   bool areVideoSizeAndFrameRateSupported = OH_AVCapability_AreVideoSizeAndFrameRateSupported(capability, 1920, 1080, 30);
120
121   // Obtain the supported color formats and the number of supported color formats.
122   const int32_t *pixFormats;
123   uint32_t pixFormatNum = 0;
124   int32_t pixFormatRet = OH_AVCapability_GetVideoSupportedPixelFormats(capability, &pixFormats, &pixFormatNum);
125
126
127   // Obtain the profiles supported.
128   const int32_t *profiles;
129   uint32_t profileNum = 0;
130   int32_t profilesRet = OH_AVCapability_GetSupportedProfiles(capability, &profiles, &profileNum);
131
132
133   // Obtain the level range of a specific profile.
134   const int32_t *levels;
135   uint32_t levelNum = 0;
136   int32_t levelsRet = OH_AVCapability_GetSupportedLevelsForProfile(capability, 0, &levels, &levelNum);
137
138   // Check whether the codec capability instance supports the combination of a profile and level.
139   bool areProfileAndLevelSupported = OH_AVCapability_AreProfileAndLevelSupported(capability, AVC_PROFILE_BASELINE, 1);
140   ```
141