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