• 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 "media_manager_proxy.h"
17 #include "ipc_file_descriptor.h"
18 #include "dp_log.h"
19 namespace OHOS {
20 namespace CameraStandard {
21 namespace DeferredProcessing {
22 typedef MediaManagerIntf* (*CreateMediaManagerIntf)();
23 
MediaManagerProxy(std::shared_ptr<Dynamiclib> mediaManagerLib,std::shared_ptr<MediaManagerIntf> mediaManagerIntf)24 MediaManagerProxy::MediaManagerProxy(
25     std::shared_ptr<Dynamiclib> mediaManagerLib, std::shared_ptr<MediaManagerIntf> mediaManagerIntf)
26     : mediaManagerLib_(mediaManagerLib), mediaManagerIntf_(mediaManagerIntf)
27 {
28     DP_DEBUG_LOG("MediaManagerProxy constructor");
29 }
30 
CreateMediaManagerProxy()31 std::shared_ptr<MediaManagerProxy> MediaManagerProxy::CreateMediaManagerProxy()
32 {
33     std::shared_ptr<Dynamiclib> dynamiclib = CameraDynamicLoader::GetDynamiclib(MEDIA_MANAGER_SO);
34     DP_CHECK_ERROR_RETURN_RET_LOG(dynamiclib == nullptr, nullptr, "Failed to load media library");
35     CreateMediaManagerIntf createMediaManagerIntf =
36         (CreateMediaManagerIntf)dynamiclib->GetFunction("createMediaManagerIntf");
37     DP_CHECK_ERROR_RETURN_RET_LOG(
38         createMediaManagerIntf == nullptr, nullptr, "Failed to get createMediaManagerIntf function");
39     MediaManagerIntf* mediaManagerIntf = createMediaManagerIntf();
40     DP_CHECK_ERROR_RETURN_RET_LOG(
41         mediaManagerIntf == nullptr, nullptr, "Failed to create MediaManagerIntf instance");
42     std::shared_ptr<MediaManagerProxy> mediaManagerProxy =
43         std::make_shared<MediaManagerProxy>(dynamiclib, std::shared_ptr<MediaManagerIntf>(mediaManagerIntf));
44     return mediaManagerProxy;
45 }
46 
~MediaManagerProxy()47 MediaManagerProxy::~MediaManagerProxy()
48 {
49     DP_DEBUG_LOG("MediaManagerProxy destructor");
50 }
51 
MpegAcquire(const std::string & requestId,const sptr<IPCFileDescriptor> & inputFd)52 int32_t MediaManagerProxy::MpegAcquire(const std::string& requestId, const sptr<IPCFileDescriptor>& inputFd)
53 {
54     DP_DEBUG_LOG("MpegAcquire requestId: %{public}s", requestId.c_str());
55     DP_CHECK_ERROR_RETURN_RET_LOG(mediaManagerIntf_ == nullptr, DP_ERR, "MediaManagerIntf is null");
56     return mediaManagerIntf_->MpegAcquire(requestId, inputFd);
57 }
58 
MpegUnInit(const int32_t result)59 int32_t MediaManagerProxy::MpegUnInit(const int32_t result)
60 {
61     DP_DEBUG_LOG("MpegUnInit result: %{public}d", result);
62     DP_CHECK_ERROR_RETURN_RET_LOG(mediaManagerIntf_ == nullptr, DP_ERR, "MediaManagerIntf is null");
63     return mediaManagerIntf_->MpegUnInit(result);
64 }
65 
MpegGetResultFd()66 sptr<IPCFileDescriptor> MediaManagerProxy::MpegGetResultFd()
67 {
68     DP_DEBUG_LOG("MpegGetResultFd");
69     DP_CHECK_ERROR_RETURN_RET_LOG(mediaManagerIntf_ == nullptr, nullptr, "MediaManagerIntf is null");
70     return mediaManagerIntf_->MpegGetResultFd();
71 }
72 
MpegAddUserMeta(std::unique_ptr<MediaUserInfo> userInfo)73 void MediaManagerProxy::MpegAddUserMeta(std::unique_ptr<MediaUserInfo> userInfo)
74 {
75     DP_DEBUG_LOG("MpegAddUserMeta");
76     DP_CHECK_ERROR_RETURN_LOG(mediaManagerIntf_ == nullptr, "MediaManagerIntf is null");
77     mediaManagerIntf_->MpegAddUserMeta(std::move(userInfo));
78 }
79 
MpegGetProcessTimeStamp()80 uint64_t MediaManagerProxy::MpegGetProcessTimeStamp()
81 {
82     DP_DEBUG_LOG("MpegGetProcessTimeStamp");
83     DP_CHECK_ERROR_RETURN_RET_LOG(mediaManagerIntf_ == nullptr, 0, "MediaManagerIntf is null");
84     return mediaManagerIntf_->MpegGetProcessTimeStamp();
85 }
86 
MpegGetSurface()87 sptr<Surface> MediaManagerProxy::MpegGetSurface()
88 {
89     DP_DEBUG_LOG("MpegGetSurface");
90     DP_CHECK_ERROR_RETURN_RET_LOG(mediaManagerIntf_ == nullptr, nullptr, "MediaManagerIntf is null");
91     return mediaManagerIntf_->MpegGetSurface();
92 }
93 
MpegGetMakerSurface()94 sptr<Surface> MediaManagerProxy::MpegGetMakerSurface()
95 {
96     DP_DEBUG_LOG("MpegGetMakerSurface");
97     DP_CHECK_ERROR_RETURN_RET_LOG(mediaManagerIntf_ == nullptr, nullptr, "MediaManagerIntf is null");
98     return mediaManagerIntf_->MpegGetMakerSurface();
99 }
100 
MpegSetMarkSize(int32_t size)101 void MediaManagerProxy::MpegSetMarkSize(int32_t size)
102 {
103     DP_DEBUG_LOG("MpegSetMarkSize size: %{public}d", size);
104     DP_CHECK_ERROR_RETURN_LOG(mediaManagerIntf_ == nullptr, "MediaManagerIntf is null");
105     mediaManagerIntf_->MpegSetMarkSize(size);
106 }
107 
MpegRelease()108 int32_t MediaManagerProxy::MpegRelease()
109 {
110     DP_DEBUG_LOG("MpegRelease");
111     DP_CHECK_ERROR_RETURN_RET_LOG(mediaManagerIntf_ == nullptr, DP_ERR, "MediaManagerIntf is null");
112     return mediaManagerIntf_->MpegRelease();
113 }
114 } // namespace DeferredProcessing
115 } // namespace CameraStandard
116 } // namespace OHOS