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_adapter/bridge/ark_media_avsession_adapter_wrapper.h"
17 
18 #include "ohos_adapter/bridge/ark_media_avsession_callback_adapter_impl.h"
19 #include "ohos_adapter/bridge/ark_media_avsession_metadata_adapter_impl.h"
20 #include "ohos_adapter/bridge/ark_media_avsession_position_adapter_impl.h"
21 
22 #include "base/bridge/ark_web_bridge_macros.h"
23 
24 namespace OHOS::ArkWeb {
25 
ArkMediaAVSessionAdapterWrapper(ArkWebRefPtr<ArkMediaAVSessionAdapter> ref)26 ArkMediaAVSessionAdapterWrapper::ArkMediaAVSessionAdapterWrapper(ArkWebRefPtr<ArkMediaAVSessionAdapter> ref)
27     : ctocpp_(ref)
28 {}
29 
CreateAVSession(NWeb::MediaAVSessionType type)30 bool ArkMediaAVSessionAdapterWrapper::CreateAVSession(NWeb::MediaAVSessionType type)
31 {
32     return ctocpp_->CreateAVSession((int32_t)type);
33 }
34 
DestroyAVSession()35 void ArkMediaAVSessionAdapterWrapper::DestroyAVSession()
36 {
37     ctocpp_->DestroyAVSession();
38 }
39 
RegistCallback(std::shared_ptr<NWeb::MediaAVSessionCallbackAdapter> callbackAdapter)40 bool ArkMediaAVSessionAdapterWrapper::RegistCallback(
41     std::shared_ptr<NWeb::MediaAVSessionCallbackAdapter> callbackAdapter)
42 {
43     if (CHECK_SHARED_PTR_IS_NULL(callbackAdapter)) {
44         return ctocpp_->RegistCallback(nullptr);
45     }
46 
47     return ctocpp_->RegistCallback(new ArkMediaAVSessionCallbackAdapterImpl(callbackAdapter));
48 }
49 
IsActivated()50 bool ArkMediaAVSessionAdapterWrapper::IsActivated()
51 {
52     return ctocpp_->IsActivated();
53 }
54 
Activate()55 bool ArkMediaAVSessionAdapterWrapper::Activate()
56 {
57     return ctocpp_->Activate();
58 }
59 
DeActivate()60 void ArkMediaAVSessionAdapterWrapper::DeActivate()
61 {
62     ctocpp_->DeActivate();
63 }
64 
SetMetadata(const std::shared_ptr<NWeb::MediaAVSessionMetadataAdapter> metadata)65 void ArkMediaAVSessionAdapterWrapper::SetMetadata(const std::shared_ptr<NWeb::MediaAVSessionMetadataAdapter> metadata)
66 {
67     if (CHECK_SHARED_PTR_IS_NULL(metadata)) {
68         ctocpp_->SetMetadata(nullptr);
69     } else {
70         return ctocpp_->SetMetadata(new ArkMediaAVSessionMetadataAdapterImpl(metadata));
71     }
72 }
73 
SetPlaybackState(OHOS::NWeb::MediaAVSessionPlayState state)74 void ArkMediaAVSessionAdapterWrapper::SetPlaybackState(OHOS::NWeb::MediaAVSessionPlayState state)
75 {
76     ctocpp_->SetPlaybackState((int32_t)state);
77 }
78 
SetPlaybackPosition(const std::shared_ptr<NWeb::MediaAVSessionPositionAdapter> position)79 void ArkMediaAVSessionAdapterWrapper::SetPlaybackPosition(
80     const std::shared_ptr<NWeb::MediaAVSessionPositionAdapter> position)
81 {
82     if (CHECK_SHARED_PTR_IS_NULL(position)) {
83         ctocpp_->SetPlaybackPosition(nullptr);
84     } else {
85         return ctocpp_->SetPlaybackPosition(new ArkMediaAVSessionPositionAdapterImpl(position));
86     }
87 }
88 } // namespace OHOS::ArkWeb
89