1/*
2 * Copyright (c) 2023 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#include <cstddef>
17#include <cstdint>
18#include "avcodec_common.h"
19#include "avcodec_audio_common.h"
20#include "native_avcodec_audioencoder.h"
21#include "common/native_mfmagic.h"
22#include "native_avcodec_audiocodec.h"
23#include "avcodec_audio_encoder.h"
24#define FUZZ_PROJECT_NAME "audiodecoderConfigure_fuzzer"
25namespace OHOS {
26bool AudioAACConfigureFuzzTest(const uint8_t *data, size_t size)
27{
28    if (size < sizeof(int64_t)) {
29        return false;
30    }
31    OH_AVCodec *source =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC, true);
32
33    int32_t intData = *reinterpret_cast<const int32_t *>(data);
34    int64_t longData = *reinterpret_cast<const int64_t *>(data);
35    OH_AVFormat *format = OH_AVFormat_Create();
36    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
37    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
38    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
39    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
40    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
41    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
42    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, 1); //aactest
43
44    OH_AudioCodec_Configure(source, format);
45    if (source) {
46        OH_AudioCodec_Destroy(source);
47    }
48    if (format != nullptr) {
49        OH_AVFormat_Destroy(format);
50        format = nullptr;
51    }
52
53    OH_AVCodec *encodersource =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC, false);
54    if (encodersource == nullptr) {
55        return false;
56    }
57
58    format = OH_AVFormat_Create();
59    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
60    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
61    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
62    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
63    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
64    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
65
66    OH_AudioCodec_Configure(encodersource, format);
67    if (encodersource) {
68        OH_AudioCodec_Destroy(encodersource);
69    }
70    if (format != nullptr) {
71        OH_AVFormat_Destroy(format);
72        format = nullptr;
73    }
74    return true;
75}
76
77bool AudioFlacConfigureFuzzTest(const uint8_t *data, size_t size)
78{
79    if (size < sizeof(int64_t)) {
80        return false;
81    }
82    OH_AVCodec *decodersource =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_FLAC, true);
83    if (decodersource == nullptr) {
84        return false;
85    }
86    int32_t intData = *reinterpret_cast<const int32_t *>(data);
87    int64_t longData = *reinterpret_cast<const int64_t *>(data);
88    OH_AVFormat *format = OH_AVFormat_Create();
89    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
90    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
91    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
92    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
93    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
94    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
95
96    OH_AudioCodec_Configure(decodersource, format);
97    if (decodersource) {
98        OH_AudioCodec_Destroy(decodersource);
99    }
100    if (format != nullptr) {
101        OH_AVFormat_Destroy(format);
102        format = nullptr;
103    }
104
105    OH_AVCodec *encodersource =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_FLAC, false);
106    if (encodersource == nullptr) {
107        return false;
108    }
109
110    format = OH_AVFormat_Create();
111    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
112    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
113    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
114    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
115    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
116    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
117
118    OH_AudioCodec_Configure(encodersource, format);
119    if (encodersource) {
120        OH_AudioCodec_Destroy(encodersource);
121    }
122    if (format != nullptr) {
123        OH_AVFormat_Destroy(format);
124        format = nullptr;
125    }
126    return true;
127}
128
129bool AudioMP3ConfigureFuzzTest(const uint8_t *data, size_t size)
130{
131    if (size < sizeof(int64_t)) {
132        return false;
133    }
134    OH_AVCodec *decodersource =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_MPEG, true);
135    if (decodersource == nullptr) {
136        return false;
137    }
138    int32_t intData = *reinterpret_cast<const int32_t *>(data);
139    int64_t longData = *reinterpret_cast<const int64_t *>(data);
140    OH_AVFormat *format = OH_AVFormat_Create();
141    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
142    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
143    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
144    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
145    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
146    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
147
148    OH_AudioCodec_Configure(decodersource, format);
149    if (decodersource) {
150        OH_AudioCodec_Destroy(decodersource);
151    }
152    if (format != nullptr) {
153        OH_AVFormat_Destroy(format);
154        format = nullptr;
155    }
156    return true;
157}
158
159bool AudioVorbisConfigureFuzzTest(const uint8_t *data, size_t size)
160{
161    if (size < sizeof(int64_t)) {
162        return false;
163    }
164    OH_AVCodec *decodersource =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_VORBIS, true);
165    if (decodersource == nullptr) {
166        return false;
167    }
168    int32_t intData = *reinterpret_cast<const int32_t *>(data);
169    int64_t longData = *reinterpret_cast<const int64_t *>(data);
170    OH_AVFormat *format = OH_AVFormat_Create();
171    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
172    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
173    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
174    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
175    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
176    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
177
178    OH_AudioCodec_Configure(decodersource, format);
179    if (decodersource) {
180        OH_AudioCodec_Destroy(decodersource);
181    }
182    if (format != nullptr) {
183        OH_AVFormat_Destroy(format);
184        format = nullptr;
185    }
186    return true;
187}
188
189bool AudioLBVCConfigureFuzzTest(const uint8_t *data, size_t size)
190{
191    if (size < sizeof(int64_t)) {
192        return false;
193    }
194    OH_AVCodec *decodersource =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_LBVC, true);
195    if (decodersource == nullptr) {
196        return false;
197    }
198    int32_t intData = *reinterpret_cast<const int32_t *>(data);
199    int64_t longData = *reinterpret_cast<const int64_t *>(data);
200    OH_AVFormat *format = OH_AVFormat_Create();
201    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
202    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
203    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
204    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
205    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
206    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
207
208    OH_AudioCodec_Configure(decodersource, format);
209    if (decodersource) {
210        OH_AudioCodec_Destroy(decodersource);
211    }
212    if (format != nullptr) {
213        OH_AVFormat_Destroy(format);
214        format = nullptr;
215    }
216
217    OH_AVCodec *encodersource =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_LBVC, false);
218    if (encodersource == nullptr) {
219        return false;
220    }
221
222    format = OH_AVFormat_Create();
223    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
224    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
225    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
226    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
227    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
228    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
229
230    OH_AudioCodec_Configure(encodersource, format);
231    if (encodersource) {
232        OH_AudioCodec_Destroy(encodersource);
233    }
234    if (format != nullptr) {
235        OH_AVFormat_Destroy(format);
236        format = nullptr;
237    }
238    return true;
239}
240
241bool AudioAMRNBConfigureFuzzTest(const uint8_t *data, size_t size)
242{
243    if (size < sizeof(int64_t)) {
244        return false;
245    }
246    OH_AVCodec *decodersource =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AMR_NB, true);
247    if (decodersource == nullptr) {
248        return false;
249    }
250    int32_t intData = *reinterpret_cast<const int32_t *>(data);
251    int64_t longData = *reinterpret_cast<const int64_t *>(data);
252    OH_AVFormat *format = OH_AVFormat_Create();
253    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
254    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
255    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
256    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
257    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
258    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
259
260    OH_AudioCodec_Configure(decodersource, format);
261    if (decodersource) {
262        OH_AudioCodec_Destroy(decodersource);
263    }
264    if (format != nullptr) {
265        OH_AVFormat_Destroy(format);
266        format = nullptr;
267    }
268
269    OH_AVCodec *encodersource =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AMR_NB, false);
270    if (encodersource == nullptr) {
271        return false;
272    }
273
274    format = OH_AVFormat_Create();
275    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
276    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
277    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
278    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
279    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
280    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
281
282    OH_AudioCodec_Configure(encodersource, format);
283    if (encodersource) {
284        OH_AudioCodec_Destroy(encodersource);
285    }
286    if (format != nullptr) {
287        OH_AVFormat_Destroy(format);
288        format = nullptr;
289    }
290    return true;
291}
292
293bool AudioAMRWBConfigureFuzzTest(const uint8_t *data, size_t size)
294{
295    if (size < sizeof(int64_t)) {
296        return false;
297    }
298    OH_AVCodec *decodersource =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AMR_WB, true);
299    if (decodersource == nullptr) {
300        return false;
301    }
302    int32_t intData = *reinterpret_cast<const int32_t *>(data);
303    int64_t longData = *reinterpret_cast<const int64_t *>(data);
304    OH_AVFormat *format = OH_AVFormat_Create();
305    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
306    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
307    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
308    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
309    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
310    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
311
312    OH_AudioCodec_Configure(decodersource, format);
313    if (decodersource) {
314        OH_AudioCodec_Destroy(decodersource);
315    }
316    if (format != nullptr) {
317        OH_AVFormat_Destroy(format);
318        format = nullptr;
319    }
320
321    OH_AVCodec *encodersource =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AMR_WB, false);
322    if (encodersource == nullptr) {
323        return false;
324    }
325
326    format = OH_AVFormat_Create();
327    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
328    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
329    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
330    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
331    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
332    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
333
334    OH_AudioCodec_Configure(encodersource, format);
335    if (encodersource) {
336        OH_AudioCodec_Destroy(encodersource);
337    }
338    if (format != nullptr) {
339        OH_AVFormat_Destroy(format);
340        format = nullptr;
341    }
342    return true;
343}
344
345bool AudioAPEConfigureFuzzTest(const uint8_t *data, size_t size)
346{
347    if (size < sizeof(int64_t)) {
348        return false;
349    }
350    OH_AVCodec *decodersource =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_APE, true);
351    if (decodersource == nullptr) {
352        return false;
353    }
354    int32_t intData = *reinterpret_cast<const int32_t *>(data);
355    int64_t longData = *reinterpret_cast<const int64_t *>(data);
356    OH_AVFormat *format = OH_AVFormat_Create();
357    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
358    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
359    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
360    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
361    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
362    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
363
364    OH_AudioCodec_Configure(decodersource, format);
365    if (decodersource) {
366        OH_AudioCodec_Destroy(decodersource);
367    }
368    if (format != nullptr) {
369        OH_AVFormat_Destroy(format);
370        format = nullptr;
371    }
372
373    OH_AVCodec *encodersource =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_APE, false);
374    if (encodersource == nullptr) {
375        return false;
376    }
377
378    format = OH_AVFormat_Create();
379    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
380    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
381    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
382    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
383    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
384    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
385
386    OH_AudioCodec_Configure(encodersource, format);
387    if (encodersource) {
388        OH_AudioCodec_Destroy(encodersource);
389    }
390    if (format != nullptr) {
391        OH_AVFormat_Destroy(format);
392        format = nullptr;
393    }
394    return true;
395}
396
397bool AudioOPUSConfigureFuzzTest(const uint8_t *data, size_t size)
398{
399    if (size < sizeof(int64_t)) {
400        return false;
401    }
402    OH_AVCodec *decodersource =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_OPUS, true);
403    if (decodersource == nullptr) {
404        return false;
405    }
406    int32_t intData = *reinterpret_cast<const int32_t *>(data);
407    int64_t longData = *reinterpret_cast<const int64_t *>(data);
408    OH_AVFormat *format = OH_AVFormat_Create();
409    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
410    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
411    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
412    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
413    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
414    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
415
416    OH_AudioCodec_Configure(decodersource, format);
417    if (decodersource) {
418        OH_AudioCodec_Destroy(decodersource);
419    }
420    if (format != nullptr) {
421        OH_AVFormat_Destroy(format);
422        format = nullptr;
423    }
424
425    OH_AVCodec *encodersource =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_OPUS, false);
426    if (encodersource == nullptr) {
427        return false;
428    }
429
430    format = OH_AVFormat_Create();
431    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
432    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
433    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
434    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
435    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
436    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
437
438    OH_AudioCodec_Configure(encodersource, format);
439    if (encodersource) {
440        OH_AudioCodec_Destroy(encodersource);
441    }
442    if (format != nullptr) {
443        OH_AVFormat_Destroy(format);
444        format = nullptr;
445    }
446    return true;
447}
448
449bool AudioG711ConfigureFuzzTest(const uint8_t *data, size_t size)
450{
451    if (size < sizeof(int64_t)) {
452        return false;
453    }
454    OH_AVCodec *decodersource =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU, true);
455    if (decodersource == nullptr) {
456        return false;
457    }
458    int32_t intData = *reinterpret_cast<const int32_t *>(data);
459    int64_t longData = *reinterpret_cast<const int64_t *>(data);
460    OH_AVFormat *format = OH_AVFormat_Create();
461    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
462    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
463    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
464    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
465    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
466    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
467
468    OH_AudioCodec_Configure(decodersource, format);
469    if (decodersource) {
470        OH_AudioCodec_Destroy(decodersource);
471    }
472    if (format != nullptr) {
473        OH_AVFormat_Destroy(format);
474        format = nullptr;
475    }
476
477    OH_AVCodec *encodersource =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU, false);
478    if (encodersource == nullptr) {
479        return false;
480    }
481
482    format = OH_AVFormat_Create();
483    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
484    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
485    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
486    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
487    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
488    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
489
490    OH_AudioCodec_Configure(encodersource, format);
491    if (encodersource) {
492        OH_AudioCodec_Destroy(encodersource);
493    }
494    if (format != nullptr) {
495        OH_AVFormat_Destroy(format);
496        format = nullptr;
497    }
498    return true;
499}
500
501bool AudioVividConfigureFuzzTest(const uint8_t *data, size_t size)
502{
503    if (size < sizeof(int64_t)) {
504        return false;
505    }
506    OH_AVCodec *decodersource =  OH_AudioCodec_CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_VIVID, true);
507    if (decodersource == nullptr) {
508        return false;
509    }
510    int32_t intData = *reinterpret_cast<const int32_t *>(data);
511    int64_t longData = *reinterpret_cast<const int64_t *>(data);
512    OH_AVFormat *format = OH_AVFormat_Create();
513    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, intData);
514    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, intData);
515    OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, longData);
516    OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, intData);
517    OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, intData);
518    OH_AVFormat_SetIntValue(format, OH_MD_KEY_COMPLIANCE_LEVEL, intData);
519
520    OH_AudioCodec_Configure(decodersource, format);
521    if (decodersource) {
522        OH_AudioCodec_Destroy(decodersource);
523    }
524    if (format != nullptr) {
525        OH_AVFormat_Destroy(format);
526        format = nullptr;
527    }
528    return true;
529}
530
531} // namespace OHOS
532
533/* Fuzzer entry point */
534extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
535{
536    /* Run your code on data */
537    OHOS::AudioAACConfigureFuzzTest(data, size);
538    OHOS::AudioFlacConfigureFuzzTest(data, size);
539    OHOS::AudioMP3ConfigureFuzzTest(data, size);
540    OHOS::AudioVorbisConfigureFuzzTest(data, size);
541    OHOS::AudioLBVCConfigureFuzzTest(data, size);
542    OHOS::AudioAMRNBConfigureFuzzTest(data, size);
543    OHOS::AudioAMRWBConfigureFuzzTest(data, size);
544    OHOS::AudioAPEConfigureFuzzTest(data, size);
545    OHOS::AudioOPUSConfigureFuzzTest(data, size);
546    OHOS::AudioG711ConfigureFuzzTest(data, size);
547    OHOS::AudioVividConfigureFuzzTest(data, size);
548    return 0;
549}
550