• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "audio_hdi_common.h"
17 #include "audio_adm_common.h"
18 
19 using namespace HMOS::Audio;
20 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)21 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
22 {
23     struct HdfIoService *service = nullptr;
24     struct HdfSBuf *sBuf = nullptr;
25     struct HdfSBuf *reply = nullptr;
26     struct AudioPcmHwParams hwParams {
27         .streamType = AUDIO_CAPTURE_STREAM, .channels = 2, .rate = 11025, .periodSize = 8192,
28         .periodCount = 32, .format = AUDIO_FORMAT_PCM_24_BIT, .cardServiceName = "hdf_audio_codec_dev0",
29         .isBigEndian = 0, .isSignedData = 1, .silenceThreshold = 16385
30     };
31 
32     service = HdfIoServiceBind(HDF_CAPTURE_SERVICE.c_str());
33     if (service == nullptr || service->dispatcher == nullptr) {
34         return 0;
35     }
36     sBuf = HdfSbufObtainDefaultSize();
37     if (sBuf == nullptr) {
38         return 0;
39     }
40     int32_t ret = WriteHwParamsToBuf(sBuf, hwParams);
41     if (ret < 0) {
42         return 0;
43     }
44     ret = service->dispatcher->Dispatch(&service->object, size, sBuf, reply);
45     HdfSbufRecycle(sBuf);
46     HdfIoServiceRecycle(service);
47     return 0;
48 }
49