• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         CLOGE("surface is null, surface uniqueId %llu", surfaceUniqueId);
63         return CAST_ENGINE_ERROR;
64     }
65     sptr<IBufferProducer> producer = surface->GetProducer();
66     if (!producer) {
67         CLOGE("producer is null");
68         return CAST_ENGINE_ERROR;
69     }
70     return proxy_ ? proxy_->SetSurface(producer) : CAST_ENGINE_ERROR;
71 }
72 
SetAppInfo(const AppInfo & appInfo)73 int32_t MirrorPlayer::SetAppInfo(const AppInfo &appInfo)
74 {
75     return proxy_ ? proxy_->SetAppInfo(appInfo) : CAST_ENGINE_ERROR;
76 }
77 
DeliverInputEvent(OHRemoteControlEvent event)78 int32_t MirrorPlayer::DeliverInputEvent(OHRemoteControlEvent event)
79 {
80     return proxy_ ? proxy_->DeliverInputEvent(event) : CAST_ENGINE_ERROR;
81 }
82 
InjectEvent(const OHRemoteControlEvent & event)83 int32_t MirrorPlayer::InjectEvent(const OHRemoteControlEvent &event)
84 {
85     return proxy_ ? proxy_->InjectEvent(event) : CAST_ENGINE_ERROR;
86 }
87 
Release()88 int32_t MirrorPlayer::Release()
89 {
90     return proxy_ ? proxy_->Release() : CAST_ENGINE_ERROR;
91 }
92 
GetDisplayId(std::string & displayId)93 int32_t MirrorPlayer::GetDisplayId(std::string &displayId)
94 {
95     return proxy_ ? proxy_->GetDisplayId(displayId) : CAST_ENGINE_ERROR;
96 }
97 
ResizeVirtualScreen(uint32_t width,uint32_t height)98 int32_t MirrorPlayer::ResizeVirtualScreen(uint32_t width, uint32_t height)
99 {
100     return proxy_ ? proxy_->ResizeVirtualScreen(width, height) : CAST_ENGINE_ERROR;
101 }
102 
103 } // namespace CastEngineClient
104 } // namespace CastEngine
105 } // namespace OHOS