1 /*
2 * Copyright (c) 2023 Shenzhen Kaihong DID Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <codec_jpeg_vdi.h>
16 #include <hdf_base.h>
17 #include <hdf_log.h>
18 #include <memory>
19 #include "codec_jpeg_impl.h"
20 #include "codec_log_wrapper.h"
21 using namespace OHOS::VDI::JPEG;
22 static std::shared_ptr<CodecJpegImpl> g_JpegImpl = nullptr;
JpegInit()23 static int32_t JpegInit()
24 {
25 CODEC_LOGI("enter.");
26 if (g_JpegImpl != nullptr) {
27 CODEC_LOGE("jpeg impl is inited.");
28 return HDF_ERR_DEVICE_BUSY;
29 }
30 g_JpegImpl = std::make_shared<CodecJpegImpl>();
31 return g_JpegImpl->Init();
32 }
33
JpegDeInit()34 static int32_t JpegDeInit()
35 {
36 CODEC_LOGI("enter.");
37 if (g_JpegImpl) {
38 g_JpegImpl->DeInit();
39 }
40 g_JpegImpl = nullptr;
41 return HDF_SUCCESS;
42 }
43
AllocateBuffer(BufferHandle ** buffer,uint32_t size)44 static int32_t AllocateBuffer(BufferHandle **buffer, uint32_t size)
45 {
46 CODEC_LOGI("enter.");
47 if (g_JpegImpl == nullptr) {
48 CODEC_LOGE("jpeg decoder is not init.");
49 return HDF_ERR_NOPERM;
50 }
51 return g_JpegImpl->AllocateBuffer(buffer, size);
52 }
53
FreeBuffer(BufferHandle * buffer)54 static int32_t FreeBuffer(BufferHandle *buffer)
55 {
56 CODEC_LOGI("enter.");
57 if (g_JpegImpl == nullptr) {
58 CODEC_LOGE("jpeg decoder is not init.");
59 return HDF_ERR_NOPERM;
60 }
61 return g_JpegImpl->FreeBuffer(buffer);
62 }
63
DoJpegDecode(BufferHandle * buffer,BufferHandle * outBuffer,const struct CodecJpegDecInfo * decInfo)64 static int32_t DoJpegDecode(BufferHandle *buffer, BufferHandle *outBuffer, const struct CodecJpegDecInfo *decInfo)
65 {
66 CODEC_LOGI("enter.");
67 if (g_JpegImpl == nullptr) {
68 CODEC_LOGE("jpeg decoder is not init.");
69 return HDF_ERR_NOPERM;
70 }
71
72 return g_JpegImpl->DeCode(buffer, outBuffer, *decInfo);
73 }
74
75 static ICodecJpegHwi g_jpegHwi = {.JpegInit = JpegInit,
76 .JpegDeInit = JpegDeInit,
77 .AllocateInBuffer = AllocateBuffer,
78 .FreeInBuffer = FreeBuffer,
79 .DoJpegDecode = DoJpegDecode};
80
GetCodecJpegHwi()81 extern "C" ICodecJpegHwi *GetCodecJpegHwi()
82 {
83 return &g_jpegHwi;
84 }
85