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 #ifndef OHOS_HDI_CODEC_V2_0_CODECIMAGESERVICE_H
17 #define OHOS_HDI_CODEC_V2_0_CODECIMAGESERVICE_H
18 
19 #include <map>
20 #include <mutex>
21 #include "buffer_handle.h"
22 #include "codec_image_config.h"
23 #include "v2_0/icodec_image.h"
24 #include "codec_jpeg_service.h"
25 #include "codec_heif_encode_service.h"
26 
27 constexpr uint32_t CODEC_IMAGE_MAX_BUFFER_SIZE = 50 * 1024 *1024;
28 namespace OHOS {
29 namespace HDI {
30 namespace Codec {
31 namespace Image {
32 namespace V2_0 {
33 class CodecImageService : public ICodecImage {
34 public:
35     explicit CodecImageService();
36 
37     virtual ~CodecImageService() = default;
38 
39     int32_t GetImageCapability(std::vector<CodecImageCapability>& capList) override;
40 
41     int32_t Init(enum CodecImageRole role) override;
42 
43     int32_t DeInit(enum CodecImageRole role) override;
44 
45     int32_t DoJpegDecode(const CodecImageBuffer& inBuffer, const CodecImageBuffer& outBuffer,
46         const CodecJpegDecInfo& decInfo) override;
47 
48     int32_t AllocateInBuffer(CodecImageBuffer& inBuffer, uint32_t size, CodecImageRole role) override;
49 
50     int32_t FreeInBuffer(const CodecImageBuffer& buffer) override;
51 
52     int32_t DoHeifEncode(const std::vector<ImageItem>& inputImgs, const std::vector<MetaItem>& inputMetas,
53                          const std::vector<ItemRef>& refs, const SharedBuffer& output,
54                          uint32_t& filledLen) override;
55 
56 private:
57     std::unique_ptr<CodecJpegService> jpegImpl_;
58     std::unique_ptr<CodecHeifEncodeService> heifEncodeImpl_;
59 };
60 } // V2_0
61 } // Image
62 } // Codec
63 } // HDI
64 } // OHOS
65 
66 #endif // OHOS_HDI_CODEC_V2_0_CODECIMAGESERVICE_H
67