• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ERROR_RETURN_LOG(pictureLib_ == nullptr, "PictureProxy construct pictureLib is null");
28     CHECK_ERROR_RETURN_LOG(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     if (!pictureIntf) {
41         MEDIA_ERR_LOG("PictureProxy::Create pictureIntf_ is nullptr");
42         return;
43     }
44     pictureIntf->Create(surfaceBuffer);
45 }
46 
47 typedef PictureIntf* (*CreatePictureIntf)();
CreatePictureProxy()48 std::shared_ptr<PictureProxy> PictureProxy::CreatePictureProxy()
49 {
50     auto dynamiclib = CameraDynamicLoader::GetDynamiclib(PICTURE_SO);
51     CHECK_ERROR_RETURN_RET_LOG(
52         dynamiclib == nullptr, nullptr, "PictureProxy::CreatePictureProxy get dynamiclib fail");
53     CreatePictureIntf createPictureIntf = (CreatePictureIntf)dynamiclib->GetFunction("createPictureAdapterIntf");
54     CHECK_ERROR_RETURN_RET_LOG(
55         createPictureIntf == nullptr, nullptr, "PictureProxy::CreatePictureProxy get createPictureIntf fail");
56     PictureIntf* pictureIntf = createPictureIntf();
57     CHECK_ERROR_RETURN_RET_LOG(
58         pictureIntf == nullptr, nullptr, "PictureProxy::CreatePictureProxy get pictureIntf fail");
59     std::shared_ptr<PictureProxy> pictureProxy =
60         std::make_shared<PictureProxy>(dynamiclib, std::shared_ptr<PictureIntf>(pictureIntf));
61     return pictureProxy;
62 }
63 
GetPictureIntf()64 std::shared_ptr<PictureIntf> PictureProxy::GetPictureIntf()
65 {
66     return pictureIntf_;
67 }
SetAuxiliaryPicture(sptr<SurfaceBuffer> & surfaceBuffer,CameraAuxiliaryPictureType type)68 void PictureProxy::SetAuxiliaryPicture(sptr<SurfaceBuffer> &surfaceBuffer, CameraAuxiliaryPictureType type)
69 {
70     MEDIA_INFO_LOG("PictureProxy::SetAuxiliaryPicture enter");
71     std::shared_ptr<PictureIntf> pictureIntf = GetPictureIntf();
72     if (!pictureIntf) {
73         MEDIA_ERR_LOG("PictureProxy::SetAuxiliaryPicture pictureIntf_ is nullptr");
74         return;
75     }
76     pictureIntf->SetAuxiliaryPicture(surfaceBuffer, type);
77 }
78 
Marshalling(Parcel & data)79 bool PictureProxy::Marshalling(Parcel &data)
80 {
81     MEDIA_INFO_LOG("PictureProxy::Marshalling enter");
82     std::shared_ptr<PictureIntf> pictureIntf = GetPictureIntf();
83     if (pictureIntf == nullptr) {
84         MEDIA_ERR_LOG("PictureProxy::Marshalling pictureIntf_ is nullptr");
85         return false;
86     }
87     return pictureIntf->Marshalling(data);
88 }
89 
Unmarshalling(Parcel & data)90 void PictureProxy::Unmarshalling(Parcel &data)
91 {
92     MEDIA_INFO_LOG("PictureProxy::Unmarshalling enter");
93     std::shared_ptr<PictureIntf> pictureIntf = GetPictureIntf();
94     if (!pictureIntf) {
95         MEDIA_ERR_LOG("PictureProxy::Unmarshalling failed! pictureIntf is nullptr");
96         return;
97     }
98     pictureIntf->Unmarshalling(data);
99 }
100 
SetExifMetadata(sptr<SurfaceBuffer> & surfaceBuffer)101 int32_t PictureProxy::SetExifMetadata(sptr<SurfaceBuffer> &surfaceBuffer)
102 {
103     MEDIA_INFO_LOG("PictureProxy::SetExifMetadata enter");
104     int32_t retCode = -1;
105     std::shared_ptr<PictureIntf> pictureIntf = GetPictureIntf();
106     if (!pictureIntf) {
107         MEDIA_ERR_LOG("PictureProxy::SetExifMetadata pictureIntf is nullptr");
108         return retCode;
109     }
110     retCode = pictureIntf->SetExifMetadata(surfaceBuffer);
111     return retCode;
112 }
113 
SetMaintenanceData(sptr<SurfaceBuffer> & surfaceBuffer)114 bool PictureProxy::SetMaintenanceData(sptr<SurfaceBuffer> &surfaceBuffer)
115 {
116     bool retCode = false;
117     std::shared_ptr<PictureIntf> pictureIntf = GetPictureIntf();
118     if (!pictureIntf) {
119         MEDIA_ERR_LOG("PictureProxy::SetMaintenanceData pictureIntf is nullptr");
120         return retCode;
121     }
122     retCode = pictureIntf->SetMaintenanceData(surfaceBuffer);
123     return retCode;
124 }
125 
RotatePicture()126 void PictureProxy::RotatePicture()
127 {
128     std::shared_ptr<PictureIntf> pictureIntf = GetPictureIntf();
129     if (!pictureIntf) {
130         MEDIA_ERR_LOG("PictureProxy::RotatePicture pictureIntf is nullptr");
131         return;
132     }
133     pictureIntf->RotatePicture();
134 }
135 // LCOV_EXCL_STOP
136 }  // namespace CameraStandard
137 }  // namespace OHOS