• 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: Stream Player function realization.
15  * Author: huangchanggui
16  * Create: 2023-01-12
17  */
18 
19 #include "stream_player.h"
20 
21 #include "cast_engine_errors.h"
22 #include "cast_engine_log.h"
23 #include "stream_player_listener_impl_stub.h"
24 
25 namespace OHOS {
26 namespace CastEngine {
27 namespace CastEngineClient {
28 DEFINE_CAST_ENGINE_LABEL("Cast-Client-StreamPlayer");
29 
~StreamPlayer()30 StreamPlayer::~StreamPlayer()
31 {
32     CLOGD("destructor in");
33 }
34 
RegisterListener(std::shared_ptr<IStreamPlayerListener> listener)35 int32_t StreamPlayer::RegisterListener(std::shared_ptr<IStreamPlayerListener> listener)
36 {
37     if (listener == nullptr) {
38         CLOGE("listener is null");
39         return ERR_INVALID_PARAM;
40     }
41     sptr<IStreamPlayerListenerImpl> listenerStub = new (std::nothrow) StreamPlayerListenerImplStub(listener);
42     if (listenerStub == nullptr) {
43         CLOGE("Failed to new a stream player listener");
44         return CAST_ENGINE_ERROR;
45     }
46 
47     return proxy_ ? proxy_->RegisterListener(listenerStub) : CAST_ENGINE_ERROR;
48 }
49 
UnregisterListener()50 int32_t StreamPlayer::UnregisterListener()
51 {
52     return proxy_ ? proxy_->UnregisterListener() : CAST_ENGINE_ERROR;
53 }
54 
SetSurface(const std::string & surfaceId)55 int32_t StreamPlayer::SetSurface(const std::string &surfaceId)
56 {
57     errno = 0;
58     char *end = nullptr;
59 
60     uint64_t surfaceUniqueId = static_cast<uint64_t>(std::strtoll(surfaceId.c_str(), &end, 10));
61     if (errno == ERANGE || (surfaceUniqueId == 0 && *end != '\0')) {
62         return ERR_INVALID_PARAM;
63     }
64 
65     sptr<Surface> surface = SurfaceUtils::GetInstance()->GetSurface(surfaceUniqueId);
66     if (!surface) {
67         CLOGE("surface is null, surface uniqueId %" PRIu64, surfaceUniqueId);
68         return CAST_ENGINE_ERROR;
69     }
70 
71     sptr<IBufferProducer> producer = surface->GetProducer();
72     if (!producer) {
73         CLOGE("producer is null");
74         return CAST_ENGINE_ERROR;
75     }
76 
77     return proxy_ ? proxy_->SetSurface(producer) : CAST_ENGINE_ERROR;
78 }
79 
Load(const MediaInfo & mediaInfo)80 int32_t StreamPlayer::Load(const MediaInfo &mediaInfo)
81 {
82     return proxy_ ? proxy_->Load(mediaInfo) : CAST_ENGINE_ERROR;
83 }
84 
Play(const MediaInfo & mediaInfo)85 int32_t StreamPlayer::Play(const MediaInfo &mediaInfo)
86 {
87     return proxy_ ? proxy_->Play(mediaInfo) : CAST_ENGINE_ERROR;
88 }
89 
Play(int index)90 int32_t StreamPlayer::Play(int index)
91 {
92     return proxy_ ? proxy_->Play(index) : CAST_ENGINE_ERROR;
93 }
94 
Play()95 int32_t StreamPlayer::Play()
96 {
97     return proxy_ ? proxy_->Play() : CAST_ENGINE_ERROR;
98 }
99 
Pause()100 int32_t StreamPlayer::Pause()
101 {
102     return proxy_ ? proxy_->Pause() : CAST_ENGINE_ERROR;
103 }
104 
Stop()105 int32_t StreamPlayer::Stop()
106 {
107     return proxy_ ? proxy_->Stop() : CAST_ENGINE_ERROR;
108 }
109 
Next()110 int32_t StreamPlayer::Next()
111 {
112     return proxy_ ? proxy_->Next() : CAST_ENGINE_ERROR;
113 }
114 
Previous()115 int32_t StreamPlayer::Previous()
116 {
117     return proxy_ ? proxy_->Previous() : CAST_ENGINE_ERROR;
118 }
119 
Seek(int position)120 int32_t StreamPlayer::Seek(int position)
121 {
122     return proxy_ ? proxy_->Seek(position) : CAST_ENGINE_ERROR;
123 }
124 
FastForward(int delta)125 int32_t StreamPlayer::FastForward(int delta)
126 {
127     return proxy_ ? proxy_->FastForward(delta) : CAST_ENGINE_ERROR;
128 }
129 
FastRewind(int delta)130 int32_t StreamPlayer::FastRewind(int delta)
131 {
132     return proxy_ ? proxy_->FastRewind(delta) : CAST_ENGINE_ERROR;
133 }
134 
SetVolume(int volume)135 int32_t StreamPlayer::SetVolume(int volume)
136 {
137     return proxy_ ? proxy_->SetVolume(volume) : CAST_ENGINE_ERROR;
138 }
139 
SetMute(bool mute)140 int32_t StreamPlayer::SetMute(bool mute)
141 {
142     return proxy_ ? proxy_->SetMute(mute) : CAST_ENGINE_ERROR;
143 }
144 
SetLoopMode(const LoopMode mode)145 int32_t StreamPlayer::SetLoopMode(const LoopMode mode)
146 {
147     return proxy_ ? proxy_->SetLoopMode(mode) : CAST_ENGINE_ERROR;
148 }
149 
SetAvailableCapability(const StreamCapability & streamCapability)150 int32_t StreamPlayer::SetAvailableCapability(const StreamCapability &streamCapability)
151 {
152     return proxy_ ? proxy_->SetAvailableCapability(streamCapability) : CAST_ENGINE_ERROR;
153 }
154 
SetSpeed(const PlaybackSpeed speed)155 int32_t StreamPlayer::SetSpeed(const PlaybackSpeed speed)
156 {
157     return proxy_ ? proxy_->SetSpeed(speed) : CAST_ENGINE_ERROR;
158 }
159 
GetPlayerStatus(PlayerStates & playerStates)160 int32_t StreamPlayer::GetPlayerStatus(PlayerStates &playerStates)
161 {
162     return proxy_ ? proxy_->GetPlayerStatus(playerStates) : CAST_ENGINE_ERROR;
163 }
164 
GetPosition(int & position)165 int32_t StreamPlayer::GetPosition(int &position)
166 {
167     return proxy_ ? proxy_->GetPosition(position) : CAST_ENGINE_ERROR;
168 }
169 
GetDuration(int & duration)170 int32_t StreamPlayer::GetDuration(int &duration)
171 {
172     return proxy_ ? proxy_->GetDuration(duration) : CAST_ENGINE_ERROR;
173 }
174 
GetVolume(int & volume,int & maxVolume)175 int32_t StreamPlayer::GetVolume(int &volume, int &maxVolume)
176 {
177     return proxy_ ? proxy_->GetVolume(volume, maxVolume) : CAST_ENGINE_ERROR;
178 }
179 
GetMute(bool & mute)180 int32_t StreamPlayer::GetMute(bool &mute)
181 {
182     return proxy_ ? proxy_->GetMute(mute) : CAST_ENGINE_ERROR;
183 }
184 
GetLoopMode(LoopMode & loopMode)185 int32_t StreamPlayer::GetLoopMode(LoopMode &loopMode)
186 {
187     return proxy_ ? proxy_->GetLoopMode(loopMode) : CAST_ENGINE_ERROR;
188 }
189 
GetAvailableCapability(StreamCapability & streamCapability)190 int32_t StreamPlayer::GetAvailableCapability(StreamCapability &streamCapability)
191 {
192     return proxy_ ? proxy_->GetAvailableCapability(streamCapability) : CAST_ENGINE_ERROR;
193 }
194 
GetPlaySpeed(PlaybackSpeed & playbackSpeed)195 int32_t StreamPlayer::GetPlaySpeed(PlaybackSpeed &playbackSpeed)
196 {
197     return proxy_ ? proxy_->GetPlaySpeed(playbackSpeed) : CAST_ENGINE_ERROR;
198 }
199 
GetMediaInfoHolder(MediaInfoHolder & mediaInfoHolder)200 int32_t StreamPlayer::GetMediaInfoHolder(MediaInfoHolder &mediaInfoHolder)
201 {
202     return proxy_ ? proxy_->GetMediaInfoHolder(mediaInfoHolder) : CAST_ENGINE_ERROR;
203 }
204 
ProvideKeyResponse(const std::string & mediaId,const std::vector<uint8_t> & response)205 int32_t StreamPlayer::ProvideKeyResponse(const std::string &mediaId, const std::vector<uint8_t> &response)
206 {
207     return proxy_ ? proxy_->ProvideKeyResponse(mediaId, response) : CAST_ENGINE_ERROR;
208 }
209 
Release()210 int32_t StreamPlayer::Release()
211 {
212     return proxy_ ? proxy_->Release() : CAST_ENGINE_ERROR;
213 }
214 
GetMediaCapabilities(std::string & jsonCapabilities)215 int32_t StreamPlayer::GetMediaCapabilities(std::string &jsonCapabilities)
216 {
217     return CAST_ENGINE_ERROR;
218 }
219 
220 } // namespace CastEngineClient
221 } // namespace CastEngine
222 } // namespace OHOS