1 /*
2 * Copyright (c) 2022-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 */
15
16 #include "player_impl.h"
17
18 namespace OHOS {
19 namespace Media {
PlayerClient()20 Player::PlayerClient::PlayerClient()
21 : impl_(new (std::nothrow) PlayerImpl())
22 {
23 MEDIA_INFO_LOG("PlayerClient process");
24 }
25
~PlayerClient()26 Player::PlayerClient::~PlayerClient()
27 {
28 MEDIA_INFO_LOG("PlayerClient out");
29 }
30
31
SetSource(const Source & source)32 int32_t Player::PlayerClient::SetSource(const Source &source)
33 {
34 if (impl_ == nullptr) {
35 MEDIA_ERR_LOG("impl_ null");
36 return -1;
37 }
38 return impl_->SetSource(source);
39 }
40
Prepare()41 int32_t Player::PlayerClient::Prepare()
42 {
43 if (impl_ == nullptr) {
44 MEDIA_ERR_LOG("impl_ null");
45 return -1;
46 }
47 return impl_->Prepare();
48 }
49
Play()50 int32_t Player::PlayerClient::Play()
51 {
52 if (impl_ == nullptr) {
53 MEDIA_ERR_LOG("impl_ null");
54 return -1;
55 }
56 return impl_->Play();
57 }
58
IsPlaying()59 bool Player::PlayerClient::IsPlaying()
60 {
61 if (impl_ == nullptr) {
62 MEDIA_ERR_LOG("ptr null");
63 return false;
64 }
65 return impl_->IsPlaying();
66 }
67
Pause()68 int32_t Player::PlayerClient::Pause()
69 {
70 if (impl_ == nullptr) {
71 MEDIA_ERR_LOG("impl_ null");
72 return -1;
73 }
74 return impl_->Pause();
75 }
76
Stop()77 int32_t Player::PlayerClient::Stop()
78 {
79 if (impl_ == nullptr) {
80 MEDIA_ERR_LOG("impl_ null");
81 return -1;
82 }
83 return impl_->Stop();
84 }
Rewind(int64_t mSeconds,int32_t mode)85 int32_t Player::PlayerClient::Rewind(int64_t mSeconds, int32_t mode)
86 {
87 if (impl_ == nullptr) {
88 MEDIA_ERR_LOG("impl_ null");
89 return -1;
90 }
91 return impl_->Rewind(mSeconds, mode);
92 }
93
SetVolume(float leftVolume,float rightVolume)94 int32_t Player::PlayerClient::SetVolume(float leftVolume, float rightVolume)
95 {
96 if (impl_ == nullptr) {
97 MEDIA_ERR_LOG("impl_ null");
98 return -1;
99 }
100 return impl_->SetVolume(leftVolume, rightVolume);
101 }
102
SetSurface(Surface * surface)103 int32_t Player::PlayerClient::SetSurface(Surface *surface)
104 {
105 if (impl_ == nullptr) {
106 MEDIA_ERR_LOG("impl_ null");
107 return -1;
108 }
109 return impl_->SetSurface(surface);
110 }
111
SetLoop(bool loop)112 int32_t Player::PlayerClient::SetLoop(bool loop)
113 {
114 if (impl_ == nullptr) {
115 MEDIA_ERR_LOG("impl_ null");
116 return -1;
117 }
118 return impl_->SetLoop(loop);
119 }
120
IsSingleLooping()121 bool Player::PlayerClient::IsSingleLooping()
122 {
123 if (impl_ == nullptr) {
124 MEDIA_ERR_LOG("impl_ null");
125 return false;
126 }
127 return impl_->IsSingleLooping();
128 }
129
GetCurrentPosition(int64_t & time) const130 int32_t Player::PlayerClient::GetCurrentPosition(int64_t &time) const
131 {
132 if (impl_ == nullptr) {
133 MEDIA_ERR_LOG("impl_ null");
134 return -1;
135 }
136 return impl_->GetCurrentPosition(time);
137 }
138
GetDuration(int64_t & duration) const139 int32_t Player::PlayerClient::GetDuration(int64_t &duration) const
140 {
141 if (impl_ == nullptr) {
142 MEDIA_ERR_LOG("impl_ null");
143 return -1;
144 }
145 return impl_->GetDuration(duration);
146 }
GetVideoWidth(int32_t & videoWidth)147 int32_t Player::PlayerClient::GetVideoWidth(int32_t &videoWidth)
148 {
149 if (impl_ == nullptr) {
150 MEDIA_ERR_LOG("impl_ null");
151 return -1;
152 }
153 return impl_->GetVideoWidth(videoWidth);
154 }
155
GetVideoHeight(int32_t & videoHeight)156 int32_t Player::PlayerClient::GetVideoHeight(int32_t &videoHeight)
157 {
158 if (impl_ == nullptr) {
159 MEDIA_ERR_LOG("impl_ null");
160 return -1;
161 }
162 return impl_->GetVideoHeight(videoHeight);
163 }
164
Reset()165 int32_t Player::PlayerClient::Reset()
166 {
167 if (impl_ == nullptr) {
168 MEDIA_ERR_LOG("impl_ null");
169 return -1;
170 }
171 return impl_->Reset();
172 }
173
Release()174 int32_t Player::PlayerClient::Release()
175 {
176 if (impl_ == nullptr) {
177 MEDIA_ERR_LOG("impl_ null");
178 return -1;
179 }
180 return impl_->Release();
181 }
182
SetPlayerCallback(const std::shared_ptr<PlayerCallback> & cb)183 void Player::PlayerClient::SetPlayerCallback(const std::shared_ptr<PlayerCallback> &cb)
184 {
185 if (impl_ == nullptr) {
186 MEDIA_ERR_LOG("impl_ null");
187 return;
188 }
189 impl_->SetPlayerCallback(cb);
190 }
191
GetPlayerState(int32_t & state) const192 int32_t Player::PlayerClient::GetPlayerState(int32_t &state) const
193 {
194 if (impl_ == nullptr) {
195 MEDIA_ERR_LOG("impl_ null");
196 return PLAYER_STATE_ERROR;
197 }
198 return impl_->GetPlayerState(state);
199 }
200
SetPlaybackSpeed(float speed)201 int32_t Player::PlayerClient::SetPlaybackSpeed(float speed)
202 {
203 if (impl_ == nullptr) {
204 MEDIA_ERR_LOG("impl_ null");
205 return -1;
206 }
207 return impl_->SetPlaybackSpeed(speed);
208 }
209
GetPlaybackSpeed(float & speed)210 int32_t Player::PlayerClient::GetPlaybackSpeed(float &speed)
211 {
212 if (impl_ == nullptr) {
213 MEDIA_ERR_LOG("impl_ null");
214 return -1;
215 }
216 return impl_->GetPlaybackSpeed(speed);
217 }
218
SetParameter(const Format & params)219 int32_t Player::PlayerClient::SetParameter(const Format ¶ms)
220 {
221 if (impl_ == nullptr) {
222 MEDIA_ERR_LOG("impl_ null");
223 return -1;
224 }
225 return impl_->SetParameter(params);
226 }
227
SetAudioStreamType(int32_t type)228 int32_t Player::PlayerClient::SetAudioStreamType(int32_t type)
229 {
230 if (impl_ == nullptr) {
231 MEDIA_ERR_LOG("impl_ null");
232 return -1;
233 }
234 return impl_->SetAudioStreamType(type);
235 }
236
GetAudioStreamType(int32_t & type)237 void Player::PlayerClient::GetAudioStreamType(int32_t &type)
238 {
239 if (impl_ == nullptr) {
240 MEDIA_ERR_LOG("impl_ null");
241 return ;
242 }
243 impl_->GetAudioStreamType(type);
244 }
245 }
246 }
247