diff --git a/codec/hal/v1.0/buffer_manager/BUILD.gn b/codec/hal/v1.0/buffer_manager/BUILD.gn index 3110cfbfb41bf9d1638134c4bffb05b87a5cfea5..fc80a48a281b33bd31e40bd12153d71bae7db535 100644 --- a/codec/hal/v1.0/buffer_manager/BUILD.gn +++ b/codec/hal/v1.0/buffer_manager/BUILD.gn @@ -26,6 +26,8 @@ ohos_shared_library("libcodec_buffer_manager") { if (is_standard_system) { external_deps = [ + "drivers_peripheral_display:hdi_gralloc_client", + "graphic_chipsetsdk:buffer_handle", "hdf_core:libhdf_host", "hdf_core:libhdf_ipc_adapter", "hdf_core:libhdf_utils", diff --git a/codec/hal/v1.0/buffer_manager/include/buffer_manager_wrapper.h b/codec/hal/v1.0/buffer_manager/include/buffer_manager_wrapper.h index 4c46f7ffd4faf87bf94fe2744165364680a6d429..9eb5d67117be6fb61c96a4b4eb7614e0c42f6f35 100644 --- a/codec/hal/v1.0/buffer_manager/include/buffer_manager_wrapper.h +++ b/codec/hal/v1.0/buffer_manager/include/buffer_manager_wrapper.h @@ -28,16 +28,16 @@ struct BufferManagerWrapper { void *outputBufferManager; bool (*IsInputDataBufferReady)(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs); - InputInfo* (*GetInputDataBuffer)(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs); - InputInfo* (*GetUsedInputDataBuffer)(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs); - void (*PutInputDataBuffer)(struct BufferManagerWrapper *bufferManagerWrapper, InputInfo *info); - void (*PutUsedInputDataBuffer)(struct BufferManagerWrapper *bufferManagerWrapper, InputInfo *info); + CodecBuffer* (*GetInputDataBuffer)(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs); + CodecBuffer* (*GetUsedInputDataBuffer)(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs); + void (*PutInputDataBuffer)(struct BufferManagerWrapper *bufferManagerWrapper, CodecBuffer *info); + void (*PutUsedInputDataBuffer)(struct BufferManagerWrapper *bufferManagerWrapper, CodecBuffer *info); bool (*IsUsedOutputDataBufferReady)(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs); - OutputInfo* (*GetOutputDataBuffer)(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs); - OutputInfo* (*GetUsedOutputDataBuffer)(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs); - void (*PutOutputDataBuffer)(struct BufferManagerWrapper *bufferManagerWrapper, OutputInfo *info); - void (*PutUsedOutputDataBuffer)(struct BufferManagerWrapper *bufferManagerWrapper, OutputInfo *info); + CodecBuffer* (*GetOutputDataBuffer)(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs); + CodecBuffer* (*GetUsedOutputDataBuffer)(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs); + void (*PutOutputDataBuffer)(struct BufferManagerWrapper *bufferManagerWrapper, CodecBuffer *info); + void (*PutUsedOutputDataBuffer)(struct BufferManagerWrapper *bufferManagerWrapper, CodecBuffer *info); }; struct BufferManagerWrapper* GetBufferManager(void); diff --git a/codec/hal/v1.0/buffer_manager/src/buffer_manager.cpp b/codec/hal/v1.0/buffer_manager/src/buffer_manager.cpp index e5a7d471cbfe26dab8ba9efc723c96abfa06b384..595191ea6a9cd6349d1868b28c4dcd17f3e0e8b9 100644 --- a/codec/hal/v1.0/buffer_manager/src/buffer_manager.cpp +++ b/codec/hal/v1.0/buffer_manager/src/buffer_manager.cpp @@ -143,5 +143,4 @@ void BufferManager::PutUsedBuffer(T *info) OsalMutexUnlock(&usedBufferQueueLock); } -template class BufferManager; -template class BufferManager; +template class BufferManager; diff --git a/codec/hal/v1.0/buffer_manager/src/buffer_manager_wrapper.cpp b/codec/hal/v1.0/buffer_manager/src/buffer_manager_wrapper.cpp index c85d6622b4bdcac64d1dfbf34d628970f0bf72fa..3453c6dbbbde1f9407f571c0f74e405e3b7bb5ca 100644 --- a/codec/hal/v1.0/buffer_manager/src/buffer_manager_wrapper.cpp +++ b/codec/hal/v1.0/buffer_manager/src/buffer_manager_wrapper.cpp @@ -29,52 +29,52 @@ static bool IsInputDataBufferReadyImpl(struct BufferManagerWrapper *bufferManage return false; } - InputInfo *buffer = - ((BufferManager*)(bufferManagerWrapper->inputBufferManager))->GetBuffer(timeoutMs, true); + CodecBuffer *buffer = + ((BufferManager*)(bufferManagerWrapper->inputBufferManager))->GetBuffer(timeoutMs, true); return (buffer != nullptr); } -static InputInfo* GetInputDataBufferImpl(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs) +static CodecBuffer* GetInputDataBufferImpl(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs) { if (bufferManagerWrapper == nullptr) { HDF_LOGE("%{public}s: invalid params!", __func__); return nullptr; } - InputInfo *buffer = - ((BufferManager*)(bufferManagerWrapper->inputBufferManager))->GetBuffer(timeoutMs, false); + CodecBuffer *buffer = + ((BufferManager*)(bufferManagerWrapper->inputBufferManager))->GetBuffer(timeoutMs, false); return buffer; } -static InputInfo* GetUsedInputDataBufferImpl(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs) +static CodecBuffer* GetUsedInputDataBufferImpl(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs) { if (bufferManagerWrapper == nullptr) { HDF_LOGE("%{public}s: invalid params!", __func__); return nullptr; } - InputInfo *buffer = - ((BufferManager*)(bufferManagerWrapper->inputBufferManager))->GetUsedBuffer(timeoutMs, false); + CodecBuffer *buffer = + ((BufferManager*)(bufferManagerWrapper->inputBufferManager))->GetUsedBuffer(timeoutMs, false); return buffer; } -static void PutInputDataBufferImpl(struct BufferManagerWrapper *bufferManagerWrapper, InputInfo *info) +static void PutInputDataBufferImpl(struct BufferManagerWrapper *bufferManagerWrapper, CodecBuffer *info) { if (bufferManagerWrapper == nullptr || info == nullptr) { HDF_LOGE("%{public}s: invalid params!", __func__); return; } - ((BufferManager*)(bufferManagerWrapper->inputBufferManager))->PutBuffer(info); + ((BufferManager*)(bufferManagerWrapper->inputBufferManager))->PutBuffer(info); } -static void PutUsedInputDataBufferImpl(struct BufferManagerWrapper *bufferManagerWrapper, InputInfo *info) +static void PutUsedInputDataBufferImpl(struct BufferManagerWrapper *bufferManagerWrapper, CodecBuffer *info) { if (bufferManagerWrapper == nullptr || info == nullptr) { HDF_LOGE("%{public}s: invalid params!", __func__); return; } - ((BufferManager*)(bufferManagerWrapper->inputBufferManager))->PutUsedBuffer(info); + ((BufferManager*)(bufferManagerWrapper->inputBufferManager))->PutUsedBuffer(info); } static bool IsUsedOutputDataBufferReadyImpl(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs) @@ -84,52 +84,52 @@ static bool IsUsedOutputDataBufferReadyImpl(struct BufferManagerWrapper *bufferM return false; } - OutputInfo *buffer = - ((BufferManager*)(bufferManagerWrapper->outputBufferManager))->GetUsedBuffer(timeoutMs, true); + CodecBuffer *buffer = + ((BufferManager*)(bufferManagerWrapper->outputBufferManager))->GetUsedBuffer(timeoutMs, true); return (buffer != nullptr); } -static OutputInfo* GetOutputDataBufferImpl(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs) +static CodecBuffer* GetOutputDataBufferImpl(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs) { if (bufferManagerWrapper == nullptr) { HDF_LOGE("%{public}s: invalid params!", __func__); return nullptr; } - OutputInfo *buffer = - ((BufferManager*)(bufferManagerWrapper->outputBufferManager))->GetBuffer(timeoutMs, false); + CodecBuffer *buffer = + ((BufferManager*)(bufferManagerWrapper->outputBufferManager))->GetBuffer(timeoutMs, false); return buffer; } -static OutputInfo* GetUsedOutputDataBufferImpl(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs) +static CodecBuffer* GetUsedOutputDataBufferImpl(struct BufferManagerWrapper *bufferManagerWrapper, uint32_t timeoutMs) { if (bufferManagerWrapper == nullptr) { HDF_LOGE("%{public}s: invalid params!", __func__); return nullptr; } - OutputInfo *buffer = - ((BufferManager*)(bufferManagerWrapper->outputBufferManager))->GetUsedBuffer(timeoutMs, false); + CodecBuffer *buffer = + ((BufferManager*)(bufferManagerWrapper->outputBufferManager))->GetUsedBuffer(timeoutMs, false); return buffer; } -static void PutOutputDataBufferImpl(struct BufferManagerWrapper *bufferManagerWrapper, OutputInfo *info) +static void PutOutputDataBufferImpl(struct BufferManagerWrapper *bufferManagerWrapper, CodecBuffer *info) { if (bufferManagerWrapper == nullptr || info == nullptr) { HDF_LOGE("%{public}s: invalid params!", __func__); return; } - ((BufferManager*)(bufferManagerWrapper->outputBufferManager))->PutBuffer(info); + ((BufferManager*)(bufferManagerWrapper->outputBufferManager))->PutBuffer(info); } -static void PutUsedOutputDataBufferImpl(struct BufferManagerWrapper *bufferManagerWrapper, OutputInfo *info) +static void PutUsedOutputDataBufferImpl(struct BufferManagerWrapper *bufferManagerWrapper, CodecBuffer *info) { if (bufferManagerWrapper == nullptr || info == nullptr) { HDF_LOGE("%{public}s: invalid params!", __func__); return; } - ((BufferManager*)(bufferManagerWrapper->outputBufferManager))->PutUsedBuffer(info); + ((BufferManager*)(bufferManagerWrapper->outputBufferManager))->PutUsedBuffer(info); } static void ConstructBufferManager(struct BufferManagerWrapper *bufferManager) @@ -149,16 +149,16 @@ static void ConstructBufferManager(struct BufferManagerWrapper *bufferManager) struct BufferManagerWrapper* GetBufferManager(void) { struct BufferManagerWrapper *bufferManager = new struct BufferManagerWrapper; - bufferManager->inputBufferManager = new BufferManager(); - bufferManager->outputBufferManager = new BufferManager(); + bufferManager->inputBufferManager = new BufferManager(); + bufferManager->outputBufferManager = new BufferManager(); ConstructBufferManager(bufferManager); return bufferManager; } void DeleteBufferManager(struct BufferManagerWrapper **ppBufferManager) { - delete (BufferManager*)((*ppBufferManager)->inputBufferManager); - delete (BufferManager*)((*ppBufferManager)->outputBufferManager); + delete (BufferManager*)((*ppBufferManager)->inputBufferManager); + delete (BufferManager*)((*ppBufferManager)->outputBufferManager); delete *ppBufferManager; } diff --git a/codec/hal/v1.0/codec_instance/include/codec_instance.h b/codec/hal/v1.0/codec_instance/include/codec_instance.h index 37d5ca59374bb69da0b22ad38c2d88f2170dbcce..a20384a079a4f196045b3a61266aef5cb628cea3 100644 --- a/codec/hal/v1.0/codec_instance/include/codec_instance.h +++ b/codec/hal/v1.0/codec_instance/include/codec_instance.h @@ -43,8 +43,8 @@ struct CodecInstance { ShareMemory outputBuffers[MAX_BUFFER_NUM]; int32_t inputBuffersCount; int32_t outputBuffersCount; - InputInfo *inputInfos[MAX_BUFFER_NUM]; - OutputInfo *outputInfos[MAX_BUFFER_NUM]; + CodecBuffer *inputInfos[MAX_BUFFER_NUM]; + CodecBuffer *outputInfos[MAX_BUFFER_NUM]; int32_t inputInfoCount; int32_t outputInfoCount; @@ -64,23 +64,25 @@ struct CodecInstance { struct CodecInstance* GetCodecInstance(void); void InitCodecInstance(struct CodecInstance *instance); -void AddInputShm(struct CodecInstance *instance, CodecBufferInfo *bufferInfo); -void AddOutputShm(struct CodecInstance *instance, CodecBufferInfo *bufferInfo); +void RunCodecInstance(struct CodecInstance *instance); +void StopCodecInstance(struct CodecInstance *instance); +void DestroyCodecInstance(struct CodecInstance *instance); +void AddInputShm(struct CodecInstance *instance, const CodecBufferInfo *bufferInfo, int32_t bufferId); +void AddOutputShm(struct CodecInstance *instance, const CodecBufferInfo *bufferInfo, int32_t bufferId); ShareMemory* GetInputShm(struct CodecInstance *instance, int32_t id); ShareMemory* GetOutputShm(struct CodecInstance *instance, int32_t id); int32_t GetFdById(struct CodecInstance *instance, int32_t id); void ReleaseInputShm(struct CodecInstance *instance); void ReleaseOutputShm(struct CodecInstance *instance); -void AddInputInfo(struct CodecInstance *instance, InputInfo *info); -void AddOutputInfo(struct CodecInstance *instance, OutputInfo *info); -InputInfo* GetInputInfo(struct CodecInstance *instance, int32_t id); -OutputInfo* GetOutputInfo(struct CodecInstance *instance, int32_t id); +void AddInputInfo(struct CodecInstance *instance, CodecBuffer *info); +void AddOutputInfo(struct CodecInstance *instance, CodecBuffer *info); +CodecBuffer* GetInputInfo(struct CodecInstance *instance, uint32_t id); +CodecBuffer* GetOutputInfo(struct CodecInstance *instance, uint32_t id); void ReleaseInputInfo(struct CodecInstance *instance); void ReleaseOutputInfo(struct CodecInstance *instance); void ResetBuffers(struct CodecInstance *instance); -void RunCodecInstance(struct CodecInstance *instance); -void StopCodecInstance(struct CodecInstance *instance); -void DestroyCodecInstance(struct CodecInstance *instance); +bool CopyCodecBuffer(CodecBuffer *dst, const CodecBuffer *src); +CodecBuffer* DupCodecBuffer(const CodecBuffer *src); #ifdef __cplusplus } diff --git a/codec/hal/v1.0/codec_instance/src/codec_instance.c b/codec/hal/v1.0/codec_instance/src/codec_instance.c index 014fe3c0eeb7908f8c791e87800abfaec7accfcd..62e437b65121e5d54e33221e2d53d952ee4d2dc8 100644 --- a/codec/hal/v1.0/codec_instance/src/codec_instance.c +++ b/codec/hal/v1.0/codec_instance/src/codec_instance.c @@ -23,6 +23,7 @@ #define CODEC_OEM_INTERFACE_LIB_NAME "libcodec_oem_interface.z.so" #define CODEC_BUFFER_MANAGER_LIB_NAME "libcodec_buffer_manager.z.so" +#define BUFFER_COUNT 1 static void InitCodecOemIf(struct CodecInstance *instance) { @@ -84,24 +85,18 @@ static void InitBufferManagerIf(struct CodecInstance *instance) instance->bufferManagerLibHandle = libHandle; } -static int32_t WaitForBufferData(struct CodecInstance *instance, CodecBufferInfo *outputDataBuffer, - OutputInfo *outputData) +static int32_t WaitForBufferData(struct CodecInstance *instance, CodecBuffer *outputData) { struct BufferManagerWrapper *bmWrapper = instance->bufferManagerWrapper; - OutputInfo *output = NULL; + CodecBuffer *output = NULL; while (instance->codecStatus == CODEC_STATUS_STARTED) { if (bmWrapper->IsInputDataBufferReady(bmWrapper, QUEUE_TIME_OUT) && bmWrapper->IsUsedOutputDataBufferReady(bmWrapper, QUEUE_TIME_OUT)) { output = bmWrapper->GetUsedOutputDataBuffer(bmWrapper, QUEUE_TIME_OUT); if (output != NULL) { - memset_s(outputDataBuffer, sizeof(CodecBufferInfo), 0, sizeof(CodecBufferInfo)); - outputDataBuffer->type = BUFFER_TYPE_VIRTUAL; - outputDataBuffer->addr = GetOutputShm(instance, output->buffers->offset)->virAddr; - outputDataBuffer->size = output->buffers->size; - outputDataBuffer->offset = output->buffers->offset; - memset_s(outputData, sizeof(OutputInfo), 0, sizeof(OutputInfo)); - outputData->buffers = outputDataBuffer; - outputData->bufferCnt = 1; + CopyCodecBuffer(outputData, output); + outputData->buffer[0].type = BUFFER_TYPE_VIRTUAL; + outputData->buffer[0].buf = (intptr_t)GetOutputShm(instance, output->bufferId)->virAddr; break; } } @@ -123,14 +118,15 @@ static void *CodecTaskThread(void *arg) } HDF_LOGI("%{public}s: CodecTaskThread start!", __func__); - CodecBufferInfo inputDataBuffer; - InputInfo inputData; - CodecBufferInfo outputDataBuffer; - OutputInfo outputData; - InputInfo *input = NULL; - int32_t ret; + int32_t codecBufferSize = sizeof(CodecBuffer) + sizeof(CodecBufferInfo) * BUFFER_COUNT; + CodecBuffer *inputData = (CodecBuffer *)OsalMemCalloc(codecBufferSize); + CodecBuffer *outputData = (CodecBuffer *)OsalMemCalloc(codecBufferSize); + CodecBuffer *input = NULL; + int32_t ret = HDF_FAILURE; - if (WaitForBufferData(instance, &outputDataBuffer, &outputData) != HDF_SUCCESS) { + inputData->bufferCnt = BUFFER_COUNT; + outputData->bufferCnt = BUFFER_COUNT; + if (WaitForBufferData(instance, outputData) != HDF_SUCCESS) { return NULL; } @@ -144,27 +140,22 @@ static void *CodecTaskThread(void *arg) continue; } - memset_s(&inputDataBuffer, sizeof(CodecBufferInfo), 0, sizeof(CodecBufferInfo)); - inputDataBuffer.type = BUFFER_TYPE_VIRTUAL; - inputDataBuffer.addr = GetInputShm(instance, input->buffers->offset)->virAddr; - inputDataBuffer.size = input->buffers->size; - inputDataBuffer.offset = input->buffers->offset; - memset_s(&inputData, sizeof(InputInfo), 0, sizeof(InputInfo)); - inputData.buffers = &inputDataBuffer; - inputData.bufferCnt = 1; - inputData.flag = input->flag; - + CopyCodecBuffer(inputData, input); + inputData->buffer[0].type = BUFFER_TYPE_VIRTUAL; + inputData->buffer[0].buf = (intptr_t)GetInputShm(instance, input->bufferId)->virAddr; if (instance->codecType == VIDEO_DECODER) { ret = instance->codecOemIface->CodecDecode(instance->handle, inputData, outputData, QUEUE_TIME_OUT); } else if (instance->codecType == VIDEO_ENCODER) { ret = instance->codecOemIface->CodecEncode(instance->handle, inputData, outputData, QUEUE_TIME_OUT); } - if (ret == HDF_SUCCESS || (outputData.flag & STREAM_FLAG_EOS)) { + if (ret == HDF_SUCCESS || (outputData->flag & STREAM_FLAG_EOS)) { HDF_LOGI("%{public}s: output reach STREAM_FLAG_EOS!", __func__); instance->codecStatus = CODEC_STATUS_STOPED; } } - + + OsalMemFree(inputData); + OsalMemFree(outputData); HDF_LOGI("%{public}s: codec task thread finished!", __func__); return NULL; } @@ -203,30 +194,83 @@ void InitCodecInstance(struct CodecInstance *instance) InitBufferManagerIf(instance); } -void AddInputShm(struct CodecInstance *instance, CodecBufferInfo *bufferInfo) +void RunCodecInstance(struct CodecInstance *instance) +{ + if (instance == NULL) { + HDF_LOGE("%{public}s: Invalid param!", __func__); + return; + } + + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); + + instance->codecStatus = CODEC_STATUS_STARTED; + int32_t ret = pthread_create(&instance->task, NULL, CodecTaskThread, instance); + if (ret != 0) { + HDF_LOGE("%{public}s: run codec task thread failed!", __func__); + } +} + +void StopCodecInstance(struct CodecInstance *instance) +{ + if (instance == NULL) { + HDF_LOGE("%{public}s: Invalid param!", __func__); + return; + } + instance->codecStatus = CODEC_STATUS_STOPED; +} + +void DestroyCodecInstance(struct CodecInstance *instance) +{ + if (instance == NULL) { + HDF_LOGE("%{public}s: Invalid param!", __func__); + return; + } + + instance->codecStatus = CODEC_STATUS_STOPED; + pthread_join(instance->task, NULL); + + ReleaseInputShm(instance); + ReleaseOutputShm(instance); + ReleaseInputInfo(instance); + ReleaseOutputInfo(instance); + + dlclose(instance->oemLibHandle); + if (instance->codecOemIface != NULL) { + OsalMemFree(instance->codecOemIface); + } + instance->bufferManagerIface->DeleteBufferManager(&(instance->bufferManagerWrapper)); + dlclose(instance->bufferManagerLibHandle); + if (instance->bufferManagerIface != NULL) { + OsalMemFree(instance->bufferManagerIface); + } +} + +void AddInputShm(struct CodecInstance *instance, const CodecBufferInfo *bufferInfo, int32_t bufferId) { if (instance == NULL || bufferInfo == NULL) { HDF_LOGE("%{public}s: Invalid param!", __func__); return; } int32_t count = instance->inputBuffersCount; - instance->inputBuffers[count].id = bufferInfo->offset; - instance->inputBuffers[count].fd = bufferInfo->fd; - instance->inputBuffers[count].size = bufferInfo->size; + instance->inputBuffers[count].id = bufferId; + instance->inputBuffers[count].fd = (int32_t)bufferInfo->buf; + instance->inputBuffers[count].size = bufferInfo->capacity; OpenShareMemory(&instance->inputBuffers[count]); instance->inputBuffersCount++; } -void AddOutputShm(struct CodecInstance *instance, CodecBufferInfo *bufferInfo) +void AddOutputShm(struct CodecInstance *instance, const CodecBufferInfo *bufferInfo, int32_t bufferId) { if (instance == NULL || bufferInfo == NULL) { HDF_LOGE("%{public}s: Invalid param!", __func__); return; } int32_t count = instance->outputBuffersCount; - instance->outputBuffers[count].id = bufferInfo->offset; - instance->outputBuffers[count].fd = bufferInfo->fd; - instance->outputBuffers[count].size = bufferInfo->size; + instance->outputBuffers[count].id = bufferId; + instance->outputBuffers[count].fd = (int32_t)bufferInfo->buf; + instance->outputBuffers[count].size = bufferInfo->capacity; OpenShareMemory(&instance->outputBuffers[count]); instance->outputBuffersCount++; } @@ -242,6 +286,7 @@ ShareMemory* GetInputShm(struct CodecInstance *instance, int32_t id) return &(instance->inputBuffers[i]); } } + HDF_LOGE("%{public}s: not found for bufferId:%{public}d!", __func__, id); return NULL; } @@ -256,6 +301,7 @@ ShareMemory* GetOutputShm(struct CodecInstance *instance, int32_t id) return &(instance->outputBuffers[i]); } } + HDF_LOGE("%{public}s: not found for bufferId:%{public}d!", __func__, id); return NULL; } @@ -276,6 +322,8 @@ int32_t GetFdById(struct CodecInstance *instance, int32_t id) return instance->outputBuffers[i].fd; } } + + HDF_LOGE("%{public}s: failed to found bufferId:%{public}d!", __func__, id); return HDF_FAILURE; } @@ -300,7 +348,7 @@ void ReleaseOutputShm(struct CodecInstance *instance) } } -void AddInputInfo(struct CodecInstance *instance, InputInfo *info) +void AddInputInfo(struct CodecInstance *instance, CodecBuffer *info) { if (instance == NULL || info == NULL) { HDF_LOGE("%{public}s: Invalid param!", __func__); @@ -310,7 +358,7 @@ void AddInputInfo(struct CodecInstance *instance, InputInfo *info) instance->inputInfoCount++; } -void AddOutputInfo(struct CodecInstance *instance, OutputInfo *info) +void AddOutputInfo(struct CodecInstance *instance, CodecBuffer *info) { if (instance == NULL || info == NULL) { HDF_LOGE("%{public}s: Invalid param!", __func__); @@ -320,28 +368,28 @@ void AddOutputInfo(struct CodecInstance *instance, OutputInfo *info) instance->outputInfoCount++; } -InputInfo* GetInputInfo(struct CodecInstance *instance, int32_t id) +CodecBuffer* GetInputInfo(struct CodecInstance *instance, uint32_t id) { if (instance == NULL) { HDF_LOGE("%{public}s: Invalid param!", __func__); return NULL; } for (int32_t i = 0; i < instance->inputInfoCount; i++) { - if (instance->inputInfos[i]->buffers[0].offset == (uint32_t)id) { + if (instance->inputInfos[i]->bufferId == id) { return instance->inputInfos[i]; } } return NULL; } -OutputInfo* GetOutputInfo(struct CodecInstance *instance, int32_t id) +CodecBuffer* GetOutputInfo(struct CodecInstance *instance, uint32_t id) { if (instance == NULL) { HDF_LOGE("%{public}s: Invalid param!", __func__); return NULL; } for (int32_t i = 0; i < instance->outputInfoCount; i++) { - if (instance->outputInfos[i]->buffers[0].offset == (uint32_t)id) { + if (instance->outputInfos[i]->bufferId == id) { return instance->outputInfos[i]; } } @@ -354,11 +402,13 @@ void ReleaseInputInfo(struct CodecInstance *instance) HDF_LOGE("%{public}s: Invalid param!", __func__); return; } - InputInfo *info; + CodecBuffer *info; for (int32_t i = 0; i < instance->inputInfoCount; i++) { info = instance->inputInfos[i]; - OsalMemFree(info->buffers); - OsalMemFree(info); + if (info != NULL) { + OsalMemFree(info); + instance->outputInfos[i] = NULL; + } } } @@ -368,11 +418,13 @@ void ReleaseOutputInfo(struct CodecInstance *instance) HDF_LOGE("%{public}s: Invalid param!", __func__); return; } - OutputInfo *info; + CodecBuffer *info; for (int32_t i = 0; i < instance->outputInfoCount; i++) { info = instance->outputInfos[i]; - OsalMemFree(info->buffers); - OsalMemFree(info); + if (info != NULL) { + OsalMemFree(info); + instance->outputInfos[i] = NULL; + } } } @@ -402,55 +454,43 @@ void ResetBuffers(struct CodecInstance *instance) instance->outputInfoCount = 0; } -void RunCodecInstance(struct CodecInstance *instance) +bool CopyCodecBuffer(CodecBuffer *dst, const CodecBuffer *src) { - if (instance == NULL) { - HDF_LOGE("%{public}s: Invalid param!", __func__); - return; + if (dst == NULL || src == NULL) { + HDF_LOGE("%{public}s: Nullpoint, dst: %{public}p, src: %{public}p", __func__, dst, src); + return false; } - - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); - - instance->codecStatus = CODEC_STATUS_STARTED; - int32_t ret = pthread_create(&instance->task, NULL, CodecTaskThread, instance); - if (ret != 0) { - HDF_LOGE("%{public}s: run codec task thread failed!", __func__); + if (dst->bufferCnt != src->bufferCnt) { + HDF_LOGE("%{public}s: size not match", __func__); + return false; } -} - -void StopCodecInstance(struct CodecInstance *instance) -{ - if (instance == NULL) { - HDF_LOGE("%{public}s: Invalid param!", __func__); - return; + int32_t size = sizeof(CodecBuffer) + sizeof(CodecBufferInfo) * src->bufferCnt; + int32_t ret = memcpy_s(dst, size, src, size); + if (ret != EOK) { + HDF_LOGE("%{public}s: memcpy_s failed, error code: %{public}d", __func__, ret); + return false; } - instance->codecStatus = CODEC_STATUS_STOPED; + return true; } -void DestroyCodecInstance(struct CodecInstance *instance) +CodecBuffer* DupCodecBuffer(const CodecBuffer *src) { - if (instance == NULL) { - HDF_LOGE("%{public}s: Invalid param!", __func__); - return; + if (src == NULL) { + HDF_LOGE("%{public}s: CodecBuffer src Nullpoint", __func__); + return NULL; } - - instance->codecStatus = CODEC_STATUS_STOPED; - pthread_join(instance->task, NULL); - - ReleaseInputShm(instance); - ReleaseOutputShm(instance); - ReleaseInputInfo(instance); - ReleaseOutputInfo(instance); - - dlclose(instance->oemLibHandle); - if (instance->codecOemIface != NULL) { - OsalMemFree(instance->codecOemIface); + int32_t size = sizeof(CodecBuffer) + sizeof(CodecBufferInfo) * src->bufferCnt; + CodecBuffer *dst = (CodecBuffer *)OsalMemAlloc(size); + if (dst == NULL) { + HDF_LOGE("%{public}s: malloc dst failed", __func__); + return NULL; } - instance->bufferManagerIface->DeleteBufferManager(&(instance->bufferManagerWrapper)); - dlclose(instance->bufferManagerLibHandle); - if (instance->bufferManagerIface != NULL) { - OsalMemFree(instance->bufferManagerIface); + int32_t ret = memcpy_s(dst, size, src, size); + if (ret != EOK) { + HDF_LOGE("%{public}s: memcpy_s failed, error code: %{public}d", __func__, ret); + OsalMemFree(dst); + return NULL; } + return dst; } + diff --git a/codec/hal/v1.0/oem_interface/include/codec_oem_if.h b/codec/hal/v1.0/oem_interface/include/codec_oem_if.h index 2db4f1585dd9e27ad12321278b11e197571801c6..a86b208eff43e938cb7190a5a23d31a522066431 100644 --- a/codec/hal/v1.0/oem_interface/include/codec_oem_if.h +++ b/codec/hal/v1.0/oem_interface/include/codec_oem_if.h @@ -27,20 +27,23 @@ extern "C" { typedef int32_t (*CodecInitType)(void); typedef int32_t (*CodecDeinitType)(void); -typedef int32_t (*CodecCreateType)(const char* name, const Param *attr, int32_t len, CODEC_HANDLETYPE *handle); +typedef int32_t (*CodecCreateType)(const char* name, CODEC_HANDLETYPE *handle); typedef int32_t (*CodecDestroyType)(CODEC_HANDLETYPE handle); -typedef int32_t (*CodecSetPortModeType)(CODEC_HANDLETYPE handle, DirectionType type, BufferMode mode); +typedef int32_t (*CodecSetPortModeType)(CODEC_HANDLETYPE handle, DirectionType direct, + AllocateBufferMode mode, BufferType type); +typedef int32_t (*CodecGetPortModeType)(CODEC_HANDLETYPE handle, DirectionType direct, + AllocateBufferMode *mode, BufferType *type); typedef int32_t (*CodecSetParameterType)(CODEC_HANDLETYPE handle, const Param *params, int32_t paramCnt); typedef int32_t (*CodecGetParameterType)(CODEC_HANDLETYPE handle, Param *params, int32_t paramCnt); typedef int32_t (*CodecStartType)(CODEC_HANDLETYPE handle); typedef int32_t (*CodecStopType)(CODEC_HANDLETYPE handle); typedef int32_t (*CodecFlushType)(CODEC_HANDLETYPE handle, DirectionType directType); typedef int32_t (*CodecSetCallbackType)(CODEC_HANDLETYPE handle, const CodecCallback *cb, UINTPTR instance); -typedef int32_t (*CodecDecodeType)(CODEC_HANDLETYPE handle, InputInfo inputData, OutputInfo outInfo, +typedef int32_t (*CodecDecodeType)(CODEC_HANDLETYPE handle, CodecBuffer *inputData, CodecBuffer *outInfo, uint32_t timeoutMs); -typedef int32_t (*CodecEncodeType)(CODEC_HANDLETYPE handle, InputInfo inputData, OutputInfo outInfo, +typedef int32_t (*CodecEncodeType)(CODEC_HANDLETYPE handle, CodecBuffer *inputData, CodecBuffer *outInfo, uint32_t timeoutMs); -typedef int32_t (*CodecEncodeHeaderType)(CODEC_HANDLETYPE handle, OutputInfo outInfo, uint32_t timeoutMs); +typedef int32_t (*CodecEncodeHeaderType)(CODEC_HANDLETYPE handle, CodecBuffer outInfo, uint32_t timeoutMs); struct CodecOemIf { CodecInitType CodecInit; diff --git a/codec/hdi_service/BUILD.gn b/codec/hdi_service/BUILD.gn index 3356067dddc8a55ddfb87947b982c725774245c5..ac1af4ae0590595f183d8641999c666b43fc3318 100644 --- a/codec/hdi_service/BUILD.gn +++ b/codec/hdi_service/BUILD.gn @@ -16,7 +16,7 @@ import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") ohos_shared_library("libcodec_client") { include_dirs = [ "//drivers/hdf_core/adapter/uhdf2/include/hdi", - "//drivers/peripheral/codec/interfaces/include/", + "//drivers/peripheral/codec/interfaces/include", ] sources = [ "codec_proxy/codec_callback_proxy.c", @@ -26,11 +26,14 @@ ohos_shared_library("libcodec_client") { if (is_standard_system) { external_deps = [ + "drivers_peripheral_display:hdi_gralloc_client", + "graphic_chipsetsdk:buffer_handle", "hdf_core:libhdf_host", "hdf_core:libhdf_ipc_adapter", "hdf_core:libhdf_utils", "hdf_core:libhdi", "hiviewdfx_hilog_native:libhilog", + "utils_base:utils", ] } else { external_deps = [ "hilog:libhilog" ] @@ -47,8 +50,8 @@ group("codec_client") { ohos_shared_library("libcodec_server") { include_dirs = [ - "//drivers/peripheral/codec/interfaces/include/", - "//drivers/peripheral/codec/hdi_service/codec_proxy/", + "//drivers/peripheral/codec/interfaces/include", + "//drivers/peripheral/codec/hdi_service/codec_proxy", "//drivers/peripheral/codec/hal/v1.0/codec_instance/include", "//drivers/peripheral/codec/hal/v1.0/share_mem/include", "//drivers/peripheral/codec/hal/v1.0/oem_interface/include", @@ -83,6 +86,8 @@ ohos_shared_library("libcodec_server") { if (is_standard_system) { external_deps = [ + "drivers_peripheral_display:hdi_gralloc_client", + "graphic_chipsetsdk:buffer_handle", "hdf_core:libhdf_host", "hdf_core:libhdf_ipc_adapter", "hdf_core:libhdf_utils", diff --git a/codec/hdi_service/codec_proxy/codec_callback_proxy.c b/codec/hdi_service/codec_proxy/codec_callback_proxy.c index e9bde24e09fe079ec7eccdd7df3bf0e30dee17cb..d6698aab760ecfb769c3c26df96d45d45badff84 100644 --- a/codec/hdi_service/codec_proxy/codec_callback_proxy.c +++ b/codec/hdi_service/codec_proxy/codec_callback_proxy.c @@ -61,8 +61,7 @@ void CodecCallbackProxySBufRecycle(struct HdfSBuf *data, struct HdfSBuf *reply) return; } -static int CodecCallbackProxyOnEvent(UINTPTR comp, UINTPTR appData, EventType event, - uint32_t data1, uint32_t data2, UINTPTR eventData) +static int CodecCallbackProxyOnEvent(UINTPTR userData, EventType event, uint32_t length, int32_t eventData[]) { int32_t ret; struct HdfSBuf *data = NULL; @@ -71,13 +70,8 @@ static int CodecCallbackProxyOnEvent(UINTPTR comp, UINTPTR appData, EventType ev HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufWriteUint32(data, (uint32_t)comp)) { - HDF_LOGE("%{public}s: write input comp failed!", __func__); - CodecCallbackProxySBufRecycle(data, reply); - return HDF_ERR_INVALID_PARAM; - } - if (!HdfSbufWriteUint32(data, (uint32_t)appData)) { - HDF_LOGE("%{public}s: write input appData failed!", __func__); + if (!HdfSbufWriteUint32(data, (uint32_t)userData)) { + HDF_LOGE("%{public}s: write input userData failed!", __func__); CodecCallbackProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } @@ -86,20 +80,16 @@ static int CodecCallbackProxyOnEvent(UINTPTR comp, UINTPTR appData, EventType ev CodecCallbackProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufWriteUint32(data, (uint32_t)data1)) { - HDF_LOGE("%{public}s: write input data1 failed!", __func__); - CodecCallbackProxySBufRecycle(data, reply); - return HDF_ERR_INVALID_PARAM; - } - if (!HdfSbufWriteUint32(data, (uint32_t)data2)) { - HDF_LOGE("%{public}s: write input data2 failed!", __func__); + if (!HdfSbufWriteUint32(data, (uint32_t)length)) { + HDF_LOGE("%{public}s: write input length failed!", __func__); CodecCallbackProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufWriteUint32(data, (uint32_t)eventData)) { - HDF_LOGE("%{public}s: write input eventData failed!", __func__); - CodecCallbackProxySBufRecycle(data, reply); - return HDF_ERR_INVALID_PARAM; + for (uint32_t i = 0; i < length; i++) { + if (!HdfSbufWriteInt32(data, eventData[i])) { + HDF_LOGE("%{public}s: write eventData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } } ret = CodecCallbackProxyCall(CMD_CODEC_ON_EVENT, data, reply); if (ret != HDF_SUCCESS) { @@ -111,7 +101,7 @@ static int CodecCallbackProxyOnEvent(UINTPTR comp, UINTPTR appData, EventType ev return ret; } -static int CodecCallbackProxyInputBufferAvailable(UINTPTR comp, UINTPTR appData, InputInfo *inBuf) +static int CodecCallbackProxyInputBufferAvailable(UINTPTR userData, CodecBuffer *inBuf, int32_t *acquireFd) { int32_t ret; struct HdfSBuf *data = NULL; @@ -123,17 +113,12 @@ static int CodecCallbackProxyInputBufferAvailable(UINTPTR comp, UINTPTR appData, HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufWriteUint32(data, (uint32_t)comp)) { - HDF_LOGE("%{public}s: write input comp failed!", __func__); + if (!HdfSbufWriteUint32(data, (uint32_t)userData)) { + HDF_LOGE("%{public}s: write input userData failed!", __func__); CodecCallbackProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufWriteUint32(data, (uint32_t)appData)) { - HDF_LOGE("%{public}s: write input appData failed!", __func__); - CodecCallbackProxySBufRecycle(data, reply); - return HDF_ERR_INVALID_PARAM; - } - if (CodecProxyPackInputInfo(data, inBuf)) { + if (CodecProxyPackCodecBuffer(data, inBuf)) { HDF_LOGE("%{public}s: write input buffer failed!", __func__); CodecCallbackProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; @@ -148,7 +133,7 @@ static int CodecCallbackProxyInputBufferAvailable(UINTPTR comp, UINTPTR appData, return ret; } -static int CodecCallbackProxyOutputBufferAvailable(UINTPTR comp, UINTPTR appData, OutputInfo *outBuf) +static int CodecCallbackProxyOutputBufferAvailable(UINTPTR userData, CodecBuffer *outBuf, int32_t *acquireFd) { int32_t ret; struct HdfSBuf *data = NULL; @@ -160,18 +145,13 @@ static int CodecCallbackProxyOutputBufferAvailable(UINTPTR comp, UINTPTR appData HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufWriteUint32(data, (uint32_t)comp)) { - HDF_LOGE("%{public}s: write input comp failed!", __func__); + if (!HdfSbufWriteUint32(data, (uint32_t)userData)) { + HDF_LOGE("%{public}s: write input userData failed!", __func__); CodecCallbackProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufWriteUint32(data, (uint32_t)appData)) { - HDF_LOGE("%{public}s: write input appData failed!", __func__); - CodecCallbackProxySBufRecycle(data, reply); - return HDF_ERR_INVALID_PARAM; - } - if (CodecProxyPackOutputInfo(data, outBuf)) { - HDF_LOGE("%{public}s: write input buffer failed!", __func__); + if (CodecProxyPackCodecBuffer(data, outBuf)) { + HDF_LOGE("%{public}s: write output buffer failed!", __func__); CodecCallbackProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } diff --git a/codec/hdi_service/codec_proxy/codec_proxy.c b/codec/hdi_service/codec_proxy/codec_proxy.c index c47b4cd17f4407b808332ec680debc80a1ee2de2..747698c8083c2b033b1fd5f0fa77c7a2d3af2312 100644 --- a/codec/hdi_service/codec_proxy/codec_proxy.c +++ b/codec/hdi_service/codec_proxy/codec_proxy.c @@ -13,11 +13,11 @@ * limitations under the License. */ -#include "proxy_msgproc.h" #include #include #include #include "icodec.h" +#include "proxy_msgproc.h" #ifdef __cplusplus extern "C" { @@ -114,7 +114,7 @@ int32_t CodecProxyDeinit(struct ICodec *self) return ret; } -int32_t CodecProxyEnumerateCapbility(struct ICodec *self, uint32_t index, CodecCapbility *cap) +int32_t CodecProxyEnumerateCapability(struct ICodec *self, uint32_t index, CodecCapability *cap) { int32_t ret; struct HdfSBuf *data = NULL; @@ -142,8 +142,8 @@ int32_t CodecProxyEnumerateCapbility(struct ICodec *self, uint32_t index, CodecC CodecProxySBufRecycle(data, reply); return ret; } - if (CodecProxyParseGottenCapbility(reply, cap) != HDF_SUCCESS) { - HDF_LOGE("%{public}s: CodecProxyParseGottenCapbility failed!", __func__); + if (CodecProxyParseGottenCapability(reply, cap) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: CodecProxyParseGottenCapability failed!", __func__); CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } @@ -151,8 +151,8 @@ int32_t CodecProxyEnumerateCapbility(struct ICodec *self, uint32_t index, CodecC return ret; } -int32_t CodecProxyGetCapbility(struct ICodec *self, AvCodecMime mime, CodecType type, - uint32_t flags, CodecCapbility *cap) +int32_t CodecProxyGetCapability(struct ICodec *self, AvCodecMime mime, CodecType type, + uint32_t flags, CodecCapability *cap) { int32_t ret; struct HdfSBuf *data = NULL; @@ -190,8 +190,8 @@ int32_t CodecProxyGetCapbility(struct ICodec *self, AvCodecMime mime, CodecType CodecProxySBufRecycle(data, reply); return ret; } - if (CodecProxyParseGottenCapbility(reply, cap) != HDF_SUCCESS) { - HDF_LOGE("%{public}s: CodecProxyParseGottenCapbility failed!", __func__); + if (CodecProxyParseGottenCapability(reply, cap) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: CodecProxyParseGottenCapability failed!", __func__); CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } @@ -199,11 +199,11 @@ int32_t CodecProxyGetCapbility(struct ICodec *self, AvCodecMime mime, CodecType return ret; } -int32_t CodecProxyCreate(struct ICodec *self, const char* name, const Param *attr, int len, CODEC_HANDLETYPE *handle) +int32_t CodecProxyCreate(struct ICodec *self, const char* name, CODEC_HANDLETYPE *handle) { struct HdfSBuf *data = NULL; struct HdfSBuf *reply = NULL; - if (self == NULL || name == NULL || attr == NULL || handle == NULL) { + if (self == NULL || name == NULL || handle == NULL) { return HDF_ERR_INVALID_PARAM; } if (CodecProxyReqSBuf(&data, &reply) != HDF_SUCCESS) { @@ -214,22 +214,6 @@ int32_t CodecProxyCreate(struct ICodec *self, const char* name, const Param *att CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufWriteUint32(data, attr->key)) { - CodecProxySBufRecycle(data, reply); - return HDF_ERR_INVALID_PARAM; - } - if (!HdfSbufWriteInt32(data, attr->size)) { - CodecProxySBufRecycle(data, reply); - return HDF_ERR_INVALID_PARAM; - } - if (!HdfSbufWriteBuffer(data, attr->val, attr->size)) { - CodecProxySBufRecycle(data, reply); - return HDF_ERR_INVALID_PARAM; - } - if (!HdfSbufWriteInt32(data, len)) { - CodecProxySBufRecycle(data, reply); - return HDF_ERR_INVALID_PARAM; - } if (!HdfSbufWriteUint64(data, (uint64_t)handle)) { CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; @@ -278,7 +262,8 @@ int32_t CodecProxyDestroy(struct ICodec *self, CODEC_HANDLETYPE handle) return ret; } -int32_t CodecProxySetPortMode(struct ICodec *self, CODEC_HANDLETYPE handle, DirectionType type, BufferMode mode) +int32_t CodecProxySetPortMode(struct ICodec *self, CODEC_HANDLETYPE handle, + DirectionType direct, AllocateBufferMode mode, BufferType type) { int32_t ret; struct HdfSBuf *data = NULL; @@ -296,17 +281,22 @@ int32_t CodecProxySetPortMode(struct ICodec *self, CODEC_HANDLETYPE handle, Dire return HDF_ERR_INVALID_PARAM; } if (!HdfSbufWriteUint64(data, (uint64_t)(uintptr_t)handle)) { - HDF_LOGE("%{public}s: Read size failed!", __func__); + HDF_LOGE("%{public}s: write handle failed!", __func__); CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufWriteUint32(data, (uint32_t)type)) { - HDF_LOGE("%{public}s: Read size failed!", __func__); + if (!HdfSbufWriteUint32(data, (uint32_t)direct)) { + HDF_LOGE("%{public}s: write DirectionType failed!", __func__); CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } if (!HdfSbufWriteUint32(data, (uint32_t)mode)) { - HDF_LOGE("%{public}s: Read size failed!", __func__); + HDF_LOGE("%{public}s: write AllocateBufferMode failed!", __func__); + CodecProxySBufRecycle(data, reply); + return HDF_ERR_INVALID_PARAM; + } + if (!HdfSbufWriteUint32(data, (uint32_t)type)) { + HDF_LOGE("%{public}s: write BufferType failed!", __func__); CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } @@ -318,6 +308,54 @@ int32_t CodecProxySetPortMode(struct ICodec *self, CODEC_HANDLETYPE handle, Dire return ret; } +int32_t CodecProxyGetPortMode(struct ICodec *self, CODEC_HANDLETYPE handle, + DirectionType direct, AllocateBufferMode *mode, BufferType *type) +{ + int32_t ret; + struct HdfSBuf *data = NULL; + struct HdfSBuf *reply = NULL; + if (self == NULL || handle == NULL) { + return HDF_ERR_INVALID_PARAM; + } + if (CodecProxyReqSBuf(&data, &reply) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__); + return HDF_FAILURE; + } + if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data)) { + HDF_LOGE("write interface token failed"); + CodecProxySBufRecycle(data, reply); + return HDF_ERR_INVALID_PARAM; + } + if (!HdfSbufWriteUint64(data, (uint64_t)(uintptr_t)handle)) { + HDF_LOGE("%{public}s: write handle failed!", __func__); + CodecProxySBufRecycle(data, reply); + return HDF_ERR_INVALID_PARAM; + } + if (!HdfSbufWriteUint32(data, (uint32_t)direct)) { + HDF_LOGE("%{public}s: write DirectionType failed!", __func__); + CodecProxySBufRecycle(data, reply); + return HDF_ERR_INVALID_PARAM; + } + ret = CodecProxyCall(self, CMD_CODEC_GET_MODE, data, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); + CodecProxySBufRecycle(data, reply); + return ret; + } + if (!HdfSbufReadUint32(reply, (uint32_t*)mode)) { + HDF_LOGE("%{public}s: read AllocateBufferMode failed!", __func__); + CodecProxySBufRecycle(data, reply); + return HDF_FAILURE; + } + if (!HdfSbufReadUint32(reply, (uint32_t*)type)) { + HDF_LOGE("%{public}s: read BufferType failed!", __func__); + CodecProxySBufRecycle(data, reply); + return HDF_FAILURE; + } + CodecProxySBufRecycle(data, reply); + return HDF_SUCCESS; +} + int32_t CodecProxySetParameter(struct ICodec *self, CODEC_HANDLETYPE handle, const Param *params, int paramCnt) { int32_t ret; @@ -400,7 +438,7 @@ int32_t CodecProxyGetParameter(struct ICodec *self, CODEC_HANDLETYPE handle, Par return ret; } for (int32_t i = 0; i < paramCnt; i++) { - if (CodecProxyParseParam(data, ¶ms[i]) != HDF_SUCCESS) { + if (CodecProxyParseParam(reply, ¶ms[i]) != HDF_SUCCESS) { HDF_LOGE("%{public}s: read params failed!", __func__); CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; @@ -409,6 +447,7 @@ int32_t CodecProxyGetParameter(struct ICodec *self, CODEC_HANDLETYPE handle, Par CodecProxySBufRecycle(data, reply); return ret; } + int32_t CodecProxyStart(struct ICodec *self, CODEC_HANDLETYPE handle) { int32_t ret; @@ -439,6 +478,7 @@ int32_t CodecProxyStart(struct ICodec *self, CODEC_HANDLETYPE handle) CodecProxySBufRecycle(data, reply); return ret; } + int32_t CodecProxyStop(struct ICodec *self, CODEC_HANDLETYPE handle) { int32_t ret; @@ -469,6 +509,7 @@ int32_t CodecProxyStop(struct ICodec *self, CODEC_HANDLETYPE handle) CodecProxySBufRecycle(data, reply); return ret; } + int32_t CodecProxyFlush(struct ICodec *self, CODEC_HANDLETYPE handle, DirectionType directType) { int32_t ret; @@ -504,8 +545,9 @@ int32_t CodecProxyFlush(struct ICodec *self, CODEC_HANDLETYPE handle, DirectionT CodecProxySBufRecycle(data, reply); return ret; } + int32_t CodecPorxyQueueInput(struct ICodec *self, CODEC_HANDLETYPE handle, - const InputInfo *inputData, uint32_t timeoutMs) + const CodecBuffer *inputData, uint32_t timeoutMs, int releaseFenceFd) { int32_t ret; struct HdfSBuf *data = NULL; @@ -528,7 +570,7 @@ int32_t CodecPorxyQueueInput(struct ICodec *self, CODEC_HANDLETYPE handle, CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } - if (CodecProxyPackInputInfo(data, inputData)) { + if (CodecProxyPackCodecBuffer(data, inputData)) { HDF_LOGE("%{public}s: write input buffer failed!", __func__); CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; @@ -538,6 +580,11 @@ int32_t CodecPorxyQueueInput(struct ICodec *self, CODEC_HANDLETYPE handle, CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } + if (CodecProxyPackFenceFd(data, releaseFenceFd) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: write releaseFenceFd failed!", __func__); + CodecProxySBufRecycle(data, reply); + return HDF_ERR_INVALID_PARAM; + } ret = CodecProxyCall(self, CMD_CODEC_QUEQUE_INPUT, data, reply); if (ret != HDF_SUCCESS) { HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); @@ -545,9 +592,10 @@ int32_t CodecPorxyQueueInput(struct ICodec *self, CODEC_HANDLETYPE handle, CodecProxySBufRecycle(data, reply); return ret; } -int32_t CodecProxyDequeInput(struct ICodec *self, CODEC_HANDLETYPE handle, uint32_t timeoutMs, InputInfo *inputData) + +int32_t CodecProxyDequeueInput(struct ICodec *self, CODEC_HANDLETYPE handle, + uint32_t timeoutMs, int32_t *acquireFd, CodecBuffer *inputData) { - int32_t ret; struct HdfSBuf *data = NULL; struct HdfSBuf *reply = NULL; if (self == NULL || handle == NULL || inputData == NULL || inputData->bufferCnt == 0) { @@ -578,7 +626,7 @@ int32_t CodecProxyDequeInput(struct ICodec *self, CODEC_HANDLETYPE handle, uint3 CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } - ret = CodecProxyCall(self, CMD_CODEC_DEQUEQUE_INPUT, data, reply); + int32_t ret = CodecProxyCall(self, CMD_CODEC_DEQUEQUE_INPUT, data, reply); if (ret != HDF_SUCCESS) { if (ret != HDF_ERR_TIMEOUT) { HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ret); @@ -586,16 +634,21 @@ int32_t CodecProxyDequeInput(struct ICodec *self, CODEC_HANDLETYPE handle, uint3 CodecProxySBufRecycle(data, reply); return ret; } - if (CodecProxyParseInputInfo(reply, inputData)) { - HDF_LOGE("%{public}s: read struct reply failed!", __func__); + if (CodecProxyParseFenceFd(reply, acquireFd) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: read acquireFd failed!", __func__); CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } + if (CodecProxyParseCodecBuffer(reply, inputData)) { + HDF_LOGE("%{public}s: read input CodecBuffer failed!", __func__); + ret = HDF_ERR_INVALID_PARAM; + } CodecProxySBufRecycle(data, reply); return ret; } -int32_t CodecProxyQueueOutput(struct ICodec *self, CODEC_HANDLETYPE handle, OutputInfo *outInfo, - uint32_t timeoutMs, int releaseFenceFd) + +int32_t CodecProxyQueueOutput(struct ICodec *self, CODEC_HANDLETYPE handle, + CodecBuffer *outInfo, uint32_t timeoutMs, int releaseFenceFd) { int32_t ret; struct HdfSBuf *data = NULL; @@ -614,22 +667,22 @@ int32_t CodecProxyQueueOutput(struct ICodec *self, CODEC_HANDLETYPE handle, Outp return HDF_ERR_INVALID_PARAM; } if (!HdfSbufWriteUint64(data, (uint64_t)(uintptr_t)handle)) { - HDF_LOGE("%{public}s: write input handle failed!", __func__); + HDF_LOGE("%{public}s: write handle failed!", __func__); CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } - if (CodecProxyPackOutputInfo(data, outInfo)) { - HDF_LOGE("%{public}s: write output buffer failed!", __func__); + if (CodecProxyPackCodecBuffer(data, outInfo)) { + HDF_LOGE("%{public}s: write buffer failed!", __func__); CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } if (!HdfSbufWriteUint32(data, timeoutMs)) { - HDF_LOGE("%{public}s: write input timeoutMs failed!", __func__); + HDF_LOGE("%{public}s: write timeoutMs failed!", __func__); CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufWriteFileDescriptor(data, releaseFenceFd)) { - HDF_LOGE("%{public}s: write input releaseFenceFd failed!", __func__); + if (CodecProxyPackFenceFd(data, releaseFenceFd) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: write releaseFenceFd failed!", __func__); CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } @@ -640,8 +693,9 @@ int32_t CodecProxyQueueOutput(struct ICodec *self, CODEC_HANDLETYPE handle, Outp CodecProxySBufRecycle(data, reply); return ret; } -int32_t CodecProxyDequeueOutput(struct ICodec *self, CODEC_HANDLETYPE handle, uint32_t timeoutMs, - int *acquireFd, OutputInfo *outInfo) + +int32_t CodecProxyDequeueOutput(struct ICodec *self, CODEC_HANDLETYPE handle, + uint32_t timeoutMs, int32_t *acquireFd, CodecBuffer *outInfo) { int32_t ret; struct HdfSBuf *data = NULL; @@ -661,7 +715,7 @@ int32_t CodecProxyDequeueOutput(struct ICodec *self, CODEC_HANDLETYPE handle, ui return HDF_ERR_INVALID_PARAM; } if (!HdfSbufWriteUint32(data, timeoutMs)) { - HDF_LOGE("%{public}s: write input timeoutMs failed!", __func__); + HDF_LOGE("%{public}s: write timeoutMs failed!", __func__); CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } @@ -678,14 +732,13 @@ int32_t CodecProxyDequeueOutput(struct ICodec *self, CODEC_HANDLETYPE handle, ui CodecProxySBufRecycle(data, reply); return ret; } - *acquireFd = HdfSbufReadFileDescriptor(reply); - if (*acquireFd < 0) { + if (CodecProxyParseFenceFd(reply, acquireFd) != HDF_SUCCESS) { HDF_LOGE("%{public}s: read acquireFd failed!", __func__); CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } - if (CodecProxyParseOutputInfo(reply, outInfo)) { - HDF_LOGE("%{public}s: read reply failed!", __func__); + if (CodecProxyParseCodecBuffer(reply, outInfo)) { + HDF_LOGE("%{public}s: read output CodecBuffer failed!", __func__); CodecProxySBufRecycle(data, reply); return HDF_ERR_INVALID_PARAM; } @@ -739,18 +792,19 @@ static void CodecIpmlConstruct(struct ICodec *instance) { instance->CodecInit = CodecPorxyInit; instance->CodecDeinit = CodecProxyDeinit; - instance->CodecEnumerateCapbility = CodecProxyEnumerateCapbility; - instance->CodecGetCapbility = CodecProxyGetCapbility; + instance->CodecEnumerateCapability = CodecProxyEnumerateCapability; + instance->CodecGetCapability = CodecProxyGetCapability; instance->CodecCreate = CodecProxyCreate; instance->CodecDestroy = CodecProxyDestroy; instance->CodecSetPortMode = CodecProxySetPortMode; + instance->CodecGetPortMode = CodecProxyGetPortMode; instance->CodecSetParameter = CodecProxySetParameter; instance->CodecGetParameter = CodecProxyGetParameter; instance->CodecStart = CodecProxyStart; instance->CodecStop = CodecProxyStop; instance->CodecFlush = CodecProxyFlush; instance->CodecQueueInput = CodecPorxyQueueInput; - instance->CodecDequeInput = CodecProxyDequeInput; + instance->CodecDequeueInput = CodecProxyDequeueInput; instance->CodecQueueOutput = CodecProxyQueueOutput; instance->CodecDequeueOutput = CodecProxyDequeueOutput; instance->CodecSetCallback = CodecProxySetCallback; diff --git a/codec/hdi_service/codec_proxy/icodec.h b/codec/hdi_service/codec_proxy/icodec.h index 5d6b10421e203ddcb9a55ac52f0628738a0e5266..bb84812a9cd86c68bbea40bf9414764978c6ccf6 100644 --- a/codec/hdi_service/codec_proxy/icodec.h +++ b/codec/hdi_service/codec_proxy/icodec.h @@ -32,10 +32,12 @@ enum { CMD_CODEC_CREATE, CMD_CODEC_DESTROY, CMD_CODEC_SET_MODE, + CMD_CODEC_GET_MODE, CMD_CODEC_SET_PARAMS, CMD_CODEC_GET_PARAMS, CMD_CODEC_START, CMD_CODEC_STOP, + CMD_CODEC_RESET, CMD_CODEC_FLUSH, CMD_CODEC_QUEQUE_INPUT, CMD_CODEC_DEQUEQUE_INPUT, @@ -48,26 +50,30 @@ struct ICodec { struct HdfRemoteService *remote; int32_t (*CodecInit)(struct ICodec *self); int32_t (*CodecDeinit)(struct ICodec *self); - int32_t (*CodecEnumerateCapbility)(struct ICodec *self, uint32_t index, CodecCapbility *cap); - int32_t (*CodecGetCapbility)(struct ICodec *self, AvCodecMime mime, CodecType type, - uint32_t flags, CodecCapbility *cap); - int32_t (*CodecCreate)(struct ICodec *self, const char* name, const Param *attr, - int len, CODEC_HANDLETYPE *handle); + int32_t (*CodecEnumerateCapability)(struct ICodec *self, uint32_t index, CodecCapability *cap); + int32_t (*CodecGetCapability)(struct ICodec *self, AvCodecMime mime, CodecType type, + uint32_t flags, CodecCapability *cap); + int32_t (*CodecCreate)(struct ICodec *self, const char* name, CODEC_HANDLETYPE *handle); + int32_t (*CodecCreateByType)(struct ICodec *self, CodecType type, AvCodecMime mime, CODEC_HANDLETYPE *handle); int32_t (*CodecDestroy)(struct ICodec *self, CODEC_HANDLETYPE handle); - int32_t (*CodecSetPortMode)(struct ICodec *self, CODEC_HANDLETYPE handle, DirectionType type, BufferMode mode); + int32_t (*CodecSetPortMode)(struct ICodec *self, CODEC_HANDLETYPE handle, DirectionType direct, + AllocateBufferMode mode, BufferType type); + int32_t (*CodecGetPortMode)(struct ICodec *self, CODEC_HANDLETYPE handle, DirectionType direct, + AllocateBufferMode *mode, BufferType *type); int32_t (*CodecSetParameter)(struct ICodec *self, CODEC_HANDLETYPE handle, const Param *params, int paramCnt); int32_t (*CodecGetParameter)(struct ICodec *self, CODEC_HANDLETYPE handle, Param *params, int paramCnt); int32_t (*CodecStart)(struct ICodec *self, CODEC_HANDLETYPE handle); int32_t (*CodecStop)(struct ICodec *self, CODEC_HANDLETYPE handle); + int32_t (*CodecReset)(struct ICodec *self, CODEC_HANDLETYPE handle); int32_t (*CodecFlush)(struct ICodec *self, CODEC_HANDLETYPE handle, DirectionType directType); int32_t (*CodecQueueInput)(struct ICodec *self, CODEC_HANDLETYPE handle, - const InputInfo *inputData, uint32_t timeoutMs); - int32_t (*CodecDequeInput)(struct ICodec *self, CODEC_HANDLETYPE handle, - uint32_t timeoutMs, InputInfo *inputData); - int32_t (*CodecQueueOutput)(struct ICodec *self, CODEC_HANDLETYPE handle, OutputInfo *outInfo, - uint32_t timeoutMs, int releaseFenceFd); - int32_t (*CodecDequeueOutput)(struct ICodec *self, CODEC_HANDLETYPE handle, uint32_t timeoutMs, - int *acquireFd, OutputInfo *outInfo); + const CodecBuffer *inputData, uint32_t timeoutMs, int releaseFenceFd); + int32_t (*CodecDequeueInput)(struct ICodec *self, CODEC_HANDLETYPE handle, + uint32_t timeoutMs, int32_t *acquireFd, CodecBuffer *inputData); + int32_t (*CodecQueueOutput)(struct ICodec *self, CODEC_HANDLETYPE handle, + CodecBuffer *outInfo, uint32_t timeoutMs, int releaseFenceFd); + int32_t (*CodecDequeueOutput)(struct ICodec *self, CODEC_HANDLETYPE handle, + uint32_t timeoutMs, int32_t *acquireFd, CodecBuffer *outInfo); int32_t (*CodecSetCallback)(struct ICodec *self, CODEC_HANDLETYPE handle, struct ICodecCallback *cb, UINTPTR instance); }; diff --git a/codec/hdi_service/codec_proxy/proxy_msgproc.c b/codec/hdi_service/codec_proxy/proxy_msgproc.c index 70863511b1e564c224fde33a887a7e716f9f4d0c..7173f794d77e04eb93de0f14c5bce66b3db74be3 100644 --- a/codec/hdi_service/codec_proxy/proxy_msgproc.c +++ b/codec/hdi_service/codec_proxy/proxy_msgproc.c @@ -15,6 +15,7 @@ #include "proxy_msgproc.h" #include #include +#include #ifdef __cplusplus extern "C" { @@ -56,71 +57,115 @@ int32_t CodecProxyParseRect(struct HdfSBuf *reply, Rect *rectangle) return HDF_SUCCESS; } -int32_t CodecProxyParseArray(struct HdfSBuf *reply, ResizableArray *resArr) +static bool CodecCapabilityBaseUnmarshalling(struct HdfSBuf *reply, CodecCapability *cap) { - if (reply == NULL || resArr == NULL) { - HDF_LOGE("%{public}s: params NULL!", __func__); - return HDF_ERR_INVALID_PARAM; + if (!HdfSbufReadUint32(reply, (uint32_t*)&cap->mime)) { + HDF_LOGE("%{public}s: read cap->mime failed!", __func__); + return false; } - resArr->actualLen = 0; - if (!HdfSbufReadUint32(reply, &resArr->actualLen)) { - HDF_LOGE("%{public}s: read actualLen failed!", __func__); - return HDF_FAILURE; + if (!HdfSbufReadUint32(reply, (uint32_t*)&cap->type)) { + HDF_LOGE("%{public}s: read cap->type failed!", __func__); + return false; } - for (uint32_t i = 0; i < resArr->actualLen; i++) { - if (!HdfSbufReadUint32(reply, &resArr->element[i])) { - HDF_LOGE("%{public}s: read element failed!", __func__); - return HDF_FAILURE; + for (uint32_t i = 0; i < NAME_LENGTH; i++) { + if (!HdfSbufReadUint8(reply, (uint8_t *)&(cap->name)[i])) { + HDF_LOGE("%{public}s: read name[i] failed!", __func__); + return false; } } - return HDF_SUCCESS; -} - -int32_t CodecProxyParseGottenCapbility(struct HdfSBuf *reply, CodecCapbility *cap) -{ - if (reply == NULL || cap == NULL) { - return HDF_ERR_INVALID_PARAM; + for (uint32_t j = 0; j < PROFILE_NUM; j++) { + if (!HdfSbufReadInt32(reply, &(cap->supportProfiles)[j])) { + HDF_LOGE("%{public}s: read supportProfiles[i] failed!", __func__); + return false; + } } - if (!HdfSbufReadUint32(reply, (uint32_t*)&cap->mime)) { - return HDF_FAILURE; + if (!HdfSbufReadInt8(reply, (int8_t *)&cap->isSoftwareCodec)) { + HDF_LOGE("%{public}s: read cap->isSoftwareCodec failed!", __func__); + return false; } - if (!HdfSbufReadUint32(reply, (uint32_t*)&cap->type)) { - return HDF_FAILURE; + if (!HdfSbufReadInt32(reply, &cap->processModeMask)) { + HDF_LOGE("%{public}s: read cap->processModeMask failed!", __func__); + return false; } - if (CodecProxyParseAlignment(reply, &cap->whAlignment) != HDF_SUCCESS) { - return HDF_FAILURE; + if (!HdfSbufReadUint32(reply, &cap->capsMask)) { + HDF_LOGE("%{public}s: read cap->capsMask failed!", __func__); + return false; } - if (CodecProxyParseRect(reply, &cap->minSize) != HDF_SUCCESS) { - return HDF_FAILURE; + if (!HdfSbufReadUint32(reply, &cap->allocateMask)) { + HDF_LOGE("%{public}s: read cap->allocateMask failed!", __func__); + return false; } - if (CodecProxyParseRect(reply, &cap->maxSize) != HDF_SUCCESS) { - return HDF_FAILURE; + return true; +} + +static bool CodecCapabilityRangeValueUnmarshalling(struct HdfSBuf *reply, RangeValue *dataBlock) +{ + if (dataBlock == NULL) { + return false; } - if (!HdfSbufReadUint64(reply, &cap->minBitRate)) { - return HDF_FAILURE; + if (!HdfSbufReadInt32(reply, &dataBlock->min)) { + HDF_LOGE("%{public}s: read dataBlock->min failed!", __func__); + return false; } - if (!HdfSbufReadUint64(reply, &cap->maxBitRate)) { - return HDF_FAILURE; + if (!HdfSbufReadInt32(reply, &dataBlock->max)) { + HDF_LOGE("%{public}s: read dataBlock->max failed!", __func__); + return false; + } + return true; +} + +static bool CodecCapabilityPortUnmarshalling(struct HdfSBuf *reply, CodecCapability *cap) +{ + if (cap->type < AUDIO_DECODER) { + const VideoPortCap *video = (const VideoPortCap *)HdfSbufReadUnpadBuffer(reply, sizeof(VideoPortCap)); + if (video == NULL) { + HDF_LOGE("%{public}s: read video failed!", __func__); + return false; + } + (void)memcpy_s(&cap->port, sizeof(VideoPortCap), video, sizeof(VideoPortCap)); + } else if (cap->type < INVALID_TYPE) { + const AudioPortCap *audio = (const AudioPortCap *)HdfSbufReadUnpadBuffer(reply, sizeof(AudioPortCap)); + if (audio == NULL) { + HDF_LOGE("%{public}s: read audio failed!", __func__); + return false; + } + (void)memcpy_s(&cap->port, sizeof(AudioPortCap), audio, sizeof(AudioPortCap)); + } else { + (void)memset_s(&cap->port, sizeof(cap->port), 0, sizeof(cap->port)); } - if (CodecProxyParseArray(reply, &cap->supportProfiles) != HDF_SUCCESS) { + return true; +} + +int32_t CodecProxyParseGottenCapability(struct HdfSBuf *reply, CodecCapability *cap) +{ + if (reply == NULL || cap == NULL) { + return HDF_ERR_INVALID_PARAM; + } + if (!CodecCapabilityBaseUnmarshalling(reply, cap)) { return HDF_FAILURE; } - if (CodecProxyParseArray(reply, &cap->supportLevels) != HDF_SUCCESS) { + if (!CodecCapabilityRangeValueUnmarshalling(reply, &cap->inputBufferNum)) { + HDF_LOGE("%{public}s: read &cap->inputBufferNum failed!", __func__); return HDF_FAILURE; } - if (CodecProxyParseArray(reply, &cap->supportPixelFormats) != HDF_SUCCESS) { + if (!CodecCapabilityRangeValueUnmarshalling(reply, &cap->outputBufferNum)) { + HDF_LOGE("%{public}s: read &cap->outputBufferNum failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufReadUint32(reply, &cap->minInputBufferNum)) { + if (!CodecCapabilityRangeValueUnmarshalling(reply, &cap->bitRate)) { + HDF_LOGE("%{public}s: read &cap->bitRate failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufReadUint32(reply, &cap->minOutputBufferNum)) { + if (!HdfSbufReadInt32(reply, &cap->inputBufferSize)) { + HDF_LOGE("%{public}s: read cap->inputBufferSize failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufReadUint32(reply, &cap->allocateMask)) { + if (!HdfSbufReadInt32(reply, &cap->outputBufferSize)) { + HDF_LOGE("%{public}s: read cap->outputBufferSize failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufReadUint32(reply, &cap->capsMask)) { + if (!CodecCapabilityPortUnmarshalling(reply, cap)) { + HDF_LOGE("%{public}s: read cap->port failed!", __func__); return HDF_FAILURE; } @@ -191,255 +236,175 @@ int32_t CodecProxyParseParam(struct HdfSBuf *reply, Param *param) return HDF_SUCCESS; } -int32_t CodecProxyPackBufferHandle(struct HdfSBuf *data, CodecBufferHandle *bufferHandle) +int32_t CodecProxyPackBufferInfo(struct HdfSBuf *data, const CodecBufferInfo *buffer) { - if (data == NULL || bufferHandle == NULL) { + if (data == NULL || buffer == NULL) { HDF_LOGE("%{public}s: params NULL!", __func__); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufWriteUint64(data, (uint64_t)bufferHandle->virAddr)) { - HDF_LOGE("%{public}s: Write virAddr failed!", __func__); + if (!HdfSbufWriteUint32(data, (uint32_t)buffer->type)) { + HDF_LOGE("%{public}s: Write BufferType failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufWriteUint32(data, (uint32_t)bufferHandle->handle)) { - HDF_LOGE("%{public}s: Write handle failed!", __func__); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -int32_t CodecProxyPackBufferInfo(struct HdfSBuf *data, CodecBufferInfo *buffers) -{ - if (data == NULL || buffers == NULL) { - HDF_LOGE("%{public}s: params NULL!", __func__); - return HDF_ERR_INVALID_PARAM; - } - if (!HdfSbufWriteUint32(data, (uint32_t)buffers->type)) { - HDF_LOGE("%{public}s: Write tempType failed!", __func__); - return HDF_FAILURE; - } - if (buffers->type == BUFFER_TYPE_VIRTUAL) { - if (!HdfSbufWriteBuffer(data, buffers->addr, buffers->length)) { + if (buffer->type == BUFFER_TYPE_VIRTUAL) { + if (!HdfSbufWriteBuffer(data, (void *)buffer->buf, buffer->length)) { HDF_LOGE("%{public}s: Write addr failed!", __func__); return HDF_FAILURE; } - } else if (buffers->type == BUFFER_TYPE_FD) { - if (!HdfSbufWriteFileDescriptor(data, buffers->fd)) { + } else if (buffer->type == BUFFER_TYPE_FD) { + if (!HdfSbufWriteFileDescriptor(data, (int32_t)buffer->buf)) { HDF_LOGE("%{public}s: Write fd failed!", __func__); return HDF_FAILURE; } - } else if (buffers->type == BUFFER_TYPE_HANDLE) { - if (CodecProxyPackBufferHandle(data, &buffers->handle)) { - HDF_LOGE("%{public}s: Write handle failed!", __func__); - return HDF_FAILURE; - } + } else if (buffer->type == BUFFER_TYPE_HANDLE) { + return HDF_FAILURE; } else { - HDF_LOGE("%{public}s: buffers->type is err!", __func__); + HDF_LOGE("%{public}s: buffer->type is err!", __func__); return HDF_FAILURE; } - if (!HdfSbufWriteUint32(data, buffers->offset)) { + if (!HdfSbufWriteUint32(data, buffer->offset)) { HDF_LOGE("%{public}s: Write offset failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufWriteUint32(data, buffers->length)) { + if (!HdfSbufWriteUint32(data, buffer->length)) { HDF_LOGE("%{public}s: Write length failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufWriteUint32(data, buffers->size)) { + if (!HdfSbufWriteUint32(data, buffer->capacity)) { HDF_LOGE("%{public}s: Write size failed!", __func__); return HDF_FAILURE; } return HDF_SUCCESS; } -int32_t CodecProxyPackInputInfo(struct HdfSBuf *data, const InputInfo *inputData) -{ - if (data == NULL || inputData == NULL || inputData->buffers == NULL) { - HDF_LOGE("%{public}s: params NULL!", __func__); - return HDF_ERR_INVALID_PARAM; - } - if (!HdfSbufWriteUint32(data, inputData->bufferCnt)) { - HDF_LOGE("%{public}s: Write bufferCnt failed!", __func__); - return HDF_FAILURE; - } - for (uint32_t i = 0; i < inputData->bufferCnt; i++) { - if (CodecProxyPackBufferInfo(data, &inputData->buffers[i])) { - HDF_LOGE("%{public}s: Write buffers failed!", __func__); - return HDF_FAILURE; - } - } - if (!HdfSbufWriteInt64(data, inputData->pts)) { - HDF_LOGE("%{public}s: Write pts failed!", __func__); - return HDF_FAILURE; - } - if (!HdfSbufWriteInt32(data, inputData->flag)) { - HDF_LOGE("%{public}s: Write flag failed!", __func__); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -int32_t CodecProxyParseBufferHandle(struct HdfSBuf *reply, CodecBufferHandle *bufferHandle) +int32_t CodecProxyParseBufferInfo(struct HdfSBuf *reply, CodecBufferInfo *buffer) { - if (reply == NULL || bufferHandle == NULL) { - HDF_LOGE("%{public}s: params NULL!", __func__); - return HDF_ERR_INVALID_PARAM; - } - if (!HdfSbufReadUint64(reply, (uint64_t *)&bufferHandle->virAddr)) { - HDF_LOGE("%{public}s: read virAddr failed!", __func__); - return HDF_FAILURE; - } - if (!HdfSbufReadUint32(reply, (uint32_t *)&bufferHandle->handle)) { - HDF_LOGE("%{public}s: read handle failed!", __func__); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -int32_t CodecProxyParseBufferInfo(struct HdfSBuf *reply, CodecBufferInfo *buffers) -{ - uint32_t tempType = 0; uint32_t readLen = 0; - if (reply == NULL || buffers == NULL) { - HDF_LOGE("%{public}s: buffers null!", __func__); + if (reply == NULL || buffer == NULL) { + HDF_LOGE("%{public}s: buffer null!", __func__); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufReadUint32(reply, &tempType)) { + if (!HdfSbufReadUint32(reply, (uint32_t *)&buffer->type)) { HDF_LOGE("%{public}s: read type failed!", __func__); return HDF_FAILURE; } - buffers->type = (BufferType)tempType; - if (buffers->type == BUFFER_TYPE_VIRTUAL) { - if (!HdfSbufReadBuffer(reply, (const void **)&buffers->addr, &readLen)) { + if (buffer->type == BUFFER_TYPE_VIRTUAL) { + void *buf = (void *)buffer->buf; + if (!HdfSbufReadBuffer(reply, (const void **)&buf, &readLen)) { HDF_LOGE("%{public}s: read addr failed!", __func__); return HDF_FAILURE; } - } else if (buffers->type == BUFFER_TYPE_FD) { - buffers->fd = HdfSbufReadFileDescriptor(reply); - if (buffers->fd < 0) { + } else if (buffer->type == BUFFER_TYPE_FD) { + buffer->buf = (intptr_t)HdfSbufReadFileDescriptor(reply); + if (buffer->buf < 0) { HDF_LOGE("%{public}s: read fd failed!", __func__); return HDF_FAILURE; } - } else if (buffers->type == BUFFER_TYPE_HANDLE) { - if (CodecProxyParseBufferHandle(reply, &buffers->handle)) { - HDF_LOGE("%{public}s: read handle failed!", __func__); - return HDF_FAILURE; - } + } else if (buffer->type == BUFFER_TYPE_HANDLE) { + return HDF_FAILURE; } - if (!HdfSbufReadUint32(reply, &buffers->offset)) { + if (!HdfSbufReadUint32(reply, &buffer->offset)) { HDF_LOGE("%{public}s: read offset failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufReadUint32(reply, &buffers->length)) { + if (!HdfSbufReadUint32(reply, &buffer->length)) { HDF_LOGE("%{public}s: read length failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufReadUint32(reply, &buffers->size)) { + if (!HdfSbufReadUint32(reply, &buffer->capacity)) { HDF_LOGE("%{public}s: read size failed!", __func__); return HDF_FAILURE; } return HDF_SUCCESS; } -int32_t CodecProxyParseInputInfo(struct HdfSBuf *reply, InputInfo *inputData) +int32_t CodecProxyParseCodecBuffer(struct HdfSBuf *reply, CodecBuffer *codecBuffer) { - if (reply == NULL || inputData == NULL || inputData->buffers == NULL) { + if (reply == NULL || codecBuffer == NULL) { HDF_LOGE("%{public}s: params error!", __func__); return HDF_ERR_INVALID_PARAM; } - for (uint32_t i = 0; i < inputData->bufferCnt; i++) { - if (CodecProxyParseBufferInfo(reply, &inputData->buffers[i])) { - HDF_LOGE("%{public}s: read buffers failed!", __func__); - return HDF_FAILURE; - } + if (!HdfSbufReadUint32(reply, &codecBuffer->bufferId)) { + HDF_LOGE("%{public}s: read sequence failed!", __func__); + return HDF_FAILURE; } - if (!HdfSbufReadInt64(reply, &inputData->pts)) { - HDF_LOGE("%{public}s: read pts failed!", __func__); + if (!HdfSbufReadInt64(reply, &codecBuffer->timeStamp)) { + HDF_LOGE("%{public}s: read timeStamp failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufReadInt32(reply, &inputData->flag)) { + if (!HdfSbufReadUint32(reply, &codecBuffer->flag)) { HDF_LOGE("%{public}s: read flag failed!", __func__); return HDF_FAILURE; } + for (uint32_t i = 0; i < codecBuffer->bufferCnt; i++) { + if (CodecProxyParseBufferInfo(reply, &codecBuffer->buffer[i])) { + HDF_LOGE("%{public}s: read buffers failed!", __func__); + return HDF_FAILURE; + } + } return HDF_SUCCESS; } -int32_t CodecProxyParseOutputInfo(struct HdfSBuf *reply, OutputInfo *outInfo) +int32_t CodecProxyPackCodecBuffer(struct HdfSBuf *data, const CodecBuffer *codecBuffer) { - if (reply == NULL || outInfo == NULL || outInfo->buffers == NULL) { + if (data == NULL || codecBuffer == NULL) { HDF_LOGE("%{public}s: params error!", __func__); return HDF_ERR_INVALID_PARAM; } - for (uint32_t i = 0; i < outInfo->bufferCnt; i++) { - if (CodecProxyParseBufferInfo(reply, &outInfo->buffers[i])) { - HDF_LOGE("%{public}s: read buffers failed!", __func__); - return HDF_FAILURE; - } - } - if (!HdfSbufReadInt64(reply, &outInfo->timeStamp)) { - HDF_LOGE("%{public}s: read timeStamp failed!", __func__); + if (!HdfSbufWriteUint32(data, codecBuffer->bufferCnt)) { + HDF_LOGE("%{public}s: write bufferCnt failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufReadUint32(reply, &outInfo->sequence)) { - HDF_LOGE("%{public}s: read sequence failed!", __func__); + if (!HdfSbufWriteUint32(data, codecBuffer->bufferId)) { + HDF_LOGE("%{public}s: write bufferId failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufReadUint32(reply, &outInfo->flag)) { - HDF_LOGE("%{public}s: read flag failed!", __func__); + if (!HdfSbufWriteInt64(data, codecBuffer->timeStamp)) { + HDF_LOGE("%{public}s: write timeStamp failed!", __func__); return HDF_FAILURE; } - uint32_t tempType = 0; - if (!HdfSbufReadUint32(reply, &tempType)) { - HDF_LOGE("%{public}s: read tempType failed!", __func__); + if (!HdfSbufWriteUint32(data, codecBuffer->flag)) { + HDF_LOGE("%{public}s: write flag failed!", __func__); return HDF_FAILURE; } - outInfo->type = (CodecType)tempType; - if (!HdfSbufReadUint64(reply, (uint64_t *)&outInfo->vendorPrivate)) { - HDF_LOGE("%{public}s: read vendorPrivate failed!", __func__); - return HDF_FAILURE; + for (uint32_t i = 0; i < codecBuffer->bufferCnt; i++) { + if (CodecProxyPackBufferInfo(data, &codecBuffer->buffer[i])) { + HDF_LOGE("%{public}s: write buffers failed!", __func__); + return HDF_FAILURE; + } } return HDF_SUCCESS; } -int32_t CodecProxyPackOutputInfo(struct HdfSBuf *data, OutputInfo *outInfo) +int32_t CodecProxyParseFenceFd(struct HdfSBuf *reply, int32_t *fenceFd) { - if (data == NULL || outInfo == NULL || outInfo->buffers == NULL) { - HDF_LOGE("%{public}s: params error!", __func__); - return HDF_ERR_INVALID_PARAM; - } - if (!HdfSbufWriteUint32(data, outInfo->bufferCnt)) { - HDF_LOGE("%{public}s: write bufferCnt failed!", __func__); + uint8_t validFd = 0; + if (!HdfSbufReadUint8(reply, &validFd)) { + HDF_LOGE("%{public}s: read validFd failed!", __func__); return HDF_FAILURE; } - for (uint32_t i = 0; i < outInfo->bufferCnt; i++) { - if (CodecProxyPackBufferInfo(data, &outInfo->buffers[i])) { - HDF_LOGE("%{public}s: write buffers failed!", __func__); - return HDF_FAILURE; - } - } - if (!HdfSbufWriteInt64(data, outInfo->timeStamp)) { - HDF_LOGE("%{public}s: write timeStamp failed!", __func__); - return HDF_FAILURE; - } - if (!HdfSbufWriteUint32(data, outInfo->sequence)) { - HDF_LOGE("%{public}s: write sequence failed!", __func__); - return HDF_FAILURE; - } - if (!HdfSbufWriteUint32(data, outInfo->flag)) { - HDF_LOGE("%{public}s: write flag failed!", __func__); - return HDF_FAILURE; + if (validFd != 0) { + *fenceFd = HdfSbufReadFileDescriptor(reply); + } else { + *fenceFd = -1; } - if (!HdfSbufWriteUint32(data, outInfo->type)) { - HDF_LOGE("%{public}s: write outInfo->type failed!", __func__); - return HDF_FAILURE; + return HDF_SUCCESS; +} + +int32_t CodecProxyPackFenceFd(struct HdfSBuf *data, int fenceFd) +{ + uint8_t validFd = fenceFd >= 0; + if (!HdfSbufWriteUint8(data, validFd)) { + HDF_LOGE("%{public}s: write validFd flag failed!", __func__); + return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufWriteUint64(data, (uint64_t)&outInfo->vendorPrivate)) { - HDF_LOGE("%{public}s: write vendorPrivate failed!", __func__); - return HDF_FAILURE; + if (validFd != 0 && !HdfSbufWriteFileDescriptor(data, fenceFd)) { + HDF_LOGE("%{public}s: write fenceFd failed!", __func__); + return HDF_ERR_INVALID_PARAM; } return HDF_SUCCESS; } #ifdef __cplusplus } -#endif /* __cplusplus */ \ No newline at end of file +#endif /* __cplusplus */ diff --git a/codec/hdi_service/codec_proxy/proxy_msgproc.h b/codec/hdi_service/codec_proxy/proxy_msgproc.h index 59c762809fb1f35463073a0cbacef9c2053e05d8..523e577eb327da5c1fb588cbd93f2edc1329440e 100644 --- a/codec/hdi_service/codec_proxy/proxy_msgproc.h +++ b/codec/hdi_service/codec_proxy/proxy_msgproc.h @@ -22,13 +22,13 @@ extern "C" { #endif /* __cplusplus */ -int32_t CodecProxyParseGottenCapbility(struct HdfSBuf *reply, CodecCapbility *cap); +int32_t CodecProxyParseGottenCapability(struct HdfSBuf *reply, CodecCapability *cap); int32_t CodecProxyPackParam(struct HdfSBuf *data, const Param *param); -int32_t CodecProxyPackInputInfo(struct HdfSBuf *data, const InputInfo *inputData); -int32_t CodecProxyParseInputInfo(struct HdfSBuf *reply, InputInfo *inputData); -int32_t CodecProxyParseOutputInfo(struct HdfSBuf *reply, OutputInfo *outInfo); int32_t CodecProxyParseParam(struct HdfSBuf *reply, Param *param); -int32_t CodecProxyPackOutputInfo(struct HdfSBuf *data, OutputInfo *outInfo); +int32_t CodecProxyPackCodecBuffer(struct HdfSBuf *data, const CodecBuffer *codecBuffer); +int32_t CodecProxyParseCodecBuffer(struct HdfSBuf *reply, CodecBuffer *codecBuffer); +int32_t CodecProxyParseFenceFd(struct HdfSBuf *reply, int32_t *fenceFd); +int32_t CodecProxyPackFenceFd(struct HdfSBuf *data, int32_t fenceFd); #ifdef __cplusplus } diff --git a/codec/hdi_service/codec_service_stub/codec_callback_service.c b/codec/hdi_service/codec_service_stub/codec_callback_service.c index cc40705de54cabd4166729a4adca22f7da048159..b12c7a0728fa1bac802033a9e0c0391a05d61d4a 100644 --- a/codec/hdi_service/codec_service_stub/codec_callback_service.c +++ b/codec/hdi_service/codec_service_stub/codec_callback_service.c @@ -20,18 +20,17 @@ extern "C" { #endif /* __cplusplus */ -int CodecCallbackOnEvent(UINTPTR comp, UINTPTR appData, EventType event, - uint32_t data1, uint32_t data2, UINTPTR eventData) +int CodecCallbackOnEvent(UINTPTR userData, EventType event, uint32_t length, int32_t eventData[]) { return HDF_SUCCESS; } -int CodecCallbackInputBufferAvailable(UINTPTR comp, UINTPTR appData, InputInfo *inBuf) +int CodecCallbackInputBufferAvailable(UINTPTR userData, CodecBuffer *inBuf, int32_t *acquireFd) { return HDF_SUCCESS; } -int CodecCallbackOutputBufferAvailable(UINTPTR comp, UINTPTR appData, OutputInfo *outBuf) +int CodecCallbackOutputBufferAvailable(UINTPTR userData, CodecBuffer *outBuf, int32_t *acquireFd) { return HDF_SUCCESS; } diff --git a/codec/hdi_service/codec_service_stub/codec_callback_service.h b/codec/hdi_service/codec_service_stub/codec_callback_service.h index d5bcbb80362733d2c17d6f5c487c5a842491ba2f..f1d3fce95b98079da9d652edc225fcdf072a5adc 100644 --- a/codec/hdi_service/codec_service_stub/codec_callback_service.h +++ b/codec/hdi_service/codec_service_stub/codec_callback_service.h @@ -23,10 +23,9 @@ extern "C" { #endif /* __cplusplus */ void CodecCallbackServiceConstruct(struct ICodecCallback *service); -int CodecCallbackOnEvent(UINTPTR comp, UINTPTR appData, EventType event, - uint32_t data1, uint32_t data2, UINTPTR eventData); -int CodecCallbackInputBufferAvailable(UINTPTR comp, UINTPTR appData, InputInfo *inBuf); -int CodecCallbackOutputBufferAvailable(UINTPTR comp, UINTPTR appData, OutputInfo *outBuf); +int CodecCallbackOnEvent(UINTPTR userData, EventType event, uint32_t length, int32_t eventData[]); +int CodecCallbackInputBufferAvailable(UINTPTR userData, CodecBuffer *inBuf, int32_t *acquireFd); +int CodecCallbackOutputBufferAvailable(UINTPTR userData, CodecBuffer *outBuf, int32_t *acquireFd); #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/codec/hdi_service/codec_service_stub/codec_callback_stub.c b/codec/hdi_service/codec_service_stub/codec_callback_stub.c index ababbcdf112ec30f7e0de27ab72c0eebe792ea7c..be7bd464726cf5dfb70e61cecee0b26071649212 100644 --- a/codec/hdi_service/codec_service_stub/codec_callback_stub.c +++ b/codec/hdi_service/codec_service_stub/codec_callback_stub.c @@ -13,11 +13,11 @@ * limitations under the License. */ -#include "stub_msgproc.h" #include #include #include #include "codec_callback_service.h" +#include "stub_msgproc.h" #ifdef __cplusplus extern "C" { @@ -26,118 +26,126 @@ extern "C" { int32_t SerCodecOnEvent(struct ICodecCallback *serviceImpl, struct HdfSBuf *data, struct HdfSBuf *reply) { int32_t ret; - UINTPTR comp = 0; - UINTPTR appData = 0; + UINTPTR userData = 0; EventType event = 0; - uint32_t data1 = 0; - uint32_t data2 = 0; - UINTPTR eventData = 0; - if (!HdfSbufReadUint32(data, (uint32_t *)&comp)) { + uint32_t length = 0; + int32_t *eventData = NULL; + + if (!HdfSbufReadUint32(data, (uint32_t *)&userData)) { HDF_LOGE("%{public}s: read comp data failed!", __func__); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufReadUint32(data, (uint32_t *)&appData)) { - HDF_LOGE("%{public}s: read appData data failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } if (!HdfSbufReadUint32(data, (uint32_t *)&event)) { HDF_LOGE("%{public}s: read event data failed!", __func__); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufReadUint32(data, &data1)) { + if (!HdfSbufReadUint32(data, &length)) { HDF_LOGE("%{public}s: read data1 data failed!", __func__); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufReadUint32(data, &data2)) { - HDF_LOGE("%{public}s: read data2 data failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - if (!HdfSbufReadUint32(data, (uint32_t *)&eventData)) { - HDF_LOGE("%{public}s: read event data failed!", __func__); - return HDF_ERR_INVALID_PARAM; + if (length > 0) { + eventData = (int32_t *)OsalMemCalloc(length); + if (eventData == NULL) { + HDF_LOGE("%{public}s: OsalMemAlloc eventData failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + for (uint32_t i = 0; i < length; i++) { + if (!HdfSbufReadInt32(data, &eventData[i])) { + HDF_LOGE("%{public}s: read eventData failed!", __func__); + OsalMemFree(eventData); + return HDF_ERR_INVALID_PARAM; + } + } } - ret = serviceImpl->callback.OnEvent(comp, appData, event, data1, data2, eventData); + ret = serviceImpl->callback.OnEvent(userData, event, length, eventData); if (ret != HDF_SUCCESS) { HDF_LOGE("%{public}s: call OnEvent fuc failed!", __func__); + OsalMemFree(eventData); + return ret; } + OsalMemFree(eventData); return ret; } int32_t SerCodecInputBufferAvailable(struct ICodecCallback *serviceImpl, struct HdfSBuf *data, struct HdfSBuf *reply) { - int32_t ret; - uint32_t bufCnt; - UINTPTR comp = 0; - UINTPTR appData = 0; - InputInfo inBuf = {0}; - if (!HdfSbufReadUint32(data, (uint32_t *)&comp)) { - HDF_LOGE("%{public}s: read comp data failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - if (!HdfSbufReadUint32(data, (uint32_t *)&appData)) { - HDF_LOGE("%{public}s: read appData data failed!", __func__); + int32_t ret = HDF_FAILURE; + uint32_t bufCnt = 0; + UINTPTR userData = 0; + CodecBuffer *inBuf = NULL; + int32_t acquireFd; + + if (!HdfSbufReadUint32(data, (uint32_t *)&userData)) { + HDF_LOGE("%{public}s: read userData failed!", __func__); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufReadUint32(data, (uint32_t *)&inBuf.bufferCnt)) { + if (!HdfSbufReadUint32(data, &bufCnt)) { HDF_LOGE("%{public}s: read bufferCnt failed!", __func__); return HDF_FAILURE; } - bufCnt = inBuf.bufferCnt; - inBuf.buffers = (CodecBufferInfo *)OsalMemAlloc(sizeof(CodecBufferInfo) * bufCnt); - if (inBuf.buffers == NULL) { - HDF_LOGE("%{public}s: OsalMemAlloc CodecCallbackStub obj failed!", __func__); + if (bufCnt <= 0) { + HDF_LOGE("%{public}s: invalid bufferCnt!", __func__); + return HDF_ERR_INVALID_PARAM; + } + inBuf = (CodecBuffer *)OsalMemAlloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo) * bufCnt); + if (inBuf == NULL) { + HDF_LOGE("%{public}s: OsalMemAlloc inBuf failed!", __func__); return HDF_ERR_MALLOC_FAIL; } - if (CodecSerParseInputInfo(data, &inBuf)) { - HDF_LOGE("%{public}s: read struct reply failed!", __func__); - OsalMemFree(inBuf.buffers); + inBuf->bufferCnt = bufCnt; + if (CodecSerParseCodecBuffer(data, inBuf)) { + HDF_LOGE("%{public}s: read inBuf failed!", __func__); + OsalMemFree(inBuf); return HDF_ERR_INVALID_PARAM; } - ret = serviceImpl->callback.InputBufferAvailable(comp, appData, &inBuf); + ret = serviceImpl->callback.InputBufferAvailable(userData, inBuf, &acquireFd); if (ret != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call OnEvent fuc failed!", __func__); + HDF_LOGE("%{public}s: call InputBufferAvailable fuc failed!", __func__); + OsalMemFree(inBuf); + return ret; } - OsalMemFree(inBuf.buffers); + OsalMemFree(inBuf); return ret; } int32_t SerCodecOutputBufferAvailable(struct ICodecCallback *serviceImpl, struct HdfSBuf *data, struct HdfSBuf *reply) { - int32_t ret; - uint32_t bufCnt; - UINTPTR comp = 0; - UINTPTR appData = 0; - OutputInfo outBuf = {0}; - if (!HdfSbufReadUint32(data, (uint32_t *)&comp)) { - HDF_LOGE("%{public}s: read comp data failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - if (!HdfSbufReadUint32(data, (uint32_t *)&appData)) { - HDF_LOGE("%{public}s: read appData data failed!", __func__); + int32_t ret = HDF_FAILURE; + uint32_t bufCnt = 0; + UINTPTR userData = 0; + CodecBuffer *outBuf = NULL; + int32_t acquireFd; + + if (!HdfSbufReadUint32(data, (uint32_t *)&userData)) { + HDF_LOGE("%{public}s: read userData failed!", __func__); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufReadUint32(data, (uint32_t *)&outBuf.bufferCnt)) { + if (!HdfSbufReadUint32(data, (uint32_t *)&bufCnt)) { HDF_LOGE("%{public}s: read bufferCnt failed!", __func__); - return HDF_FAILURE; + return HDF_ERR_INVALID_PARAM; } - bufCnt = outBuf.bufferCnt; - outBuf.buffers = (CodecBufferInfo *)OsalMemAlloc(sizeof(CodecBufferInfo) * bufCnt); - if (outBuf.buffers == NULL) { - HDF_LOGE("%{public}s: OsalMemAlloc failed!", __func__); + if (bufCnt == 0) { + HDF_LOGE("%{public}s: invalid bufferCnt!", __func__); return HDF_ERR_INVALID_PARAM; } - if (CodecSerParseOutputInfo(data, &outBuf)) { - HDF_LOGE("%{public}s: read struct outBuf failed!", __func__); - OsalMemFree(outBuf.buffers); + outBuf = (CodecBuffer *)OsalMemAlloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo) * bufCnt); + if (outBuf == NULL) { + HDF_LOGE("%{public}s: OsalMemAlloc outBuf failed!", __func__); + return HDF_ERR_MALLOC_FAIL; + } + outBuf->bufferCnt = bufCnt; + if (CodecSerParseCodecBuffer(data, outBuf)) { + HDF_LOGE("%{public}s: read outBuf failed!", __func__); + OsalMemFree(outBuf); return HDF_ERR_INVALID_PARAM; } - ret = serviceImpl->callback.OutputBufferAvailable(comp, appData, &outBuf); + ret = serviceImpl->callback.OutputBufferAvailable(userData, outBuf, &acquireFd); if (ret != HDF_SUCCESS) { - HDF_LOGE("%{public}s: call OnEvent fuc failed!", __func__); - OsalMemFree(outBuf.buffers); + HDF_LOGE("%{public}s: call OutputBufferAvailable fuc failed!", __func__); + OsalMemFree(outBuf); return ret; } - OsalMemFree(outBuf.buffers); + OsalMemFree(outBuf); return ret; } @@ -164,7 +172,7 @@ struct CodecCallbackStub { struct HdfRemoteDispatcher dispatcher; }; -struct ICodecCallback *CodecCallbackStubObtain() +struct ICodecCallback *CodecCallbackStubObtain(void) { struct CodecCallbackStub *stub = (struct CodecCallbackStub *)OsalMemAlloc(sizeof(struct CodecCallbackStub)); if (stub == NULL) { diff --git a/codec/hdi_service/codec_service_stub/codec_config_parser.c b/codec/hdi_service/codec_service_stub/codec_config_parser.c index c11919135a722dc9abd929cce893040a314a11cf..0336d03cbb3a2b8b9efe39cb49f5286bf1bf9242 100644 --- a/codec/hdi_service/codec_service_stub/codec_config_parser.c +++ b/codec/hdi_service/codec_service_stub/codec_config_parser.c @@ -20,6 +20,11 @@ #include "hdf_log.h" #define HDF_LOG_TAG "codec_config_parser" +#ifdef __ARM64__ +#define MASK_NUM_LIMIT 64 +#else +#define MASK_NUM_LIMIT 32 +#endif static CodecCapablites codecCapabilites = {0}; static const struct DeviceResourceNode *resourceNode; @@ -51,36 +56,86 @@ static int32_t GetGroupCapabilitiesNumber(const struct DeviceResourceNode *node, return HDF_SUCCESS; } -static int32_t GetUintTableConfig(const struct DeviceResourceIface *iface, - const struct DeviceResourceNode *node, const char *attrName, ResizableArray *table) +static int32_t GetCapabilityBase(const struct DeviceResourceIface *iface, + const struct DeviceResourceNode *childNode, CodecCapability *cap) { - int32_t count = iface->GetElemNum(node, attrName); - table->actualLen = 0; - if (count <= 0) { - HDF_LOGE("%{public}s, %{public}s not set!", __func__, attrName); + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIME, + (uint32_t*)&cap->mime, MEDIA_MIMETYPE_INVALID) != HDF_SUCCESS) { + cap->mime = MEDIA_MIMETYPE_INVALID; + HDF_LOGE("%{public}s, failed to get mime for: %{public}s! Discarded", __func__, childNode->name); return HDF_FAILURE; } - if (count > ELEMENT_MAX_LEN) { - HDF_LOGE("%{public}s, table size: %{public}d, exceeded max size %{public}d!", - __func__, count, ELEMENT_MAX_LEN); + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_TYPE, (uint32_t*)&cap->type, INVALID_TYPE) != HDF_SUCCESS) { + cap->mime = MEDIA_MIMETYPE_INVALID; + cap->type = INVALID_TYPE; + HDF_LOGE("%{public}s, failed to get type for: %{public}s! Discarded", __func__, childNode->name); + return HDF_FAILURE; + } + const char *name = NULL; + if (iface->GetString(childNode, CODEC_CONFIG_KEY_NAME, &name, "") != HDF_SUCCESS) { + cap->mime = MEDIA_MIMETYPE_INVALID; + HDF_LOGE("%{public}s, failed to get name for: %{public}s! Discarded", __func__, childNode->name); return HDF_FAILURE; } - iface->GetUint32Array(node, attrName, table->element, count, 0); - table->actualLen = count; + if (name == NULL || strlen(name) >= NAME_LENGTH || strlen(name) == 0) { + cap->mime = MEDIA_MIMETYPE_INVALID; + HDF_LOGE("%{public}s, name(%{public}s) is illegal", __func__, childNode->name); + return HDF_FAILURE; + } + int32_t ret = strcpy_s(cap->name, NAME_LENGTH, name); + if (ret != EOK) { + cap->mime = MEDIA_MIMETYPE_INVALID; + HDF_LOGE("%{public}s, strcpy_s is failed, error code: %{public}d!", __func__, ret); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static int32_t GetUintTableConfig(const struct DeviceResourceIface *iface, + const struct DeviceResourceNode *node, ConfigUintArrayNodeAttr *attr) +{ + if (iface == NULL || node == NULL || attr == NULL) { + HDF_LOGE("%{public}s, failed, invalid param!", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (attr->array == NULL || attr->attrName == NULL) { + HDF_LOGE("%{public}s, failed, invalid attr!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + int32_t count = iface->GetElemNum(node, attr->attrName); + if (count < 0 || count >= attr->length) { + HDF_LOGE("%{public}s, %{public}s table size: %{public}d incorrect or exceed max size %{public}d!", + __func__, attr->attrName, count, attr->length - 1); + return HDF_FAILURE; + } + + if (count > 0) { + iface->GetUint32Array(node, attr->attrName, (uint32_t *)attr->array, count, 0); + } + attr->array[count] = attr->endValue; + return HDF_SUCCESS; } static int32_t GetMaskedConfig(const struct DeviceResourceIface *iface, const struct DeviceResourceNode *node, const char *attrName, uint32_t *mask) { - int32_t index = 0; + if (iface == NULL || node == NULL || attrName == NULL || mask == NULL) { + HDF_LOGE("%{public}s, failed, invalid param!", __func__); + return HDF_ERR_INVALID_PARAM; + } + uint32_t *values = NULL; int32_t count = iface->GetElemNum(node, attrName); *mask = 0; - if (count <= 0) { - HDF_LOGE("%{public}s, %{public}s not set!", __func__, attrName); + if (count < 0 || count > MASK_NUM_LIMIT) { + HDF_LOGE("%{public}s, failed, %{public}s count %{public}d incorrect!", __func__, attrName, count); return HDF_FAILURE; + } else if (count == 0) { + // mask is not set, do not need to read + return HDF_SUCCESS; } values = (uint32_t *)OsalMemAlloc(sizeof(uint32_t) * count); @@ -89,7 +144,7 @@ static int32_t GetMaskedConfig(const struct DeviceResourceIface *iface, return HDF_FAILURE; } iface->GetUint32Array(node, attrName, values, count, 0); - for (index = 0; index < count; index++) { + for (int32_t index = 0; index < count; index++) { *mask |= values[index]; } OsalMemFree(values); @@ -97,134 +152,195 @@ static int32_t GetMaskedConfig(const struct DeviceResourceIface *iface, return HDF_SUCCESS; } -static int32_t GetAudioOfCapability(const struct DeviceResourceIface *iface, - const struct DeviceResourceNode *childNode, CodecCapbility *cap) +static int32_t GetBufferConfig(const struct DeviceResourceIface *iface, + const struct DeviceResourceNode *childNode, CodecCapability *cap) { - if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIN_BITRATE, (uint32_t*)&cap->minBitRate, 0) != HDF_SUCCESS) { + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIN_INPUT_BUFFER_NUM, (uint32_t*)&cap->inputBufferNum.min, 0) + != HDF_SUCCESS) { cap->mime = MEDIA_MIMETYPE_INVALID; - HDF_LOGE("%{public}s, failed to get %{public}s for: %{public}s! Discarded", - __func__, CODEC_CONFIG_KEY_MIN_BITRATE, childNode->name); + HDF_LOGE("%{public}s, %{public}s:min%{public}s not config.", + __func__, childNode->name, CODEC_CONFIG_KEY_MIN_INPUT_BUFFER_NUM); + return HDF_FAILURE; + } + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MAX_INPUT_BUFFER_NUM, (uint32_t*)&cap->inputBufferNum.max, 0) + != HDF_SUCCESS) { + cap->mime = MEDIA_MIMETYPE_INVALID; + HDF_LOGE("%{public}s, %{public}s:max%{public}s not config.", + __func__, childNode->name, CODEC_CONFIG_KEY_MAX_INPUT_BUFFER_NUM); return HDF_FAILURE; } - if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MAX_BITRATE, (uint32_t*)&cap->maxBitRate, 0) != HDF_SUCCESS) { + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIN_OUTPUT_BUFFER_NUM, (uint32_t*)&cap->outputBufferNum.min, 0) + != HDF_SUCCESS) { cap->mime = MEDIA_MIMETYPE_INVALID; - HDF_LOGE("%{public}s, failed to get %{public}s for: %{public}s! Discarded", - __func__, CODEC_CONFIG_KEY_MAX_BITRATE, childNode->name); + HDF_LOGE("%{public}s, %{public}s:min%{public}s not config.", + __func__, childNode->name, CODEC_CONFIG_KEY_MIN_OUTPUT_BUFFER_NUM); + return HDF_FAILURE; + } + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MAX_OUTPUT_BUFFER_NUM, (uint32_t*)&cap->outputBufferNum.max, 0) + != HDF_SUCCESS) { + cap->mime = MEDIA_MIMETYPE_INVALID; + HDF_LOGE("%{public}s, %{public}s:max%{public}s not config.", + __func__, childNode->name, CODEC_CONFIG_KEY_MAX_OUTPUT_BUFFER_NUM); + return HDF_FAILURE; + } + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_INPUT_BUFFER_SIZE, (uint32_t*)&cap->inputBufferSize, 0) + != HDF_SUCCESS) { + cap->mime = MEDIA_MIMETYPE_INVALID; + HDF_LOGE("%{public}s, %{public}s:%{public}s not config.", + __func__, childNode->name, CODEC_CONFIG_KEY_INPUT_BUFFER_SIZE); + return HDF_FAILURE; + } + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_OUTPUT_BUFFER_SIZE, (uint32_t*)&cap->outputBufferSize, 0) + != HDF_SUCCESS) { + cap->mime = MEDIA_MIMETYPE_INVALID; + HDF_LOGE("%{public}s, %{public}s:%{public}s not config.", + __func__, childNode->name, CODEC_CONFIG_KEY_OUTPUT_BUFFER_SIZE); return HDF_FAILURE; } return HDF_SUCCESS; } -static int32_t GetVideoOfCapability(const struct DeviceResourceIface *iface, - const struct DeviceResourceNode *childNode, CodecCapbility *cap) +static int32_t GetBitRateConfig(const struct DeviceResourceIface *iface, + const struct DeviceResourceNode *childNode, CodecCapability *cap) { - if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_WIDTH_ALIGNMENT, - (uint32_t*)&cap->whAlignment.widthAlignment, 0) != HDF_SUCCESS) { + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIN_BITRATE, (uint32_t*)&cap->bitRate.min, 0) + != HDF_SUCCESS) { cap->mime = MEDIA_MIMETYPE_INVALID; - HDF_LOGE("%{public}s, failed to get %{public}s for: %{public}s! Discarded", - __func__, CODEC_CONFIG_KEY_WIDTH_ALIGNMENT, childNode->name); + HDF_LOGE("%{public}s, %{public}s:min%{public}s not config.", + __func__, childNode->name, CODEC_CONFIG_KEY_MIN_BITRATE); return HDF_FAILURE; } - if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_HEIGHT_ALIGNMENT, - (uint32_t*)&cap->whAlignment.heightAlignment, 0) != HDF_SUCCESS) { + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MAX_BITRATE, (uint32_t*)&cap->bitRate.max, 0) + != HDF_SUCCESS) { cap->mime = MEDIA_MIMETYPE_INVALID; - HDF_LOGE("%{public}s, failed to get %{public}s for: %{public}s! Discarded", - __func__, CODEC_CONFIG_KEY_HEIGHT_ALIGNMENT, childNode->name); + HDF_LOGE("%{public}s, %{public}s:max%{public}s not config.", + __func__, childNode->name, CODEC_CONFIG_KEY_MAX_BITRATE); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static int32_t GetAudioOfCapability(const struct DeviceResourceIface *iface, + const struct DeviceResourceNode *childNode, CodecCapability *cap) +{ + ConfigUintArrayNodeAttr sampleFormatsAttr = {CODEC_CONFIG_KEY_SAMPLE_FORMATS, cap->port.audio.sampleFormats, + SAMPLE_FORMAT_NUM, 0}; + if (GetUintTableConfig(iface, childNode, &sampleFormatsAttr) != HDF_SUCCESS) { + HDF_LOGE("%{public}s, failed to get %{public}s for: %{public}s!", + __func__, CODEC_CONFIG_KEY_SAMPLE_FORMATS, childNode->name); + return HDF_FAILURE; + } + + ConfigUintArrayNodeAttr sampleRateAttr = {CODEC_CONFIG_KEY_SAMPLE_RATE, cap->port.audio.sampleRate, + SAMPLE_RATE_NUM, 0}; + if (GetUintTableConfig(iface, childNode, &sampleRateAttr) != HDF_SUCCESS) { + HDF_LOGE("%{public}s, failed to get %{public}s for: %{public}s!", + __func__, CODEC_CONFIG_KEY_SAMPLE_RATE, childNode->name); + return HDF_FAILURE; + } + + ConfigUintArrayNodeAttr channelLayoutsAttr = {CODEC_CONFIG_KEY_CHANNEL_LAYOUTS, cap->port.audio.channelLayouts, + CHANNEL_NUM, 0}; + if (GetUintTableConfig(iface, childNode, &channelLayoutsAttr) != HDF_SUCCESS) { + HDF_LOGE("%{public}s, failed to get %{public}s for: %{public}s!", + __func__, CODEC_CONFIG_KEY_CHANNEL_LAYOUTS, childNode->name); return HDF_FAILURE; } - if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIN_WIDTH, (uint32_t*)&cap->minSize.width, 0) != HDF_SUCCESS) { + return HDF_SUCCESS; +} + +static int32_t GetVideoOfCapability(const struct DeviceResourceIface *iface, + const struct DeviceResourceNode *childNode, CodecCapability *cap) +{ + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIN_WIDTH, (uint32_t*)&cap->port.video.minSize.width, 0) + != HDF_SUCCESS) { cap->mime = MEDIA_MIMETYPE_INVALID; HDF_LOGE("%{public}s, failed to get %{public}s for: %{public}s! Discarded", __func__, CODEC_CONFIG_KEY_MIN_WIDTH, childNode->name); return HDF_FAILURE; } - if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIN_HEIGHT, (uint32_t*)&cap->minSize.height, 0) != HDF_SUCCESS) { + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIN_HEIGHT, (uint32_t*)&cap->port.video.minSize.height, 0) + != HDF_SUCCESS) { cap->mime = MEDIA_MIMETYPE_INVALID; HDF_LOGE("%{public}s, failed to get %{public}s for: %{public}s! Discarded", __func__, CODEC_CONFIG_KEY_MIN_HEIGHT, childNode->name); return HDF_FAILURE; } - if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MAX_WIDTH, (uint32_t*)&cap->maxSize.width, 0) != HDF_SUCCESS) { + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MAX_WIDTH, (uint32_t*)&cap->port.video.maxSize.width, 0) + != HDF_SUCCESS) { cap->mime = MEDIA_MIMETYPE_INVALID; HDF_LOGE("%{public}s, failed to get %{public}s for: %{public}s! Discarded", __func__, CODEC_CONFIG_KEY_MAX_WIDTH, childNode->name); return HDF_FAILURE; } - if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MAX_HEIGHT, (uint32_t*)&cap->maxSize.height, 0) != HDF_SUCCESS) { + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MAX_HEIGHT, (uint32_t*)&cap->port.video.maxSize.height, 0) + != HDF_SUCCESS) { cap->mime = MEDIA_MIMETYPE_INVALID; HDF_LOGE("%{public}s, failed to get %{public}s for: %{public}s! Discarded", __func__, CODEC_CONFIG_KEY_MAX_HEIGHT, childNode->name); return HDF_FAILURE; } - return HDF_SUCCESS; -} - -static int32_t GetBufferConfig(const struct DeviceResourceIface *iface, - const struct DeviceResourceNode *childNode, CodecCapbility *cap) -{ - if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIN_INPUT_BUFFER_NUM, &cap->minInputBufferNum, 0) - != HDF_SUCCESS) { + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_WIDTH_ALIGNMENT, + (uint32_t*)&cap->port.video.whAlignment.widthAlignment, 0) != HDF_SUCCESS) { cap->mime = MEDIA_MIMETYPE_INVALID; - HDF_LOGE("%{public}s, %{public}s:%{public}s not config.", - __func__, childNode->name, CODEC_CONFIG_KEY_MIN_INPUT_BUFFER_NUM); + HDF_LOGE("%{public}s, failed to get %{public}s for: %{public}s! Discarded", + __func__, CODEC_CONFIG_KEY_WIDTH_ALIGNMENT, childNode->name); return HDF_FAILURE; } - if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIN_OUTPUT_BUFFER_NUM, &cap->minOutputBufferNum, 0) - != HDF_SUCCESS) { + if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_HEIGHT_ALIGNMENT, + (uint32_t*)&cap->port.video.whAlignment.heightAlignment, 0) != HDF_SUCCESS) { cap->mime = MEDIA_MIMETYPE_INVALID; - HDF_LOGE("%{public}s, %{public}s:%{public}s not config.", - __func__, childNode->name, CODEC_CONFIG_KEY_MIN_OUTPUT_BUFFER_NUM); + HDF_LOGE("%{public}s, failed to get %{public}s for: %{public}s! Discarded", + __func__, CODEC_CONFIG_KEY_HEIGHT_ALIGNMENT, childNode->name); + return HDF_FAILURE; + } + ConfigUintArrayNodeAttr attr = {CODEC_CONFIG_KEY_SUPPORT_PIXELF_MTS, cap->port.video.supportPixFmts, + PIX_FMT_NUM, INVALID_PROFILE}; + if (GetUintTableConfig(iface, childNode, &attr) != HDF_SUCCESS) { return HDF_FAILURE; } return HDF_SUCCESS; } - static int32_t GetOneCapability(const struct DeviceResourceIface *iface, - const struct DeviceResourceNode *childNode, CodecCapbility *cap) + const struct DeviceResourceNode *childNode, CodecCapability *cap, bool isVideoGroup) { if (iface == NULL || childNode == NULL || cap == NULL) { + HDF_LOGE("%{public}s, failed, invalid param!", __func__); return HDF_FAILURE; } - if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MIME, - (uint32_t*)&cap->mime, MEDIA_MIMETYPE_INVALID) != HDF_SUCCESS) { - cap->mime = MEDIA_MIMETYPE_INVALID; - HDF_LOGE("%{public}s, failed to get mime for: %{public}s! Discarded", __func__, childNode->name); + if (GetCapabilityBase(iface, childNode, cap) != HDF_SUCCESS) { return HDF_FAILURE; } - if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_TYPE, (uint32_t*)&cap->type, INVALID_TYPE) != HDF_SUCCESS) { - cap->mime = MEDIA_MIMETYPE_INVALID; - cap->type = INVALID_TYPE; - HDF_LOGE("%{public}s, failed to get type for: %{public}s! Discarded", __func__, childNode->name); + ConfigUintArrayNodeAttr attr = {CODEC_CONFIG_KEY_SUPPORT_PROFILES, + cap->supportProfiles, PROFILE_NUM, INVALID_PROFILE}; + if (GetUintTableConfig(iface, childNode, &attr) != HDF_SUCCESS) { return HDF_FAILURE; } - if (iface->GetUint32(childNode, CODEC_CONFIG_KEY_MAX_BITRATE, (uint32_t*)&cap->maxBitRate, 0) != HDF_SUCCESS) { - cap->mime = MEDIA_MIMETYPE_INVALID; - HDF_LOGE("%{public}s, failed to get %{public}s for: %{public}s! Discarded", - __func__, CODEC_CONFIG_KEY_MAX_BITRATE, childNode->name); + cap->isSoftwareCodec = iface->GetBool(childNode, CODEC_CONFIG_KEY_IS_SOFTWARE_CODEC); + if (GetMaskedConfig(iface, childNode, CODEC_CONFIG_KEY_PROCESS_MODE_MASK, + (uint32_t *)&cap->processModeMask) != HDF_SUCCESS) { return HDF_FAILURE; } - if ((GetUintTableConfig(iface, childNode, CODEC_CONFIG_KEY_SUPPORT_PROFILES, &(cap->supportProfiles)) - != HDF_SUCCESS) - || (GetUintTableConfig(iface, childNode, CODEC_CONFIG_KEY_SUPPORT_LEVELS, &(cap->supportLevels)) - != HDF_SUCCESS) - || (GetUintTableConfig(iface, childNode, CODEC_CONFIG_KEY_SUPPORT_PIXELF_MTS, &(cap->supportPixelFormats)) - != HDF_SUCCESS)) { - cap->mime = MEDIA_MIMETYPE_INVALID; + if (GetMaskedConfig(iface, childNode, CODEC_CONFIG_KEY_CAPS_MASK, &cap->capsMask) != HDF_SUCCESS) { return HDF_FAILURE; } - if ((GetMaskedConfig(iface, childNode, CODEC_CONFIG_KEY_ALLOCATE_MASK, &cap->allocateMask) != HDF_SUCCESS) - || (GetMaskedConfig(iface, childNode, CODEC_CONFIG_KEY_CAPS_MASK, &cap->capsMask) != HDF_SUCCESS)) { - cap->mime = MEDIA_MIMETYPE_INVALID; + if (GetMaskedConfig(iface, childNode, CODEC_CONFIG_KEY_ALLOCATE_MASK, &cap->allocateMask) != HDF_SUCCESS) { return HDF_FAILURE; } if (GetBufferConfig(iface, childNode, cap) != HDF_SUCCESS) { return HDF_FAILURE; } - if (GetAudioOfCapability(iface, childNode, cap) != HDF_SUCCESS) { + if (GetBitRateConfig(iface, childNode, cap) != HDF_SUCCESS) { return HDF_FAILURE; } - if (GetVideoOfCapability(iface, childNode, cap) != HDF_SUCCESS) { - return HDF_FAILURE; + if (isVideoGroup) { + if (GetVideoOfCapability(iface, childNode, cap) != HDF_SUCCESS) { + return HDF_FAILURE; + } + } else { + if (GetAudioOfCapability(iface, childNode, cap) != HDF_SUCCESS) { + return HDF_FAILURE; + } } return HDF_SUCCESS; } @@ -232,8 +348,9 @@ static int32_t GetOneCapability(const struct DeviceResourceIface *iface, static int32_t GetGroupCapabilities(const struct DeviceResourceNode *node, const char *nodeName, CodecCapablityGroup *capsGroup) { - CodecCapbility *cap; + CodecCapability *cap; int32_t index = 0; + bool isVideoGroup = true; const struct DeviceResourceNode *codecGroupNode = NULL; struct DeviceResourceNode *childNode = NULL; struct DeviceResourceIface *iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); @@ -248,13 +365,16 @@ static int32_t GetGroupCapabilities(const struct DeviceResourceNode *node, HDF_LOGE("%{public}s, failed to get child node: %{public}s!", __func__, nodeName); return HDF_FAILURE; } + if (strstr(nodeName, "Video") == NULL) { + isVideoGroup = false; + } DEV_RES_NODE_FOR_EACH_CHILD_NODE(codecGroupNode, childNode) { if (index >= capsGroup->num) { HDF_LOGE("%{public}s, failed to get child node: %{public}s, index error!", __func__, nodeName); return HDF_FAILURE; } cap = &(capsGroup->capablitis[index++]); - GetOneCapability(iface, childNode, cap); + GetOneCapability(iface, childNode, cap, isVideoGroup); } return HDF_SUCCESS; } @@ -285,8 +405,8 @@ int32_t LoadCodecCapabilityFromHcs(const struct DeviceResourceNode *node) if (GetGroupCapabilitiesNumber(node, codecGroupsNodeName[index], &codecNum) == HDF_SUCCESS) { codecCapGroup->num = codecNum; if (codecNum > 0) { - size_t capablitisSize = sizeof(CodecCapbility) * codecNum; - codecCapGroup->capablitis = (CodecCapbility *)OsalMemAlloc(capablitisSize); + size_t capablitisSize = sizeof(CodecCapability) * codecNum; + codecCapGroup->capablitis = (CodecCapability *)OsalMemAlloc(capablitisSize); memset_s(codecCapGroup->capablitis, capablitisSize, 0, capablitisSize); } else { codecCapGroup->capablitis = NULL; diff --git a/codec/hdi_service/codec_service_stub/codec_config_parser.h b/codec/hdi_service/codec_service_stub/codec_config_parser.h index 979845d2b0c54b5c24a83702e4a203599ce366ea..da1a70e9b50ace39af105c861838f4272fdd1c25 100644 --- a/codec/hdi_service/codec_service_stub/codec_config_parser.h +++ b/codec/hdi_service/codec_service_stub/codec_config_parser.h @@ -27,8 +27,10 @@ #define CODEC_CONFIG_KEY_MIME "mime" #define CODEC_CONFIG_KEY_TYPE "type" +#define CODEC_CONFIG_KEY_NAME "name" #define CODEC_CONFIG_KEY_SUPPORT_PROFILES "supportProfiles" #define CODEC_CONFIG_KEY_IS_SOFTWARE_CODEC "isSoftwareCodec" +#define CODEC_CONFIG_KEY_PROCESS_MODE_MASK "processModeMask" #define CODEC_CONFIG_KEY_CAPS_MASK "capsMask" #define CODEC_CONFIG_KEY_ALLOCATE_MASK "allocateMask" #define CODEC_CONFIG_KEY_MIN_INPUT_BUFFER_NUM "minInputBufferNum" @@ -37,7 +39,8 @@ #define CODEC_CONFIG_KEY_MAX_OUTPUT_BUFFER_NUM "maxOutputBufferNum" #define CODEC_CONFIG_KEY_MIN_BITRATE "minBitRate" #define CODEC_CONFIG_KEY_MAX_BITRATE "maxBitRate" -#define CODEC_CONFIG_KEY_BUFFER_SIZE "bufferSize" +#define CODEC_CONFIG_KEY_INPUT_BUFFER_SIZE "inputBufferSize" +#define CODEC_CONFIG_KEY_OUTPUT_BUFFER_SIZE "outputBufferSize" #define CODEC_CONFIG_KEY_MIN_WIDTH "minWidth" #define CODEC_CONFIG_KEY_MIN_HEIGHT "minHeight" #define CODEC_CONFIG_KEY_MAX_WIDTH "maxWidth" @@ -45,10 +48,10 @@ #define CODEC_CONFIG_KEY_WIDTH_ALIGNMENT "widthAlignment" #define CODEC_CONFIG_KEY_HEIGHT_ALIGNMENT "heightAlignment" #define CODEC_CONFIG_KEY_SUPPORT_PIXELF_MTS "supportPixelFmts" -#define CODEC_CONFIG_KEY_SUPPORT_LEVELS "supportLevels" + #define CODEC_CONFIG_KEY_SAMPLE_FORMATS "sampleFormats" #define CODEC_CONFIG_KEY_SAMPLE_RATE "sampleRate" -#define CODEC_CONFIG_KEY_CHANNEL_COUNT "channelCount" +#define CODEC_CONFIG_KEY_CHANNEL_LAYOUTS "channelLayouts" #define CODEC_CAPABLITY_GROUP_NUM 8 @@ -62,7 +65,7 @@ typedef enum { typedef struct { int num; - CodecCapbility *capablitis; + CodecCapability *capablitis; } CodecCapablityGroup; typedef struct { @@ -77,6 +80,13 @@ typedef struct { CodecCapablityGroup audioSwDecoderGroup; } CodecCapablites; +typedef struct { + const char *attrName; + int32_t *array; + int32_t length; + int32_t endValue; +} ConfigUintArrayNodeAttr; + int32_t LoadCodecCapabilityFromHcs(const struct DeviceResourceNode *node); int32_t ClearCapabilityGroup(); CodecCapablityGroup *GetCapablityGroup(int32_t groupIndex); diff --git a/codec/hdi_service/codec_service_stub/codec_service.c b/codec/hdi_service/codec_service_stub/codec_service.c index 6ea9e7a72eff5d21971d5551000ad8a8a27cdbc5..176d3c9efbb4fad1142e32bfd9b4d6e845d1ba32 100644 --- a/codec/hdi_service/codec_service_stub/codec_service.c +++ b/codec/hdi_service/codec_service_stub/codec_service.c @@ -33,138 +33,53 @@ struct CodecInstance *g_codecInstance = NULL; -static void CopyInputInfo(InputInfo *dst, const InputInfo *src) -{ - if (dst == NULL || src == NULL) { - HDF_LOGE("%{public}s: Nullpoint, dst: %{public}p, src: %{public}p", __func__, dst, src); - return; - } - dst->bufferCnt = src->bufferCnt; - dst->pts = src->pts; - dst->flag = src->flag; - if (dst->bufferCnt > 0) { - int32_t size = sizeof(CodecBufferInfo) * dst->bufferCnt; - memcpy_s(dst->buffers, size, src->buffers, size); - } -} - -static InputInfo* DupInputInfo(const InputInfo *src) -{ - if (src == NULL) { - HDF_LOGE("%{public}s: inputinfo src Nullpoint", __func__); - return NULL; - } - InputInfo *dst = (InputInfo *)OsalMemAlloc(sizeof(InputInfo)); - if (dst == NULL) { - HDF_LOGE("%{public}s: dst Nullpoint", __func__); - return NULL; - } - dst->bufferCnt = src->bufferCnt; - dst->pts = src->pts; - dst->flag = src->flag; - if (dst->bufferCnt > 0) { - int32_t size = sizeof(CodecBufferInfo) * dst->bufferCnt; - dst->buffers = (CodecBufferInfo *)OsalMemAlloc(size); - if (dst->buffers != NULL) { - memcpy_s(dst->buffers, size, src->buffers, size); - } - } - return dst; -} - -static void CopyOutputInfo(OutputInfo *dst, OutputInfo *src) -{ - if (dst == NULL || src == NULL) { - HDF_LOGE("%{public}s: Nullpoint, dst: %{public}p, src: %{public}p", __func__, dst, src); - return; - } - dst->bufferCnt = src->bufferCnt; - dst->timeStamp = src->timeStamp; - dst->sequence = src->sequence; - dst->flag = src->flag; - dst->type = src->type; - dst->vendorPrivate = src->vendorPrivate; - if (dst->bufferCnt > 0) { - int32_t size = sizeof(CodecBufferInfo) * dst->bufferCnt; - memcpy_s(dst->buffers, size, src->buffers, size); - } -} - -static OutputInfo* DupOutputInfo(OutputInfo *src) -{ - if (src == NULL) { - HDF_LOGE("%{public}s: src Nullpoint", __func__); - return NULL; - } - OutputInfo *dst = (OutputInfo *)OsalMemAlloc(sizeof(OutputInfo)); - if (dst == NULL) { - HDF_LOGE("%{public}s: dst Nullpoint", __func__); - return NULL; - } - dst->bufferCnt = src->bufferCnt; - dst->timeStamp = src->timeStamp; - dst->sequence = src->sequence; - dst->flag = src->flag; - dst->type = src->type; - dst->vendorPrivate = src->vendorPrivate; - if (dst->bufferCnt > 0) { - int32_t size = sizeof(CodecBufferInfo) * dst->bufferCnt; - dst->buffers = (CodecBufferInfo *)OsalMemAlloc(size); - if (dst->buffers != NULL) { - memcpy_s(dst->buffers, size, src->buffers, size); - } - } - return dst; -} - -static int32_t DefaultCbOnEvent(UINTPTR comp, UINTPTR appData, EventType event, - uint32_t data1, uint32_t data2, UINTPTR eventData) +static int32_t DefaultCbOnEvent(UINTPTR userData, EventType event, uint32_t length, int32_t eventData[]) { return HDF_SUCCESS; } -static int32_t DefaultCbInputBufferAvailable(UINTPTR comp, UINTPTR appData, InputInfo *inBuf) +static int32_t DefaultCbInputBufferAvailable(UINTPTR userData, CodecBuffer *inBuf, int32_t *acquireFd) { - if (inBuf == NULL || inBuf->buffers == NULL) { - HDF_LOGE("%{public}s: inBuf Nullpoint", __func__); + if (inBuf == NULL || inBuf->bufferCnt == 0) { + HDF_LOGE("%{public}s: inBuf Nullpoint or buf not assigned", __func__); return HDF_FAILURE; } - InputInfo *inputInfo = GetInputInfo(g_codecInstance, inBuf->buffers->offset); - if (inputInfo == NULL || inputInfo->buffers == NULL) { - HDF_LOGE("%{public}s: inputInfo Nullpoint", __func__); + CodecBuffer *inputInfo = GetInputInfo(g_codecInstance, inBuf->bufferId); + if (inputInfo == NULL || inputInfo->bufferCnt == 0) { + HDF_LOGE("%{public}s: inputInfo Nullpoint or buf not assigned", __func__); return HDF_FAILURE; } - inputInfo->buffers->fd = GetFdById(g_codecInstance, inBuf->buffers->offset); - inputInfo->buffers->type = BUFFER_TYPE_FD; + inputInfo->buffer[0].buf = (intptr_t)GetFdById(g_codecInstance, inBuf->bufferId); + inputInfo->buffer[0].type = BUFFER_TYPE_FD; g_codecInstance->bufferManagerWrapper->PutUsedInputDataBuffer(g_codecInstance->bufferManagerWrapper, inputInfo); return HDF_SUCCESS; } -static int32_t DefaultCbOutputBufferAvailable(UINTPTR comp, UINTPTR appData, OutputInfo *outBuf) +static int32_t DefaultCbOutputBufferAvailable(UINTPTR userData, CodecBuffer *outBuf, int32_t *acquireFd) { - if (outBuf == NULL || outBuf->buffers == NULL) { - HDF_LOGE("%{public}s: outBuf Nullpoint", __func__); + if (outBuf == NULL || outBuf->bufferCnt == 0) { + HDF_LOGE("%{public}s: outBuf Nullpoint or buf not assigned", __func__); return HDF_FAILURE; } struct BufferManagerWrapper *bmWrapper = g_codecInstance->bufferManagerWrapper; - OutputInfo *outputInfo = GetOutputInfo(g_codecInstance, outBuf->buffers->offset); - if (outputInfo == NULL || outputInfo->buffers == NULL) { - HDF_LOGE("%{public}s: outputInfo Nullpoint", __func__); + CodecBuffer *outputInfo = GetOutputInfo(g_codecInstance, outBuf->bufferId); + if (outputInfo == NULL || outputInfo->bufferCnt == 0) { + HDF_LOGE("%{public}s: outputInfo Nullpoint or buf not assigned", __func__); return HDF_FAILURE; } - CopyOutputInfo(outputInfo, outBuf); - outputInfo->buffers->fd = GetFdById(g_codecInstance, outBuf->buffers->offset); - outputInfo->buffers->type = BUFFER_TYPE_FD; + CopyCodecBuffer(outputInfo, outBuf); + outputInfo->buffer[0].buf = (intptr_t)GetFdById(g_codecInstance, outBuf->bufferId); + outputInfo->buffer[0].type = BUFFER_TYPE_FD; bmWrapper->PutOutputDataBuffer(bmWrapper, outputInfo); // get a new OutputBuffer - OutputInfo *output = NULL; + CodecBuffer *output = NULL; while (output == NULL && g_codecInstance->codecStatus == CODEC_STATUS_STARTED) { output = bmWrapper->GetUsedOutputDataBuffer(bmWrapper, QUEUE_TIME_OUT); } - outBuf->buffers->type = BUFFER_TYPE_VIRTUAL; - outBuf->buffers->offset = output->buffers->offset; - outBuf->buffers->addr = GetOutputShm(g_codecInstance, output->buffers->offset)->virAddr; + outBuf->buffer[0].type = BUFFER_TYPE_VIRTUAL; + outBuf->bufferId = output->bufferId; + outBuf->buffer[0].buf = (intptr_t)GetOutputShm(g_codecInstance, output->bufferId)->virAddr; return HDF_SUCCESS; } @@ -194,11 +109,15 @@ int32_t CodecDeinit() return HDF_SUCCESS; } -int32_t CodecEnumerateCapbility(uint32_t index, CodecCapbility *cap) +int32_t CodecEnumerateCapability(uint32_t index, CodecCapability *cap) { int32_t loopIndex; uint32_t cursor = index; CodecCapablityGroup *group = NULL; + if (cursor + 1 < cursor) { + HDF_LOGE("%{public}s: the index out of bounds!", __func__); + return HDF_FAILURE; + } for (loopIndex = 0; loopIndex < CODEC_CAPABLITY_GROUP_NUM; loopIndex++) { group = GetCapablityGroup(loopIndex); if (group == NULL) { @@ -215,12 +134,12 @@ int32_t CodecEnumerateCapbility(uint32_t index, CodecCapbility *cap) return HDF_FAILURE; } -int32_t CodecGetCapbility(AvCodecMime mime, CodecType type, uint32_t flags, CodecCapbility *cap) +int32_t CodecGetCapability(AvCodecMime mime, CodecType type, uint32_t flags, CodecCapability *cap) { int32_t groupIndex; int32_t capIndex; CodecCapablityGroup *group = NULL; - CodecCapbility *capItem; + CodecCapability *capItem; bool inputHardwareFlag = flags == 0; for (groupIndex = 0; groupIndex < CODEC_CAPABLITY_GROUP_NUM; groupIndex++) { @@ -246,13 +165,13 @@ int32_t CodecGetCapbility(AvCodecMime mime, CodecType type, uint32_t flags, Code return HDF_FAILURE; } -int32_t CodecCreate(const char* name, const Param *attr, int32_t len, CODEC_HANDLETYPE *handle) +int32_t CodecCreate(const char* name, CODEC_HANDLETYPE *handle) { if (g_codecInstance == NULL || g_codecInstance->codecOemIface == NULL) { HDF_LOGE("%{public}s: g_codecInstance or oemIface is NULL!", __func__); return HDF_FAILURE; } - g_codecInstance->codecOemIface->CodecCreate(name, attr, len, handle); + g_codecInstance->codecOemIface->CodecCreate(name, handle); g_codecInstance->handle = *handle; HDF_LOGI("%{public}s codec created", __func__); return HDF_SUCCESS; @@ -268,7 +187,12 @@ int32_t CodecDestroy(CODEC_HANDLETYPE handle) return HDF_SUCCESS; } -int32_t CodecSetPortMode(CODEC_HANDLETYPE handle, DirectionType type, BufferMode mode) +int32_t CodecSetPortMode(CODEC_HANDLETYPE handle, DirectionType direct, AllocateBufferMode mode, BufferType type) +{ + return HDF_SUCCESS; +} + +int32_t CodecGetPortMode(CODEC_HANDLETYPE handle, DirectionType direct, AllocateBufferMode *mode, BufferType *type) { return HDF_SUCCESS; } @@ -279,6 +203,10 @@ int32_t CodecSetParameter(CODEC_HANDLETYPE handle, const Param *params, int32_t HDF_LOGE("%{public}s: g_codecInstance or oemIface is NULL!", __func__); return HDF_FAILURE; } + if (params == NULL || paramCnt <= 0) { + HDF_LOGE("%{public}s: params empty!", __func__); + return HDF_FAILURE; + } for (int32_t i = 0; i < paramCnt; i++) { if (params[i].key == KEY_CODEC_TYPE) { int32_t codecType = 0; @@ -296,6 +224,10 @@ int32_t CodecGetParameter(CODEC_HANDLETYPE handle, Param *params, int32_t paramC HDF_LOGE("%{public}s: g_codecInstance or oemIface is NULL!", __func__); return HDF_FAILURE; } + if (params == NULL || paramCnt <= 0) { + HDF_LOGE("%{public}s: params empty!", __func__); + return HDF_FAILURE; + } g_codecInstance->codecOemIface->CodecGetParameter(handle, params, paramCnt); return HDF_SUCCESS; } @@ -336,7 +268,7 @@ int32_t CodecFlush(CODEC_HANDLETYPE handle, DirectionType directType) return HDF_SUCCESS; } -int32_t CodecQueueInput(CODEC_HANDLETYPE handle, const InputInfo *inputInfo, uint32_t timeoutMs) +int32_t CodecQueueInput(CODEC_HANDLETYPE handle, const CodecBuffer *inputData, uint32_t timeoutMs, int releaseFenceFd) { if (g_codecInstance == NULL) { HDF_LOGE("%{public}s: g_codecInstance is NULL!", __func__); @@ -347,37 +279,38 @@ int32_t CodecQueueInput(CODEC_HANDLETYPE handle, const InputInfo *inputInfo, uin uint32_t i; if (g_codecInstance->codecType == VIDEO_DECODER || g_codecInstance->codecType == AUDIO_DECODER || g_codecInstance->codecType == VIDEO_ENCODER || g_codecInstance->codecType == AUDIO_ENCODER) { - for (i = 0; i < inputInfo->bufferCnt; i++) { - AddInputShm(g_codecInstance, &inputInfo->buffers[i]); + for (i = 0; i < inputData->bufferCnt; i++) { + AddInputShm(g_codecInstance, &inputData->buffer[i], inputData->bufferId); } } else { HDF_LOGE("%{public}s: codecType invalid, queue input buffer failed!", __func__); return HDF_FAILURE; } - InputInfo *dup = DupInputInfo(inputInfo); + CodecBuffer *dup = DupCodecBuffer(inputData); AddInputInfo(g_codecInstance, dup); g_codecInstance->bufferManagerWrapper->PutUsedInputDataBuffer(g_codecInstance->bufferManagerWrapper, dup); return HDF_SUCCESS; } else if (g_codecInstance->codecStatus == CODEC_STATUS_STARTED) { - InputInfo *info = GetInputInfo(g_codecInstance, inputInfo->buffers[0].offset); - CopyInputInfo(info, inputInfo); + CodecBuffer *info = GetInputInfo(g_codecInstance, inputData->bufferId); + CopyCodecBuffer(info, inputData); g_codecInstance->bufferManagerWrapper->PutInputDataBuffer(g_codecInstance->bufferManagerWrapper, info); return HDF_SUCCESS; } return HDF_SUCCESS; } -int32_t CodecDequeInput(CODEC_HANDLETYPE handle, uint32_t timeoutMs, InputInfo *inputData) +int32_t CodecDequeueInput(CODEC_HANDLETYPE handle, uint32_t timeoutMs, int32_t *acquireFd, CodecBuffer *inputData) { if (g_codecInstance == NULL) { HDF_LOGE("%{public}s: g_codecInstance is NULL!", __func__); return HDF_FAILURE; } - InputInfo *info = g_codecInstance->bufferManagerWrapper->GetUsedInputDataBuffer( + CodecBuffer *info = g_codecInstance->bufferManagerWrapper->GetUsedInputDataBuffer( g_codecInstance->bufferManagerWrapper, QUEUE_TIME_OUT); if (info != NULL) { - CopyInputInfo(inputData, info); + *acquireFd = -1; + CopyCodecBuffer(inputData, info); } else { return HDF_ERR_TIMEOUT; } @@ -385,7 +318,7 @@ int32_t CodecDequeInput(CODEC_HANDLETYPE handle, uint32_t timeoutMs, InputInfo * return HDF_SUCCESS; } -int32_t CodecQueueOutput(CODEC_HANDLETYPE handle, OutputInfo *outInfo, uint32_t timeoutMs, int32_t releaseFenceFd) +int32_t CodecQueueOutput(CODEC_HANDLETYPE handle, CodecBuffer *outInfo, uint32_t timeoutMs, int releaseFenceFd) { if (g_codecInstance == NULL || g_codecInstance->bufferManagerWrapper == NULL) { HDF_LOGE("%{public}s: g_codecInstance or buffermanager is NULL!", __func__); @@ -397,40 +330,40 @@ int32_t CodecQueueOutput(CODEC_HANDLETYPE handle, OutputInfo *outInfo, uint32_t if (g_codecInstance->codecType == VIDEO_DECODER || g_codecInstance->codecType == AUDIO_DECODER || g_codecInstance->codecType == VIDEO_ENCODER || g_codecInstance->codecType == AUDIO_ENCODER) { for (i = 0; i < outInfo->bufferCnt; i++) { - AddOutputShm(g_codecInstance, &outInfo->buffers[i]); + AddOutputShm(g_codecInstance, &outInfo->buffer[i], outInfo->bufferId); } } else { HDF_LOGE("%{public}s: codecType invalid, queue output buffer failed!", __func__); return HDF_FAILURE; } - OutputInfo *dup = DupOutputInfo(outInfo); + CodecBuffer *dup = DupCodecBuffer(outInfo); AddOutputInfo(g_codecInstance, dup); g_codecInstance->bufferManagerWrapper->PutUsedOutputDataBuffer(g_codecInstance->bufferManagerWrapper, dup); return HDF_SUCCESS; } else if (g_codecInstance->codecStatus == CODEC_STATUS_STARTED) { - OutputInfo *info = GetOutputInfo(g_codecInstance, outInfo->buffers->offset); - CopyOutputInfo(info, outInfo); + CodecBuffer *info = GetOutputInfo(g_codecInstance, outInfo->bufferId); + CopyCodecBuffer(info, outInfo); g_codecInstance->bufferManagerWrapper->PutUsedOutputDataBuffer(g_codecInstance->bufferManagerWrapper, info); return HDF_SUCCESS; } else if (g_codecInstance->codecStatus == CODEC_STATUS_STOPED) { - OutputInfo *dup = DupOutputInfo(outInfo); + CodecBuffer *dup = DupCodecBuffer(outInfo); g_codecInstance->bufferManagerWrapper->PutOutputDataBuffer(g_codecInstance->bufferManagerWrapper, dup); } return HDF_SUCCESS; } -int32_t CodecDequeueOutput(CODEC_HANDLETYPE handle, uint32_t timeoutMs, int32_t *acquireFd, OutputInfo *outInfo) +int32_t CodecDequeueOutput(CODEC_HANDLETYPE handle, uint32_t timeoutMs, int32_t *acquireFd, CodecBuffer *outInfo) { if (g_codecInstance == NULL || g_codecInstance->bufferManagerWrapper == NULL) { HDF_LOGE("%{public}s: g_codecInstance or buffermanager is NULL!", __func__); return HDF_FAILURE; } - OutputInfo *info = g_codecInstance->bufferManagerWrapper->GetOutputDataBuffer( + CodecBuffer *info = g_codecInstance->bufferManagerWrapper->GetOutputDataBuffer( g_codecInstance->bufferManagerWrapper, QUEUE_TIME_OUT); if (info != NULL) { - *acquireFd = 1; - CopyOutputInfo(outInfo, info); + *acquireFd = -1; + CopyCodecBuffer(outInfo, info); } else { return HDF_ERR_TIMEOUT; } diff --git a/codec/hdi_service/codec_service_stub/codec_service.h b/codec/hdi_service/codec_service_stub/codec_service.h index 7f4fa6407855553a6b9b18ff86fab76a4b6385d5..f71b8b2a62b7c1733ede5bd07cccbb17d59bef6d 100644 --- a/codec/hdi_service/codec_service_stub/codec_service.h +++ b/codec/hdi_service/codec_service_stub/codec_service.h @@ -27,20 +27,21 @@ extern "C" int32_t CodecInit(); int32_t CodecDeinit(); -int32_t CodecEnumerateCapbility(uint32_t index, CodecCapbility *cap); -int32_t CodecGetCapbility(AvCodecMime mime, CodecType type, uint32_t flags, CodecCapbility *cap); -int32_t CodecCreate(const char* name, const Param *attr, int len, CODEC_HANDLETYPE *handle); +int32_t CodecEnumerateCapability(uint32_t index, CodecCapability *cap); +int32_t CodecGetCapability(AvCodecMime mime, CodecType type, uint32_t flags, CodecCapability *cap); +int32_t CodecCreate(const char* name, CODEC_HANDLETYPE *handle); int32_t CodecDestroy(CODEC_HANDLETYPE handle); -int32_t CodecSetPortMode(CODEC_HANDLETYPE handle, DirectionType type, BufferMode mode); +int32_t CodecSetPortMode(CODEC_HANDLETYPE handle, DirectionType direct, AllocateBufferMode mode, BufferType type); +int32_t CodecGetPortMode(CODEC_HANDLETYPE handle, DirectionType direct, AllocateBufferMode *mode, BufferType *type); int32_t CodecSetParameter(CODEC_HANDLETYPE handle, const Param *params, int paramCnt); int32_t CodecGetParameter(CODEC_HANDLETYPE handle, Param *params, int paramCnt); int32_t CodecStart(CODEC_HANDLETYPE handle); int32_t CodecStop(CODEC_HANDLETYPE handle); int32_t CodecFlush(CODEC_HANDLETYPE handle, DirectionType directType); -int32_t CodecQueueInput(CODEC_HANDLETYPE handle, const InputInfo *inputData, uint32_t timeoutMs); -int32_t CodecDequeInput(CODEC_HANDLETYPE handle, uint32_t timeoutMs, InputInfo *inputData); -int32_t CodecQueueOutput(CODEC_HANDLETYPE handle, OutputInfo *outInfo, uint32_t timeoutMs, int releaseFenceFd); -int32_t CodecDequeueOutput(CODEC_HANDLETYPE handle, uint32_t timeoutMs, int *acquireFd, OutputInfo *outInfo); +int32_t CodecQueueInput(CODEC_HANDLETYPE handle, const CodecBuffer *inputData, uint32_t timeoutMs, int releaseFenceFd); +int32_t CodecDequeueInput(CODEC_HANDLETYPE handle, uint32_t timeoutMs, int32_t *acquireFd, CodecBuffer *inputData); +int32_t CodecQueueOutput(CODEC_HANDLETYPE handle, CodecBuffer *outInfo, uint32_t timeoutMs, int releaseFenceFd); +int32_t CodecDequeueOutput(CODEC_HANDLETYPE handle, uint32_t timeoutMs, int32_t *acquireFd, CodecBuffer *outInfo); int32_t CodecSetCallback(CODEC_HANDLETYPE handle, const CodecCallback *cb, UINTPTR instance); #ifdef __cplusplus diff --git a/codec/hdi_service/codec_service_stub/codec_stub.c b/codec/hdi_service/codec_service_stub/codec_stub.c index f02ede23a05b93b09daa6b0cf96c89263b987d3f..1ef78b1f5e5a832dabe89430a1564cb998cbef96 100644 --- a/codec/hdi_service/codec_service_stub/codec_stub.c +++ b/codec/hdi_service/codec_service_stub/codec_stub.c @@ -54,11 +54,11 @@ static int32_t SerCodecDeinit(struct HdfDeviceIoClient *client, struct HdfSBuf * return errNum; } -static int32_t SerCodecEnumerateCapbility(struct HdfDeviceIoClient *client, struct HdfSBuf *data, +static int32_t SerCodecEnumerateCapability(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { uint32_t index; - CodecCapbility capbility; + CodecCapability Capability; if (!HdfSbufReadUint32(data, &index)) { HDF_LOGE("%{public}s: read index failed!", __func__); @@ -68,27 +68,27 @@ static int32_t SerCodecEnumerateCapbility(struct HdfDeviceIoClient *client, stru HDF_LOGE("%{public}s: codec capabilities not inited!", __func__); return HDF_FAILURE; } - if (CodecEnumerateCapbility(index, &capbility) != HDF_SUCCESS) { + if (CodecEnumerateCapability(index, &Capability) != HDF_SUCCESS) { HDF_LOGE("%{public}s: EnumrateCapablity - no more capability to Enumrate!", __func__); return HDF_FAILURE; } - if (capbility.mime == MEDIA_MIMETYPE_INVALID) { + if (Capability.mime == MEDIA_MIMETYPE_INVALID) { HDF_LOGE("%{public}s: Capability invalid, discard!", __func__); return HDF_FAILURE; } - if (CodecSerPackCapbility(reply, &capbility) != HDF_SUCCESS) { - HDF_LOGE("%{public}s: write capbility to sbuf failed!", __func__); + if (CodecSerPackCapability(reply, &Capability) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: write Capability to sbuf failed!", __func__); return HDF_FAILURE; } return HDF_SUCCESS; } -static int32_t SerCodecGetCapbility(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +static int32_t SerCodecGetCapability(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { uint32_t flags; AvCodecMime mime; CodecType type; - CodecCapbility capbility; + CodecCapability Capability; if (!HdfSbufReadUint32(data, (uint32_t*)&mime)) { HDF_LOGE("%{public}s: read input mime failed!", __func__); @@ -102,12 +102,12 @@ static int32_t SerCodecGetCapbility(struct HdfDeviceIoClient *client, struct Hdf HDF_LOGE("%{public}s: read input flags failed!", __func__); return HDF_ERR_INVALID_PARAM; } - if (CodecGetCapbility(mime, type, flags, &capbility) != HDF_SUCCESS) { + if (CodecGetCapability(mime, type, flags, &Capability) != HDF_SUCCESS) { HDF_LOGE("%{public}s: GetCapability - got nothing!", __func__); return HDF_FAILURE; } - if (CodecSerPackCapbility(reply, &capbility) != HDF_SUCCESS) { - HDF_LOGE("%{public}s: write capbility to sbuf failed!", __func__); + if (CodecSerPackCapability(reply, &Capability) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: write Capability to sbuf failed!", __func__); return HDF_FAILURE; } return HDF_SUCCESS; @@ -115,39 +115,20 @@ static int32_t SerCodecGetCapbility(struct HdfDeviceIoClient *client, struct Hdf static int32_t SerCodecCreate(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { - int32_t len = 0; int32_t errNum; uint64_t handle = 0; - uint32_t dateSize = 0; const char *name = NULL; - Param attr; name = HdfSbufReadString(data); if (name == NULL) { HDF_LOGE("%{public}s: Read name failed!", __func__); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufReadUint32(data, (uint32_t *)&attr.key)) { - HDF_LOGE("%{public}s: Read name failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - if (!HdfSbufReadInt32(data, &attr.size)) { - HDF_LOGE("%{public}s: Read size failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } - if (!HdfSbufReadBuffer(data, (const void **)&attr.val, &dateSize)) { - HDF_LOGE("%{public}s: struct attr's value Read failed", __func__); - return HDF_ERR_INVALID_PARAM; - } - if (!HdfSbufReadInt32(data, &len)) { - HDF_LOGE("%{public}s: Read name failed!", __func__); - return HDF_ERR_INVALID_PARAM; - } if (!HdfSbufReadUint64(data, &handle)) { HDF_LOGE("%{public}s: Read handle failed!", __func__); return HDF_ERR_INVALID_PARAM; } - errNum = CodecCreate(name, (const Param *)&attr, len, (CODEC_HANDLETYPE *)&handle); + errNum = CodecCreate(name, (CODEC_HANDLETYPE *)&handle); if (errNum != HDF_SUCCESS) { HDF_LOGE("%{public}s: call CodecCreate fuc failed!", __func__); return errNum; @@ -158,6 +139,7 @@ static int32_t SerCodecCreate(struct HdfDeviceIoClient *client, struct HdfSBuf * } return errNum; } + static int32_t SerCodecDestroy(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { int32_t errNum; @@ -178,22 +160,27 @@ static int32_t SerCodecSetPortMode(struct HdfDeviceIoClient *client, struct HdfS { int32_t errNum; uint64_t handle = 0; - DirectionType type; - BufferMode mode; + DirectionType direct; + AllocateBufferMode mode; + BufferType type; if (!HdfSbufReadUint64(data, &handle)) { - HDF_LOGE("%{public}s: Read size failed!", __func__); + HDF_LOGE("%{public}s: Read handle failed!", __func__); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufReadUint32(data, (uint32_t*)&type)) { - HDF_LOGE("%{public}s: Read size failed!", __func__); + if (!HdfSbufReadUint32(data, (uint32_t*)&direct)) { + HDF_LOGE("%{public}s: Read DirectionType failed!", __func__); return HDF_ERR_INVALID_PARAM; } if (!HdfSbufReadUint32(data, (uint32_t*)&mode)) { - HDF_LOGE("%{public}s: Read size failed!", __func__); + HDF_LOGE("%{public}s: Read AllocateBufferMode failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (!HdfSbufReadUint32(data, (uint32_t*)&type)) { + HDF_LOGE("%{public}s: Read BufferType failed!", __func__); return HDF_ERR_INVALID_PARAM; } - errNum = CodecSetPortMode((CODEC_HANDLETYPE)(uintptr_t)handle, type, mode); + errNum = CodecSetPortMode((CODEC_HANDLETYPE)(uintptr_t)handle, direct, mode, type); if (errNum != HDF_SUCCESS) { HDF_LOGE("%{public}s: call CodecSetPortMode fuc failed!", __func__); return errNum; @@ -201,6 +188,38 @@ static int32_t SerCodecSetPortMode(struct HdfDeviceIoClient *client, struct HdfS return errNum; } +static int32_t SerCodecGetPortMode(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + int32_t errNum; + uint64_t handle = 0; + DirectionType direct; + AllocateBufferMode mode; + BufferType type; + + if (!HdfSbufReadUint64(data, &handle)) { + HDF_LOGE("%{public}s: Read handle failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (!HdfSbufReadUint32(data, (uint32_t*)&direct)) { + HDF_LOGE("%{public}s: Read DirectionType failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + errNum = CodecGetPortMode((CODEC_HANDLETYPE)(uintptr_t)handle, direct, &mode, &type); + if (errNum != HDF_SUCCESS) { + HDF_LOGE("%{public}s: call CodecSetPortMode fuc failed!", __func__); + return errNum; + } + if (!HdfSbufWriteUint32(reply, (uint32_t)mode)) { + HDF_LOGE("%{public}s: write AllocateBufferMode failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (!HdfSbufWriteUint32(reply, (uint32_t)type)) { + HDF_LOGE("%{public}s: write BufferType failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + return HDF_SUCCESS; +} + static void FreeParams(Param *params, int32_t paramCnt) { if (params == NULL || paramCnt <= 0) { @@ -255,6 +274,7 @@ static int32_t SerCodecSetParameter(struct HdfDeviceIoClient *client, struct Hdf FreeParams(params, paramCnt); return errNum; } + static int32_t SerCodecGetParameter(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { int32_t errNum; @@ -303,6 +323,7 @@ static int32_t SerCodecGetParameter(struct HdfDeviceIoClient *client, struct Hdf FreeParams(params, paramCnt); return errNum; } + static int32_t SerCodecStart(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { int32_t errNum; @@ -334,6 +355,7 @@ static int32_t SerCodecStop(struct HdfDeviceIoClient *client, struct HdfSBuf *da } return errNum; } + static int32_t SerCodecFlush(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { uint64_t handle = 0; @@ -353,54 +375,65 @@ static int32_t SerCodecFlush(struct HdfDeviceIoClient *client, struct HdfSBuf *d } return errNum; } -int32_t SerCodecQueueInput(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) + +static int32_t SerCodecQueueInput(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { uint32_t timeoutMs = 0; + int releaseFenceFd = -1; uint64_t handle = 0; - uint32_t bufCnt; - InputInfo inputData = {0}; + uint32_t bufCnt = 0; + CodecBuffer *inputData = NULL; if (!HdfSbufReadUint64(data, &handle)) { HDF_LOGE("%{public}s: read handle data failed!", __func__); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufReadUint32(data, (uint32_t *)&inputData.bufferCnt)) { + if (!HdfSbufReadUint32(data, &bufCnt)) { HDF_LOGE("%{public}s: read bufferCnt failed!", __func__); return HDF_ERR_INVALID_PARAM; } - bufCnt = inputData.bufferCnt; if (bufCnt <= 0) { HDF_LOGE("%{public}s: Param bufCnt err!", __func__); return HDF_ERR_INVALID_PARAM; } - inputData.buffers = (CodecBufferInfo *)OsalMemAlloc(sizeof(CodecBufferInfo) * bufCnt); - if (inputData.buffers == NULL) { + inputData = (CodecBuffer *)OsalMemAlloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo) * bufCnt); + if (inputData == NULL) { HDF_LOGE("%{public}s: OsalMemAlloc failed!", __func__); - return HDF_ERR_INVALID_PARAM; + return HDF_ERR_MALLOC_FAIL; } - if (CodecSerParseInputInfo(data, &inputData)) { + inputData->bufferCnt = bufCnt; + if (CodecSerParseCodecBuffer(data, inputData)) { HDF_LOGE("%{public}s: read inputData failed!", __func__); - OsalMemFree(inputData.buffers); + OsalMemFree(inputData); return HDF_ERR_INVALID_PARAM; } if (!HdfSbufReadUint32(data, &timeoutMs)) { HDF_LOGE("%{public}s: read timeoutMs data failed!", __func__); - OsalMemFree(inputData.buffers); + OsalMemFree(inputData); return HDF_ERR_INVALID_PARAM; } - int32_t errNum = CodecQueueInput((CODEC_HANDLETYPE)(uintptr_t)handle, &inputData, timeoutMs); + if (CodecSerParseFenceFd(data, &releaseFenceFd) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: read releaseFenceFd failed!", __func__); + OsalMemFree(inputData); + return HDF_ERR_INVALID_PARAM; + } + int32_t errNum = CodecQueueInput((CODEC_HANDLETYPE)(uintptr_t)handle, inputData, timeoutMs, releaseFenceFd); if (errNum != HDF_SUCCESS) { HDF_LOGE("%{public}s: call CodecQueueInput fuc failed!", __func__); - OsalMemFree(inputData.buffers); + OsalMemFree(inputData); return errNum; } - OsalMemFree(inputData.buffers); - return errNum; + + OsalMemFree(inputData); + return HDF_SUCCESS; } -static int32_t SerCodecDequeInput(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) + +static int32_t SerCodecDequeueInput(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { uint32_t timeoutMs = 0; uint64_t handle = 0; - InputInfo inputData = {0}; + uint32_t bufCnt = 0; + int32_t acquireFd = 0; + CodecBuffer *inputData = NULL; if (!HdfSbufReadUint64(data, &handle)) { HDF_LOGE("%{public}s: read handle data failed!", __func__); return HDF_ERR_INVALID_PARAM; @@ -409,85 +442,100 @@ static int32_t SerCodecDequeInput(struct HdfDeviceIoClient *client, struct HdfSB HDF_LOGE("%{public}s: read timeoutMs data failed!", __func__); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufReadUint32(data, &inputData.bufferCnt)) { - HDF_LOGE("%{public}s: read bufferCnt data failed!", __func__); + if (!HdfSbufReadUint32(data, &bufCnt)) { + HDF_LOGE("%{public}s: read bufferCnt failed!", __func__); return HDF_ERR_INVALID_PARAM; } - if (inputData.bufferCnt <= 0) { - HDF_LOGE("%{public}s: Param bufferCnt err!", __func__); + if (bufCnt <= 0) { + HDF_LOGE("%{public}s: Param bufCnt err!", __func__); return HDF_ERR_INVALID_PARAM; } - inputData.buffers = (CodecBufferInfo *)OsalMemAlloc(sizeof(CodecBufferInfo) * (inputData.bufferCnt)); - if (inputData.buffers == NULL) { + inputData = (CodecBuffer *)OsalMemAlloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo) * bufCnt); + if (inputData == NULL) { HDF_LOGE("%{public}s: OsalMemAlloc failed!", __func__); - return HDF_ERR_INVALID_PARAM; + return HDF_ERR_MALLOC_FAIL; } - int32_t errNum = CodecDequeInput((CODEC_HANDLETYPE)(uintptr_t)handle, timeoutMs, &inputData); + inputData->bufferCnt = bufCnt; + int32_t errNum = CodecDequeueInput((CODEC_HANDLETYPE)(uintptr_t)handle, timeoutMs, &acquireFd, inputData); if (errNum != HDF_SUCCESS) { if (errNum != HDF_ERR_TIMEOUT) { HDF_LOGE("%{public}s: call CodecDequeInput fuc failed!", __func__); } - OsalMemFree(inputData.buffers); + OsalMemFree(inputData); return errNum; } - if (CodecSerPackInputInfo(reply, &inputData)) { + if (CodecSerPackFenceFd(reply, acquireFd) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: write acquireFd failed!", __func__); + OsalMemFree(inputData); + return HDF_ERR_INVALID_PARAM; + } + if (CodecSerPackCodecBuffer(reply, inputData)) { HDF_LOGE("%{public}s: struct inputData write failed!", __func__); - OsalMemFree(inputData.buffers); + OsalMemFree(inputData); return HDF_ERR_INVALID_PARAM; } - OsalMemFree(inputData.buffers); - return errNum; + OsalMemFree(inputData); + return HDF_SUCCESS; } + static int32_t SerCodecQueueOutput(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { uint32_t timeoutMs = 0; - int releaseFenceFd = 1; + int releaseFenceFd = -1; uint64_t handle = 0; - uint32_t bufCnt; - OutputInfo outInfo = {0}; + uint32_t bufCnt = 0; + CodecBuffer *outInfo = NULL; if (!HdfSbufReadUint64(data, &handle)) { HDF_LOGE("%{public}s: read handle data failed!", __func__); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufReadUint32(data, (uint32_t *)&outInfo.bufferCnt)) { + if (!HdfSbufReadUint32(data, &bufCnt)) { HDF_LOGE("%{public}s: read bufferCnt failed!", __func__); return HDF_ERR_INVALID_PARAM; } - bufCnt = outInfo.bufferCnt; if (bufCnt <= 0) { - HDF_LOGE("%{public}s: Param bufferCnt err!", __func__); + HDF_LOGE("%{public}s: Param bufCnt err!", __func__); return HDF_ERR_INVALID_PARAM; } - outInfo.buffers = (CodecBufferInfo *)OsalMemAlloc(sizeof(CodecBufferInfo) * bufCnt); - if (outInfo.buffers == NULL) { + outInfo = (CodecBuffer *)OsalMemAlloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo) * bufCnt); + if (outInfo == NULL) { HDF_LOGE("%{public}s: OsalMemAlloc failed!", __func__); - return HDF_ERR_INVALID_PARAM; + return HDF_ERR_MALLOC_FAIL; } - if (CodecSerParseOutputInfo(data, &outInfo)) { + outInfo->bufferCnt = bufCnt; + if (CodecSerParseCodecBuffer(data, outInfo)) { HDF_LOGE("%{public}s: read struct data failed!", __func__); - OsalMemFree(outInfo.buffers); + OsalMemFree(outInfo); return HDF_ERR_INVALID_PARAM; } if (!HdfSbufReadUint32(data, &timeoutMs)) { HDF_LOGE("%{public}s: read timeoutMs data failed!", __func__); - OsalMemFree(outInfo.buffers); + OsalMemFree(outInfo); + return HDF_ERR_INVALID_PARAM; + } + if (CodecSerParseFenceFd(data, &releaseFenceFd) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: read releaseFenceFd failed!", __func__); + OsalMemFree(outInfo); return HDF_ERR_INVALID_PARAM; } - int32_t errNum = CodecQueueOutput((CODEC_HANDLETYPE)(uintptr_t)handle, &outInfo, timeoutMs, releaseFenceFd); + int32_t errNum = CodecQueueOutput((CODEC_HANDLETYPE)(uintptr_t)handle, outInfo, timeoutMs, releaseFenceFd); if (errNum != HDF_SUCCESS) { HDF_LOGE("%{public}s: call CodecQueueOutput fuc failed!", __func__); - OsalMemFree(outInfo.buffers); + OsalMemFree(outInfo); return errNum; } - OsalMemFree(outInfo.buffers); - return errNum; + + OsalMemFree(outInfo); + return HDF_SUCCESS; } + static int32_t SerCodecDequeueOutput(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) { uint32_t timeoutMs = 0; - int acquireFd = 0; + int32_t acquireFd = 0; uint64_t handle = 0; - OutputInfo outInfo = {0}; + uint32_t bufCnt = 0; + CodecBuffer *outInfo = NULL; if (!HdfSbufReadUint64(data, &handle)) { HDF_LOGE("%{public}s: read handle data failed!", __func__); return HDF_ERR_INVALID_PARAM; @@ -496,35 +544,41 @@ static int32_t SerCodecDequeueOutput(struct HdfDeviceIoClient *client, struct Hd HDF_LOGE("%{public}s: read timeoutMs data failed!", __func__); return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufReadUint32(data, &outInfo.bufferCnt)) { - HDF_LOGE("%{public}s: read bufferCnt data failed!", __func__); + if (!HdfSbufReadUint32(data, &bufCnt)) { + HDF_LOGE("%{public}s: read bufferCnt failed!", __func__); return HDF_ERR_INVALID_PARAM; } - outInfo.buffers = (CodecBufferInfo *)OsalMemAlloc(sizeof(CodecBufferInfo) * (outInfo.bufferCnt)); - if (outInfo.buffers == NULL) { - HDF_LOGE("%{public}s: OsalMemAlloc failed!", __func__); + if (bufCnt <= 0) { + HDF_LOGE("%{public}s: Param bufCnt err!", __func__); return HDF_ERR_INVALID_PARAM; } - int32_t errNum = CodecDequeueOutput((CODEC_HANDLETYPE)(uintptr_t)handle, timeoutMs, &acquireFd, &outInfo); + outInfo = (CodecBuffer *)OsalMemAlloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo) * bufCnt); + if (outInfo == NULL) { + HDF_LOGE("%{public}s: OsalMemAlloc failed!", __func__); + return HDF_ERR_MALLOC_FAIL; + } + outInfo->bufferCnt = bufCnt; + + int32_t errNum = CodecDequeueOutput((CODEC_HANDLETYPE)(uintptr_t)handle, timeoutMs, &acquireFd, outInfo); if (errNum != HDF_SUCCESS) { if (errNum != HDF_ERR_TIMEOUT) { HDF_LOGE("%{public}s: call CodecDequeueOutput fuc failed!", __func__); } - OsalMemFree(outInfo.buffers); + OsalMemFree(outInfo); return errNum; } - if (!HdfSbufWriteFileDescriptor(reply, acquireFd)) { + if (CodecSerPackFenceFd(reply, acquireFd) != HDF_SUCCESS) { HDF_LOGE("%{public}s: write acquireFd failed!", __func__); - OsalMemFree(outInfo.buffers); + OsalMemFree(outInfo); return HDF_ERR_INVALID_PARAM; } - if (CodecSerPackOutputInfo(reply, &outInfo)) { + if (CodecSerPackCodecBuffer(reply, outInfo)) { HDF_LOGE("%{public}s: write outInfo buffer failed!", __func__); - OsalMemFree(outInfo.buffers); + OsalMemFree(outInfo); return HDF_ERR_INVALID_PARAM; } - OsalMemFree(outInfo.buffers); - return errNum; + OsalMemFree(outInfo); + return HDF_SUCCESS; } static int32_t SerCodecSetCallback(struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply) @@ -554,33 +608,26 @@ static int32_t SerCodecSetCallback(struct HdfDeviceIoClient *client, struct HdfS return errNum; } -int32_t CodecServiceOnRemoteRequest(struct HdfDeviceIoClient *client, int cmdId, +int32_t HandleRequestCmd(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply) { - if (!HdfDeviceObjectCheckInterfaceDesc(client->device, data)) { - HDF_LOGE("check interface token failed"); - return HDF_ERR_INVALID_PARAM; - } - if ((cmdId == CMD_CODEC_ENUM_CAP) || (cmdId == CMD_CODEC_GET_CAP)) { - if (!CodecCapablitesInited()) { - ReloadCapabilities(); - } - } switch (cmdId) { case CMD_CODEC_INIT: return SerCodecInit(client, data, reply); case CMD_CODEC_DEINIT: return SerCodecDeinit(client, data, reply); case CMD_CODEC_ENUM_CAP: - return SerCodecEnumerateCapbility(client, data, reply); + return SerCodecEnumerateCapability(client, data, reply); case CMD_CODEC_GET_CAP: - return SerCodecGetCapbility(client, data, reply); + return SerCodecGetCapability(client, data, reply); case CMD_CODEC_CREATE: return SerCodecCreate(client, data, reply); case CMD_CODEC_DESTROY: return SerCodecDestroy(client, data, reply); case CMD_CODEC_SET_MODE: return SerCodecSetPortMode(client, data, reply); + case CMD_CODEC_GET_MODE: + return SerCodecGetPortMode(client, data, reply); case CMD_CODEC_SET_PARAMS: return SerCodecSetParameter(client, data, reply); case CMD_CODEC_GET_PARAMS: @@ -594,7 +641,7 @@ int32_t CodecServiceOnRemoteRequest(struct HdfDeviceIoClient *client, int cmdId, case CMD_CODEC_QUEQUE_INPUT: return SerCodecQueueInput(client, data, reply); case CMD_CODEC_DEQUEQUE_INPUT: - return SerCodecDequeInput(client, data, reply); + return SerCodecDequeueInput(client, data, reply); case CMD_CODEC_QUEQUE_OUTPUT: return SerCodecQueueOutput(client, data, reply); case CMD_CODEC_DEQUEQUE_OUTPUT: @@ -607,3 +654,18 @@ int32_t CodecServiceOnRemoteRequest(struct HdfDeviceIoClient *client, int cmdId, } } } + +int32_t CodecServiceOnRemoteRequest(struct HdfDeviceIoClient *client, int cmdId, + struct HdfSBuf *data, struct HdfSBuf *reply) +{ + if (!HdfDeviceObjectCheckInterfaceDesc(client->device, data)) { + HDF_LOGE("check interface token failed"); + return HDF_ERR_INVALID_PARAM; + } + if ((cmdId == CMD_CODEC_ENUM_CAP) || (cmdId == CMD_CODEC_GET_CAP)) { + if (!CodecCapablitesInited()) { + ReloadCapabilities(); + } + } + return HandleRequestCmd(client, cmdId, data, reply); +} diff --git a/codec/hdi_service/codec_service_stub/stub_msgproc.c b/codec/hdi_service/codec_service_stub/stub_msgproc.c index 484d4ec6ec91e009f6ca28890979039d6bc1a39f..e930768af37c311f4e961120e813f4ce1606a9e2 100644 --- a/codec/hdi_service/codec_service_stub/stub_msgproc.c +++ b/codec/hdi_service/codec_service_stub/stub_msgproc.c @@ -52,72 +52,114 @@ int32_t CodecSerPackRect(struct HdfSBuf *reply, Rect *rectangle) return HDF_SUCCESS; } -int32_t CodecSerPackArray(struct HdfSBuf *reply, ResizableArray *resArr) +static bool CodecCapabilityBaseMarshalling(struct HdfSBuf *reply, CodecCapability *cap) { - if (reply == NULL || resArr == NULL) { - HDF_LOGE("%{public}s: params null!", __func__); - return HDF_ERR_INVALID_PARAM; + if (!HdfSbufWriteUint32(reply, (uint32_t)cap->mime)) { + HDF_LOGE("%{public}s: write cap->mime failed!", __func__); + return false; } - - if (!HdfSbufWriteUint32(reply, resArr->actualLen)) { - HDF_LOGE("%{public}s: Write actualLen failed!", __func__); - return HDF_FAILURE; + if (!HdfSbufWriteUint32(reply, (uint32_t)cap->type)) { + HDF_LOGE("%{public}s: write cap->type failed!", __func__); + return false; } - for (uint32_t i = 0; i < resArr->actualLen; i++) { - if (!HdfSbufWriteUint32(reply, resArr->element[i])) { - HDF_LOGE("%{public}s: Write HdfSubf failed!", __func__); - return HDF_FAILURE; + for (uint32_t i = 0; i < NAME_LENGTH; i++) { + if (!HdfSbufWriteUint8(reply, (uint8_t)(cap->name)[i])) { + HDF_LOGE("%{public}s: write (cap->name)[i] failed!", __func__); + return false; } } - return HDF_SUCCESS; -} - -int32_t CodecSerPackCapbility(struct HdfSBuf *reply, CodecCapbility *cap) -{ - if (reply == NULL || cap == NULL) { - HDF_LOGE("%{public}s: params null!", __func__); - return HDF_ERR_INVALID_PARAM; + for (uint32_t i = 0; i < PROFILE_NUM; i++) { + if (!HdfSbufWriteInt32(reply, (cap->supportProfiles)[i])) { + HDF_LOGE("%{public}s: write (cap->supportProfiles)[i] failed!", __func__); + return false; + } } - if (!HdfSbufWriteUint32(reply, (uint32_t)cap->mime)) { - return HDF_FAILURE; + if (!HdfSbufWriteInt8(reply, cap->isSoftwareCodec ? 1 : 0)) { + HDF_LOGE("%{public}s: write cap->isSoftwareCodec failed!", __func__); + return false; } - if (!HdfSbufWriteUint32(reply, (uint32_t)cap->type)) { - return HDF_FAILURE; + if (!HdfSbufWriteInt32(reply, cap->processModeMask)) { + HDF_LOGE("%{public}s: write cap->processModeMask failed!", __func__); + return false; } - if (CodecSerPackAlignment(reply, &cap->whAlignment) != HDF_SUCCESS) { - return HDF_FAILURE; + if (!HdfSbufWriteUint32(reply, cap->capsMask)) { + HDF_LOGE("%{public}s: write cap->capsMask failed!", __func__); + return false; } - if (CodecSerPackRect(reply, &cap->minSize) != HDF_SUCCESS) { - return HDF_FAILURE; + if (!HdfSbufWriteUint32(reply, cap->allocateMask)) { + HDF_LOGE("%{public}s: write cap->allocateMask failed!", __func__); + return false; } - if (CodecSerPackRect(reply, &cap->maxSize) != HDF_SUCCESS) { - return HDF_FAILURE; + return true; +} + +static bool CodecCapabilityRangeValueMarshalling(struct HdfSBuf *reply, const RangeValue *dataBlock) +{ + if (!HdfSbufWriteInt32(reply, dataBlock->min)) { + HDF_LOGE("%{public}s: write dataBlock->min failed!", __func__); + return false; } - if (!HdfSbufWriteUint64(reply, cap->minBitRate)) { - return HDF_FAILURE; + + if (!HdfSbufWriteInt32(reply, dataBlock->max)) { + HDF_LOGE("%{public}s: write dataBlock->max failed!", __func__); + return false; } - if (!HdfSbufWriteUint64(reply, cap->maxBitRate)) { - return HDF_FAILURE; + + return true; +} + +static bool CodecCapabilityPortMarshalling(struct HdfSBuf *reply, CodecCapability *cap) +{ + if (cap->type < AUDIO_DECODER) { + if (!HdfSbufWriteUnpadBuffer(reply, (const uint8_t *)&cap->port, sizeof(VideoPortCap))) { + HDF_LOGE("%{public}s: write video failed!", __func__); + return false; + } + } else if (cap->type < INVALID_TYPE) { + if (!HdfSbufWriteUnpadBuffer(reply, (const uint8_t *)&cap->port, sizeof(AudioPortCap))) { + HDF_LOGE("%{public}s: write audio failed!", __func__); + return false; + } + } else { + if (!HdfSbufWriteUnpadBuffer(reply, (const uint8_t *)&cap->port, sizeof(cap->port))) { + HDF_LOGE("%{public}s: write port failed!", __func__); + return false; + } } - if (CodecSerPackArray(reply, &cap->supportProfiles) != HDF_SUCCESS) { - return HDF_FAILURE; + return true; +} + +int32_t CodecSerPackCapability(struct HdfSBuf *reply, CodecCapability *cap) +{ + if (reply == NULL || cap == NULL) { + HDF_LOGE("%{public}s: params null!", __func__); + return HDF_ERR_INVALID_PARAM; } - if (CodecSerPackArray(reply, &cap->supportLevels) != HDF_SUCCESS) { + if (!CodecCapabilityBaseMarshalling(reply, cap)) { return HDF_FAILURE; } - if (CodecSerPackArray(reply, &cap->supportPixelFormats) != HDF_SUCCESS) { + if (!CodecCapabilityRangeValueMarshalling(reply, &cap->inputBufferNum)) { + HDF_LOGE("%{public}s: write cap->inputBufferNum failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufWriteUint32(reply, cap->minInputBufferNum)) { + if (!CodecCapabilityRangeValueMarshalling(reply, &cap->outputBufferNum)) { + HDF_LOGE("%{public}s: write cap->outputBufferNum failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufWriteUint32(reply, cap->minOutputBufferNum)) { + if (!CodecCapabilityRangeValueMarshalling(reply, &cap->bitRate)) { + HDF_LOGE("%{public}s: write cap->bitRate failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufWriteUint32(reply, cap->allocateMask)) { - return HDF_FAILURE; + if (!HdfSbufWriteInt32(reply, cap->inputBufferSize)) { + HDF_LOGE("%{public}s: write cap->inputBufferSize failed!", __func__); + return false; } - if (!HdfSbufWriteUint32(reply, cap->capsMask)) { + if (!HdfSbufWriteInt32(reply, cap->outputBufferSize)) { + HDF_LOGE("%{public}s: write cap->outputBufferSize failed!", __func__); + return false; + } + if (!CodecCapabilityPortMarshalling(reply, cap)) { + HDF_LOGE("%{public}s: write cap->port failed!", __func__); return HDF_FAILURE; } return HDF_SUCCESS; @@ -185,243 +227,164 @@ int32_t CodecSerPackParam(struct HdfSBuf *reply, Param *param) return HDF_SUCCESS; } -int32_t CodecSerPackBufferHandle(struct HdfSBuf *reply, CodecBufferHandle *bufferHandle) +int32_t CodecSerPackBufferInfo(struct HdfSBuf *reply, const CodecBufferInfo *buffer) { - if (reply == NULL || bufferHandle == NULL) { + if (reply == NULL || buffer == NULL) { HDF_LOGE("%{public}s: params null!", __func__); - return HDF_ERR_INVALID_PARAM; - } - if (!HdfSbufWriteUint64(reply, (uint64_t)bufferHandle->virAddr)) { - HDF_LOGE("%{public}s: Write virAddr failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufWriteUint32(reply, (uint32_t)bufferHandle->handle)) { - HDF_LOGE("%{public}s: Write handle failed!", __func__); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -int32_t CodecSerPackBufferInfo(struct HdfSBuf *reply, CodecBufferInfo *buffers) -{ - if (reply == NULL || buffers == NULL) { - HDF_LOGE("%{public}s: params null!", __func__); - return HDF_FAILURE; - } - if (!HdfSbufWriteUint32(reply, buffers->type)) { + if (!HdfSbufWriteUint32(reply, (uint32_t)buffer->type)) { HDF_LOGE("%{public}s: Write tempType failed!", __func__); return HDF_FAILURE; } - if (buffers->type == BUFFER_TYPE_VIRTUAL) { - if (!HdfSbufWriteBuffer(reply, buffers->addr, buffers->length)) { + if (buffer->type == BUFFER_TYPE_VIRTUAL) { + if (!HdfSbufWriteBuffer(reply, (void *)buffer->buf, buffer->length)) { HDF_LOGE("%{public}s: Write addr failed!", __func__); return HDF_FAILURE; } - } else if (buffers->type == BUFFER_TYPE_FD) { - if (!HdfSbufWriteFileDescriptor(reply, buffers->fd)) { + } else if (buffer->type == BUFFER_TYPE_FD) { + if (!HdfSbufWriteFileDescriptor(reply, (int32_t)buffer->buf)) { HDF_LOGE("%{public}s: Write fd failed!", __func__); return HDF_FAILURE; } - } else if (buffers->type == BUFFER_TYPE_HANDLE) { - if (CodecSerPackBufferHandle(reply, &buffers->handle)) { - HDF_LOGE("%{public}s: Write handle failed!", __func__); - return HDF_FAILURE; - } + } else if (buffer->type == BUFFER_TYPE_HANDLE) { + return HDF_FAILURE; } - if (!HdfSbufWriteUint32(reply, buffers->offset)) { + if (!HdfSbufWriteUint32(reply, buffer->offset)) { HDF_LOGE("%{public}s: Write offset failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufWriteUint32(reply, buffers->length)) { + if (!HdfSbufWriteUint32(reply, buffer->length)) { HDF_LOGE("%{public}s: Write length failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufWriteUint32(reply, buffers->size)) { + if (!HdfSbufWriteUint32(reply, buffer->capacity)) { HDF_LOGE("%{public}s: Write size failed!", __func__); return HDF_FAILURE; } return HDF_SUCCESS; } -int32_t CodecSerPackInputInfo(struct HdfSBuf *reply, InputInfo *inputData) -{ - if (reply == NULL || inputData == NULL || inputData->buffers == NULL) { - HDF_LOGE("%{public}s: params null!", __func__); - return HDF_FAILURE; - } - for (uint32_t i = 0; i < inputData->bufferCnt; i++) { - if (CodecSerPackBufferInfo(reply, &inputData->buffers[i])) { - HDF_LOGE("%{public}s: Write buffers failed!", __func__); - return HDF_FAILURE; - } - } - if (!HdfSbufWriteInt64(reply, inputData->pts)) { - HDF_LOGE("%{public}s: Write pts failed!", __func__); - return HDF_FAILURE; - } - if (!HdfSbufWriteInt32(reply, inputData->flag)) { - HDF_LOGE("%{public}s: Write flag failed!", __func__); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -int32_t CodecSerParseBufferHandle(struct HdfSBuf *reply, CodecBufferHandle *bufferHandle) -{ - if (reply == NULL || bufferHandle == NULL) { - HDF_LOGE("%{public}s: params null!", __func__); - return HDF_FAILURE; - } - if (!HdfSbufReadUint64(reply, (uint64_t *)&bufferHandle->virAddr)) { - HDF_LOGE("%{public}s: read virAddr failed!", __func__); - return HDF_FAILURE; - } - if (!HdfSbufReadUint32(reply, (uint32_t *)&bufferHandle->handle)) { - HDF_LOGE("%{public}s: read handle failed!", __func__); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -int32_t CodecSerParseBufferInfo(struct HdfSBuf *data, CodecBufferInfo *buffers) +int32_t CodecSerParseBufferInfo(struct HdfSBuf *data, CodecBufferInfo *buffer) { - if (data == NULL || buffers == NULL) { - HDF_LOGE("%{public}s: params null!", __func__); - return HDF_FAILURE; - } - uint32_t tempType = 0; uint32_t readLen = 0; - if (buffers == NULL) { - HDF_LOGE("%{public}s: buffers is NULL!", __func__); + if (data == NULL || buffer == NULL) { + HDF_LOGE("%{public}s: params null!", __func__); return HDF_FAILURE; } - if (!HdfSbufReadUint32(data, &tempType)) { + if (!HdfSbufReadUint32(data, (uint32_t *)&buffer->type)) { HDF_LOGE("%{public}s: read type failed!", __func__); return HDF_FAILURE; } - buffers->type = (BufferType)tempType; - if (buffers->type == BUFFER_TYPE_VIRTUAL) { - if (!HdfSbufReadBuffer(data, (const void **)&buffers->addr, &readLen)) { + if (buffer->type == BUFFER_TYPE_VIRTUAL) { + void *buf = (void *)buffer->buf; + if (!HdfSbufReadBuffer(data, (const void **)&buf, &readLen)) { HDF_LOGE("%{public}s: read addr failed!", __func__); return HDF_FAILURE; } - } else if (buffers->type == BUFFER_TYPE_FD) { - buffers->fd = HdfSbufReadFileDescriptor(data); - if (buffers->fd < 0) { + } else if (buffer->type == BUFFER_TYPE_FD) { + buffer->buf = (intptr_t)HdfSbufReadFileDescriptor(data); + if (buffer->buf < 0) { HDF_LOGE("%{public}s: read fd failed!", __func__); return HDF_FAILURE; } - } else if (buffers->type == BUFFER_TYPE_HANDLE) { - if (CodecSerParseBufferHandle(data, &buffers->handle)) { - HDF_LOGE("%{public}s: read handle failed!", __func__); - return HDF_FAILURE; - } + } else if (buffer->type == BUFFER_TYPE_HANDLE) { + return HDF_FAILURE; } - if (!HdfSbufReadUint32(data, &buffers->offset)) { + if (!HdfSbufReadUint32(data, &buffer->offset)) { HDF_LOGE("%{public}s: read offset failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufReadUint32(data, &buffers->length)) { + if (!HdfSbufReadUint32(data, &buffer->length)) { HDF_LOGE("%{public}s: read length failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufReadUint32(data, &buffers->size)) { + if (!HdfSbufReadUint32(data, &buffer->capacity)) { HDF_LOGE("%{public}s: read size failed!", __func__); return HDF_FAILURE; } return HDF_SUCCESS; } -int32_t CodecSerParseInputInfo(struct HdfSBuf *data, InputInfo *inputData) +int32_t CodecSerParseCodecBuffer(struct HdfSBuf *data, CodecBuffer *codecBuffer) { - if (data == NULL || inputData == NULL || inputData->buffers == NULL) { - HDF_LOGE("%{public}s: params NULL!", __func__); + if (data == NULL || codecBuffer == NULL) { + HDF_LOGE("%{public}s: params null!", __func__); return HDF_FAILURE; } - for (uint32_t i = 0; i < inputData->bufferCnt; i++) { - if (CodecSerParseBufferInfo(data, &inputData->buffers[i])) { - HDF_LOGE("%{public}s: read buffers failed!", __func__); - return HDF_FAILURE; - } + if (!HdfSbufReadUint32(data, &codecBuffer->bufferId)) { + HDF_LOGE("%{public}s: read sequence failed!", __func__); + return HDF_FAILURE; } - if (!HdfSbufReadInt64(data, &inputData->pts)) { - HDF_LOGE("%{public}s: read pts failed!", __func__); + if (!HdfSbufReadInt64(data, &codecBuffer->timeStamp)) { + HDF_LOGE("%{public}s: read timeStamp failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufReadInt32(data, &inputData->flag)) { + if (!HdfSbufReadUint32(data, &codecBuffer->flag)) { HDF_LOGE("%{public}s: read flag failed!", __func__); return HDF_FAILURE; } + for (uint32_t i = 0; i < codecBuffer->bufferCnt; i++) { + if (CodecSerParseBufferInfo(data, &codecBuffer->buffer[i])) { + HDF_LOGE("%{public}s: read buffers failed!", __func__); + return HDF_FAILURE; + } + } return HDF_SUCCESS; } -int32_t CodecSerParseOutputInfo(struct HdfSBuf *data, OutputInfo *outInfo) +int32_t CodecSerPackCodecBuffer(struct HdfSBuf *reply, const CodecBuffer *codecBuffer) { - if (data == NULL || outInfo == NULL || outInfo->buffers == NULL) { + if (reply == NULL || codecBuffer == NULL) { HDF_LOGE("%{public}s: params null!", __func__); return HDF_FAILURE; } - for (uint32_t i = 0; i < outInfo->bufferCnt; i++) { - if (CodecSerParseBufferInfo(data, &outInfo->buffers[i])) { - HDF_LOGE("%{public}s: read buffers failed!", __func__); - return HDF_FAILURE; - } - } - if (!HdfSbufReadInt64(data, &outInfo->timeStamp)) { - HDF_LOGE("%{public}s: read timeStamp failed!", __func__); - return HDF_FAILURE; - } - if (!HdfSbufReadUint32(data, &outInfo->sequence)) { - HDF_LOGE("%{public}s: read sequence failed!", __func__); - return HDF_FAILURE; - } - if (!HdfSbufReadUint32(data, &outInfo->flag)) { - HDF_LOGE("%{public}s: read flag failed!", __func__); - return HDF_FAILURE; - } - uint32_t tempType = 0; - if (!HdfSbufReadUint32(data, &tempType)) { - HDF_LOGE("%{public}s: read tempType failed!", __func__); + if (!HdfSbufWriteUint32(reply, codecBuffer->bufferId)) { + HDF_LOGE("%{public}s: write sequence failed!", __func__); return HDF_FAILURE; } - outInfo->type = (CodecType)tempType; - if (!HdfSbufReadUint64(data, (uint64_t *)&outInfo->vendorPrivate)) { - HDF_LOGE("%{public}s: read vendorPrivate failed!", __func__); + if (!HdfSbufWriteInt64(reply, codecBuffer->timeStamp)) { + HDF_LOGE("%{public}s: write timeStamp failed!", __func__); return HDF_FAILURE; } - return HDF_SUCCESS; -} -int32_t CodecSerPackOutputInfo(struct HdfSBuf *reply, OutputInfo *outInfo) -{ - if (reply == NULL || outInfo == NULL || outInfo->buffers == NULL) { - HDF_LOGE("%{public}s: params null!", __func__); + if (!HdfSbufWriteUint32(reply, codecBuffer->flag)) { + HDF_LOGE("%{public}s: write flag failed!", __func__); return HDF_FAILURE; } - for (uint32_t i = 0; i < outInfo->bufferCnt; i++) { - if (CodecSerPackBufferInfo(reply, &outInfo->buffers[i])) { + for (uint32_t i = 0; i < codecBuffer->bufferCnt; i++) { + if (CodecSerPackBufferInfo(reply, &codecBuffer->buffer[i])) { HDF_LOGE("%{public}s: write buffers failed!", __func__); return HDF_FAILURE; } } - if (!HdfSbufWriteInt64(reply, outInfo->timeStamp)) { - HDF_LOGE("%{public}s: write timeStamp failed!", __func__); + return HDF_SUCCESS; +} + +int32_t CodecSerParseFenceFd(struct HdfSBuf *data, int32_t *fenceFd) +{ + uint8_t validFd = 0; + if (!HdfSbufReadUint8(data, &validFd)) { + HDF_LOGE("%{public}s: read validFd failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufWriteUint32(reply, outInfo->sequence)) { - HDF_LOGE("%{public}s: write sequence failed!", __func__); - return HDF_FAILURE; + if (validFd != 0) { + *fenceFd = HdfSbufReadFileDescriptor(data); + } else { + *fenceFd = -1; } - if (!HdfSbufWriteUint32(reply, outInfo->flag)) { - HDF_LOGE("%{public}s: write flag failed!", __func__); - return HDF_FAILURE; - } - if (!HdfSbufWriteUint32(reply, outInfo->type)) { - HDF_LOGE("%{public}s: write outInfo->type failed!", __func__); - return HDF_FAILURE; + return HDF_SUCCESS; +} + +int32_t CodecSerPackFenceFd(struct HdfSBuf *reply, int32_t fenceFd) +{ + uint8_t validFd = fenceFd >= 0; + if (!HdfSbufWriteUint8(reply, validFd)) { + HDF_LOGE("%{public}s: write validFd flag failed!", __func__); + return HDF_ERR_INVALID_PARAM; } - if (!HdfSbufWriteUint64(reply, (uint64_t)&outInfo->vendorPrivate)) { - HDF_LOGE("%{public}s: write vendorPrivate failed!", __func__); - return HDF_FAILURE; + if (validFd != 0 && !HdfSbufWriteFileDescriptor(reply, fenceFd)) { + HDF_LOGE("%{public}s: write fenceFd failed!", __func__); + return HDF_ERR_INVALID_PARAM; } return HDF_SUCCESS; } diff --git a/codec/hdi_service/codec_service_stub/stub_msgproc.h b/codec/hdi_service/codec_service_stub/stub_msgproc.h index 700ad76d89289112a5c08b217631dcd378b064a3..9528788af35f822053adfd765cf37aa6932f2250 100644 --- a/codec/hdi_service/codec_service_stub/stub_msgproc.h +++ b/codec/hdi_service/codec_service_stub/stub_msgproc.h @@ -22,13 +22,13 @@ extern "C" { #endif /* __cplusplus */ -int32_t CodecSerPackCapbility(struct HdfSBuf *reply, CodecCapbility *cap); +int32_t CodecSerPackCapability(struct HdfSBuf *reply, CodecCapability *cap); int32_t CodecSerParseParam(struct HdfSBuf *data, Param *param); int32_t CodecSerPackParam(struct HdfSBuf *reply, Param *param); -int32_t CodecSerPackInputInfo(struct HdfSBuf *reply, InputInfo *inputData); -int32_t CodecSerParseInputInfo(struct HdfSBuf *data, InputInfo *inputData); -int32_t CodecSerParseOutputInfo(struct HdfSBuf *data, OutputInfo *outInfo); -int32_t CodecSerPackOutputInfo(struct HdfSBuf *reply, OutputInfo *outInfo); +int32_t CodecSerParseCodecBuffer(struct HdfSBuf *data, CodecBuffer *codecBuffer); +int32_t CodecSerPackCodecBuffer(struct HdfSBuf *reply, const CodecBuffer *codecBuffer); +int32_t CodecSerParseFenceFd(struct HdfSBuf *data, int32_t *fenceFd); +int32_t CodecSerPackFenceFd(struct HdfSBuf *reply, int32_t fenceFd); #ifdef __cplusplus } diff --git a/codec/interfaces/include/codec_common_type.h b/codec/interfaces/include/codec_common_type.h index 5d77e896440031afd8f104b3d2b141f0e357097f..0cf91c3a05a67481697868e0e70f2f9086ec548a 100755 --- a/codec/interfaces/include/codec_common_type.h +++ b/codec/interfaces/include/codec_common_type.h @@ -177,6 +177,37 @@ typedef enum { PROCESS_NONBLOCKING_CONTROL_FLOW = 0X400, } CodecProcessMode; +/** + * @brief Enumerate the audio sampling formats. + * + * For the planar sampling format, the data of each channel is independently stored in data. + * For the packed sampling format, only the first data is used, and the data of each channel is interleaved. + */ +typedef enum { + /** Unsigned 8 bits, packed */ + AUDIO_SAMPLE_FMT_U8, + /** Signed 16 bits, packed */ + AUDIO_SAMPLE_FMT_S16, + /** Signed 32 bits, packed */ + AUDIO_SAMPLE_FMT_S32, + /** Float, packed */ + AUDIO_SAMPLE_FMT_FLOAT, + /** Double, packed */ + AUDIO_SAMPLE_FMT_DOUBLE, + /** Unsigned 8 bits, planar */ + AUDIO_SAMPLE_FMT_U8P, + /** Signed 16 bits, planar */ + AUDIO_SAMPLE_FMT_S16P, + /** Signed 32 bits, planar */ + AUDIO_SAMPLE_FMT_S32P, + /** Float, planar */ + AUDIO_SAMPLE_FMT_FLOATP, + /** Double, planar */ + AUDIO_SAMPLE_FMT_DOUBLEP, + /** Invalid sampling format */ + AUDIO_SAMPLE_FMT_INVALID, +} CodecAudioSampleFormat; + #ifdef __cplusplus #if __cplusplus } diff --git a/codec/interfaces/include/codec_component_type.h b/codec/interfaces/include/codec_component_type.h index cb55a079f6e4b7781db3a2be87d5a021f2f9a6b1..49a256b8bb450849dead6e1e79438efb5398d82e 100644 --- a/codec/interfaces/include/codec_component_type.h +++ b/codec/interfaces/include/codec_component_type.h @@ -83,37 +83,6 @@ typedef enum { MEDIA_ROLETYPE_INVALID, } AvCodecRole; -/** - * @brief Enumerate the audio sampling formats. - * - * For the planar sampling format, the data of each channel is independently stored in data. - * For the packed sampling format, only the first data is used, and the data of each channel is interleaved. - */ -typedef enum { - /** Unsigned 8 bits, packed */ - AUDIO_SAMPLE_FMT_U8, - /** Signed 16 bits, packed */ - AUDIO_SAMPLE_FMT_S16, - /** Signed 32 bits, packed */ - AUDIO_SAMPLE_FMT_S32, - /** Float, packed */ - AUDIO_SAMPLE_FMT_FLOAT, - /** Double, packed */ - AUDIO_SAMPLE_FMT_DOUBLE, - /** Unsigned 8 bits, planar */ - AUDIO_SAMPLE_FMT_U8P, - /** Signed 16 bits, planar */ - AUDIO_SAMPLE_FMT_S16P, - /** Signed 32 bits, planar */ - AUDIO_SAMPLE_FMT_S32P, - /** Float, planar */ - AUDIO_SAMPLE_FMT_FLOATP, - /** Double, planar */ - AUDIO_SAMPLE_FMT_DOUBLEP, - /** Invalid sampling format */ - AUDIO_SAMPLE_FMT_INVALID, -} AudioSampleFormat; - /** * @brief Defines the video encoding and decoding capabilities. */ @@ -157,7 +126,7 @@ typedef struct { #define CHANNEL_NUM 16 /** Size of the audio channel array supported. */ typedef struct { int32_t sampleFormats[SAMPLE_FMT_NUM]; /** Supported audio sampling formats. For details, - see {@link AudioSampleFormat}. */ + see {@link CodecAudioSampleFormat}. */ int32_t sampleRate[SAMPLE_RATE_NUM]; /** Supported audio sampling rates. For details, see {@link AudioSampleRate}. */ int32_t channelLayouts[CHANNEL_NUM]; /** Supported audio channel layouts. */ diff --git a/codec/interfaces/include/codec_interface.h b/codec/interfaces/include/codec_interface.h index 5e9d141bf6d2c25c35b4d88c59eab37c560211ca..058965ec0b3cc3d83d45ca381e25b2794d19ab3e 100644 --- a/codec/interfaces/include/codec_interface.h +++ b/codec/interfaces/include/codec_interface.h @@ -81,7 +81,7 @@ int32_t CodecDeinit(); * @return Returns 0 if the capabilities corresponding to the index are available; * returns -1 otherwise. */ -int32_t CodecEnumerateCapbility(uint32_t index, CodecCapbility *cap); +int32_t CodecEnumerateCapability(uint32_t index, CodecCapability *cap); /** * @brief Obtains the capabilities of a specified media type. @@ -100,22 +100,34 @@ int32_t CodecEnumerateCapbility(uint32_t index, CodecCapbility *cap); * @return Returns 0 if the codec is supported and capabilities are available; * returns a non-zero value if the codec is not supported or the capabilities are unavailable. */ -int32_t CodecGetCapbility(AvCodecMime mime, CodecType type, uint32_t flags, CodecCapbility *cap); +int32_t CodecGetCapability(AvCodecMime mime, CodecType type, uint32_t flags, CodecCapability *cap); /** - * @brief Creates a specific codec component and returns the component context through a handle. + * @brief Creates a specific codec component by name and returns the component context through a handle. * * You can adjust the parameters required for creating a component based on service requirements. * * @param name Indicates the pointer to the unique name of the component, for example, * codec.avc.hardware.decoder. - * @param attr Indicates the pointer to the parameters in the array required for creating the component. - * @param len Indicates the number of elements in the parameter array. * @param handle Indicates the pointer to the codec handle returned. * @return Returns 0 if the codec component is created and the handle is available; * returns a non-zero value otherwise. */ -int32_t CodecCreate(const char* name, const Param *attr, int len, CODEC_HANDLETYPE *handle); +int32_t CodecCreate(const char* name, CODEC_HANDLETYPE *handle); + +/** + * @brief Creates a specific codec component by codec type and codec format, + * returns the component context through a handle. + * + * You can adjust the parameters required for creating a component based on service requirements. + * + * @param type Indicates the codec type, for example, VIDEO_DECODER. + * @param mime Indicates the codec format, for example, MEDIA_MIMETYPE_VIDEO_AVC. + * @param handle Indicates the pointer to the codec handle returned. + * @return Returns 0 if the codec component is created and the handle is available; + * returns a non-zero value otherwise. + */ +int32_t CodecCreateByType(CodecType type, AvCodecMime mime, CODEC_HANDLETYPE *handle); /** * @brief Destroys a codec component. @@ -130,15 +142,18 @@ int32_t CodecDestroy(CODEC_HANDLETYPE handle); * @brief Sets the input or output buffer mode. * * You can learn about the support of the codec input/output buffer for internal and external buffer modes - * by calling {@link CodecGetCapbility}. In this way, you can determine whether to use an internal or + * by calling {@link CodecGetCapability}. In this way, you can determine whether to use an internal or * external buffer mode. If the current codec can use only the specific buffer mode, you do not need to set it. * * @param handle Indicates the handle of the codec component. - * @param type Specifies whether the buffer type is an input type or an output type. + * @param direct Specifies whether the buffer type is an input type or an output type. * @param mode Specifies whether to use an internal or external buffer mode. + * @param type Specifies the buffer memory type. * @return Returns 0 if the setting is successful; returns a non-zero value otherwise. */ -int32_t CodecSetPortMode(CODEC_HANDLETYPE handle, DirectionType type, BufferMode mode); +int32_t CodecSetPortMode(CODEC_HANDLETYPE handle, DirectionType direct, AllocateBufferMode mode, BufferType type); + +int32_t CodecGetPortMode(CODEC_HANDLETYPE handle, DirectionType direct, AllocateBufferMode *mode, BufferType *type); /** * @brief Sets parameters required by a codec component. @@ -185,6 +200,14 @@ int32_t CodecStart(CODEC_HANDLETYPE handle); */ int32_t CodecStop(CODEC_HANDLETYPE handle); +/** + * @brief Reset a codec component. + * + * @param handle Indicates the handle of the codec component. + * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. + */ +int32_t CodecReset(CODEC_HANDLETYPE handle); + /** * @brief Clears the cache when the codec component is the running state. * @@ -205,7 +228,7 @@ int32_t CodecFlush(CODEC_HANDLETYPE handle, DirectionType directType); * @param timeoutMs Indicates the timeout duration. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. */ -int32_t CodecQueueInput(CODEC_HANDLETYPE handle, const InputInfo *inputData, uint32_t timeoutMs); +int32_t CodecQueueInput(CODEC_HANDLETYPE handle, const CodecBuffer *inputData, uint32_t timeoutMs, int releaseFenceFd); /** * @brief Dequeues input data that has been used. @@ -217,7 +240,7 @@ int32_t CodecQueueInput(CODEC_HANDLETYPE handle, const InputInfo *inputData, uin * @param inputData Indicates the pointer to the input data that is used. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. */ -int32_t CodecDequeInput(CODEC_HANDLETYPE handle, uint32_t timeoutMs, InputInfo *inputData); +int32_t CodecDequeueInput(CODEC_HANDLETYPE handle, uint32_t timeoutMs, int *acquireFd, CodecBuffer *inputData); /** * @brief Queues output data. @@ -232,7 +255,7 @@ int32_t CodecDequeInput(CODEC_HANDLETYPE handle, uint32_t timeoutMs, InputInfo * * The value -1 indicates that releaseFenceFd is invalid. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. */ -int32_t CodecQueueOutput(CODEC_HANDLETYPE handle, OutputInfo *outInfo, uint32_t timeoutMs, int releaseFenceFd); +int32_t CodecQueueOutput(CODEC_HANDLETYPE handle, CodecBuffer *outInfo, uint32_t timeoutMs, int releaseFenceFd); /** * @brief Dequeues output data. @@ -247,7 +270,7 @@ int32_t CodecQueueOutput(CODEC_HANDLETYPE handle, OutputInfo *outInfo, uint32_t * @param outInfo Indicates the pointer to the output data. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. */ -int32_t CodecDequeueOutput(CODEC_HANDLETYPE handle, uint32_t timeoutMs, int *acquireFd, OutputInfo *outInfo); +int32_t CodecDequeueOutput(CODEC_HANDLETYPE handle, uint32_t timeoutMs, int *acquireFd, CodecBuffer *outInfo); /** * @brief Sets the callback function. diff --git a/codec/interfaces/include/codec_type.h b/codec/interfaces/include/codec_type.h index d16cf4d6a8c47707c8e5420eb191948f2448bd2a..29d35415bfa8886fe3d32f190a96c632c46223fc 100644 --- a/codec/interfaces/include/codec_type.h +++ b/codec/interfaces/include/codec_type.h @@ -42,6 +42,7 @@ #include #include #include "codec_common_type.h" +#include "display_type.h" #ifdef __cplusplus #if __cplusplus @@ -58,98 +59,74 @@ typedef void *CODEC_HANDLETYPE; * @brief Enumerates indexes of parameter types. */ typedef enum { - KEY_MIMETYPE = 0x01, /**< MIME type. For the value type, see {@link AvCodecMime}. */ + KEY_CODEC_START_NONE = 0, + KEY_MIMETYPE, /**< MIME type. For the value type, see {@link AvCodecMime}. */ KEY_BUFFERSIZE, /**< Buffer size. The value type is uint32_t. */ - KEY_LEFT_STREAM_FRAMES, /**< Number of frames in the remaining data streams. The value type is uint32_t. */ KEY_CODEC_TYPE, /**< Codec type. For the value type, see {@link CodecType}. */ - KEY_DIRECTION_TYPE, /**< Input/Output type. For the value type, see {@link DirectionType}. */ - + KEY_INIT_PARAM_KEYS, /**< Get the minimum initialization param keys, see {@link ParamKey}(read only). */ + KEY_INPUT_BUFFERS, /**< External input buffer in preset mode, see {@link CodecBufferInfo}. */ + KEY_OUTPUT_BUFFERS, /**< External output buffer in preset mode, see {@link CodecBufferInfo}. */ + KEY_DEVICE_ID, /**< Device ID. The value type is uint32_t. */ KEY_BITRATE = 0x500, /**< Bit rate. The value type is uint32_t. */ - KEY_WIDTH = 0x1000, /**< Width. The value type is uint32_t. */ - KEY_HEIGHT, /**< Height. The value type is uint32_t. */ - KEY_STRIDE, /**< Stride. The value type is uint32_t. */ + + KEY_VIDEO_START_NONE = 0x1000, + KEY_VIDEO_WIDTH, /**< Width. The value type is uint32_t. */ + KEY_VIDEO_HEIGHT, /**< Hight. The value type is uint32_t. */ + KEY_VIDEO_STRIDE, /**< Stride. The value type is uint32_t. */ KEY_VIDEO_FIELD, /**< Video field. For the value type, see {@link VideoField}. */ - KEY_PIXEL_FORMAT, /**< Pixel format. For the value type, see {@link PixelFormat}. */ - KEY_VIDEO_RC_MODE, /**< Rate control mode. For the value type, see {@link VenCodeRcMode}. */ - KEY_VIDEO_GOP_MODE, /**< GOP mode. For the value type, see {@link VenCodeGopMode}. */ - KEY_VIDEO_PIC_SIZE, /**< Image resolution. For the value type, see {@link PicSize}. */ + KEY_PIXEL_FORMAT, /**< Pixel format. For the value type, see {@link CodecPixelFormat}. */ + KEY_VIDEO_RC_MODE, /**< Rate control mode. For the value type, see {@link VideoCodecRcMode}. */ + KEY_VIDEO_GOP_MODE, /**< GOP mode. For the value type, see {@link VideoCodecGopMode}. */ + KEY_VIDEO_PIC_SIZE, /**< Image resolution. */ KEY_VIDEO_PROFILE, /**< Codec profile. The value type is uint32_t. */ KEY_VIDEO_FRAME_RATE, /**< Frame rate. The value type is uint32_t. */ KEY_IMAGE_Q_FACTOR, /**< Quality factor, range is [1, 99]. The value type is uint32_t */ - KEY_SAMPLE_RATE = 0x1500, /**< Sampling rate. The value type is uint32_t. */ + KEY_AUDIO_START_NONE = 0x1500, + KEY_AUDIO_SAMPLE_RATE, /**< Sampling rate. The value type is uint32_t. */ KEY_AUDIO_PROFILE, /**< Audio encoding profile. The value type is uint32_t. */ - KEY_CHANNEL_COUNT, /**< Number of channels. The value type is uint32_t. */ - KEY_BITWITH, /**< Bit width. For the value type, see {@link AudioBitWidth}. */ - KEY_SOUND_MODE, /**< Audio channel mode. For the value type, see {@link AudioSoundMode}. */ - KEY_POINT_NUM_PER_FRAME, /**< Number of sampling points per frame. The value type is uint32_t. */ - KEY_DEVICE_ID, /**< Device ID. The value type is uint32_t. */ - KEY_EXT_START = 0xF000, /**< Manufacture extended features. The keys should be defined in oem adapter files. */ - KEY_EXT_END = 0xFFFF, + KEY_AUDIO_CHANNEL_COUNT, /**< Number of channels. The value type is uint32_t. */ + KEY_AUDIO_SOUND_MODE, /**< Audio channel mode. For the value type, see {@link AudioSoundMode}. */ + KEY_AUDIO_POINTS_PER_FRAME, /**< Number of sampling points per frame. The value type is uint32_t. */ + KEY_AUDIO_SAMPLE_FORMAT, /**< Audio sample format. For the value type, see {@link CodecAudioSampleFormat}. */ + + KEY_VENDOR_START_NONE = 0x60000000, + + KEY_PARAM_MAX = 0x7FFFFFFF } ParamKey; /** * @brief Enumerates control modes of the channel encoding rate. */ typedef enum { - VENCOD_RC_CBR = 0, /**< Fixed bit rate*/ - VENCOD_RC_VBR, /**< Variable bit rate */ - VENCOD_RC_AVBR, /**< Adaptive variable bit rate */ - VENCOD_RC_QVBR, /**< Quality-defined variable bit rate */ - VENCOD_RC_CVBR, /**< Constrained variable bit rate */ - VENCOD_RC_QPMAP, /**< Configuration-mapped quantization parameters */ - VENCOD_RC_FIXQP /**< Fixed quantization parameters */ -} VenCodeRcMode; - -/** - * @brief Enumerates resolutions. - */ -typedef enum { - RESOLUTION_CIF, /**< 352x288 */ - RESOLUTION_360P, /**< 640x360 */ - RESOLUTION_D1_PAL, /**< 720x576 */ - RESOLUTION_D1_NTSC, /**< 720x480 */ - RESOLUTION_720P, /**< 1280x720 */ - RESOLUTION_1080P, /**< 1920x1080 */ - RESOLUTION_2560X1440, /**< 2560x1440 */ - RESOLUTION_2592X1520, /**< 2592x1520 */ - RESOLUTION_2592X1536, /**< 2592x1536 */ - RESOLUTION_2592X1944, /**< 2592x1944 */ - RESOLUTION_2688X1536, /**< 2688x1536 */ - RESOLUTION_2716X1524, /**< 2716x1524 */ - RESOLUTION_3840X2160, /**< 3840x2160 */ - RESOLUTION_4096X2160, /**< 4096x2160 */ - RESOLUTION_3000X3000, /**< 3000x3000 */ - RESOLUTION_4000X3000, /**< 4000x3000 */ - RESOLUTION_7680X4320, /**< 7680x4320 */ - RESOLUTION_3840X8640, /**< 3840x8640 */ - RESOLUTION_INVALID /**< Invalid resolution */ -} PicSize; + VID_CODEC_RC_CBR = 0, /**< Fixed bit rate*/ + VID_CODEC_RC_VBR, /**< Variable bit rate */ + VID_CODEC_RC_AVBR, /**< Adaptive variable bit rate */ + VID_CODEC_RC_QVBR, /**< Quality-defined variable bit rate */ + VID_CODEC_RC_CVBR, /**< Constrained variable bit rate */ + VID_CODEC_RC_QPMAP, /**< Configuration-mapped quantization parameters */ + VID_CODEC_RC_FIXQP /**< Fixed quantization parameters */ +} VideoCodecRcMode; /** * @brief Enumerates types of group of pictures (GOP). */ typedef enum { - VENCOD_GOPMODE_NORMALP = 0, /**< P-frames using only one reference frame during encoding */ - VENCOD_GOPMODE_DUALP = 1, /**< P-frames using two reference frames during encoding */ - VENCOD_GOPMODE_SMARTP = 2, /**< Smart P-frames for encoding */ - VENCOD_GOPMODE_ADVSMARTP = 3, /**< Advanced smart P-frames for encoding */ - VENCOD_GOPMODE_BIPREDB = 4, /**< B-frames for encoding */ - VENCOD_GOPMODE_LOWDELAYB = 5, /**< B-frames using only previous frames as references during encoding. */ - VENCOD_GOPMODE_INVALID, /**< Invalid type */ -} VenCodeGopMode; - -/** - * @brief Defines the pointer to the type of the dynamic parameter value. - */ -typedef void *ValueType; + VID_CODEC_GOPMODE_NORMALP = 0, /**< P-frames using only one reference frame during encoding */ + VID_CODEC_GOPMODE_DUALP = 1, /**< P-frames using two reference frames during encoding */ + VID_CODEC_GOPMODE_SMARTP = 2, /**< Smart P-frames for encoding */ + VID_CODEC_GOPMODE_ADVSMARTP = 3, /**< Advanced smart P-frames for encoding */ + VID_CODEC_GOPMODE_BIPREDB = 4, /**< B-frames for encoding */ + VID_CODEC_GOPMODE_LOWDELAYB = 5, /**< B-frames using only previous frames as references during encoding. */ + VID_CODEC_GOPMODE_INVALID, /**< Invalid type */ +} VideoCodecGopMode; /** * @brief Describes the dynamic parameter structure, which is mainly used * by {@link CodecCreate} and {@link CodecSetParameter}. */ typedef struct { - ParamKey key; /**< Parameter type index */ + ParamKey key; /**< Parameter type index */ void *val; /**< Pointer to the parameter value */ int size; /**< Parameter value size */ } Param; @@ -169,127 +146,97 @@ typedef enum { * @brief Enumerates pixel formats. */ typedef enum { - YVU_SEMIPLANAR_420 = 0, /**< YUV 420 SP */ - YVU_SEMIPLANAR_420_TILE, /**< YUV SP 420 TILE */ - PIX_FORMAT_INVALID /**< Invalid format */ + PIXEL_FORMAT_NONE, + PIXEL_FORMAT_YUV_422_I, /**< YUV422 interleaved format */ + PIXEL_FORMAT_YCBCR_422_SP, /**< YCBCR422 semi-planar format */ + PIXEL_FORMAT_YCRCB_422_SP, /**< YCRCB422 semi-planar format */ + PIXEL_FORMAT_YCBCR_420_SP, /**< YCBCR420 semi-planar format */ + PIXEL_FORMAT_YCRCB_420_SP, /**< YCRCB420 semi-planar format */ + PIXEL_FORMAT_YCBCR_422_P, /**< YCBCR422 planar format */ + PIXEL_FORMAT_YCRCB_422_P, /**< YCRCB422 planar format */ + PIXEL_FORMAT_YCBCR_420_P, /**< YCBCR420 planar format */ + PIXEL_FORMAT_YCRCB_420_P, /**< YCRCB420 planar format */ + PIXEL_FORMAT_YUYV_422_PKG, /**< YUYV422 packed format */ + PIXEL_FORMAT_UYVY_422_PKG, /**< UYVY422 packed format */ + PIXEL_FORMAT_YVYU_422_PKG, /**< YVYU422 packed format */ + PIXEL_FORMAT_VYUY_422_PKG, /**< VYUY422 packed format */ + + PIXEL_FORMAT_VENDOR_MASK = 0x7F000000, /**< Reserved region for introducting Vendor Extensions, eg. + PIX_FORMAT_VENDOR_MASK | PIXEL_FORMAT_YCBCR_420_SP. */ + PIXEL_FORMAT_MAX = 0x7FFFFFFF, /**< Invalid format */ } CodecPixelFormat; /** * @brief Enumerates audio channel modes. */ typedef enum { - AUD_SOUND_MODE_MONO = 0, /**< Mono channel */ - AUD_SOUND_MODE_STEREO = 1, /**< Stereo mode*/ - AUD_SOUND_MODE_INVALID /**< Invalid mode */ -} AudioSoundMode; + AUD_CHANNEL_FRONT_LEFT = 0x1, /**< Front left channel */ + AUD_CHANNEL_FRONT_RIGHT = 0x2, /**< Front right channel */ -/** - * @brief Enumerates audio bit rates. - */ -typedef enum { - AUD_BITRATE_8K = 8000, /**< 8 kbit/s */ - AUD_BITRATE_16K = 16000, /**< 16 kbit/s */ - AUD_BITRATE_22K = 22000, /**< 22 kbit/s */ - AUD_BITRATE_24K = 24000, /**< 24 kbit/s */ - AUD_BITRATE_32K = 32000, /**< 32 kbit/s */ - AUD_BITRATE_40K = 40000, /**< 40 kbit/s */ - AUD_BITRATE_48K = 48000, /**< 48 kbit/s */ - AUD_BITRATE_64K = 64000, /**< 64 kbit/s */ - AUD_BITRATE_96K = 96000, /**< 96 kbit/s */ - AUD_BITRATE_128K = 128000, /**< 128 kbit/s */ - AUD_BITRATE_132K = 132000, /**< 132 kbit/s */ - AUD_BITRATE_144K = 144000, /**< 144 kbit/s */ - AUD_BITRATE_192K = 192000, /**< 192 kbit/s */ - AUD_BITRATE_256K = 256000, /**< 256 kbit/s */ - AUD_BITRATE_265K = 265000, /**< 265 kbit/s */ - AUD_BITRATE_288K = 288000, /**< 288 kbit/s */ - AUD_BITRATE_320K = 320000, /**< 320 kbit/s */ -} AudioBitRate; + AUD_SOUND_MODE_INVALID = 0x0, /**< Invalid mode */ + AUD_SOUND_MODE_MONO = 0x1, /**< Mono channel */ + AUD_SOUND_MODE_STEREO = 0x3, /**< Stereo channel, consisting of front left and front right channels */ +} AudioSoundMode; /** * @brief Enumerates stream flags. */ typedef enum { - STREAM_FLAG_KEYFRAME = 1, /**< Keyframe */ - STREAM_FLAG_CODEC_SPECIFIC_INF = 2, /**< Codec specifications */ - STREAM_FLAG_EOS = 4, /**< End of streams */ - STREAM_FLAG_PART_OF_FRAME = 8, /**< Partial frame */ - STREAM_FLAG_END_OF_FRAME = 16, /**< End of frames, used in pair with STREAM_FLAG_PART_OF_FRAME */ + STREAM_FLAG_KEYFRAME = 0x1, /**< Keyframe */ + STREAM_FLAG_CODEC_SPECIFIC_INF = 0x2, /**< Codec specifications */ + STREAM_FLAG_EOS = 0x4, /**< End of streams */ + STREAM_FLAG_PART_OF_FRAME = 0x8, /**< Partial frame */ + STREAM_FLAG_END_OF_FRAME = 0x10, /**< End of frames, used in pair with STREAM_FLAG_PART_OF_FRAME */ + STREAM_FLAG_OUTPUT_CHANGED = 0x20, } StreamFlagType; -/** - * @brief Defines the codec buffer handle type. The virtual address of a handle maps to its physical address. - */ -typedef struct { - uint8_t *virAddr; /**< Virtual address */ - uintptr_t handle; /**< Physical address */ -} CodecBufferHandle; - /** * @brief Enumerates buffer types. */ typedef enum { - BUFFER_TYPE_VIRTUAL = 0, /**< Virtual memory */ - BUFFER_TYPE_FD, /**< File descriptor, which can be used cross processes */ - BUFFER_TYPE_HANDLE, /**< Handle, which can be used cross processes */ + BUFFER_TYPE_VIRTUAL = 0, /**< Data described by this buffer */ + BUFFER_TYPE_FD, /**< Share mem file descriptor, which can be used cross processes */ + BUFFER_TYPE_HANDLE, /**< Video frame buffer handle, For details, see {@link BufferHandle} */ } BufferType; /** * @brief Describes buffer information. */ typedef struct { - BufferType type; /**< Buffer type */ - /** - * @brief Describes the buffer address. - */ - union { - uint8_t *addr; /**< Virtual address */ - int32_t fd; /**< File descriptor */ - CodecBufferHandle handle; /**< Data handle. For details, see {@link CodecBufferHandle} */ - }; - uint32_t offset; /**< Buffer offset */ - uint32_t length; /**< Length of valid data */ - uint32_t size; /**< Total size of buffer blocks*/ + BufferType type; /**< Buffer type */ + intptr_t buf; /**< A reference to a data buffer */ + uint32_t offset; /**< Buffer offset */ + uint32_t length; /**< Length of valid data */ + uint32_t capacity; /**< Total size of buffer blocks*/ } CodecBufferInfo; /** - * @brief Describes input information. + * @brief Describes input and output codec buffer. */ typedef struct { - uint32_t bufferCnt; /**< Number of buffers */ - CodecBufferInfo *buffers; /**< Pointer to the buffer description. For details, see {@link CodecBufferInfo}. */ - int64_t pts; /**< Input timestamp */ - int32_t flag; /**< Input flag. For details, see {@link StreamFlagType}. */ -} InputInfo; - -/** - * @brief Describes output information. - */ -typedef struct { - uint32_t bufferCnt; /**< Number of buffers */ - CodecBufferInfo *buffers; /**< Pointer to the buffer description. For details, see {@link CodecBufferInfo}. */ - int64_t timeStamp; /**< Output timestamp */ - uint32_t sequence; /**< Corresponding input sequence number */ - uint32_t flag; /**< Output flag */ - CodecType type; /**< Codec type */ - void *vendorPrivate; /**< Private information about a device vendor */ -} OutputInfo; + uint32_t bufferId; /**< Corresponding buffer index number */ + int64_t timeStamp; /**< buffer timestamp */ + uint32_t flag; /**< buffer flag. For details, see {@link StreamFlagType}. */ + uint32_t bufferCnt; /**< Number of buffers */ + CodecBufferInfo buffer[0]; /**< Pointer to the buffer description. For details, see {@link CodecBufferInfo} */ +} CodecBuffer; /** * @brief Enumerates MIME types. */ typedef enum { - MEDIA_MIMETYPE_IMAGE_JPEG = 0, /**< JPEG image */ - MEDIA_MIMETYPE_VIDEO_AVC, /**< H.264 video */ - MEDIA_MIMETYPE_VIDEO_HEVC, /**< H.265 video */ - MEDIA_MIMETYPE_AUDIO_AAC, /**< AAC audio */ - MEDIA_MIMETYPE_AUDIO_G711A, /**< G711A audio */ - MEDIA_MIMETYPE_AUDIO_G711U, /**< G711U audio */ - MEDIA_MIMETYPE_AUDIO_G726, /**< G726 audio */ - MEDIA_MIMETYPE_AUDIO_PCM, /**< PCM audio */ - MEDIA_MIMETYPE_AUDIO_MP3, /**< MP3 audio */ - MEDIA_MIMETYPE_VIDEO_MJPEG, /**< JPEG video */ - MEDIA_MIMETYPE_INVALID, /**< Invalid MIME type */ + MEDIA_MIMETYPE_IMAGE_JPEG = 0, /**< JPEG image */ + MEDIA_MIMETYPE_VIDEO_AVC, /**< H.264 video */ + MEDIA_MIMETYPE_VIDEO_HEVC, /**< H.265 video */ + + MEDIA_MIMETYPE_AUDIO_FIRST = 0x10000, /**< Dummy id pointing at the start of audio codecs */ + MEDIA_MIMETYPE_AUDIO_AAC = 0x10000, /**< AAC audio */ + MEDIA_MIMETYPE_AUDIO_G711A, /**< G711A audio */ + MEDIA_MIMETYPE_AUDIO_G711U, /**< G711U audio */ + MEDIA_MIMETYPE_AUDIO_G726, /**< G726 audio */ + MEDIA_MIMETYPE_AUDIO_PCM, /**< PCM audio */ + MEDIA_MIMETYPE_AUDIO_MP3, /**< MP3 audio */ + MEDIA_MIMETYPE_INVALID, /**< Invalid MIME type */ } AvCodecMime; /** @@ -303,67 +250,111 @@ typedef enum { } Level; /** - * @brief Indicates the maximum number of reserved parameters in the array. + * @brief Enumerates allocation modes of input and output buffers. */ -#define ELEMENT_MAX_LEN 50 +typedef enum { + ALLOCATE_INPUT_BUFFER_CODEC_PRESET = 0x0001, /**< Preset input buffer allocated within the Codec module */ + ALLOCATE_INPUT_BUFFER_CODEC_DYNAMIC = 0x0002, /**< Dynamic input buffer allocated within the Codec module */ + + ALLOCATE_INPUT_BUFFER_USER_PRESET = 0x0010, /**< Preset input buffer allocated by an external user */ + ALLOCATE_INPUT_BUFFER_USER_DYNAMIC = 0x0020, /**< Dynamic input buffer allocated by an external user */ + + ALLOCATE_OUTPUT_BUFFER_CODEC_PRESET = 0x0100, /**< Preset output buffer allocated within the Codec module */ + ALLOCATE_OUTPUT_BUFFER_CODEC_DYNAMIC = 0x0200, /**< Dynamic output buffer allocated within the Codec module */ + + ALLOCATE_OUTPUT_BUFFER_USER_PRESET = 0x1000, /**< Preset output buffer allocated by an external user */ + ALLOCATE_OUTPUT_BUFFER_USER_DYNAMIC = 0x2000, /**< Dynamic output buffer allocated by an external user */ +} AllocateBufferMode; /** - * @brief Defines a variable-length queue. + * @brief Defines the video codec capabilities. */ +#define PIX_FMT_NUM 16 /** Size of the supported pixel format array */ typedef struct { - uint32_t element[ELEMENT_MAX_LEN]; /**< Array of reserved parameters */ - uint32_t actualLen; /**< Number of actual parameters */ -} ResizableArray; + Rect minSize; /** Minimum resolution supported. */ + Rect maxSize; /** Maximum resolution supported. */ + Alignment whAlignment; /** Values to align with the width and height. */ + int32_t supportPixFmts[PIX_FMT_NUM]; /** Supported pixel formats, array is terminated by PIXEL_FORMAT_NONE. */ +} VideoPortCap; /** - * @brief Enumerates allocation modes of input and output buffers. + * @brief Defines the audio codec port capabilities. */ -typedef enum { - ALLOCATE_INPUT_BUFFER_CODEC = 0x1, /**< Input buffer allocated within the Codec module */ - ALLOCATE_INPUT_BUFFER_USER = 0x2, /**< Input buffer allocated by an external user */ - ALLOCATE_OUTPUT_BUFFER_CODEC = 0x4, /**< Output buffer allocated within the Codec module */ - ALLOCATE_OUTPUT_BUFFER_USER = 0x8, /**< Output buffer allocated by an external user */ -} AllocateBufferMode; +#define SAMPLE_FORMAT_NUM 12 /** Size of the audio sampling format array supported. */ +#define SAMPLE_RATE_NUM 16 /** Size of the audio sampling rate array supported. */ +#define CHANNEL_NUM 16 /** Size of the audio channel array supported. */ +typedef struct { + int32_t sampleFormats[SAMPLE_FORMAT_NUM]; /** Supported audio sampling formats. For details, + see {@link CodecAudioSampleFormat}. */ + int32_t sampleRate[SAMPLE_RATE_NUM]; /** Supported audio sampling rates. For details, + see {@link AudioSampleRate}. */ + int32_t channelLayouts[CHANNEL_NUM]; /** Supported audio channel layouts. */ +} AudioPortCap; /** - * @brief Enumerates playback capabilities. + * @brief Defines the codec capability. */ -typedef enum { - ADAPTIVE_PLAYBACK = 0x1, /**< Adaptive playback */ - SECURE_PLAYBACK = 0x2, /**< Secure playback */ -} CapsMask; +#define PROFILE_NUM 256 /** Size of the profile array supported. */ +#define NAME_LENGTH 32 /** Size of the component name. */ +typedef struct { + AvCodecMime mime; /**< MIME type */ + CodecType type; /**< Codec type */ + char name[NAME_LENGTH]; /**< Codec name char string */ + int32_t supportProfiles[PROFILE_NUM]; /**< Supported profiles. For details, see {@link Profile}. */ + bool isSoftwareCodec; /**< Whether it is software codec or hardware codec. */ + int32_t processModeMask; /**< Codec processing mode mask. For details, + see {@link CodecProcessMode}. */ + uint32_t capsMask; /**< Capability mask. For details, see {@link CapsMask}. */ + uint32_t allocateMask; /**< Buffer allocation mode. For details, see {@link AllocateBufferMode}. */ + RangeValue inputBufferNum; /**< Range number of input buffers required for running */ + RangeValue outputBufferNum; /**< Range number of output buffers required for running */ + RangeValue bitRate; /** Supported bit rate range. */ + int32_t inputBufferSize; /** Min size of external input buffer. */ + int32_t outputBufferSize; /** Min size of external output buffer. */ + union { + VideoPortCap video; /** Video encoding and decoding capabilities */ + AudioPortCap audio; /** Audio encoding and decoding capabilities */ + } port; +} CodecCapability; /** - * @brief Defines the codec capability. + * @brief Enumerates input and output types. */ -typedef struct { - AvCodecMime mime; /**< MIME type */ - CodecType type; /**< Codec type */ - Alignment whAlignment; /**< Value to align with the width and height */ - Rect minSize; /**< Minimum resolution supported */ - Rect maxSize; /**< Maximum resolution supported */ - uint64_t minBitRate; /**< Minimum bit rate supported */ - uint64_t maxBitRate; /**< Maximum bit rate supported */ - ResizableArray supportProfiles; /**< Supported profiles */ - ResizableArray supportLevels; /**< Supported levels */ - ResizableArray supportPixelFormats; /**< Supported pixel formats */ - uint32_t minInputBufferNum; /**< Minimum number of input buffers required for running */ - uint32_t minOutputBufferNum; /**< Minimum number of output buffers required for running */ - uint32_t allocateMask; /**< Buffer allocation mode. For details, see {@link AllocateBufferMode}. */ - uint32_t capsMask; /**< Capability mask. For details, see {@link CapsMask}. */ -} CodecCapbility; +typedef enum { + INPUT_TYPE, /**< Input */ + OUTPUT_TYPE, /**< Output */ + ALL_TYPE, /**< Input and output */ +} DirectionType; /** * @brief Enumerates event types. */ typedef enum { - EVENT_ERROR, /**< Event error */ - EVENT_FLUSH_COMPLETE, /**< Buffer flush completed */ - EVENT_STOP_COMPLETE, /**< Codec stopped */ - EVENT_OUT_FORMAT_CHANGED, /**< Output format changed */ - EVENT_MAX = 0x1FFFFFFF /**< Maximum event value */ + EVENT_ERROR, /**< Event error */ + EVENT_FLUSH_COMPLETE, /**< Buffer flush completed */ + EVENT_STOP_COMPLETE, /**< Codec stopped */ + EVENT_OUT_FORMAT_CHANGED, /**< Output format changed. For details, see {@link FormatChange}. */ + EVENT_START_COMPLETE, /**< Codec started */ + EVENT_EOS_COMPLETE, + + EVENT_MAX = 0x7FFFFFFF /**< Maximum event value */ } EventType; +/** + * @brief Defines format change reporting information. + */ +typedef struct { + DirectionType direct; /**< Input or output type. */ + RangeValue bufferNum; /**< Range number of output buffers. Report when decode the first frame, + or report when the bit stream resolution changed. */ + int32_t width; /**< Width. */ + int32_t height; /**< Height. */ + int32_t widthStride; /**< Image width stride. */ + int32_t heightStride; /**< Image height stride. */ + PixelFormat format; /**< Pixel format. For details, see {@link PixelFormat}. */ + Rect outputRect; +} FormatChange; + /** * @brief Redefines the unsigned pointer type, which is used for pointer conversion. */ @@ -378,73 +369,63 @@ typedef struct { * * Reports event errors and output format changes. * - * @param hComponent Indicates the handle of the codec component. - * @param pAppData Indicates upper-layer data, which is generally + * @param userData Indicates upper-layer data, which is generally * an upper-layer instance passed when this callback is set. * @param EVENTTYPE Indicates the event type. - * @param nData1 Indicates the first value contained in the reported event. This parameter is optional. - * @param nData2 Indicates the second value contained in the reported event. This parameter is optional. - * @param pEventData Indicates the pointer to data contained in the reported event. This parameter is optional. - * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. + * @param length Indicates the length of eventData array. + * @param eventData Indicates the pointer to data contained in the reported event. + * @return Returns 0 if the operation is successful; returns a non-zero {@link CodecResult} value otherwise. */ - int (*OnEvent)(UINTPTR comp, UINTPTR appData, EventType event, - uint32_t data1, uint32_t data2, UINTPTR eventData); + int32_t (*OnEvent)(UINTPTR userData, EventType event, uint32_t length, int32_t eventData[]); /** * @brief Reports that the input data has been used. * * This callback is invoked in asynchronous mode. * - * @param hComponent Indicates the handle of the codec component. - * @param pAppData Indicates upper-layer data, which is generally + * @param userData Indicates upper-layer data, which is generally * an upper-layer instance passed when this callback is set. - * @param pBuffer Indicates the pointer to the input data that has been used. - * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. + * @param inBuf Indicates the pointer to the input data that has been used. + * @return Returns 0 if the operation is successful; returns a non-zero {@link CodecResult} value otherwise. */ - int (*InputBufferAvailable)(UINTPTR comp, UINTPTR appData, InputInfo *inBuf); + int32_t (*InputBufferAvailable)(UINTPTR userData, CodecBuffer *inBuf, int32_t *acquireFd); /** * @brief Reports that the output is complete. * * This callback is invoked in asynchronous mode. * - * @param hComponent Indicates the handle of the codec component. - * @param pAppData Indicates upper-layer data, which is generally + * @param userData Indicates upper-layer data, which is generally * an upper-layer instance passed when this callback is registered. * @param pBuffer Indicates the pointer to the output data that has been generated. - * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. + * @return Returns 0 if the operation is successful; returns a non-zero {@link CodecResult} value otherwise. */ - int (*OutputBufferAvailable)(UINTPTR comp, UINTPTR appData, OutputInfo *outBuf); + int32_t (*OutputBufferAvailable)(UINTPTR userData, CodecBuffer *outBuf, int32_t *acquireFd); } CodecCallback; /** - * @brief Enumerates input and output types. - */ -typedef enum { - INPUT_TYPE, /**< Input */ - OUTPUT_TYPE, /**< Output */ - ALL_TYPE, /**< Input and output */ -} DirectionType; - -/** - * @brief Enumerates allocation types. + * @brief Enumerates codec result types. */ typedef enum { - INTERNAL, /**< Internal */ - EXTERNAL, /**< External */ -} BufferMode; - -/** - * @brief Enumerates codec error types. - */ -enum { - CODEC_SUCCESS = 0, /**< success */ - CODEC_ERR_STREAM_BUF_FULL = 100, /**< Elementary stream buffer queue is full. */ - CODEC_ERR_FRAME_BUF_EMPTY, /**< Frame buffer queue is empty. */ - CODEC_RECEIVE_EOS, /**< End of streams */ - CODEC_ERR_INVALID_OP, /**< Invalid operation */ - CODEC_ERR_UNKOWN /**< unknown error */ -}; + CODEC_SUCCESS = 0, /**< Success */ + CODEC_RECEIVE_EOS, /**< End of streams */ + CODEC_ERR_UNKOWN = (int32_t)0x80001000, /**< Unknown error */ + CODEC_ERR_INVALID_NAME = (int32_t)0x80001001, /**< The codec name was not valid */ + CODEC_ERR_INVALID_MIME = (int32_t)0x80001002, /**< The codec mime was not valid */ + CODEC_ERR_INVALID_PARAM = (int32_t)0x80001003, /**< One or more parameters were not valid */ + CODEC_ERR_INVALID_CODEC = (int32_t)0x80001004, /**< The codec handle was not valid */ + CODEC_ERR_INVALID_OP = (int32_t)0x80001005, /**< Invalid operation */ + CODEC_ERR_UNSUPPORT_PARAM = (int32_t)0x80001006, /**< One or more parameters were not supported */ + CODEC_ERR_NOT_INIT = (int32_t)0x80001007, /**< The codec was not initialized */ + CODEC_ERR_NOT_READY = (int32_t)0x80001008, /**< The codec was not ready */ + CODEC_ERR_NOT_FOUND = (int32_t)0x80001009, /**< The codec was not found */ + CODEC_ERR_NO_MEMORY = (int32_t)0x8000100A, /**< The codec memory allocation failed */ + CODEC_ERR_TIMEOUT = (int32_t)0x8000100B, /**< There was a timeout that occurred */ + CODEC_ERR_INVALID_BUFFER = (int32_t)0x8000100C, /**< The buffer was not valid */ + CODEC_ERR_UNDER_FLOW = (int32_t)0x8000100D, /**< The buffer was emptied before the next buffer was ready */ + CODEC_ERR_OVER_FLOW = (int32_t)0x8000100E, /**< The buffer was not available when it was needed */ + CODEC_ERR_MAX = 0x7FFFFFFF +} CodecResult; #ifdef __cplusplus #if __cplusplus diff --git a/codec/test/demo/v1.0/BUILD.gn b/codec/test/demo/v1.0/BUILD.gn index 0c3a9cf6f54dc30ba9fdbf388570bf44a160f080..862f74caaa3b6ec0a09b0f95d23b3c963533b004 100644 --- a/codec/test/demo/v1.0/BUILD.gn +++ b/codec/test/demo/v1.0/BUILD.gn @@ -28,8 +28,8 @@ ohos_executable("codec_decode_test_ipc") { "//device/soc/rockchip/rk3568/hardware/mpp/include", "//drivers/peripheral/codec/interfaces/include", "//drivers/peripheral/codec/hal/v1.0/share_mem/include", - "//drivers/peripheral/codec/hdi_service/codec_proxy/", - "//drivers/peripheral/codec/hdi_service/codec_service_stub/", + "//drivers/peripheral/codec/hdi_service/codec_proxy", + "//drivers/peripheral/codec/hdi_service/codec_service_stub", ] cflags_c = [ @@ -54,6 +54,8 @@ ohos_executable("codec_decode_test_ipc") { if (is_standard_system) { external_deps = [ + "drivers_peripheral_display:hdi_gralloc_client", + "graphic_chipsetsdk:buffer_handle", "hdf_core:libhdf_host", "hdf_core:libhdf_ipc_adapter", "hdf_core:libhdf_utils", @@ -83,8 +85,8 @@ ohos_executable("codec_encode_test_ipc") { "//device/soc/rockchip/rk3568/hardware/mpp/include", "//drivers/peripheral/codec/interfaces/include", "//drivers/peripheral/codec/hal/v1.0/share_mem/include", - "//drivers/peripheral/codec/hdi_service/codec_proxy/", - "//drivers/peripheral/codec/hdi_service/codec_service_stub/", + "//drivers/peripheral/codec/hdi_service/codec_proxy", + "//drivers/peripheral/codec/hdi_service/codec_service_stub", ] cflags_c = [ @@ -108,6 +110,8 @@ ohos_executable("codec_encode_test_ipc") { ] if (is_standard_system) { external_deps = [ + "drivers_peripheral_display:hdi_gralloc_client", + "graphic_chipsetsdk:buffer_handle", "hdf_core:libhdf_host", "hdf_core:libhdf_ipc_adapter", "hdf_core:libhdf_utils", diff --git a/codec/test/demo/v1.0/codec_decode_test_ipc.c b/codec/test/demo/v1.0/codec_decode_test_ipc.c index 0c3a0430a1a0834a77bb8f9a97aff11586150276..21344360b590c8f8a3b36d29601a11f7c4e7e215 100644 --- a/codec/test/demo/v1.0/codec_decode_test_ipc.c +++ b/codec/test/demo/v1.0/codec_decode_test_ipc.c @@ -52,8 +52,8 @@ static struct ICodec *g_codecProxy = NULL; static CODEC_HANDLETYPE g_handle = NULL; ShareMemory *g_inputBuffers = NULL; ShareMemory *g_outputBuffers = NULL; -InputInfo *g_inputInfosData = NULL; -OutputInfo *g_outputInfosData = NULL; +CodecBuffer **g_inputInfosData = NULL; +CodecBuffer **g_outputInfosData = NULL; struct ICodecCallback *g_callback = NULL; CodecCmd g_cmd = {0}; @@ -129,74 +129,71 @@ static void ReleaseShm(void) } } -static void ReleaseInfoBuffer(void) +static void ReleaseCodecBuffer(void) { int32_t i; if (g_inputInfosData != NULL) { for (i = 0; i < STREAM_PACKET_BUFFER_NUM; i++) { - if (g_inputInfosData[i].buffers != NULL) { - OsalMemFree(g_inputInfosData[i].buffers); + if (g_inputInfosData[i] != NULL) { + OsalMemFree(g_inputInfosData[i]); } } } if (g_outputInfosData != NULL) { for (i = 0; i < MEDIA_FRAME_BUFFER_NUM; i++) { - if (g_outputInfosData[i].buffers != NULL) { - OsalMemFree(g_outputInfosData[i].buffers); + if (g_outputInfosData[i] != NULL) { + OsalMemFree(g_outputInfosData[i]); } } } } -static bool InitBuffer(int32_t packetBufferNum, int32_t packetBufferSize, - int32_t frameBufferNum, int32_t frameBufferSize) +static bool InitBuffer(int32_t inputBufferNum, int32_t inputBufferSize, + int32_t outputBufferNum, int32_t outputBufferSize) { int32_t queueRet = 0; - g_inputBuffers = (ShareMemory *)OsalMemCalloc(sizeof(ShareMemory) * STREAM_PACKET_BUFFER_NUM); - g_outputBuffers = (ShareMemory *)OsalMemCalloc(sizeof(ShareMemory) * MEDIA_FRAME_BUFFER_NUM); - g_inputInfosData = (InputInfo *)OsalMemCalloc(sizeof(InputInfo) * STREAM_PACKET_BUFFER_NUM); - g_outputInfosData = (OutputInfo *)OsalMemCalloc(sizeof(OutputInfo) * MEDIA_FRAME_BUFFER_NUM); + g_inputBuffers = (ShareMemory *)OsalMemCalloc(sizeof(ShareMemory) * inputBufferNum); + g_outputBuffers = (ShareMemory *)OsalMemCalloc(sizeof(ShareMemory) * outputBufferNum); + g_inputInfosData = (CodecBuffer **)OsalMemCalloc(sizeof(CodecBuffer*) * inputBufferNum); + g_outputInfosData = (CodecBuffer **)OsalMemCalloc(sizeof(CodecBuffer*) * outputBufferNum); if (g_inputBuffers == NULL || g_outputBuffers == NULL || g_inputInfosData == NULL || g_outputInfosData == NULL) { HDF_LOGE("%{public}s: buffer and info mem alloc failed!", __func__); return false; } - for (int32_t i = 0; i < packetBufferNum; i++) { + int32_t bufCount = 1; + for (int32_t i = 0; i < inputBufferNum; i++) { g_inputBuffers[i].id = i; - g_inputBuffers[i].size = packetBufferSize; + g_inputBuffers[i].size = inputBufferSize; CreateShareMemory(&g_inputBuffers[i]); - g_inputInfosData[i].bufferCnt = 1; - g_inputInfosData[i].flag = STREAM_FLAG_CODEC_SPECIFIC_INF; - g_inputInfosData[i].buffers = (CodecBufferInfo *)OsalMemCalloc(sizeof(CodecBufferInfo)); - if (g_inputInfosData[i].buffers != NULL) { - g_inputInfosData[i].buffers->type = BUFFER_TYPE_FD; - g_inputInfosData[i].buffers->fd = g_inputBuffers[i].fd; - g_inputInfosData[i].buffers->offset = g_inputBuffers[i].id; - g_inputInfosData[i].buffers->size = packetBufferSize; - } + g_inputInfosData[i] = (CodecBuffer *)OsalMemCalloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo) * bufCount); + g_inputInfosData[i]->bufferCnt = 1; + g_inputInfosData[i]->flag = STREAM_FLAG_CODEC_SPECIFIC_INF; + g_inputInfosData[i]->bufferId = g_inputBuffers[i].id; + g_inputInfosData[i]->buffer[0].type = BUFFER_TYPE_FD; + g_inputInfosData[i]->buffer[0].buf = (intptr_t)g_inputBuffers[i].fd; + g_inputInfosData[i]->buffer[0].capacity = inputBufferSize; queueRet = g_codecProxy->CodecQueueInput(g_codecProxy, (CODEC_HANDLETYPE)g_handle, - &g_inputInfosData[i], (uint32_t)0); + g_inputInfosData[i], (uint32_t)0, -1); if (queueRet != HDF_SUCCESS) { HDF_LOGE("%{public}s: input buffer initial failed!", __func__); return false; } } - for (int32_t j = 0; j < frameBufferNum; j++) { + for (int32_t j = 0; j < outputBufferNum; j++) { g_outputBuffers[j].id = STREAM_PACKET_BUFFER_NUM + j; - g_outputBuffers[j].size = frameBufferSize; + g_outputBuffers[j].size = outputBufferSize; CreateShareMemory(&g_outputBuffers[j]); - g_outputInfosData[j].bufferCnt = 1; - g_outputInfosData[j].flag = STREAM_FLAG_CODEC_SPECIFIC_INF; - g_outputInfosData[j].buffers = (CodecBufferInfo *)OsalMemCalloc(sizeof(CodecBufferInfo)); - if (g_outputInfosData[j].buffers != NULL) { - g_outputInfosData[j].buffers->type = BUFFER_TYPE_FD; - g_outputInfosData[j].buffers->fd = g_outputBuffers[j].fd; - g_outputInfosData[j].buffers->offset = g_outputBuffers[j].id; - g_outputInfosData[j].buffers->size = frameBufferSize; - } + g_outputInfosData[j] = (CodecBuffer *)OsalMemCalloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo) * bufCount); + g_outputInfosData[j]->bufferCnt = 1; + g_outputInfosData[j]->bufferId = g_outputBuffers[j].id; + g_outputInfosData[j]->flag = STREAM_FLAG_CODEC_SPECIFIC_INF; + g_outputInfosData[j]->buffer[0].type = BUFFER_TYPE_FD; + g_outputInfosData[j]->buffer[0].buf = (intptr_t)g_outputBuffers[j].fd; + g_outputInfosData[j]->buffer[0].capacity = outputBufferSize; queueRet = g_codecProxy->CodecQueueOutput(g_codecProxy, (CODEC_HANDLETYPE)g_handle, - &g_outputInfosData[j], (uint32_t)0, 1); + g_outputInfosData[j], (uint32_t)0, -1); if (queueRet != HDF_SUCCESS) { HDF_LOGE("%{public}s: output buffer initial failed!", __func__); return false; @@ -205,22 +202,21 @@ static bool InitBuffer(int32_t packetBufferNum, int32_t packetBufferSize, return true; } -int32_t TestOnEvent(UINTPTR comp, UINTPTR appData, EventType event, - uint32_t data1, uint32_t data2, UINTPTR eventData) +int32_t TestOnEvent(UINTPTR userData, EventType event, uint32_t length, int32_t eventData[]) { HDF_LOGI("%{public}s: TestOnEvent : event = %{public}d", __func__, event); return HDF_SUCCESS; } -int32_t TestInputBufferAvailable(UINTPTR comp, UINTPTR appData, InputInfo *inBuf) +int32_t TestInputBufferAvailable(UINTPTR userData, CodecBuffer *inBuf, int32_t *acquireFd) { HDF_LOGI("%{public}s: TestInputBufferAvailable enter", __func__); return HDF_SUCCESS; } -int32_t TestOutputBufferAvailable(UINTPTR comp, UINTPTR appData, OutputInfo *outBuf) +int32_t TestOutputBufferAvailable(UINTPTR userData, CodecBuffer *outBuf, int32_t *acquireFd) { - HDF_LOGI("%{public}s: TestOutputBufferAvailable write %{public}d", __func__, outBuf->buffers->size); + HDF_LOGI("%{public}s: TestOutputBufferAvailable write %{public}d", __func__, outBuf->buffer[0].length); return HDF_SUCCESS; } @@ -233,7 +229,7 @@ int32_t SetExtDecParameter(void) // set split_parse enable mpp internal frame spliter when the input paramCnt = 1; memset_s(¶m, sizeof(Param), 0, sizeof(Param)); - param.key = (ParamKey)KEY_SPLIT_PARSE_RK; + param.key = (ParamKey)KEY_EXT_SPLIT_PARSE_RK; int32_t needSplit = 1; param.val = &needSplit; param.size = sizeof(int32_t); @@ -247,7 +243,7 @@ int32_t SetExtDecParameter(void) memset_s(¶m, sizeof(Param), 0, sizeof(Param)); paramCnt = 1; int32_t num = g_data.frameNum; - param.key = (ParamKey)KEY_DEC_FRAME_NUM_RK; + param.key = (ParamKey)KEY_EXT_DEC_FRAME_NUM_RK; param.val = # param.size = sizeof(int32_t); ret = g_codecProxy->CodecSetParameter(g_codecProxy, (CODEC_HANDLETYPE)g_handle, ¶m, paramCnt); @@ -280,7 +276,7 @@ int32_t SetDecParameter(void) // get default config memset_s(¶m, sizeof(Param), 0, sizeof(Param)); paramCnt = 1; - param.key = (ParamKey)KEY_DEFAULT_CFG_RK; + param.key = (ParamKey)KEY_EXT_DEFAULT_CFG_RK; int32_t needDefault = 1; param.val = &needDefault; param.size = sizeof(int32_t); @@ -294,7 +290,7 @@ int32_t SetDecParameter(void) memset_s(¶m, sizeof(Param), 0, sizeof(Param)); paramCnt = 1; param.key = KEY_PIXEL_FORMAT; - CodecPixelFormat fmt = PIX_FORMAT_INVALID; + CodecPixelFormat fmt = PIXEL_FORMAT_NONE; param.val = &fmt; param.size = sizeof(CodecPixelFormat); ret = g_codecProxy->CodecGetParameter(g_codecProxy, (CODEC_HANDLETYPE)g_handle, ¶m, paramCnt); @@ -315,32 +311,30 @@ void DecodeLoopHandleInput(MpiDecLoopData *g_data) int32_t ret = 0; uint8_t readData[STREAM_PACKET_BUFFER_SIZE]; int32_t readSize = 0; - CodecBufferInfo inputBuffer; - - memset_s(&inputBuffer, sizeof(CodecBufferInfo), 0, sizeof(CodecBufferInfo)); - inputBuffer.type = BUFFER_TYPE_FD; - InputInfo inputData; - memset_s(&inputData, sizeof(InputInfo), 0, sizeof(InputInfo)); - inputData.bufferCnt = 1; - inputData.buffers = &inputBuffer; - inputData.flag = STREAM_FLAG_CODEC_SPECIFIC_INF; - - ret = g_codecProxy->CodecDequeInput(g_codecProxy, (CODEC_HANDLETYPE)g_handle, QUEUE_TIME_OUT, &inputData); + int32_t acquireFd = 0; + + CodecBuffer *inputData = (CodecBuffer *)OsalMemCalloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo)); + inputData->buffer[0].type = BUFFER_TYPE_FD; + inputData->bufferCnt = 1; + inputData->flag = STREAM_FLAG_CODEC_SPECIFIC_INF; + ret = g_codecProxy->CodecDequeueInput(g_codecProxy, (CODEC_HANDLETYPE)g_handle, QUEUE_TIME_OUT, + &acquireFd, inputData); if (ret == HDF_SUCCESS) { // when packet size is valid read the input binary file readSize = ReadInputFromFile(g_data->fpInput, readData); g_pktEos = (readSize <= 0); if (g_pktEos) { HDF_LOGD("%{public}s: client inputData reach STREAM_FLAG_EOS", __func__); - inputData.flag = STREAM_FLAG_EOS; + inputData->flag = STREAM_FLAG_EOS; } g_totalSrcSize += readSize; - ShareMemory *sm = GetShareMemoryById(inputBuffer.offset); + ShareMemory *sm = GetShareMemoryById(inputData->bufferId); memcpy_s(sm->virAddr, readSize, (uint8_t*)readData, readSize); - inputBuffer.size = readSize; - g_codecProxy->CodecQueueInput(g_codecProxy, (CODEC_HANDLETYPE)g_handle, &inputData, QUEUE_TIME_OUT); + inputData->buffer[0].capacity = readSize; + g_codecProxy->CodecQueueInput(g_codecProxy, (CODEC_HANDLETYPE)g_handle, inputData, QUEUE_TIME_OUT, -1); } + OsalMemFree(inputData); } static int32_t DecodeLoop(MpiDecLoopData *g_data) @@ -351,38 +345,34 @@ static int32_t DecodeLoop(MpiDecLoopData *g_data) DecodeLoopHandleInput(g_data); } - CodecBufferInfo outputBuffer; - memset_s(&outputBuffer, sizeof(CodecBufferInfo), 0, sizeof(CodecBufferInfo)); - outputBuffer.type = BUFFER_TYPE_FD; - OutputInfo outputData; - memset_s(&outputData, sizeof(OutputInfo), 0, sizeof(OutputInfo)); - outputData.bufferCnt = 1; - outputData.buffers = &outputBuffer; - outputData.flag = STREAM_FLAG_CODEC_SPECIFIC_INF; + CodecBuffer *outputData = (CodecBuffer *)OsalMemCalloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo)); + outputData->buffer[0].type = BUFFER_TYPE_FD; + outputData->bufferCnt = 1; + outputData->flag = STREAM_FLAG_CODEC_SPECIFIC_INF; int32_t acquireFd = 0; ret = g_codecProxy->CodecDequeueOutput(g_codecProxy, (CODEC_HANDLETYPE)g_handle, QUEUE_TIME_OUT, - &acquireFd, &outputData); + &acquireFd, outputData); if (ret == HDF_SUCCESS) { g_totalFrames++; - ShareMemory *sm = GetShareMemoryById(outputBuffer.offset); + ShareMemory *sm = GetShareMemoryById(outputData->bufferId); + HDF_LOGD("%{public}s: get output, g_currentFrames:%{public}d", __func__, g_totalFrames); DumpOutputToFile(g_data->fp_output, sm->virAddr); - CodecBufferInfo queOutputBuffer; - memset_s(&queOutputBuffer, sizeof(CodecBufferInfo), 0, sizeof(CodecBufferInfo)); - queOutputBuffer.type = BUFFER_TYPE_FD; - queOutputBuffer.fd = outputData.buffers->fd; - queOutputBuffer.offset = outputData.buffers->offset; - OutputInfo queOutputData; - memset_s(&queOutputData, sizeof(OutputInfo), 0, sizeof(OutputInfo)); - queOutputData.bufferCnt = 1; - queOutputData.buffers = &queOutputBuffer; - queOutputData.flag = STREAM_FLAG_CODEC_SPECIFIC_INF; - g_codecProxy->CodecQueueOutput(g_codecProxy, (CODEC_HANDLETYPE)g_handle, &queOutputData, QUEUE_TIME_OUT, 1); - if (outputData.flag & STREAM_FLAG_EOS) { + + CodecBuffer *queOutputData = (CodecBuffer *)OsalMemCalloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo)); + queOutputData->buffer[0].type = BUFFER_TYPE_FD; + queOutputData->buffer[0].buf = outputData->buffer[0].buf; + queOutputData->bufferId = outputData->bufferId; + queOutputData->bufferCnt = 1; + queOutputData->flag = STREAM_FLAG_CODEC_SPECIFIC_INF; + g_codecProxy->CodecQueueOutput(g_codecProxy, (CODEC_HANDLETYPE)g_handle, queOutputData, QUEUE_TIME_OUT, -1); + if (outputData->flag & STREAM_FLAG_EOS) { HDF_LOGD("%{public}s: reach STREAM_FLAG_EOS, loop_end, g_totalFrames:%{public}d", __func__, g_totalFrames); g_data->loop_end = 1; } + OsalMemFree(queOutputData); } + OsalMemFree(outputData); return ret; } @@ -423,7 +413,7 @@ void RevertDecodeStep2(void) void RevertDecodeStep3(void) { ReleaseShm(); - ReleaseInfoBuffer(); + ReleaseCodecBuffer(); if (g_inputBuffers != NULL) { OsalMemFree(g_inputBuffers); @@ -498,13 +488,7 @@ int32_t Decode(void) return HDF_FAILURE; } - Param params; - memset_s(¶ms, sizeof(Param), 0, sizeof(Param)); - int32_t val = VIDEO_DECODER; - params.key = KEY_CODEC_TYPE; - params.val = &val; - params.size = sizeof(val); - ret = g_codecProxy->CodecCreate(g_codecProxy, g_data.codecName, ¶ms, 1, &g_handle); + ret = g_codecProxy->CodecCreate(g_codecProxy, g_data.codecName, &g_handle); if (ret != HDF_SUCCESS) { HDF_LOGE("%{public}s: CodecCreate failed, ret:%{public}d", __func__, ret); RevertDecodeStep2(); diff --git a/codec/test/demo/v1.0/codec_encode_test_ipc.c b/codec/test/demo/v1.0/codec_encode_test_ipc.c index 9797efdbcf83d0345299bd63c0c88b11b8fbb599..e5ec2bdc7e3dcef258ad268536d28cca08c0ff64 100644 --- a/codec/test/demo/v1.0/codec_encode_test_ipc.c +++ b/codec/test/demo/v1.0/codec_encode_test_ipc.c @@ -80,13 +80,12 @@ static struct ICodec *g_codecProxy = NULL; static CODEC_HANDLETYPE g_handle = NULL; ShareMemory *g_inputBuffers = NULL; ShareMemory *g_outputBuffers = NULL; -InputInfo *g_inputInfosData = NULL; -OutputInfo *g_outputInfosData = NULL; +CodecBuffer **g_inputInfosData = NULL; +CodecBuffer **g_outputInfosData = NULL; struct ICodecCallback *g_callback = NULL; CodecCmd g_cmd = {0}; CodecEnvData g_data = {0}; -CodecBufferInfo g_outputBuffer = {0}; RKHdiEncodeSetup g_encodeSetup = {0}; bool g_pktEos = false; @@ -147,20 +146,20 @@ static void ReleaseShm(void) } } -static void ReleaseInfoBuffer(void) +static void ReleaseCodecBuffer(void) { int32_t i; if (g_inputInfosData != NULL) { for (i = 0; i < INPUT_BUFFER_NUM; i++) { - if (g_inputInfosData[i].buffers != NULL) { - OsalMemFree(g_inputInfosData[i].buffers); + if (g_inputInfosData[i] != NULL) { + OsalMemFree(g_inputInfosData[i]); } } } if (g_outputInfosData != NULL) { for (i = 0; i < OUTPUT_BUFFER_NUM; i++) { - if (g_outputInfosData[i].buffers != NULL) { - OsalMemFree(g_outputInfosData[i].buffers); + if (g_outputInfosData[i] != NULL) { + OsalMemFree(g_outputInfosData[i]); } } } @@ -172,48 +171,46 @@ static bool InitBuffer(int32_t inputBufferNum, int32_t inputBufferSize, int32_t queueRet = 0; g_inputBuffers = (ShareMemory *)OsalMemCalloc(sizeof(ShareMemory) * inputBufferNum); g_outputBuffers = (ShareMemory *)OsalMemCalloc(sizeof(ShareMemory) * outputBufferNum); - g_inputInfosData = (InputInfo *)OsalMemCalloc(sizeof(InputInfo) * inputBufferNum); - g_outputInfosData = (OutputInfo *)OsalMemCalloc(sizeof(OutputInfo) * outputBufferNum); + g_inputInfosData = (CodecBuffer **)OsalMemCalloc(sizeof(CodecBuffer*) * inputBufferNum); + g_outputInfosData = (CodecBuffer **)OsalMemCalloc(sizeof(CodecBuffer*) * outputBufferNum); if (g_inputBuffers == NULL || g_outputBuffers == NULL || g_inputInfosData == NULL || g_outputInfosData == NULL) { HDF_LOGE("%{public}s: buffer and info mem alloc failed!", __func__); return false; } + + int32_t bufCount = 1; for (int32_t i = 0; i < inputBufferNum; i++) { g_inputBuffers[i].id = i; g_inputBuffers[i].size = inputBufferSize; CreateShareMemory(&g_inputBuffers[i]); - g_inputInfosData[i].bufferCnt = 1; - g_inputInfosData[i].flag = STREAM_FLAG_CODEC_SPECIFIC_INF; - g_inputInfosData[i].buffers = (CodecBufferInfo *)OsalMemCalloc(sizeof(CodecBufferInfo)); - if (g_inputInfosData[i].buffers != NULL) { - g_inputInfosData[i].buffers->type = BUFFER_TYPE_FD; - g_inputInfosData[i].buffers->fd = g_inputBuffers[i].fd; - g_inputInfosData[i].buffers->offset = g_inputBuffers[i].id; - g_inputInfosData[i].buffers->size = inputBufferSize; - } - + g_inputInfosData[i] = (CodecBuffer *)OsalMemCalloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo) * bufCount); + g_inputInfosData[i]->bufferCnt = 1; + g_inputInfosData[i]->flag = STREAM_FLAG_CODEC_SPECIFIC_INF; + g_inputInfosData[i]->bufferId = g_inputBuffers[i].id; + g_inputInfosData[i]->buffer[0].type = BUFFER_TYPE_FD; + g_inputInfosData[i]->buffer[0].buf = (intptr_t)g_inputBuffers[i].fd; + g_inputInfosData[i]->buffer[0].capacity = inputBufferSize; queueRet = g_codecProxy->CodecQueueInput(g_codecProxy, (CODEC_HANDLETYPE)g_handle, - &g_inputInfosData[i], (uint32_t)0); + g_inputInfosData[i], (uint32_t)0, -1); if (queueRet != HDF_SUCCESS) { HDF_LOGE("%{public}s: input buffer initial failed!", __func__); return false; } } + for (int32_t j = 0; j < outputBufferNum; j++) { g_outputBuffers[j].id = INPUT_BUFFER_NUM + j; g_outputBuffers[j].size = outputBufferSize; CreateShareMemory(&g_outputBuffers[j]); - g_outputInfosData[j].bufferCnt = 1; - g_outputInfosData[j].flag = STREAM_FLAG_CODEC_SPECIFIC_INF; - g_outputInfosData[j].buffers = (CodecBufferInfo *)OsalMemCalloc(sizeof(CodecBufferInfo)); - if (g_outputInfosData[j].buffers != NULL) { - g_outputInfosData[j].buffers->type = BUFFER_TYPE_FD; - g_outputInfosData[j].buffers->fd = g_outputBuffers[j].fd; - g_outputInfosData[j].buffers->offset = g_outputBuffers[j].id; - g_outputInfosData[j].buffers->size = outputBufferSize; - } + g_outputInfosData[j] = (CodecBuffer *)OsalMemCalloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo) * bufCount); + g_outputInfosData[j]->bufferCnt = 1; + g_outputInfosData[j]->bufferId = g_outputBuffers[j].id; + g_outputInfosData[j]->flag = STREAM_FLAG_CODEC_SPECIFIC_INF; + g_outputInfosData[j]->buffer[0].type = BUFFER_TYPE_FD; + g_outputInfosData[j]->buffer[0].buf = (intptr_t)g_outputBuffers[j].fd; + g_outputInfosData[j]->buffer[0].capacity = outputBufferSize; queueRet = g_codecProxy->CodecQueueOutput(g_codecProxy, (CODEC_HANDLETYPE)g_handle, - &g_outputInfosData[j], (uint32_t)0, 1); + g_outputInfosData[j], (uint32_t)0, -1); if (queueRet != HDF_SUCCESS) { HDF_LOGE("%{public}s: output buffer initial failed!", __func__); return false; @@ -222,22 +219,21 @@ static bool InitBuffer(int32_t inputBufferNum, int32_t inputBufferSize, return true; } -int32_t TestOnEvent(UINTPTR comp, UINTPTR appData, EventType event, - uint32_t data1, uint32_t data2, UINTPTR eventData) +int32_t TestOnEvent(UINTPTR userData, EventType event, uint32_t length, int32_t eventData[]) { HDF_LOGI("%{public}s: TestOnEvent: event = %{public}d", __func__, event); return HDF_SUCCESS; } -int32_t TestInputBufferAvailable(UINTPTR comp, UINTPTR appData, InputInfo *inBuf) +int32_t TestInputBufferAvailable(UINTPTR userData, CodecBuffer *inBuf, int32_t *acquireFd) { HDF_LOGI("%{public}s: TestInputBufferAvailable enter", __func__); return HDF_SUCCESS; } -int32_t TestOutputBufferAvailable(UINTPTR comp, UINTPTR appData, OutputInfo *outBuf) +int32_t TestOutputBufferAvailable(UINTPTR userData, CodecBuffer *outBuf, int32_t *acquireFd) { - HDF_LOGI("%{public}s: TestOutputBufferAvailable datasize: %{public}d", __func__, outBuf->buffers->size); + HDF_LOGI("%{public}s: TestOutputBufferAvailable write %{public}d", __func__, outBuf->buffer[0].length); return HDF_SUCCESS; } @@ -336,12 +332,11 @@ void SetCodecTypeData(RKHdiCodecTypeSetup *codecTypeSet) codecTypeSet->avcSetup.trans8x8 = AVC_SETUP_TRANS_DEFAULT; break; } - case MEDIA_MIMETYPE_VIDEO_HEVC: - case MEDIA_MIMETYPE_VIDEO_MJPEG: { + case MEDIA_MIMETYPE_VIDEO_HEVC: { break; } default: { - HDF_LOGE("%{public}s: unsupported encoder coding type %{public}d", __func__, codecTypeSet->mimeCodecType); + HDF_LOGE("%{public}s: unsupport encoder coding type %{public}d", __func__, codecTypeSet->mimeCodecType); break; } } @@ -375,7 +370,7 @@ int32_t SetupExtEncParams(Param *params, RKHdiEncodeSetup *encSetup, int32_t cou param = ¶ms[paramCount++]; param->key = KEY_VIDEO_RC_MODE; - encSetup->rc.rcMode = VENCOD_RC_VBR; + encSetup->rc.rcMode = VID_CODEC_RC_VBR; encSetup->rc.bpsTarget = g_cmd.width * g_cmd.height * BPS_TARGET / BPS_BASE * (encSetup->fps.fpsOutNum / encSetup->fps.fpsOutDen); CalcBpsRange(encSetup); @@ -384,7 +379,7 @@ int32_t SetupExtEncParams(Param *params, RKHdiEncodeSetup *encSetup, int32_t cou param = ¶ms[paramCount++]; param->key = KEY_VIDEO_GOP_MODE; - encSetup->gop.gopMode = VENCOD_GOPMODE_NORMALP; + encSetup->gop.gopMode = VID_CODEC_GOPMODE_NORMALP; encSetup->gop.gopLen = 0; encSetup->gop.viLen = 0; encSetup->gop.gop = encSetup->gop.gopLen ? encSetup->gop.gopLen: encSetup->fps.fpsOutNum * @@ -405,25 +400,25 @@ int32_t SetupEncParams(RKHdiEncodeSetup *encSetup) int32_t paramCount = 0; param = ¶ms[paramCount++]; - param->key = KEY_WIDTH; + param->key = KEY_VIDEO_WIDTH; encSetup->width = g_cmd.width; param->val = &(encSetup->width); param->size = sizeof(encSetup->width); param = ¶ms[paramCount++]; - param->key = KEY_HEIGHT; + param->key = KEY_VIDEO_HEIGHT; encSetup->height = g_cmd.height; param->val = &(encSetup->height); param->size = sizeof(encSetup->height); param = ¶ms[paramCount++]; param->key = KEY_PIXEL_FORMAT; - encSetup->fmt = YVU_SEMIPLANAR_420; + encSetup->fmt = PIXEL_FORMAT_YCBCR_420_SP; param->val = &(encSetup->fmt); param->size = sizeof(encSetup->fmt); param = ¶ms[paramCount++]; - param->key = KEY_STRIDE; + param->key = KEY_VIDEO_STRIDE; encSetup->stride.horStride = GetDefaultHorStride(g_cmd.width, encSetup->fmt); encSetup->stride.verStride = g_cmd.height; param->val = &(encSetup->stride); @@ -453,17 +448,14 @@ void EncodeLoopHandleInput(CodecEnvData *p_data, uint8_t *readData) { int32_t ret = 0; int32_t readSize = 0; + int32_t acquireFd = 0; - CodecBufferInfo inputBuffer; - memset_s(&inputBuffer, sizeof(CodecBufferInfo), 0, sizeof(CodecBufferInfo)); - inputBuffer.type = BUFFER_TYPE_FD; - InputInfo inputData; - memset_s(&inputData, sizeof(InputInfo), 0, sizeof(InputInfo)); - inputData.bufferCnt = 1; - inputData.buffers = &inputBuffer; - inputData.flag = STREAM_FLAG_CODEC_SPECIFIC_INF; - - ret = g_codecProxy->CodecDequeInput(g_codecProxy, (CODEC_HANDLETYPE)g_handle, QUEUE_TIME_OUT, &inputData); + CodecBuffer *inputData = (CodecBuffer *)OsalMemCalloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo)); + inputData->buffer[0].type = BUFFER_TYPE_FD; + inputData->bufferCnt = 1; + inputData->flag = STREAM_FLAG_CODEC_SPECIFIC_INF; + ret = g_codecProxy->CodecDequeueInput(g_codecProxy, (CODEC_HANDLETYPE)g_handle, QUEUE_TIME_OUT, + &acquireFd, inputData); if (ret == HDF_SUCCESS) { // when packet size is valid read the input binary file g_frameCount++; @@ -473,15 +465,16 @@ void EncodeLoopHandleInput(CodecEnvData *p_data, uint8_t *readData) if (g_pktEos) { HDF_LOGD("%{public}s: client inputData reach STREAM_FLAG_EOS, g_frameCount:%{public}d", __func__, g_frameCount); - inputData.flag = STREAM_FLAG_EOS; + inputData->flag = STREAM_FLAG_EOS; } g_totalSrcSize += readSize; - ShareMemory *sm = GetShareMemoryById(inputBuffer.offset); + ShareMemory *sm = GetShareMemoryById(inputData->bufferId); memcpy_s(sm->virAddr, readSize, (uint8_t*)readData, readSize); - inputBuffer.size = readSize; - g_codecProxy->CodecQueueInput(g_codecProxy, (CODEC_HANDLETYPE)g_handle, &inputData, QUEUE_TIME_OUT); + inputData->buffer[0].capacity = readSize; + g_codecProxy->CodecQueueInput(g_codecProxy, (CODEC_HANDLETYPE)g_handle, inputData, QUEUE_TIME_OUT, -1); } + OsalMemFree(inputData); } static int32_t EncodeLoop(CodecEnvData *p_data, uint8_t *readData) @@ -492,38 +485,33 @@ static int32_t EncodeLoop(CodecEnvData *p_data, uint8_t *readData) EncodeLoopHandleInput(p_data, readData); } - CodecBufferInfo g_outputBuffer; - memset_s(&g_outputBuffer, sizeof(CodecBufferInfo), 0, sizeof(CodecBufferInfo)); - g_outputBuffer.type = BUFFER_TYPE_FD; - OutputInfo outputData; - memset_s(&outputData, sizeof(OutputInfo), 0, sizeof(OutputInfo)); - outputData.bufferCnt = 1; - outputData.buffers = &g_outputBuffer; - outputData.flag = STREAM_FLAG_CODEC_SPECIFIC_INF; + CodecBuffer *outputData = (CodecBuffer *)OsalMemCalloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo)); + outputData->buffer[0].type = BUFFER_TYPE_FD; + outputData->bufferCnt = 1; + outputData->flag = STREAM_FLAG_CODEC_SPECIFIC_INF; int32_t acquireFd = 0; ret = g_codecProxy->CodecDequeueOutput(g_codecProxy, (CODEC_HANDLETYPE)g_handle, QUEUE_TIME_OUT, - &acquireFd, &outputData); + &acquireFd, outputData); if (ret == HDF_SUCCESS) { - g_totalDstSize += outputData.buffers->length; - ShareMemory *sm = GetShareMemoryById(g_outputBuffer.offset); - DumpOutputToFile(p_data->fpOutput, sm->virAddr, outputData.buffers->length); - CodecBufferInfo queOutputBuffer; - memset_s(&queOutputBuffer, sizeof(CodecBufferInfo), 0, sizeof(CodecBufferInfo)); - queOutputBuffer.type = BUFFER_TYPE_FD; - queOutputBuffer.fd = outputData.buffers->fd; - queOutputBuffer.offset = outputData.buffers->offset; - OutputInfo queOutputData; - memset_s(&queOutputData, sizeof(OutputInfo), 0, sizeof(OutputInfo)); - queOutputData.bufferCnt = 1; - queOutputData.buffers = &queOutputBuffer; - queOutputData.flag = STREAM_FLAG_CODEC_SPECIFIC_INF; - g_codecProxy->CodecQueueOutput(g_codecProxy, (CODEC_HANDLETYPE)g_handle, &queOutputData, QUEUE_TIME_OUT, 1); - if (outputData.flag & STREAM_FLAG_EOS) { + g_totalDstSize += outputData->buffer[0].length; + ShareMemory *sm = GetShareMemoryById(outputData->bufferId); + DumpOutputToFile(p_data->fpOutput, sm->virAddr, outputData->buffer[0].length); + + CodecBuffer *queOutputData = (CodecBuffer *)OsalMemCalloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo)); + queOutputData->buffer[0].type = BUFFER_TYPE_FD; + queOutputData->buffer[0].buf = outputData->buffer[0].buf; + queOutputData->bufferId = outputData->bufferId; + queOutputData->bufferCnt = 1; + queOutputData->flag = STREAM_FLAG_CODEC_SPECIFIC_INF; + g_codecProxy->CodecQueueOutput(g_codecProxy, (CODEC_HANDLETYPE)g_handle, queOutputData, QUEUE_TIME_OUT, -1); + if (outputData->flag & STREAM_FLAG_EOS) { HDF_LOGD("%{public}s: client reach STREAM_FLAG_EOS, CodecEncode loop_end", __func__); p_data->loop_end = 1; } + OsalMemFree(queOutputData); } + OsalMemFree(outputData); return ret; } @@ -571,7 +559,7 @@ void RevertEncodeStep2(void) void RevertEncodeStep3(void) { ReleaseShm(); - ReleaseInfoBuffer(); + ReleaseCodecBuffer(); if (g_inputBuffers != NULL) { OsalMemFree(g_inputBuffers); @@ -649,13 +637,7 @@ int32_t Encode(void) return HDF_FAILURE; } - Param param; - memset_s(¶m, sizeof(Param), 0, sizeof(Param)); - int32_t val = VIDEO_ENCODER; - param.key = KEY_CODEC_TYPE; - param.val = &val; - param.size = sizeof(val); - ret = g_codecProxy->CodecCreate(g_codecProxy, g_data.codecName, ¶m, 1, &g_handle); + ret = g_codecProxy->CodecCreate(g_codecProxy, g_data.codecName, &g_handle); if (ret != HDF_SUCCESS) { HDF_LOGE("%{public}s: CodecCreate failed, ret:%{public}d", __func__, ret); RevertEncodeStep2(); diff --git a/codec/test/unittest/hdi_v1.0/BUILD.gn b/codec/test/unittest/hdi_v1.0/BUILD.gn index ecfecea5ed4d6f94960194b1d4d53f0c3742c7a2..96747c9b9a9ccfa93ff69debd2b0daf93699b204 100644 --- a/codec/test/unittest/hdi_v1.0/BUILD.gn +++ b/codec/test/unittest/hdi_v1.0/BUILD.gn @@ -17,13 +17,22 @@ module_output_path = "hdf/codec" ohos_unittest("codec_hdi_1.0_test") { module_out_path = module_output_path - include_dirs = [ - "//drivers/peripheral/codec/interfaces/include/", - "//drivers/peripheral/codec/hdi_service/codec_proxy/", - "//drivers/peripheral/codec/hdi_service/codec_service_stub/", - "//drivers/peripheral/codec/hal/v1.0/share_mem/include", - ] - sources = [ "codec_proxy_test.cpp" ] + CODEC_OEM_PATH = rebase_path( + "//device/soc/${device_company}/${product_name}/hardware/codec") + cmd = "if [ -f ${CODEC_OEM_PATH}/BUILD.gn ]; then echo true; else echo false; fi" + HAVE_CODEC_OEM_PATH = + exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value") + + if (HAVE_CODEC_OEM_PATH) { + include_dirs = [ + "${CODEC_OEM_PATH}/include", + "//drivers/peripheral/codec/interfaces/include", + "//drivers/peripheral/codec/hdi_service/codec_proxy", + "//drivers/peripheral/codec/hdi_service/codec_service_stub", + "//drivers/peripheral/codec/hal/v1.0/share_mem/include", + ] + sources = [ "codec_proxy_test.cpp" ] + } cflags = [ "-Wall", @@ -42,11 +51,14 @@ ohos_unittest("codec_hdi_1.0_test") { if (is_standard_system) { external_deps = [ + "drivers_peripheral_display:hdi_gralloc_client", + "graphic_chipsetsdk:buffer_handle", "hdf_core:libhdf_host", "hdf_core:libhdf_ipc_adapter", "hdf_core:libhdf_utils", "hdf_core:libhdi", "hiviewdfx_hilog_native:libhilog", + "utils_base:utils", ] } else { external_deps = [ "hilog:libhilog" ] diff --git a/codec/test/unittest/hdi_v1.0/codec_proxy_test.cpp b/codec/test/unittest/hdi_v1.0/codec_proxy_test.cpp index 009984b4d716ce88154a1b645eb2ab4980b4e517..5bb92fc0b4cc4c63eed98a313255a1d90b889ddf 100644 --- a/codec/test/unittest/hdi_v1.0/codec_proxy_test.cpp +++ b/codec/test/unittest/hdi_v1.0/codec_proxy_test.cpp @@ -15,41 +15,33 @@ #include #include +#include #include #include "codec_callback_stub.h" #include "hdf_log.h" +#include "hdi_mpp_ext_param_keys.h" #include "icodec.h" #include "share_mem.h" +#define HDF_LOG_TAG codec_hdi_uinttest + using namespace std; using namespace testing::ext; namespace { -enum class ParamExtKeys { - KEY_START = 0xF000, - KEY_DEFAULT_CFG_RK, /**< Default config. Used for RK codec. */ - KEY_SPLIT_PARSE_RK, /**< Split parse. Used for RK codec. */ - KEY_DEC_FRAME_NUM_RK, /**< Decode frame number. Used for RK codec. */ - KEY_EXT_SETUP_DROP_MODE_RK, /**< Drop mode setup. Used for RK codec. */ - KEY_EXT_ENC_VALIDATE_SETUP_RK, /**< Validate config setup. Used for RK codec. */ - KEY_ENC_SETUP_AVC_RK, /**< AVC config setup. Used for RK codec. */ - KEY_ENC_FRAME_NUM_RK, /**< Frame num setup. Used for RK codec. */ - KEY_END = 0xFFFF, -}; - constexpr const char *TEST_SERVICE_NAME = "codec_hdi_service"; constexpr const int TEST_PACKET_BUFFER_SIZE = 4096; constexpr const int TEST_FRAME_BUFFER_SIZE = 640 * 480 * 3 / 2; -constexpr const int QUEUE_TIME_OUT = 10; -constexpr const int CAPABILITY_COUNT = 8; -struct ICodec *codecObj = nullptr; -ShareMemory inputBuffer; -ShareMemory outputBuffer; -InputInfo inputInfoData = {0}; -CodecBufferInfo inputCodecBufferInfo = {BUFFER_TYPE_FD}; -OutputInfo outputInfoData = {0}; -CodecBufferInfo outputCodecBufferInfo = {BUFFER_TYPE_FD}; -CODEC_HANDLETYPE handle = NULL; +constexpr const uint32_t QUEUE_TIME_OUT = 10; +constexpr const int CAPABILITY_COUNT = 9; +constexpr int32_t INT_TO_STR_LEN = 32; +constexpr int32_t ARRAY_TO_STR_LEN = 1000; +struct ICodec *g_codecObj = nullptr; +ShareMemory g_inputBuffer; +ShareMemory g_outputBuffer; +CodecBuffer *g_inputInfoData = nullptr; +CodecBuffer *g_outputInfoData = nullptr; +CODEC_HANDLETYPE g_handle = NULL; class CodecProxyTest : public testing::Test { public: @@ -60,108 +52,135 @@ public: void TearDown() {} }; -static void PrintArray(const char *where, const char *name, ResizableArray *array) +static char arrayStr[ARRAY_TO_STR_LEN]; +static char *GetArrayStr(int32_t *array, int32_t arrayLen, int32_t endValue) { - uint32_t index; - - if (array == NULL) { - return; + int32_t len = 0; + int32_t totalLen = 0; + int32_t ret; + char value[INT_TO_STR_LEN]; + ret = memset_s(arrayStr, sizeof(arrayStr), 0, sizeof(arrayStr)); + if (ret != EOK) { + HDF_LOGE("%{public}s: memset_s arrayStr failed, error code: %{public}d", __func__, ret); + return arrayStr; } - HDF_LOGI("%{public}s, %{public}s len: %{public}d", where, name, (int32_t)array->actualLen); - for (index = 0; index < array->actualLen; index++) { - HDF_LOGI("%{public}s, %{public}s-%{public}d: %{public}d", - where, name, index, (int32_t)array->element[index]); + for (int32_t i = 0; i < arrayLen; i++) { + if (array[i] == endValue) { + break; + } + ret = memset_s(value, sizeof(value), 0, sizeof(value)); + if (ret != EOK) { + HDF_LOGE("%{public}s: memset_s value failed, error code: %{public}d", __func__, ret); + return arrayStr; + } + ret = sprintf_s(value, sizeof(value) - 1, "0x0%X, ", array[i]); + if (ret < 0) { + HDF_LOGE("%{public}s: sprintf_s value failed, error code: %{public}d", __func__, ret); + return arrayStr; + } + len = strlen(value); + ret = memcpy_s(arrayStr + totalLen, len, value, len); + if (ret != EOK) { + HDF_LOGE("%{public}s: memcpy_s arrayStr failed, error code: %{public}d", __func__, ret); + return arrayStr; + } + totalLen += len; } + return arrayStr; } -static void PrintCapability(const char *where, CodecCapbility *cap) +static void PrintCapability(CodecCapability *cap, int index) { int32_t mime = 0; if (cap == NULL) { - HDF_LOGE("%{public}s, null capability!", where); + HDF_LOGE("null capability!"); return; } mime = (int32_t)cap->mime; if (mime < 0) { - HDF_LOGE("%{public}s, print invalid capability!", where); + HDF_LOGE("print invalid capability!"); return; } - - HDF_LOGI("%{public}s, --- start print cap ----------------------------", where); - HDF_LOGI("%{public}s, mime: %{public}d", where, (int32_t)cap->mime); - HDF_LOGI("%{public}s, type: %{public}d", where, (int32_t)cap->type); - HDF_LOGI("%{public}s, widthAlignment: %{public}d", where, (int32_t)cap->whAlignment.widthAlignment); - HDF_LOGI("%{public}s, heightAlignment: %{public}d", where, (int32_t)cap->whAlignment.heightAlignment); - HDF_LOGI("%{public}s, minwidth: %{public}d", where, (int32_t)cap->minSize.width); - HDF_LOGI("%{public}s, minHeight: %{public}d", where, (int32_t)cap->minSize.height); - HDF_LOGI("%{public}s, maxwidth: %{public}d", where, (int32_t)cap->maxSize.width); - HDF_LOGI("%{public}s, maxheight: %{public}d", where, (int32_t)cap->maxSize.height); - HDF_LOGI("%{public}s, minBitRate: %{public}d", where, (int32_t)cap->minBitRate); - HDF_LOGI("%{public}s, maxBitRate: %{public}d", where, (int32_t)cap->maxBitRate); - PrintArray(where, "supportProfiles", &(cap->supportProfiles)); - PrintArray(where, "supportLevels", &(cap->supportLevels)); - PrintArray(where, "supportPixelFormats", &(cap->supportPixelFormats)); - HDF_LOGI("%{public}s, minInputBufferNum: %{public}d", where, (int32_t)cap->minInputBufferNum); - HDF_LOGI("%{public}s, minOutputBufferNum: %{public}d", where, (int32_t)cap->minOutputBufferNum); - HDF_LOGI("%{public}s, allocateMask: %{public}d", where, (int32_t)cap->allocateMask); - HDF_LOGI("%{public}s, capsMask: %{public}d", where, (int32_t)cap->capsMask); - HDF_LOGI("%{public}s, ------------------------------ end print cap ---", where); + HDF_LOGI("-------------------------- capability %{public}d ---------------------------", index + 1); + HDF_LOGI("mime:%{public}d", cap->mime); + HDF_LOGI("type:%{public}d", cap->type); + HDF_LOGI("name:%{public}s", cap->name); + HDF_LOGI("supportProfiles:%{public}s", GetArrayStr(cap->supportProfiles, PROFILE_NUM, INVALID_PROFILE)); + HDF_LOGI("isSoftwareCodec:%{public}d", cap->isSoftwareCodec); + HDF_LOGI("processModeMask:0x0%{public}x", cap->processModeMask); + HDF_LOGI("capsMask:0x0%{public}x", cap->capsMask); + HDF_LOGI("allocateMask:0x0%{public}x", cap->allocateMask); + HDF_LOGI("inputBufferNum.min:%{public}d", cap->inputBufferNum.min); + HDF_LOGI("inputBufferNum.max:%{public}d", cap->inputBufferNum.max); + HDF_LOGI("outputBufferNum.min:%{public}d", cap->outputBufferNum.min); + HDF_LOGI("outputBufferNum.max:%{public}d", cap->outputBufferNum.max); + HDF_LOGI("bitRate.min:%{public}d", cap->bitRate.min); + HDF_LOGI("bitRate.max:%{public}d", cap->bitRate.max); + HDF_LOGI("inputBufferSize:%{public}d", cap->inputBufferSize); + HDF_LOGI("outputBufferSize:%{public}d", cap->outputBufferSize); + if (cap->mime < MEDIA_MIMETYPE_AUDIO_FIRST) { + HDF_LOGI("minSize.width:%{public}d", cap->port.video.minSize.width); + HDF_LOGI("minSize.height:%{public}d", cap->port.video.minSize.height); + HDF_LOGI("maxSize.width:%{public}d", cap->port.video.maxSize.width); + HDF_LOGI("maxSize.height:%{public}d", cap->port.video.maxSize.height); + HDF_LOGI("widthAlignment:%{public}d", cap->port.video.whAlignment.widthAlignment); + HDF_LOGI("heightAlignment:%{public}d", cap->port.video.whAlignment.heightAlignment); + HDF_LOGI("supportPixFmts:%{public}s", GetArrayStr(cap->port.video.supportPixFmts, PIX_FMT_NUM, 0)); + } else { + HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.sampleFormats, SAMPLE_FORMAT_NUM, 0)); + HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.sampleRate, SAMPLE_RATE_NUM, 0)); + HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.channelLayouts, CHANNEL_NUM, -1)); + } + HDF_LOGI("-------------------------------------------------------------------"); } HWTEST_F(CodecProxyTest, HdfCodecHdiV1GetCodecObjTest_001, TestSize.Level1) { - codecObj = HdiCodecGet(TEST_SERVICE_NAME); - ASSERT_TRUE(codecObj != nullptr); + g_codecObj = HdiCodecGet(TEST_SERVICE_NAME); + ASSERT_TRUE(g_codecObj != nullptr); } -HWTEST_F(CodecProxyTest, HdfCodecHdiV1EnumerateCapbilityTest_002, TestSize.Level1) +HWTEST_F(CodecProxyTest, HdfCodecHdiV1EnumerateCapabilityTest_002, TestSize.Level1) { int32_t ret = HDF_SUCCESS; for (int index = 0; index < CAPABILITY_COUNT; index++) { - CodecCapbility cap; - ret = codecObj->CodecEnumerateCapbility(codecObj, index, &cap); + CodecCapability cap; + ret = g_codecObj->CodecEnumerateCapability(g_codecObj, index, &cap); ASSERT_EQ(ret, HDF_SUCCESS); - PrintCapability("codec_config_utest", &cap); + PrintCapability(&cap, index); } } -HWTEST_F(CodecProxyTest, HdfCodecHdiV1GetCapbilityTest_003, TestSize.Level1) +HWTEST_F(CodecProxyTest, HdfCodecHdiV1GetCapabilityTest_003, TestSize.Level1) { - CodecCapbility cap; - int32_t ret = codecObj->CodecGetCapbility(codecObj, MEDIA_MIMETYPE_VIDEO_HEVC, VIDEO_ENCODER, 0, &cap); + CodecCapability cap; + int32_t ret = g_codecObj->CodecGetCapability(g_codecObj, MEDIA_MIMETYPE_IMAGE_JPEG, VIDEO_DECODER, 0, &cap); ASSERT_EQ(ret, HDF_SUCCESS); - PrintCapability("codec_config_utest", &cap); + PrintCapability(&cap, 0); } HWTEST_F(CodecProxyTest, HdfCodecHdiV1InitCodecTest_004, TestSize.Level1) { - ASSERT_TRUE(codecObj != nullptr); - int32_t errorCode = codecObj->CodecInit(codecObj); + ASSERT_TRUE(g_codecObj != nullptr); + int32_t errorCode = g_codecObj->CodecInit(g_codecObj); ASSERT_EQ(errorCode, HDF_SUCCESS); } HWTEST_F(CodecProxyTest, HdfCodecHdiV1CreateCodecTest_005, TestSize.Level1) { const char* name = "codec.avc.hardware.decoder"; - Param params; - params.key = KEY_CODEC_TYPE; - CodecType ct = VIDEO_DECODER; - params.val = (void *)&ct; - params.size = sizeof(ct); - int len = 1; - - int32_t errorCode = codecObj->CodecCreate(codecObj, name, ¶ms, len, &handle); + int32_t errorCode = g_codecObj->CodecCreate(g_codecObj, name, &g_handle); ASSERT_EQ(errorCode, HDF_SUCCESS); - ASSERT_TRUE(handle != nullptr); + ASSERT_TRUE(g_handle != nullptr); } HWTEST_F(CodecProxyTest, HdfCodecHdiV1SetPortModeTest_006, TestSize.Level1) { - DirectionType type = OUTPUT_TYPE; - BufferMode mode = EXTERNAL; - - int32_t errorCode = codecObj->CodecSetPortMode(codecObj, handle, type, mode); + DirectionType direct = OUTPUT_TYPE; + AllocateBufferMode mode = ALLOCATE_INPUT_BUFFER_CODEC_PRESET; + BufferType type = BUFFER_TYPE_FD; + int32_t errorCode = g_codecObj->CodecSetPortMode(g_codecObj, g_handle, direct, mode, type); ASSERT_EQ(errorCode, HDF_SUCCESS); } @@ -176,7 +195,7 @@ HWTEST_F(CodecProxyTest, HdfCodecHdiV1SetCodecTypeTest_007, TestSize.Level1) params->val = (void *)&ct; params->size = sizeof(ct); - int32_t errorCode = codecObj->CodecSetParameter(codecObj, handle, params, paramCnt); + int32_t errorCode = g_codecObj->CodecSetParameter(g_codecObj, g_handle, params, paramCnt); OsalMemFree(params); ASSERT_EQ(errorCode, HDF_SUCCESS); } @@ -187,11 +206,11 @@ HWTEST_F(CodecProxyTest, HdfCodecHdiV1GetDefaultCfgTest_008, TestSize.Level1) int paramCnt = 1; params = (Param *)OsalMemAlloc(sizeof(Param)*paramCnt); ASSERT_TRUE(params != nullptr); - params->key = (ParamKey)ParamExtKeys::KEY_DEFAULT_CFG_RK; + params->key = (ParamKey)ParamExtKey::KEY_EXT_DEFAULT_CFG_RK; params->val = nullptr; params->size = 0; - int32_t errorCode = codecObj->CodecGetParameter(codecObj, handle, params, paramCnt); + int32_t errorCode = g_codecObj->CodecGetParameter(g_codecObj, g_handle, params, paramCnt); OsalMemFree(params); ASSERT_EQ(errorCode, HDF_SUCCESS); } @@ -202,76 +221,88 @@ HWTEST_F(CodecProxyTest, HdfCodecHdiV1SetSplitModeTest_009, TestSize.Level1) int paramCnt = 1; params = (Param *)OsalMemAlloc(sizeof(Param)*paramCnt); ASSERT_TRUE(params != nullptr); - params->key = (ParamKey)ParamExtKeys::KEY_SPLIT_PARSE_RK; + params->key = (ParamKey)ParamExtKey::KEY_EXT_SPLIT_PARSE_RK; int32_t needSplit = 1; params->val = (void *)&needSplit; params->size = sizeof(needSplit); - int32_t errorCode = codecObj->CodecSetParameter(codecObj, handle, params, paramCnt); + int32_t errorCode = g_codecObj->CodecSetParameter(g_codecObj, g_handle, params, paramCnt); OsalMemFree(params); ASSERT_EQ(errorCode, HDF_SUCCESS); } HWTEST_F(CodecProxyTest, HdfCodecHdiV1QueueInputTest_010, TestSize.Level1) { - inputBuffer.id = 0; - inputBuffer.size = TEST_PACKET_BUFFER_SIZE; - int32_t ret = CreateShareMemory(&inputBuffer); + g_inputBuffer.id = 0; + g_inputBuffer.size = TEST_PACKET_BUFFER_SIZE; + int32_t ret = CreateShareMemory(&g_inputBuffer); ASSERT_EQ(ret, HDF_SUCCESS); - inputInfoData.bufferCnt = 1; - inputInfoData.flag = STREAM_FLAG_CODEC_SPECIFIC_INF; - inputInfoData.buffers = &inputCodecBufferInfo; - if (inputInfoData.buffers != NULL) { - inputInfoData.buffers->type = BUFFER_TYPE_FD; - inputInfoData.buffers->fd = inputBuffer.fd; - inputInfoData.buffers->offset = inputBuffer.id; - inputInfoData.buffers->size = TEST_PACKET_BUFFER_SIZE; - } - int32_t errorCode = codecObj->CodecQueueInput(codecObj, handle, &inputInfoData, (uint32_t)0); + + g_inputInfoData = (CodecBuffer *)OsalMemAlloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo) * 1); + g_inputInfoData->bufferId = 0; + g_inputInfoData->bufferCnt = 1; + g_inputInfoData->flag = 1; + g_inputInfoData->timeStamp = 1; + g_inputInfoData->buffer[0].type = BUFFER_TYPE_FD; + g_inputInfoData->buffer[0].offset = 1; + g_inputInfoData->buffer[0].length = 1; + g_inputInfoData->buffer[0].capacity = TEST_PACKET_BUFFER_SIZE; + g_inputInfoData->buffer[0].buf = (intptr_t)g_inputBuffer.fd; + + int32_t errorCode = g_codecObj->CodecQueueInput(g_codecObj, + g_handle, g_inputInfoData, (uint32_t)QUEUE_TIME_OUT, -1); ASSERT_EQ(errorCode, HDF_SUCCESS); } HWTEST_F(CodecProxyTest, HdfCodecHdiV1DequeInputTest_011, TestSize.Level1) { - InputInfo inputInfo = {0}; - CodecBufferInfo codecBufferInfo = {BUFFER_TYPE_FD}; + int32_t acquireFd; + CodecBuffer *inputInfo = (CodecBuffer *)OsalMemAlloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo) * 1); + inputInfo->bufferCnt = 1; - inputInfo.bufferCnt = 1; - inputInfo.buffers = &codecBufferInfo; - int32_t errorCode = codecObj->CodecDequeInput(codecObj, handle, QUEUE_TIME_OUT, &inputInfo); + int32_t errorCode = g_codecObj->CodecDequeueInput(g_codecObj, g_handle, QUEUE_TIME_OUT, &acquireFd, inputInfo); ASSERT_EQ(errorCode, HDF_SUCCESS); - ASSERT_EQ(inputInfo.buffers->type, inputInfoData.buffers->type); - ASSERT_EQ(inputInfo.buffers->size, inputInfoData.buffers->size); - ASSERT_EQ(inputInfo.buffers->offset, inputInfoData.buffers->offset); + ASSERT_EQ(inputInfo->bufferId, g_inputInfoData->bufferId); + ASSERT_EQ(inputInfo->bufferCnt, g_inputInfoData->bufferCnt); + ASSERT_EQ(inputInfo->buffer[0].type, g_inputInfoData->buffer[0].type); + ASSERT_EQ(inputInfo->buffer[0].offset, g_inputInfoData->buffer[0].offset); + ASSERT_EQ(inputInfo->buffer[0].length, g_inputInfoData->buffer[0].length); + ASSERT_EQ(inputInfo->buffer[0].capacity, g_inputInfoData->buffer[0].capacity); + OsalMemFree(inputInfo); + OsalMemFree(g_inputInfoData); } HWTEST_F(CodecProxyTest, HdfCodecHdiV1StartCodecTest_012, TestSize.Level1) { - int32_t errorCode = codecObj->CodecStart(codecObj, handle); + int32_t errorCode = g_codecObj->CodecStart(g_codecObj, g_handle); ASSERT_EQ(errorCode, HDF_SUCCESS); } HWTEST_F(CodecProxyTest, HdfCodecHdiV1StopCodecTest_013, TestSize.Level1) { - int32_t errorCode = codecObj->CodecStop(codecObj, handle); + int32_t errorCode = g_codecObj->CodecStop(g_codecObj, g_handle); ASSERT_EQ(errorCode, HDF_SUCCESS); } HWTEST_F(CodecProxyTest, HdfCodecHdiV1QueueOutputTest_014, TestSize.Level1) { - outputBuffer.id = 1; - outputBuffer.size = TEST_FRAME_BUFFER_SIZE; - CreateShareMemory(&outputBuffer); - outputInfoData.bufferCnt = 1; - outputInfoData.flag = STREAM_FLAG_CODEC_SPECIFIC_INF; - outputInfoData.buffers = &outputCodecBufferInfo; - if (outputInfoData.buffers != NULL) { - outputInfoData.buffers->type = BUFFER_TYPE_FD; - outputInfoData.buffers->fd = outputBuffer.fd; - outputInfoData.buffers->offset = outputBuffer.id; - outputInfoData.buffers->size = TEST_FRAME_BUFFER_SIZE; - } - int32_t errorCode = codecObj->CodecQueueOutput(codecObj, handle, &outputInfoData, (uint32_t)0, 1); + g_outputBuffer.id = 1; + g_outputBuffer.size = TEST_FRAME_BUFFER_SIZE; + int32_t ret = CreateShareMemory(&g_outputBuffer); + ASSERT_EQ(ret, HDF_SUCCESS); + + g_outputInfoData = (CodecBuffer *)OsalMemAlloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo) * 1); + g_outputInfoData->bufferId = 1; + g_outputInfoData->bufferCnt = 1; + g_outputInfoData->flag = 1; + g_outputInfoData->timeStamp = 1; + g_outputInfoData->buffer[0].type = BUFFER_TYPE_FD; + g_outputInfoData->buffer[0].offset = 1; + g_outputInfoData->buffer[0].length = 1; + g_outputInfoData->buffer[0].capacity = TEST_FRAME_BUFFER_SIZE; + g_outputInfoData->buffer[0].buf = (intptr_t)g_outputBuffer.fd; + + int32_t errorCode = g_codecObj->CodecQueueOutput(g_codecObj, g_handle, g_outputInfoData, (uint32_t)0, -1); ASSERT_EQ(errorCode, HDF_SUCCESS); } @@ -279,22 +310,26 @@ HWTEST_F(CodecProxyTest, HdfCodecHdiV1DequeueOutputTest_015, TestSize.Level1) { int32_t errorCode = 0; int32_t acquireFd; - OutputInfo outInfo = {0}; - CodecBufferInfo codecBufferInfo = {BUFFER_TYPE_FD}; - outInfo.bufferCnt = 1; - outInfo.buffers = &codecBufferInfo; - errorCode = codecObj->CodecDequeueOutput(codecObj, handle, QUEUE_TIME_OUT, &acquireFd, &outInfo); + CodecBuffer *outInfo = (CodecBuffer *)OsalMemAlloc(sizeof(CodecBuffer) + sizeof(CodecBufferInfo) * 1); + outInfo->bufferCnt = 1; + + errorCode = g_codecObj->CodecDequeueOutput(g_codecObj, g_handle, QUEUE_TIME_OUT, &acquireFd, outInfo); ASSERT_EQ(errorCode, HDF_SUCCESS); - ASSERT_EQ(outInfo.buffers->type, outputInfoData.buffers->type); - ASSERT_EQ(outInfo.buffers->size, outputInfoData.buffers->size); - ASSERT_EQ(outInfo.buffers->offset, outputInfoData.buffers->offset); + ASSERT_EQ(outInfo->bufferId, g_outputInfoData->bufferId); + ASSERT_EQ(outInfo->bufferCnt, g_outputInfoData->bufferCnt); + ASSERT_EQ(outInfo->buffer[0].type, g_outputInfoData->buffer[0].type); + ASSERT_EQ(outInfo->buffer[0].offset, g_outputInfoData->buffer[0].offset); + ASSERT_EQ(outInfo->buffer[0].length, g_outputInfoData->buffer[0].length); + ASSERT_EQ(outInfo->buffer[0].capacity, g_outputInfoData->buffer[0].capacity); + OsalMemFree(outInfo); + OsalMemFree(g_outputInfoData); } HWTEST_F(CodecProxyTest, HdfCodecHdiV1FlushTest_016, TestSize.Level1) { DirectionType directType = OUTPUT_TYPE; - int32_t errorCode = codecObj->CodecFlush(codecObj, handle, directType); + int32_t errorCode = g_codecObj->CodecFlush(g_codecObj, g_handle, directType); ASSERT_EQ(errorCode, HDF_SUCCESS); ASSERT_EQ(directType, OUTPUT_TYPE); } @@ -305,20 +340,20 @@ HWTEST_F(CodecProxyTest, HdfCodecHdiV1SetCallbackTest_017, TestSize.Level1) g_callback = CodecCallbackStubObtain(); ASSERT_TRUE(g_callback != nullptr); - int32_t errorCode = codecObj->CodecSetCallback(codecObj, handle, g_callback, instance); + int32_t errorCode = g_codecObj->CodecSetCallback(g_codecObj, g_handle, g_callback, instance); ASSERT_EQ(errorCode, HDF_SUCCESS); } HWTEST_F(CodecProxyTest, HdfCodecHdiV1DestroyCodecTest_018, TestSize.Level1) { - int32_t errorCode = codecObj->CodecDestroy(codecObj, handle); + int32_t errorCode = g_codecObj->CodecDestroy(g_codecObj, g_handle); ASSERT_EQ(errorCode, HDF_SUCCESS); } HWTEST_F(CodecProxyTest, HdfCodecHdiV1DeinitTest_019, TestSize.Level1) { - int32_t errorCode = codecObj->CodecDeinit(codecObj); + int32_t errorCode = g_codecObj->CodecDeinit(g_codecObj); ASSERT_EQ(errorCode, HDF_SUCCESS); - HdiCodecRelease(codecObj); + HdiCodecRelease(g_codecObj); } } diff --git a/format/interfaces/include/format_type.h b/format/interfaces/include/format_type.h index c9b278e24b3cdeee9003119e80c43484134ec9f3..76057a87393e4f0adbca9ec2aaa29b2753851e41 100644 --- a/format/interfaces/include/format_type.h +++ b/format/interfaces/include/format_type.h @@ -126,12 +126,12 @@ typedef enum { * @version 1.0 */ typedef enum { - AUDIO_SAMPLE_FMT_S8 = 0, /**< 8-bit integer for a single sample */ - AUDIO_SAMPLE_FMT_S16, /**< 16-bit integer for a single sample */ - AUDIO_SAMPLE_FMT_S24, /**< 24-bit integer for a single sample */ - AUDIO_SAMPLE_FMT_S32, /**< 32-bit integer for a single sample */ - AUDIO_SAMPLE_FMT_FLOAT, /**< Single-precision floating point number for a single sample */ -} AudioSampleFmt; + FORMAT_AUDIO_SAMPLE_FMT_S8 = 0, /**< 8-bit integer for a single sample */ + FORMAT_AUDIO_SAMPLE_FMT_S16, /**< 16-bit integer for a single sample */ + FORMAT_AUDIO_SAMPLE_FMT_S24, /**< 24-bit integer for a single sample */ + FORMAT_AUDIO_SAMPLE_FMT_S32, /**< 32-bit integer for a single sample */ + FORMAT_AUDIO_SAMPLE_FMT_FLOAT, /**< Single-precision floating point number for a single sample */ +} FormatAudioSampleFmt; /** * @brief Enumerates subtitle frame types. @@ -586,7 +586,7 @@ typedef struct { CodecFormat codecType; /**< Audio encoding type, for details, see {@link CodecFormat}. */ uint32_t sampleRate; /**< Sampling rate */ uint32_t channelCount; /**< Number of audio channels */ - AudioSampleFmt sampleBitWidth; /**< Bit width */ + FormatAudioSampleFmt sampleBitWidth; /**< Bit width */ uint32_t samplesPerFrame; /**< Number of samples per frame */ uint32_t avgBytesPerSec; /**< Average bit rate, in byte/s */ } AudioTrackSourceInfo;