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_impl.h"
17 
18 #include "ohos_nweb/bridge/ark_web_native_media_player_surface_info_impl.h"
19 #include "ohos_nweb/cpptoc/ark_web_media_source_info_vector_cpptoc.h"
20 
21 #include "base/bridge/ark_web_bridge_macros.h"
22 
23 namespace OHOS::ArkWeb {
24 
ArkWebMediaInfoImpl(std::shared_ptr<OHOS::NWeb::NWebMediaInfo> nweb_media_info)25 ArkWebMediaInfoImpl::ArkWebMediaInfoImpl(std::shared_ptr<OHOS::NWeb::NWebMediaInfo> nweb_media_info)
26     : nweb_media_info_(nweb_media_info)
27 {}
28 
GetPreload()29 int ArkWebMediaInfoImpl::GetPreload()
30 {
31     return static_cast<int>(nweb_media_info_->GetPreload());
32 }
33 
GetIsMuted()34 bool ArkWebMediaInfoImpl::GetIsMuted()
35 {
36     return nweb_media_info_->GetIsMuted();
37 }
38 
GetEmbedId()39 ArkWebString ArkWebMediaInfoImpl::GetEmbedId()
40 {
41     return ArkWebStringClassToStruct(nweb_media_info_->GetEmbedId());
42 }
43 
GetPosterUrl()44 ArkWebString ArkWebMediaInfoImpl::GetPosterUrl()
45 {
46     return ArkWebStringClassToStruct(nweb_media_info_->GetPosterUrl());
47 }
48 
GetMediaType()49 int ArkWebMediaInfoImpl::GetMediaType()
50 {
51     return static_cast<int>(nweb_media_info_->GetMediaType());
52 }
53 
GetIsControlsShown()54 bool ArkWebMediaInfoImpl::GetIsControlsShown()
55 {
56     return nweb_media_info_->GetIsControlsShown();
57 }
58 
GetControls()59 ArkWebStringVector ArkWebMediaInfoImpl::GetControls()
60 {
61     return ArkWebStringVectorClassToStruct(nweb_media_info_->GetControls());
62 }
63 
GetHeaders()64 ArkWebStringMap ArkWebMediaInfoImpl::GetHeaders()
65 {
66     return ArkWebStringMapClassToStruct(nweb_media_info_->GetHeaders());
67 }
68 
GetAttributes()69 ArkWebStringMap ArkWebMediaInfoImpl::GetAttributes()
70 {
71     return ArkWebStringMapClassToStruct(nweb_media_info_->GetAttributes());
72 }
73 
GetSourceInfos()74 ArkWebMediaSourceInfoVector ArkWebMediaInfoImpl::GetSourceInfos()
75 {
76     return ArkWebMediaSourceInfoVectorClassToStruct(nweb_media_info_->GetSourceInfos());
77 }
78 
GetSurfaceInfo()79 ArkWebRefPtr<ArkWebNativeMediaPlayerSurfaceInfo> ArkWebMediaInfoImpl::GetSurfaceInfo()
80 {
81     std::shared_ptr<OHOS::NWeb::NWebNativeMediaPlayerSurfaceInfo> nweb_native_media_player_surface_info =
82         nweb_media_info_->GetSurfaceInfo();
83     if (CHECK_SHARED_PTR_IS_NULL(nweb_native_media_player_surface_info)) {
84         return nullptr;
85     }
86 
87     return new ArkWebNativeMediaPlayerSurfaceInfoImpl(nweb_native_media_player_surface_info);
88 }
89 
90 } // namespace OHOS::ArkWeb
91