• 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_RENDER_STREAM, .channels = AUDIO_CHANNEL_BOTH_RIGHT,
28         .rate = BROADCAST_AM_RATE, .periodSize = FRAME_DATA / 2,
29         .periodCount = 32, .format = AUDIO_FORMAT_PCM_24_BIT, .cardServiceName = "hdf_audio_codec_dev0",
30         .isBigEndian = 0, .isSignedData = 1, .silenceThreshold = 16385
31     };
32 
33     service = HdfIoServiceBind(HDF_RENDER_SERVICE.c_str());
34     if (service == nullptr || service->dispatcher == nullptr) {
35         return 0;
36     }
37     sBuf = HdfSbufObtainDefaultSize();
38     if (sBuf == nullptr) {
39         return 0;
40     }
41     int32_t ret = WriteHwParamsToBuf(sBuf, hwParams);
42     if (ret < 0) {
43         return 0;
44     }
45     ret = service->dispatcher->Dispatch(&service->object, size, sBuf, reply);
46     HdfSbufRecycle(sBuf);
47     HdfIoServiceRecycle(service);
48     return 0;
49 }
50