1 /* 2 * Copyright (c) 2022 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 "codeccommon_fuzzer.h" 17 #include "codec_omx_ext.h" 18 namespace OHOS { 19 namespace Codec { 20 static const int32_t DATA_BUFFERID = 10; 21 static const int32_t DATA_SIZE = 20; 22 static const int32_t DATA_VERSION_NVERSION = 30; 23 static const int32_t DATA_BUFFERTYPE = 40; 24 static const int32_t DATA_BUFFERLEN = 50; 25 static const int32_t DATA_ALLOCLEN = 60; 26 static const int32_t DATA_FILLEDLEN = 70; 27 static const int32_t DATA_OFFSET = 80; 28 static const int32_t DATA_FENCEFD = 90; 29 static const int32_t DATA_TYPE = 100; 30 static const int32_t DATA_PTS = 200; 31 static const int32_t DATA_FLAG = 300; 32 static const int32_t testingAppData = 33; 33 34 CodecComponentManager *manager = nullptr; 35 CodecComponentType *component = nullptr; 36 CodecCallbackType *callback = nullptr; 37 uint32_t componentId = 0; 38 static int32_t appData = testingAppData; 39 FillDataOmxCodecBuffer(struct OmxCodecBuffer * dataFuzz)40 void FillDataOmxCodecBuffer(struct OmxCodecBuffer *dataFuzz) 41 { 42 dataFuzz->bufferId = DATA_BUFFERID; 43 dataFuzz->size = DATA_SIZE; 44 dataFuzz->version.nVersion = DATA_VERSION_NVERSION; 45 dataFuzz->bufferType = (enum CodecBufferType)DATA_BUFFERTYPE; 46 dataFuzz->buffer = (uint8_t*)OsalMemAlloc(DATA_BUFFERLEN); 47 dataFuzz->bufferLen = DATA_BUFFERLEN; 48 dataFuzz->allocLen = DATA_ALLOCLEN; 49 dataFuzz->filledLen = DATA_FILLEDLEN; 50 dataFuzz->offset = DATA_OFFSET; 51 dataFuzz->fenceFd = DATA_FENCEFD; 52 dataFuzz->type = (enum ShareMemTypes)DATA_TYPE; 53 dataFuzz->pts = DATA_PTS; 54 dataFuzz->flag = DATA_FLAG; 55 } 56 Preconditions()57 bool Preconditions() 58 { 59 manager = GetCodecComponentManager(); 60 callback = CodecCallbackTypeStubGetInstance(); 61 if (manager == nullptr) { 62 HDF_LOGE("%{public}s: GetCodecComponentManager failed\n", __func__); 63 return false; 64 } 65 66 int32_t ret = manager->CreateComponent(&component, &componentId, (char*)"compName", appData, callback); 67 if (ret != HDF_SUCCESS) { 68 HDF_LOGE("%{public}s: CreateComponent failed\n", __func__); 69 return false; 70 } 71 72 OMX_STATETYPE state; 73 ret = component->GetState(component, &state); 74 if (ret != HDF_SUCCESS) { 75 HDF_LOGE("%{public}s: GetState Component failed\n", __func__); 76 return false; 77 } 78 79 return true; 80 } 81 Destroy()82 bool Destroy() 83 { 84 int32_t ret = manager->DestroyComponent(componentId); 85 if (ret != HDF_SUCCESS) { 86 HDF_LOGE("%{public}s: DestroyComponent failed\n", __func__); 87 return false; 88 } 89 CodecComponentTypeRelease(component); 90 CodecComponentManagerRelease(); 91 return true; 92 } 93 } // namespace codec 94 } // namespace OHOS