1 /*
2 * Copyright (C) 2023-2023 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 * Description: Cast mirror player function realization.
15 * Author: zhangjingnan
16 * Create: 2023-05-27
17 */
18
19 #include "mirror_player.h"
20 #include "cast_engine_errors.h"
21 #include "cast_engine_log.h"
22 #include "surface_utils.h"
23
24 namespace OHOS {
25 namespace CastEngine {
26 namespace CastEngineClient {
27 DEFINE_CAST_ENGINE_LABEL("Cast-Client-MirrorPlayer");
28
~MirrorPlayer()29 MirrorPlayer::~MirrorPlayer()
30 {
31 CLOGI("Stop the client mirror player.");
32 }
33
Play(const std::string &deviceId)34 int32_t MirrorPlayer::Play(const std::string &deviceId)
35 {
36 if (deviceId.empty()) {
37 CLOGE("The device id is null");
38 return ERR_INVALID_PARAM;
39 }
40 return proxy_ ? proxy_->Play(deviceId) : CAST_ENGINE_ERROR;
41 }
42
Pause(const std::string &deviceId)43 int32_t MirrorPlayer::Pause(const std::string &deviceId)
44 {
45 if (deviceId.empty()) {
46 CLOGE("The device id is null");
47 return ERR_INVALID_PARAM;
48 }
49 return proxy_ ? proxy_->Pause(deviceId) : CAST_ENGINE_ERROR;
50 }
51
SetSurface(const std::string &surfaceId)52 int32_t MirrorPlayer::SetSurface(const std::string &surfaceId)
53 {
54 errno = 0;
55 uint64_t surfaceUniqueId = static_cast<uint64_t>(std::strtoll(surfaceId.c_str(), nullptr, 10));
56 if (errno == ERANGE) {
57 return ERR_INVALID_PARAM;
58 }
59
60 sptr<Surface> surface = SurfaceUtils::GetInstance()->GetSurface(surfaceUniqueId);
61 if (!surface) {
62 return CAST_ENGINE_ERROR;
63 }
64 sptr<IBufferProducer> producer = surface->GetProducer();
65 if (!producer) {
66 CLOGE("producer is null");
67 return CAST_ENGINE_ERROR;
68 }
69 return proxy_ ? proxy_->SetSurface(producer) : CAST_ENGINE_ERROR;
70 }
71
SetAppInfo(const AppInfo &appInfo)72 int32_t MirrorPlayer::SetAppInfo(const AppInfo &appInfo)
73 {
74 return proxy_ ? proxy_->SetAppInfo(appInfo) : CAST_ENGINE_ERROR;
75 }
76
DeliverInputEvent(OHRemoteControlEvent event)77 int32_t MirrorPlayer::DeliverInputEvent(OHRemoteControlEvent event)
78 {
79 return proxy_ ? proxy_->DeliverInputEvent(event) : CAST_ENGINE_ERROR;
80 }
81
InjectEvent(const OHRemoteControlEvent &event)82 int32_t MirrorPlayer::InjectEvent(const OHRemoteControlEvent &event)
83 {
84 return proxy_ ? proxy_->InjectEvent(event) : CAST_ENGINE_ERROR;
85 }
86
Release()87 int32_t MirrorPlayer::Release()
88 {
89 return proxy_ ? proxy_->Release() : CAST_ENGINE_ERROR;
90 }
91
GetDisplayId(std::string &displayId)92 int32_t MirrorPlayer::GetDisplayId(std::string &displayId)
93 {
94 return proxy_ ? proxy_->GetDisplayId(displayId) : CAST_ENGINE_ERROR;
95 }
96
ResizeVirtualScreen(uint32_t width, uint32_t height)97 int32_t MirrorPlayer::ResizeVirtualScreen(uint32_t width, uint32_t height)
98 {
99 return proxy_ ? proxy_->ResizeVirtualScreen(width, height) : CAST_ENGINE_ERROR;
100 }
101
102 } // namespace CastEngineClient
103 } // namespace CastEngine
104 } // namespace OHOS