1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "image_source_proxy.h"
17 #include "camera_log.h"
18
19 namespace OHOS {
20 namespace CameraStandard {
ImageSourceProxy(std::shared_ptr<Dynamiclib> imageLib,std::shared_ptr<ImageSourceIntf> imageSourceIntf)21 ImageSourceProxy::ImageSourceProxy(std::shared_ptr<Dynamiclib> imageLib,
22 std::shared_ptr<ImageSourceIntf> imageSourceIntf) : imageLib_(imageLib),
23 imageSourceIntf_(imageSourceIntf)
24 {
25 MEDIA_DEBUG_LOG("ImageSourceProxy constructor");
26 CHECK_RETURN_ELOG(imageLib_ == nullptr, "imageLib_ is nullptr");
27 CHECK_RETURN_ELOG(imageSourceIntf_ == nullptr, "imageSourceIntf_ is nullptr");
28 }
29
~ImageSourceProxy()30 ImageSourceProxy::~ImageSourceProxy()
31 {
32 MEDIA_DEBUG_LOG("ImageSourceProxy destructor");
33 }
34
35 typedef ImageSourceIntf* (*CreateImageSourceIntf)();
CreateImageSourceProxy()36 std::shared_ptr<ImageSourceProxy> ImageSourceProxy::CreateImageSourceProxy()
37 {
38 MEDIA_DEBUG_LOG("CreateImageSourceProxy start");
39 auto dynamiclib = CameraDynamicLoader::GetDynamiclib(PICTURE_SO);
40 CHECK_RETURN_RET_ELOG(
41 dynamiclib == nullptr, nullptr, "get dynamiclib fail");
42 CreateImageSourceIntf createImageSourceIntf =
43 (CreateImageSourceIntf)dynamiclib->GetFunction("createImageSourceIntf");
44 CHECK_RETURN_RET_ELOG(
45 createImageSourceIntf == nullptr, nullptr, "get createImageSourceIntf fail");
46 ImageSourceIntf* imageSourceIntf = createImageSourceIntf();
47 CHECK_RETURN_RET_ELOG(
48 imageSourceIntf == nullptr, nullptr, "get imageSourceIntf fail");
49 std::shared_ptr<ImageSourceProxy> imageSourceProxy =
50 std::make_shared<ImageSourceProxy>(dynamiclib, std::shared_ptr<ImageSourceIntf>(imageSourceIntf));
51 return imageSourceProxy;
52 }
53
CreateImageSource(const uint8_t * data,uint32_t size,const Media::SourceOptions & opts,uint32_t & errorCode)54 int32_t ImageSourceProxy::CreateImageSource(const uint8_t *data, uint32_t size, const Media::SourceOptions& opts,
55 uint32_t& errorCode)
56 {
57 MEDIA_DEBUG_LOG("CreateImageSource start");
58 CHECK_RETURN_RET_ELOG(imageSourceIntf_ == nullptr, -1, "imageSourceIntf_ is nullptr");
59 int32_t ret = imageSourceIntf_->CreateImageSource(data, size, opts, errorCode);
60 CHECK_RETURN_RET_ELOG(ret == -1, ret, "CreateImageSource failed, ret: %{public}d", ret);
61 return 0;
62 }
63
CreatePixelMap(const Media::DecodeOptions & opts,uint32_t & errorCode)64 std::unique_ptr<Media::PixelMap> ImageSourceProxy::CreatePixelMap(const Media::DecodeOptions& opts, uint32_t& errorCode)
65 {
66 MEDIA_DEBUG_LOG("CreatePixelMap start");
67 CHECK_RETURN_RET_ELOG(imageSourceIntf_ == nullptr, nullptr, "imageSourceIntf_ is nullptr");
68 return imageSourceIntf_->CreatePixelMap(opts, errorCode);
69 }
70 } // namespace CameraStandard
71 } // namespace OHOS