• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "codec_log_wrapper.h"
17 #include "codec_image_service.h"
18 #include "hitrace_meter.h"
19 #include <unistd.h>
20 
21 namespace OHOS {
22 namespace HDI {
23 namespace Codec {
24 namespace Image {
25 namespace V1_0 {
CodecImageImplGetInstance(void)26 extern "C" ICodecImage *CodecImageImplGetInstance(void)
27 {
28     return new (std::nothrow) CodecImageService();
29 }
30 
CodecImageService()31 CodecImageService::CodecImageService()
32 {
33     jpegImpl_ = std::make_unique<CodecJpegService>();
34 }
35 
GetImageCapability(std::vector<CodecImageCapability> & capList)36 int32_t CodecImageService::GetImageCapability(std::vector<CodecImageCapability>& capList)
37 {
38     HITRACE_METER_NAME(HITRACE_TAG_HDF, "HdfCodecGetImageCapability");
39     return CodecImageConfig::GetInstance()->GetImageCapabilityList(capList);
40 }
41 
Init(enum CodecImageRole role)42 int32_t CodecImageService::Init(enum CodecImageRole role)
43 {
44     HITRACE_METER_NAME(HITRACE_TAG_HDF, "HdfCodecInit");
45     CODEC_LOGI("servcie impl!");
46     if (role == CODEC_IMAGE_JPEG) {
47         CHECK_AND_RETURN_RET_LOG(jpegImpl_ != nullptr, HDF_FAILURE, "jpegImpl_ is null");
48         return jpegImpl_->JpegInit();
49     } else {
50         return HDF_ERR_NOT_SUPPORT;
51     }
52 }
53 
DeInit(enum CodecImageRole role)54 int32_t CodecImageService::DeInit(enum CodecImageRole role)
55 {
56     HITRACE_METER_NAME(HITRACE_TAG_HDF, "HdfCodecDeInit");
57     CODEC_LOGI("servcie impl!");
58     if (role == CODEC_IMAGE_JPEG) {
59         CHECK_AND_RETURN_RET_LOG(jpegImpl_ != nullptr, HDF_FAILURE, "jpegImpl_ is null");
60         return jpegImpl_->JpegDeInit();
61     } else {
62         return HDF_ERR_NOT_SUPPORT;
63     }
64 }
65 
DoJpegDecode(const CodecImageBuffer & inBuffer,const CodecImageBuffer & outBuffer,const CodecJpegDecInfo & decInfo)66 int32_t CodecImageService::DoJpegDecode(const CodecImageBuffer& inBuffer, const CodecImageBuffer& outBuffer,
67     const CodecJpegDecInfo& decInfo)
68 {
69     HITRACE_METER_NAME(HITRACE_TAG_HDF, "HdfCodecDoJpegDecode");
70     CODEC_LOGI("servcie impl!");
71     if (inBuffer.fenceFd >= 0) {
72         close(inBuffer.fenceFd);
73     }
74     CHECK_AND_RETURN_RET_LOG(jpegImpl_ != nullptr, HDF_FAILURE, "jpegImpl_ is null");
75     return jpegImpl_->DoJpegDecode(inBuffer, outBuffer, decInfo);
76 }
77 
AllocateInBuffer(CodecImageBuffer & inBuffer,uint32_t size,CodecImageRole role)78 int32_t CodecImageService::AllocateInBuffer(CodecImageBuffer& inBuffer, uint32_t size, CodecImageRole role)
79 {
80     HITRACE_METER_NAME(HITRACE_TAG_HDF, "HdfCodecAllocateInBuffer");
81     CODEC_LOGI("servcie impl, size [%{public}d]", size);
82     CHECK_AND_RETURN_RET_LOG(size != 0, HDF_ERR_INVALID_PARAM, "buffer size is 0");
83     CHECK_AND_RETURN_RET_LOG(size <= CODEC_IMAGE_MAX_BUFFER_SIZE, HDF_ERR_INVALID_PARAM, "buffer size is too large");
84     inBuffer.bufferRole = role;
85     inBuffer.size = size;
86     if (role == CODEC_IMAGE_JPEG) {
87         CHECK_AND_RETURN_RET_LOG(jpegImpl_ != nullptr, HDF_FAILURE, "jpegImpl_ is null");
88         return jpegImpl_->AllocateJpegInBuffer(inBuffer, size);
89     } else {
90         return HDF_ERR_NOT_SUPPORT;
91     }
92 }
93 
FreeInBuffer(const CodecImageBuffer & inBuffer)94 int32_t CodecImageService::FreeInBuffer(const CodecImageBuffer& inBuffer)
95 {
96     HITRACE_METER_NAME(HITRACE_TAG_HDF, "HdfCodecFreeInBuffer");
97     CODEC_LOGI("servcie impl, bufferId [%{public}d]", inBuffer.id);
98     if (inBuffer.fenceFd >= 0) {
99         close(inBuffer.fenceFd);
100     }
101     if (inBuffer.bufferRole == CODEC_IMAGE_JPEG) {
102         CHECK_AND_RETURN_RET_LOG(jpegImpl_ != nullptr, HDF_FAILURE, "jpegImpl_ is null");
103         return jpegImpl_->FreeJpegInBuffer(inBuffer);
104     } else {
105         return HDF_ERR_NOT_SUPPORT;
106     }
107 }
108 } // V1_0
109 } // Image
110 } // Codec
111 } // HDI
112 } // OHOS
113