• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <cstddef>
16 #include <cstdint>
17 
18 #include "native_avcodec_videoencoder.h"
19 #include "native_averrors.h"
20 #include "native_avcodec_base.h"
21 #include "videoenc_ndk_sample.h"
22 #include "native_avcapability.h"
23 using namespace std;
24 using namespace OHOS;
25 using namespace OHOS::Media;
26 #define FUZZ_PROJECT_NAME "encoderConfigure_fuzzer"
27 
28 namespace OHOS {
encoderConfigureFuzzTest(const uint8_t * data,size_t size)29 bool encoderConfigureFuzzTest(const uint8_t *data, size_t size)
30 {
31     if (size < sizeof(int32_t)) {
32         return false;
33     }
34     bool result = false;
35     int32_t data_ = *reinterpret_cast<const int32_t *>(data);
36     VEncNdkSample *vEncSample = new VEncNdkSample();
37     vEncSample->INP_DIR = "/data/test/media/1280_720_nv.yuv";
38     OH_AVCapability *cap = OH_AVCodec_GetCapabilityByCategory("video/avc", true, HARDWARE);
39     string tmpCodecName = OH_AVCapability_GetName(cap);
40     vEncSample->CreateVideoEncoder(tmpCodecName.c_str());
41     vEncSample->SetVideoEncoderCallback();
42     vEncSample->ConfigureVideoEncoder_fuzz(data_);
43     vEncSample->StartVideoEncoder();
44     vEncSample->WaitForEOS();
45     delete vEncSample;
46     return result;
47 }
48 } // namespace OHOS
49 
50 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)51 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
52 {
53     /* Run your code on data */
54     OHOS::encoderConfigureFuzzTest(data, size);
55     return 0;
56 }
57