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 "picture_proxy.h"
17 #include "camera_log.h"
18 #include "ipc_skeleton.h"
19
20 namespace OHOS {
21 namespace CameraStandard {
22 // LCOV_EXCL_START
PictureProxy(std::shared_ptr<Dynamiclib> pictureLib,std::shared_ptr<PictureIntf> pictureIntf)23 PictureProxy::PictureProxy(
24 std::shared_ptr<Dynamiclib> pictureLib, std::shared_ptr<PictureIntf> pictureIntf)
25 : pictureLib_(pictureLib), pictureIntf_(pictureIntf)
26 {
27 CHECK_RETURN_ELOG(pictureLib_ == nullptr, "PictureProxy construct pictureLib is null");
28 CHECK_RETURN_ELOG(pictureIntf_ == nullptr, "PictureProxy construct pictureIntf is null");
29 }
30
~PictureProxy()31 PictureProxy::~PictureProxy()
32 {
33 MEDIA_INFO_LOG("PictureProxy dctor");
34 }
35
Create(sptr<SurfaceBuffer> & surfaceBuffer)36 void PictureProxy::Create(sptr<SurfaceBuffer> &surfaceBuffer)
37 {
38 MEDIA_INFO_LOG("PictureProxy ctor");
39 std::shared_ptr<PictureIntf> pictureIntf = GetPictureIntf();
40 CHECK_RETURN_ELOG(!pictureIntf, "PictureProxy::Create pictureIntf_ is nullptr");
41 pictureIntf->Create(surfaceBuffer);
42 }
43
44 typedef PictureIntf* (*CreatePictureIntf)();
CreatePictureProxy()45 std::shared_ptr<PictureProxy> PictureProxy::CreatePictureProxy()
46 {
47 auto dynamiclib = CameraDynamicLoader::GetDynamiclib(PICTURE_SO);
48 CHECK_RETURN_RET_ELOG(
49 dynamiclib == nullptr, nullptr, "PictureProxy::CreatePictureProxy get dynamiclib fail");
50 CreatePictureIntf createPictureIntf = (CreatePictureIntf)dynamiclib->GetFunction("createPictureAdapterIntf");
51 CHECK_RETURN_RET_ELOG(
52 createPictureIntf == nullptr, nullptr, "PictureProxy::CreatePictureProxy get createPictureIntf fail");
53 PictureIntf* pictureIntf = createPictureIntf();
54 CHECK_RETURN_RET_ELOG(
55 pictureIntf == nullptr, nullptr, "PictureProxy::CreatePictureProxy get pictureIntf fail");
56 std::shared_ptr<PictureProxy> pictureProxy =
57 std::make_shared<PictureProxy>(dynamiclib, std::shared_ptr<PictureIntf>(pictureIntf));
58 return pictureProxy;
59 }
60
GetPictureIntf() const61 std::shared_ptr<PictureIntf> PictureProxy::GetPictureIntf() const
62 {
63 return pictureIntf_;
64 }
SetAuxiliaryPicture(sptr<SurfaceBuffer> & surfaceBuffer,CameraAuxiliaryPictureType type)65 void PictureProxy::SetAuxiliaryPicture(sptr<SurfaceBuffer> &surfaceBuffer, CameraAuxiliaryPictureType type)
66 {
67 MEDIA_INFO_LOG("PictureProxy::SetAuxiliaryPicture enter");
68 std::shared_ptr<PictureIntf> pictureIntf = GetPictureIntf();
69 CHECK_RETURN_ELOG(!pictureIntf, "PictureProxy::SetAuxiliaryPicture pictureIntf_ is nullptr");
70 pictureIntf->SetAuxiliaryPicture(surfaceBuffer, type);
71 }
72
CreateWithDeepCopySurfaceBuffer(sptr<SurfaceBuffer> & surfaceBuffer)73 void PictureProxy::CreateWithDeepCopySurfaceBuffer(sptr<SurfaceBuffer> &surfaceBuffer)
74 {
75 MEDIA_INFO_LOG("PictureProxy::CreateWithDeepCopySurfaceBuffer enter");
76 std::shared_ptr<PictureIntf> pictureIntf = GetPictureIntf();
77 CHECK_RETURN_ELOG(!pictureIntf, "PictureProxy::CreateWithDeepCopySurfaceBuffer pictureIntf_ is nullptr");
78 pictureIntf->CreateWithDeepCopySurfaceBuffer(surfaceBuffer);
79 }
80
Marshalling(Parcel & data) const81 bool PictureProxy::Marshalling(Parcel &data) const
82 {
83 MEDIA_INFO_LOG("PictureProxy::Marshalling enter");
84 std::shared_ptr<PictureIntf> pictureIntf = GetPictureIntf();
85 CHECK_RETURN_RET_ELOG(pictureIntf == nullptr, false, "PictureProxy::Marshalling pictureIntf_ is nullptr");
86 return pictureIntf->Marshalling(data);
87 }
88
UnmarshallingPicture(Parcel & data)89 void PictureProxy::UnmarshallingPicture(Parcel &data)
90 {
91 MEDIA_INFO_LOG("PictureProxy::Unmarshalling enter");
92 std::shared_ptr<PictureIntf> pictureIntf = GetPictureIntf();
93 CHECK_RETURN_ELOG(!pictureIntf, "PictureProxy::Unmarshalling failed! pictureIntf is nullptr");
94 pictureIntf->UnmarshallingPicture(data);
95 }
96
SetExifMetadata(sptr<SurfaceBuffer> & surfaceBuffer)97 int32_t PictureProxy::SetExifMetadata(sptr<SurfaceBuffer> &surfaceBuffer)
98 {
99 MEDIA_INFO_LOG("PictureProxy::SetExifMetadata enter");
100 int32_t retCode = -1;
101 std::shared_ptr<PictureIntf> pictureIntf = GetPictureIntf();
102 CHECK_RETURN_RET_ELOG(!pictureIntf, retCode, "PictureProxy::SetExifMetadata pictureIntf is nullptr");
103 retCode = pictureIntf->SetExifMetadata(surfaceBuffer);
104 return retCode;
105 }
106
SetMaintenanceData(sptr<SurfaceBuffer> & surfaceBuffer)107 bool PictureProxy::SetMaintenanceData(sptr<SurfaceBuffer> &surfaceBuffer)
108 {
109 bool retCode = false;
110 std::shared_ptr<PictureIntf> pictureIntf = GetPictureIntf();
111 CHECK_RETURN_RET_ELOG(!pictureIntf, retCode, "PictureProxy::SetMaintenanceData pictureIntf is nullptr");
112 retCode = pictureIntf->SetMaintenanceData(surfaceBuffer);
113 return retCode;
114 }
115
RotatePicture()116 void PictureProxy::RotatePicture()
117 {
118 std::shared_ptr<PictureIntf> pictureIntf = GetPictureIntf();
119 CHECK_RETURN_ELOG(!pictureIntf, "PictureProxy::RotatePicture pictureIntf is nullptr");
120 pictureIntf->RotatePicture();
121 }
122 // LCOV_EXCL_STOP
123 } // namespace CameraStandard
124 } // namespace OHOS