1 /*
2  * Copyright (c) 2024 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 "ohos_nweb/bridge/ark_web_media_info_wrapper.h"
17 
18 #include "ohos_nweb/bridge/ark_web_native_media_player_surface_info_wrapper.h"
19 #include "ohos_nweb/ctocpp/ark_web_media_source_info_vector_ctocpp.h"
20 
21 #include "base/bridge/ark_web_bridge_macros.h"
22 
23 namespace OHOS::ArkWeb {
24 
ArkWebMediaInfoWrapper(ArkWebRefPtr<ArkWebMediaInfo> ark_web_media_info)25 ArkWebMediaInfoWrapper::ArkWebMediaInfoWrapper(ArkWebRefPtr<ArkWebMediaInfo> ark_web_media_info)
26     : ark_web_media_info_(ark_web_media_info)
27 {}
28 
GetPreload()29 ArkWebPreload ArkWebMediaInfoWrapper::GetPreload()
30 {
31     return static_cast<ArkWebPreload>(ark_web_media_info_->GetPreload());
32 }
33 
GetIsMuted()34 bool ArkWebMediaInfoWrapper::GetIsMuted()
35 {
36     return ark_web_media_info_->GetIsMuted();
37 }
38 
GetEmbedId()39 std::string ArkWebMediaInfoWrapper::GetEmbedId()
40 {
41     ArkWebString stEmbedId = ark_web_media_info_->GetEmbedId();
42 
43     std::string objEmbedId = ArkWebStringStructToClass(stEmbedId);
44     ArkWebStringStructRelease(stEmbedId);
45     return objEmbedId;
46 }
47 
GetPosterUrl()48 std::string ArkWebMediaInfoWrapper::GetPosterUrl()
49 {
50     ArkWebString stUrl = ark_web_media_info_->GetPosterUrl();
51 
52     std::string objUrl = ArkWebStringStructToClass(stUrl);
53     ArkWebStringStructRelease(stUrl);
54     return objUrl;
55 }
56 
GetMediaType()57 ArkWebMediaType ArkWebMediaInfoWrapper::GetMediaType()
58 {
59     return static_cast<ArkWebMediaType>(ark_web_media_info_->GetMediaType());
60 }
61 
GetIsControlsShown()62 bool ArkWebMediaInfoWrapper::GetIsControlsShown()
63 {
64     return ark_web_media_info_->GetIsControlsShown();
65 }
66 
GetControls()67 std::vector<std::string> ArkWebMediaInfoWrapper::GetControls()
68 {
69     ArkWebStringVector stControls = ark_web_media_info_->GetControls();
70 
71     std::vector<std::string> objControls = ArkWebStringVectorStructToClass(stControls);
72     ArkWebStringVectorStructRelease(stControls);
73     return objControls;
74 }
75 
GetHeaders()76 std::map<std::string, std::string> ArkWebMediaInfoWrapper::GetHeaders()
77 {
78     ArkWebStringMap stHeaders = ark_web_media_info_->GetHeaders();
79 
80     std::map<std::string, std::string> objHeaders = ArkWebStringMapStructToClass(stHeaders);
81     ArkWebStringMapStructRelease(stHeaders);
82     return objHeaders;
83 }
84 
GetAttributes()85 std::map<std::string, std::string> ArkWebMediaInfoWrapper::GetAttributes()
86 {
87     ArkWebStringMap stAttributes = ark_web_media_info_->GetAttributes();
88 
89     std::map<std::string, std::string> objAttributes = ArkWebStringMapStructToClass(stAttributes);
90     ArkWebStringMapStructRelease(stAttributes);
91     return objAttributes;
92 }
93 
GetSourceInfos()94 std::vector<std::shared_ptr<OHOS::NWeb::NWebMediaSourceInfo>> ArkWebMediaInfoWrapper::GetSourceInfos()
95 {
96     ArkWebMediaSourceInfoVector stMediaSourceInfoVector = ark_web_media_info_->GetSourceInfos();
97 
98     std::vector<std::shared_ptr<OHOS::NWeb::NWebMediaSourceInfo>> objMediaSourceInfoVector =
99         ArkWebMediaSourceInfoVectorStructToClass(stMediaSourceInfoVector);
100     ArkWebMediaSourceInfoVectorStructRelease(stMediaSourceInfoVector);
101     return objMediaSourceInfoVector;
102 }
103 
GetSurfaceInfo()104 std::shared_ptr<OHOS::NWeb::NWebNativeMediaPlayerSurfaceInfo> ArkWebMediaInfoWrapper::GetSurfaceInfo()
105 {
106     ArkWebRefPtr<ArkWebNativeMediaPlayerSurfaceInfo> ark_web_native_media_player_surface_info =
107         ark_web_media_info_->GetSurfaceInfo();
108     if (CHECK_REF_PTR_IS_NULL(ark_web_native_media_player_surface_info)) {
109         return nullptr;
110     }
111 
112     return std::make_shared<ArkWebNativeMediaPlayerSurfaceInfoWrapper>(ark_web_native_media_player_surface_info);
113 }
114 
115 } // namespace OHOS::ArkWeb
116