1 /*
2 * Copyright (C) 2021 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_service_stub.h"
17 #include <unistd.h>
18 #include "player_listener_proxy.h"
19 #include "media_data_source_proxy.h"
20 #include "media_server_manager.h"
21 #ifdef SUPPORT_AVPLAYER_DRM
22 #include "key_session_service_proxy.h"
23 #endif
24 #include "media_log.h"
25 #include "media_errors.h"
26 #include "media_parcel.h"
27 #include "parameter.h"
28 #include "media_dfx.h"
29 #include "player_xcollie.h"
30 #include "av_common.h"
31 #ifdef SUPPORT_AVSESSION
32 #include "avsession_background.h"
33 #endif
34
35 namespace {
36 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_PLAYER, "PlayerServiceStub"};
37 constexpr uint32_t MAX_MAP_SIZE = 100;
38 }
39
40 namespace OHOS {
41 namespace Media {
Create()42 sptr<PlayerServiceStub> PlayerServiceStub::Create()
43 {
44 sptr<PlayerServiceStub> playerStub = new(std::nothrow) PlayerServiceStub();
45 CHECK_AND_RETURN_RET_LOG(playerStub != nullptr, nullptr, "failed to new PlayerServiceStub");
46
47 int32_t ret = playerStub->Init();
48 CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, nullptr, "failed to player stub init");
49 StatisticEventWriteBundleName("create", "PlayerServiceStub");
50 return playerStub;
51 }
52
PlayerServiceStub()53 PlayerServiceStub::PlayerServiceStub()
54 : taskQue_("PlayerRequest")
55 {
56 (void)taskQue_.Start();
57 MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
58 }
59
~PlayerServiceStub()60 PlayerServiceStub::~PlayerServiceStub()
61 {
62 (void)CancellationMonitor(appPid_);
63 if (playerServer_ != nullptr) {
64 auto task = std::make_shared<TaskHandler<void>>([&, this] {
65 (void)playerServer_->Release();
66 playerServer_ = nullptr;
67 });
68 (void)taskQue_.EnqueueTask(task);
69 (void)task->GetResult();
70 }
71 (void)taskQue_.Stop();
72 MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
73 }
74
SetPlayerFuncs()75 void PlayerServiceStub::SetPlayerFuncs()
76 {
77 FillPlayerFuncPart1();
78 FillPlayerFuncPart2();
79 (void)RegisterMonitor(appPid_);
80 }
81
FillPlayerFuncPart1()82 void PlayerServiceStub::FillPlayerFuncPart1()
83 {
84 playerFuncs_[SET_LISTENER_OBJ] = { "SetListenerObject",
85 [this](MessageParcel &data, MessageParcel &reply) { return SetListenerObject(data, reply); } };
86 playerFuncs_[SET_SOURCE] = { "SetSource",
87 [this](MessageParcel &data, MessageParcel &reply) { return SetSource(data, reply); } };
88 playerFuncs_[SET_MEDIA_DATA_SRC_OBJ] = { "SetMediaDataSource",
89 [this](MessageParcel &data, MessageParcel &reply) { return SetMediaDataSource(data, reply); } };
90 playerFuncs_[SET_FD_SOURCE] = { "SetFdSource",
91 [this](MessageParcel &data, MessageParcel &reply) { return SetFdSource(data, reply); } };
92 playerFuncs_[PLAY] = { "Play",
93 [this](MessageParcel &data, MessageParcel &reply) { return Play(data, reply); } };
94 playerFuncs_[PREPARE] = { "Prepare",
95 [this](MessageParcel &data, MessageParcel &reply) { return Prepare(data, reply); } };
96 playerFuncs_[SET_RENDER_FIRST_FRAME] = { "SetRenderFirstFrame",
97 [this](MessageParcel &data, MessageParcel &reply) { return SetRenderFirstFrame(data, reply); } };
98 playerFuncs_[PREPAREASYNC] = { "PrepareAsync",
99 [this](MessageParcel &data, MessageParcel &reply) { return PrepareAsync(data, reply); } };
100 playerFuncs_[PAUSE] = { "Pause",
101 [this](MessageParcel &data, MessageParcel &reply) { return Pause(data, reply); } };
102 playerFuncs_[STOP] = { "Stop",
103 [this](MessageParcel &data, MessageParcel &reply) { return Stop(data, reply); } };
104 playerFuncs_[RESET] = { "Reset",
105 [this](MessageParcel &data, MessageParcel &reply) { return Reset(data, reply); } };
106 playerFuncs_[RELEASE] = { "Release",
107 [this](MessageParcel &data, MessageParcel &reply) { return Release(data, reply); } };
108 playerFuncs_[SET_VOLUME] = { "SetVolume",
109 [this](MessageParcel &data, MessageParcel &reply) { return SetVolume(data, reply); } };
110 playerFuncs_[SEEK] = { "Seek",
111 [this](MessageParcel &data, MessageParcel &reply) { return Seek(data, reply); } };
112 playerFuncs_[GET_CURRENT_TIME] = { "GetCurrentTime",
113 [this](MessageParcel &data, MessageParcel &reply) { return GetCurrentTime(data, reply); } };
114 playerFuncs_[GET_DURATION] = { "GetDuration",
115 [this](MessageParcel &data, MessageParcel &reply) { return GetDuration(data, reply); } };
116 playerFuncs_[SET_PLAYERBACK_SPEED] = { "SetPlaybackSpeed",
117 [this](MessageParcel &data, MessageParcel &reply) { return SetPlaybackSpeed(data, reply); } };
118 playerFuncs_[GET_PLAYERBACK_SPEED] = { "GetPlaybackSpeed",
119 [this](MessageParcel &data, MessageParcel &reply) { return GetPlaybackSpeed(data, reply); } };
120 playerFuncs_[SET_MEDIA_SOURCE] = { "SetMediaSource",
121 [this](MessageParcel &data, MessageParcel &reply) { return SetMediaSource(data, reply); } };
122 #ifdef SUPPORT_VIDEO
123 playerFuncs_[SET_VIDEO_SURFACE] = { "SetVideoSurface",
124 [this](MessageParcel &data, MessageParcel &reply) { return SetVideoSurface(data, reply); } };
125 #endif
126 playerFuncs_[IS_PLAYING] = { "IsPlaying",
127 [this](MessageParcel &data, MessageParcel &reply) { return IsPlaying(data, reply); } };
128 playerFuncs_[IS_LOOPING] = { "IsLooping",
129 [this](MessageParcel &data, MessageParcel &reply) { return IsLooping(data, reply); } };
130 playerFuncs_[SET_LOOPING] = { "SetLooping",
131 [this](MessageParcel &data, MessageParcel &reply) { return SetLooping(data, reply); } };
132 }
133
FillPlayerFuncPart2()134 void PlayerServiceStub::FillPlayerFuncPart2()
135 {
136 playerFuncs_[ADD_SUB_SOURCE] = { "AddSubSource",
137 [this](MessageParcel &data, MessageParcel &reply) { return AddSubSource(data, reply); } };
138 playerFuncs_[ADD_SUB_FD_SOURCE] = { "AddSubFdSource",
139 [this](MessageParcel &data, MessageParcel &reply) { return AddSubFdSource(data, reply); } };
140 playerFuncs_[SET_RENDERER_DESC] = { "SetParameter",
141 [this](MessageParcel &data, MessageParcel &reply) { return SetParameter(data, reply); } };
142 playerFuncs_[DESTROY] = { "DestroyStub",
143 [this](MessageParcel &data, MessageParcel &reply) { return DestroyStub(data, reply); } };
144 playerFuncs_[SET_CALLBACK] = { "SetPlayerCallback",
145 [this](MessageParcel &data, MessageParcel &reply) { return SetPlayerCallback(data, reply); } };
146 playerFuncs_[GET_VIDEO_TRACK_INFO] = { "GetVideoTrackInfo",
147 [this](MessageParcel &data, MessageParcel &reply) { return GetVideoTrackInfo(data, reply); } };
148 playerFuncs_[GET_PLAYBACK_INFO] = { "GetPlaybackInfo",
149 [this](MessageParcel &data, MessageParcel &reply) { return GetPlaybackInfo(data, reply); } };
150 playerFuncs_[GET_AUDIO_TRACK_INFO] = { "GetAudioTrackInfo",
151 [this](MessageParcel &data, MessageParcel &reply) { return GetAudioTrackInfo(data, reply); } };
152 playerFuncs_[GET_SUBTITLE_TRACK_INFO] = { "GetSubtitleTrackInfo",
153 [this](MessageParcel &data, MessageParcel &reply) { return GetSubtitleTrackInfo(data, reply); } };
154 playerFuncs_[GET_VIDEO_WIDTH] = { "GetVideoWidth",
155 [this](MessageParcel &data, MessageParcel &reply) { return GetVideoWidth(data, reply); } };
156 playerFuncs_[GET_VIDEO_HEIGHT] = { "GetVideoHeight",
157 [this](MessageParcel &data, MessageParcel &reply) { return GetVideoHeight(data, reply); } };
158 playerFuncs_[SELECT_BIT_RATE] = { "SelectBitRate",
159 [this](MessageParcel &data, MessageParcel &reply) { return SelectBitRate(data, reply); } };
160 playerFuncs_[SELECT_TRACK] = { "SelectTrack",
161 [this](MessageParcel &data, MessageParcel &reply) { return SelectTrack(data, reply); } };
162 playerFuncs_[DESELECT_TRACK] = { "DeselectTrack",
163 [this](MessageParcel &data, MessageParcel &reply) { return DeselectTrack(data, reply); } };
164 playerFuncs_[GET_CURRENT_TRACK] = { "GetCurrentTrack",
165 [this](MessageParcel &data, MessageParcel &reply) { return GetCurrentTrack(data, reply); } };
166 playerFuncs_[SET_DECRYPT_CONFIG] = { "SetDecryptConfig",
167 [this](MessageParcel &data, MessageParcel &reply) { return SetDecryptConfig(data, reply); } };
168 playerFuncs_[SET_PLAY_RANGE] = { "SetPlayRange",
169 [this](MessageParcel &data, MessageParcel &reply) { return SetPlayRange(data, reply); } };
170 playerFuncs_[SET_PLAY_RANGE_WITH_MODE] = { "SetPlayRangeWithMode",
171 [this](MessageParcel &data, MessageParcel &reply) { return SetPlayRangeWithMode(data, reply); } };
172 playerFuncs_[SET_PLAYBACK_STRATEGY] = { "SetPlaybackStrategy",
173 [this](MessageParcel &data, MessageParcel &reply) { return SetPlaybackStrategy(data, reply); } };
174 playerFuncs_[SET_MEDIA_MUTED] = { "SetMediaMuted",
175 [this](MessageParcel &data, MessageParcel &reply) { return SetMediaMuted(data, reply); } };
176 playerFuncs_[SET_MAX_AMPLITUDE_CB_STATUS] = { "Player::SetMaxAmplitudeCbStatus",
177 [this](MessageParcel &data, MessageParcel &reply) { return SetMaxAmplitudeCbStatus(data, reply); } };
178 playerFuncs_[SET_DEVICE_CHANGE_CB_STATUS] = { "Player::SetDeviceChangeCbStatus",
179 [this](MessageParcel &data, MessageParcel &reply) { return SetDeviceChangeCbStatus(data, reply); } };
180 playerFuncs_[GET_LIVES_CURRENT_TIME] = { "GetPlaybackPosition",
181 [this](MessageParcel &data, MessageParcel &reply) { return GetPlaybackPosition(data, reply); } };
182 }
183
Init()184 int32_t PlayerServiceStub::Init()
185 {
186 if (playerServer_ == nullptr) {
187 playerServer_ = PlayerServer::Create();
188 }
189 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "failed to create PlayerServer");
190
191 appUid_ = IPCSkeleton::GetCallingUid();
192 appPid_ = IPCSkeleton::GetCallingPid();
193 SetPlayerFuncs();
194 return MSERR_OK;
195 }
196
DestroyStub()197 int32_t PlayerServiceStub::DestroyStub()
198 {
199 MediaTrace trace("PlayerServiceStub::DestroyStub");
200 playerCallback_ = nullptr;
201 if (playerServer_ != nullptr) {
202 (void)playerServer_->Release();
203 playerServer_ = nullptr;
204 }
205
206 MediaServerManager::GetInstance().DestroyStubObject(MediaServerManager::PLAYER, AsObject());
207 return MSERR_OK;
208 }
209
OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)210 int PlayerServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
211 MessageOption &option)
212 {
213 MediaTrace trace("PlayerServiceStub::OnRemoteRequest");
214 auto remoteDescriptor = data.ReadInterfaceToken();
215 CHECK_AND_RETURN_RET_LOG(PlayerServiceStub::GetDescriptor() == remoteDescriptor,
216 MSERR_INVALID_OPERATION, "Invalid descriptor");
217
218 auto itFunc = playerFuncs_.find(code);
219 if (itFunc != playerFuncs_.end()) {
220 auto memberFunc = itFunc->second.second;
221 auto funcName = itFunc->second.first;
222 if (funcName.compare("SetVolume") == 0) {
223 MEDIA_LOGD("0x%{public}06" PRIXPTR " %{public}s", FAKE_POINTER(this), funcName.c_str());
224 } else {
225 MEDIA_LOGI("0x%{public}06" PRIXPTR " %{public}s", FAKE_POINTER(this), funcName.c_str());
226 }
227 if (memberFunc != nullptr) {
228 auto task = std::make_shared<TaskHandler<int>>([&, this] {
229 (void)IpcRecovery(false);
230 int32_t ret = -1;
231 ret = memberFunc(data, reply);
232 return ret;
233 });
234 (void)taskQue_.EnqueueTask(task);
235 auto result = task->GetResult();
236 CHECK_AND_RETURN_RET_LOG(result.HasResult(), MSERR_INVALID_OPERATION,
237 "failed to OnRemoteRequest code: %{public}u", code);
238 return result.Value();
239 }
240 }
241 MEDIA_LOGW("PlayerServiceStub: no member func supporting, applying default process");
242 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
243 }
244
SetListenerObject(const sptr<IRemoteObject> &object)245 int32_t PlayerServiceStub::SetListenerObject(const sptr<IRemoteObject> &object)
246 {
247 MediaTrace trace("PlayerServiceStub::SetListenerObject");
248 CHECK_AND_RETURN_RET_LOG(object != nullptr, MSERR_NO_MEMORY, "set listener object is nullptr");
249
250 sptr<IStandardPlayerListener> listener = iface_cast<IStandardPlayerListener>(object);
251 CHECK_AND_RETURN_RET_LOG(listener != nullptr, MSERR_NO_MEMORY, "failed to convert IStandardPlayerListener");
252
253 std::shared_ptr<PlayerCallback> callback = std::make_shared<PlayerListenerCallback>(listener);
254 CHECK_AND_RETURN_RET_LOG(callback != nullptr, MSERR_NO_MEMORY, "failed to new PlayerListenerCallback");
255
256 playerCallback_ = callback;
257 return MSERR_OK;
258 }
259
SetSource(const std::string &url)260 int32_t PlayerServiceStub::SetSource(const std::string &url)
261 {
262 MediaTrace trace("PlayerServiceStub::SetSource(url)");
263 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
264 return playerServer_->SetSource(url);
265 }
266
SetSource(const sptr<IRemoteObject> &object)267 int32_t PlayerServiceStub::SetSource(const sptr<IRemoteObject> &object)
268 {
269 MediaTrace trace("PlayerServiceStub::SetSource(datasource)");
270 CHECK_AND_RETURN_RET_LOG(object != nullptr, MSERR_NO_MEMORY, "set mediadatasrc object is nullptr");
271 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
272
273 sptr<IStandardMediaDataSource> proxy = iface_cast<IStandardMediaDataSource>(object);
274 CHECK_AND_RETURN_RET_LOG(proxy != nullptr, MSERR_NO_MEMORY, "failed to convert MediaDataSourceProxy");
275
276 std::shared_ptr<IMediaDataSource> mediaDataSrc = std::make_shared<MediaDataCallback>(proxy);
277 CHECK_AND_RETURN_RET_LOG(mediaDataSrc != nullptr, MSERR_NO_MEMORY, "failed to new PlayerListenerCallback");
278
279 return playerServer_->SetSource(mediaDataSrc);
280 }
281
SetSource(int32_t fd, int64_t offset, int64_t size)282 int32_t PlayerServiceStub::SetSource(int32_t fd, int64_t offset, int64_t size)
283 {
284 MediaTrace trace("PlayerServiceStub::SetSource(fd)");
285 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
286 return playerServer_->SetSource(fd, offset, size);
287 }
288
AddSubSource(const std::string &url)289 int32_t PlayerServiceStub::AddSubSource(const std::string &url)
290 {
291 MediaTrace trace("PlayerServiceStub::AddSubSource(url)");
292 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
293 return playerServer_->AddSubSource(url);
294 }
295
AddSubSource(int32_t fd, int64_t offset, int64_t size)296 int32_t PlayerServiceStub::AddSubSource(int32_t fd, int64_t offset, int64_t size)
297 {
298 MediaTrace trace("PlayerServiceStub::AddSubSource(fd)");
299 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
300 return playerServer_->AddSubSource(fd, offset, size);
301 }
302
Play()303 int32_t PlayerServiceStub::Play()
304 {
305 MediaTrace trace("PlayerServiceStub::Play");
306 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
307 #ifdef SUPPORT_AVSESSION
308 AVsessionBackground::Instance().AddListener(playerServer_, appUid_);
309 #endif
310 return playerServer_->Play();
311 }
312
Prepare()313 int32_t PlayerServiceStub::Prepare()
314 {
315 MediaTrace trace("PlayerServiceStub::Prepare");
316 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
317 return playerServer_->Prepare();
318 }
319
SetRenderFirstFrame(bool display)320 int32_t PlayerServiceStub::SetRenderFirstFrame(bool display)
321 {
322 MediaTrace trace("Stub::SetRenderFirstFrame");
323 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
324 return playerServer_->SetRenderFirstFrame(display);
325 }
326
SetPlayRange(int64_t start, int64_t end)327 int32_t PlayerServiceStub::SetPlayRange(int64_t start, int64_t end)
328 {
329 MediaTrace trace("Stub::SetPlayRange");
330 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
331 return playerServer_->SetPlayRange(start, end);
332 }
333
SetPlayRangeWithMode(int64_t start, int64_t end, PlayerSeekMode mode)334 int32_t PlayerServiceStub::SetPlayRangeWithMode(int64_t start, int64_t end, PlayerSeekMode mode)
335 {
336 MediaTrace trace("Stub::SetPlayRangeWithMode");
337 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
338 return playerServer_->SetPlayRangeWithMode(start, end, mode);
339 }
340
PrepareAsync()341 int32_t PlayerServiceStub::PrepareAsync()
342 {
343 MediaTrace trace("PlayerServiceStub::PrepareAsync");
344 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
345 return playerServer_->PrepareAsync();
346 }
347
Pause()348 int32_t PlayerServiceStub::Pause()
349 {
350 MediaTrace trace("PlayerServiceStub::Pause");
351 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
352 return playerServer_->Pause();
353 }
354
Stop()355 int32_t PlayerServiceStub::Stop()
356 {
357 MediaTrace trace("PlayerServiceStub::Stop");
358 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
359 return playerServer_->Stop();
360 }
361
Reset()362 int32_t PlayerServiceStub::Reset()
363 {
364 MediaTrace trace("PlayerServiceStub::Reset");
365 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
366 return playerServer_->Reset();
367 }
368
Release()369 int32_t PlayerServiceStub::Release()
370 {
371 MediaTrace trace("PlayerServiceStub::Release");
372 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
373 return playerServer_->Release();
374 }
375
SetVolume(float leftVolume, float rightVolume)376 int32_t PlayerServiceStub::SetVolume(float leftVolume, float rightVolume)
377 {
378 MediaTrace trace("PlayerServiceStub::SetVolume");
379 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
380 return playerServer_->SetVolume(leftVolume, rightVolume);
381 }
382
Seek(int32_t mSeconds, PlayerSeekMode mode)383 int32_t PlayerServiceStub::Seek(int32_t mSeconds, PlayerSeekMode mode)
384 {
385 MediaTrace trace("PlayerServiceStub::Seek");
386 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
387 return playerServer_->Seek(mSeconds, mode);
388 }
389
GetCurrentTime(int32_t ¤tTime)390 int32_t PlayerServiceStub::GetCurrentTime(int32_t ¤tTime)
391 {
392 MediaTrace trace("PlayerServiceStub::GetCurrentTime");
393 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
394 return playerServer_->GetCurrentTime(currentTime);
395 }
396
GetPlaybackPosition(int32_t ¤tTime)397 int32_t PlayerServiceStub::GetPlaybackPosition(int32_t ¤tTime)
398 {
399 MediaTrace trace("PlayerServiceStub::GetPlaybackPosition");
400 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
401 return playerServer_->GetPlaybackPosition(currentTime);
402 }
403
GetVideoTrackInfo(std::vector<Format> &videoTrack)404 int32_t PlayerServiceStub::GetVideoTrackInfo(std::vector<Format> &videoTrack)
405 {
406 MediaTrace trace("PlayerServiceStub::GetVideoTrackInfo");
407 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
408 return playerServer_->GetVideoTrackInfo(videoTrack);
409 }
410
GetPlaybackInfo(Format &playbackInfo)411 int32_t PlayerServiceStub::GetPlaybackInfo(Format &playbackInfo)
412 {
413 MediaTrace trace("PlayerServiceStub::GetPlaybackInfo");
414 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
415 return playerServer_->GetPlaybackInfo(playbackInfo);
416 }
417
GetAudioTrackInfo(std::vector<Format> &audioTrack)418 int32_t PlayerServiceStub::GetAudioTrackInfo(std::vector<Format> &audioTrack)
419 {
420 MediaTrace trace("PlayerServiceStub::GetAudioTrackInfo");
421 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
422 return playerServer_->GetAudioTrackInfo(audioTrack);
423 }
424
GetSubtitleTrackInfo(std::vector<Format> &subtitleTrack)425 int32_t PlayerServiceStub::GetSubtitleTrackInfo(std::vector<Format> &subtitleTrack)
426 {
427 MediaTrace trace("PlayerServiceStub::GetSubtitleTrackInfo");
428 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
429 return playerServer_->GetSubtitleTrackInfo(subtitleTrack);
430 }
431
GetVideoWidth()432 int32_t PlayerServiceStub::GetVideoWidth()
433 {
434 MediaTrace trace("PlayerServiceStub::GetVideoWidth");
435 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
436 return playerServer_->GetVideoWidth();
437 }
438
GetVideoHeight()439 int32_t PlayerServiceStub::GetVideoHeight()
440 {
441 MediaTrace trace("PlayerServiceStub::GetVideoHeight");
442 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
443 return playerServer_->GetVideoHeight();
444 }
445
GetDuration(int32_t &duration)446 int32_t PlayerServiceStub::GetDuration(int32_t &duration)
447 {
448 MediaTrace trace("PlayerServiceStub::GetDuration");
449 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
450 return playerServer_->GetDuration(duration);
451 }
452
SetPlaybackSpeed(PlaybackRateMode mode)453 int32_t PlayerServiceStub::SetPlaybackSpeed(PlaybackRateMode mode)
454 {
455 MediaTrace trace("PlayerServiceStub::SetPlaybackSpeed");
456 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
457 return playerServer_->SetPlaybackSpeed(mode);
458 }
459
SetMediaSource(const std::shared_ptr<AVMediaSource> &mediaSource, AVPlayStrategy strategy)460 int32_t PlayerServiceStub::SetMediaSource(const std::shared_ptr<AVMediaSource> &mediaSource, AVPlayStrategy strategy)
461 {
462 CHECK_AND_RETURN_RET_LOG(mediaSource != nullptr, MSERR_INVALID_VAL, "mediaSource is nullptr");
463 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
464 return playerServer_->SetMediaSource(mediaSource, strategy);
465 }
466
GetPlaybackSpeed(PlaybackRateMode &mode)467 int32_t PlayerServiceStub::GetPlaybackSpeed(PlaybackRateMode &mode)
468 {
469 MediaTrace trace("PlayerServiceStub::GetPlaybackSpeed");
470 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
471 return playerServer_->GetPlaybackSpeed(mode);
472 }
473
SelectBitRate(uint32_t bitRate)474 int32_t PlayerServiceStub::SelectBitRate(uint32_t bitRate)
475 {
476 MediaTrace trace("PlayerServiceStub::SelectBitRate");
477 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
478 return playerServer_->SelectBitRate(bitRate);
479 }
480
StopBufferring(bool flag)481 int32_t PlayerServiceStub::StopBufferring(bool flag)
482 {
483 MediaTrace trace("PlayerServiceStub::StopBufferring");
484 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
485 return playerServer_->StopBufferring(flag);
486 }
487
488 #ifdef SUPPORT_VIDEO
SetVideoSurface(sptr<Surface> surface)489 int32_t PlayerServiceStub::SetVideoSurface(sptr<Surface> surface)
490 {
491 MediaTrace trace("PlayerServiceStub::SetVideoSurface");
492 MEDIA_LOGD("SetVideoSurface");
493 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
494 return playerServer_->SetVideoSurface(surface);
495 }
496 #endif
497
SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySessionProxy, bool svp)498 int32_t PlayerServiceStub::SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySessionProxy,
499 bool svp)
500 {
501 #ifdef SUPPORT_AVPLAYER_DRM
502 MediaTrace trace("PlayerServiceStub::SetDecryptConfig");
503 MEDIA_LOGI("PlayerServiceStub SetDecryptConfig");
504 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
505 return playerServer_->SetDecryptConfig(keySessionProxy, svp);
506 #else
507 (void)keySessionProxy;
508 (void)svp;
509 return 0;
510 #endif
511 }
512
IsPlaying()513 bool PlayerServiceStub::IsPlaying()
514 {
515 MediaTrace trace("PlayerServiceStub::IsPlaying");
516 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, false, "player server is nullptr");
517 return playerServer_->IsPlaying();
518 }
519
IsLooping()520 bool PlayerServiceStub::IsLooping()
521 {
522 MediaTrace trace("PlayerServiceStub::IsLooping");
523 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, false, "player server is nullptr");
524 return playerServer_->IsLooping();
525 }
526
SetLooping(bool loop)527 int32_t PlayerServiceStub::SetLooping(bool loop)
528 {
529 MediaTrace trace("PlayerServiceStub::SetLooping");
530 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
531 return playerServer_->SetLooping(loop);
532 }
533
SetParameter(const Format ¶m)534 int32_t PlayerServiceStub::SetParameter(const Format ¶m)
535 {
536 MediaTrace trace("PlayerServiceStub::SetParameter");
537 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
538 return playerServer_->SetParameter(param);
539 }
540
SetPlayerCallback()541 int32_t PlayerServiceStub::SetPlayerCallback()
542 {
543 MediaTrace trace("PlayerServiceStub::SetPlayerCallback");
544 MEDIA_LOGD("SetPlayerCallback");
545 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
546 return playerServer_->SetPlayerCallback(playerCallback_);
547 }
548
DumpInfo(int32_t fd)549 int32_t PlayerServiceStub::DumpInfo(int32_t fd)
550 {
551 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
552 return std::static_pointer_cast<PlayerServer>(playerServer_)->DumpInfo(fd);
553 }
554
DoIpcAbnormality()555 int32_t PlayerServiceStub::DoIpcAbnormality()
556 {
557 MEDIA_LOGI("Enter DoIpcAbnormality.");
558 auto task = std::make_shared<TaskHandler<int>>([&, this] {
559 MEDIA_LOGI("DoIpcAbnormality.");
560 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, static_cast<int>(MSERR_NO_MEMORY),
561 "player server is nullptr");
562 CHECK_AND_RETURN_RET_LOG(IsPlaying(), static_cast<int>(MSERR_INVALID_OPERATION), "Not in playback state");
563 auto playerServer = std::static_pointer_cast<PlayerServer>(playerServer_);
564 int32_t ret = playerServer->BackGroundChangeState(PlayerStates::PLAYER_PAUSED, false);
565 CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, "DoIpcAbnormality End.");
566 SetIpcAlarmedFlag();
567 MEDIA_LOGI("DoIpcAbnormality End.");
568 return ret;
569 });
570 (void)taskQue_.EnqueueTask(task);
571 return MSERR_OK;
572 }
573
DoIpcRecovery(bool fromMonitor)574 int32_t PlayerServiceStub::DoIpcRecovery(bool fromMonitor)
575 {
576 MEDIA_LOGI("Enter DoIpcRecovery %{public}d.", fromMonitor);
577 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
578 if (fromMonitor) {
579 auto task = std::make_shared<TaskHandler<int>>([&, this] {
580 MEDIA_LOGI("DoIpcRecovery.");
581 auto playerServer = std::static_pointer_cast<PlayerServer>(playerServer_);
582 int32_t ret = playerServer->BackGroundChangeState(PlayerStates::PLAYER_STARTED, false);
583 CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK || ret == MSERR_INVALID_OPERATION, ret, "Failed to ChangeState");
584 UnSetIpcAlarmedFlag();
585 MEDIA_LOGI("DoIpcRecovery End.");
586 return ret;
587 });
588 (void)taskQue_.EnqueueTask(task);
589 } else {
590 auto playerServer = std::static_pointer_cast<PlayerServer>(playerServer_);
591 int32_t ret = playerServer->BackGroundChangeState(PlayerStates::PLAYER_STARTED, false);
592 CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK || ret == MSERR_INVALID_OPERATION, ret, "Failed to ChangeState");
593 UnSetIpcAlarmedFlag();
594 }
595 return MSERR_OK;
596 }
597
SelectTrack(int32_t index, PlayerSwitchMode mode)598 int32_t PlayerServiceStub::SelectTrack(int32_t index, PlayerSwitchMode mode)
599 {
600 MediaTrace trace("PlayerServiceStub::SelectTrack");
601 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
602 return playerServer_->SelectTrack(index, mode);
603 }
604
DeselectTrack(int32_t index)605 int32_t PlayerServiceStub::DeselectTrack(int32_t index)
606 {
607 MediaTrace trace("PlayerServiceStub::DeselectTrack");
608 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
609 return playerServer_->DeselectTrack(index);
610 }
611
GetCurrentTrack(int32_t trackType, int32_t &index)612 int32_t PlayerServiceStub::GetCurrentTrack(int32_t trackType, int32_t &index)
613 {
614 MediaTrace trace("PlayerServiceStub::GetCurrentTrack");
615 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
616 return playerServer_->GetCurrentTrack(trackType, index);
617 }
618
SetListenerObject(MessageParcel &data, MessageParcel &reply)619 int32_t PlayerServiceStub::SetListenerObject(MessageParcel &data, MessageParcel &reply)
620 {
621 sptr<IRemoteObject> object = data.ReadRemoteObject();
622 reply.WriteInt32(SetListenerObject(object));
623 return MSERR_OK;
624 }
625
SetSource(MessageParcel &data, MessageParcel &reply)626 int32_t PlayerServiceStub::SetSource(MessageParcel &data, MessageParcel &reply)
627 {
628 std::string url = data.ReadString();
629 reply.WriteInt32(SetSource(url));
630 return MSERR_OK;
631 }
632
SetMediaDataSource(MessageParcel &data, MessageParcel &reply)633 int32_t PlayerServiceStub::SetMediaDataSource(MessageParcel &data, MessageParcel &reply)
634 {
635 sptr<IRemoteObject> object = data.ReadRemoteObject();
636 reply.WriteInt32(SetSource(object));
637 return MSERR_OK;
638 }
639
SetFdSource(MessageParcel &data, MessageParcel &reply)640 int32_t PlayerServiceStub::SetFdSource(MessageParcel &data, MessageParcel &reply)
641 {
642 int32_t fd = data.ReadFileDescriptor();
643 int64_t offset = data.ReadInt64();
644 int64_t size = data.ReadInt64();
645 reply.WriteInt32(SetSource(fd, offset, size));
646 (void)::close(fd);
647 return MSERR_OK;
648 }
649
AddSubSource(MessageParcel &data, MessageParcel &reply)650 int32_t PlayerServiceStub::AddSubSource(MessageParcel &data, MessageParcel &reply)
651 {
652 std::string url = data.ReadString();
653 reply.WriteInt32(AddSubSource(url));
654 return MSERR_OK;
655 }
656
AddSubFdSource(MessageParcel &data, MessageParcel &reply)657 int32_t PlayerServiceStub::AddSubFdSource(MessageParcel &data, MessageParcel &reply)
658 {
659 int32_t fd = data.ReadFileDescriptor();
660 int64_t offset = data.ReadInt64();
661 int64_t size = data.ReadInt64();
662 reply.WriteInt32(AddSubSource(fd, offset, size));
663 (void)::close(fd);
664 return MSERR_OK;
665 }
666
Play(MessageParcel &data, MessageParcel &reply)667 int32_t PlayerServiceStub::Play(MessageParcel &data, MessageParcel &reply)
668 {
669 (void)data;
670 reply.WriteInt32(Play());
671 return MSERR_OK;
672 }
673
Prepare(MessageParcel &data, MessageParcel &reply)674 int32_t PlayerServiceStub::Prepare(MessageParcel &data, MessageParcel &reply)
675 {
676 (void)data;
677 reply.WriteInt32(Prepare());
678 return MSERR_OK;
679 }
680
SetRenderFirstFrame(MessageParcel &data, MessageParcel &reply)681 int32_t PlayerServiceStub::SetRenderFirstFrame(MessageParcel &data, MessageParcel &reply)
682 {
683 bool display = data.ReadBool();
684 reply.WriteInt32(SetRenderFirstFrame(display));
685 return MSERR_OK;
686 }
687
SetPlayRange(MessageParcel &data, MessageParcel &reply)688 int32_t PlayerServiceStub::SetPlayRange(MessageParcel &data, MessageParcel &reply)
689 {
690 int64_t start = data.ReadInt64();
691 int64_t end = data.ReadInt64();
692 reply.WriteInt32(SetPlayRange(start, end));
693 return MSERR_OK;
694 }
695
SetPlayRangeWithMode(MessageParcel &data, MessageParcel &reply)696 int32_t PlayerServiceStub::SetPlayRangeWithMode(MessageParcel &data, MessageParcel &reply)
697 {
698 int64_t start = data.ReadInt64();
699 int64_t end = data.ReadInt64();
700 int32_t mode = data.ReadInt32();
701 reply.WriteInt32(SetPlayRangeWithMode(start, end, static_cast<PlayerSeekMode>(mode)));
702 return MSERR_OK;
703 }
704
PrepareAsync(MessageParcel &data, MessageParcel &reply)705 int32_t PlayerServiceStub::PrepareAsync(MessageParcel &data, MessageParcel &reply)
706 {
707 (void)data;
708 reply.WriteInt32(PrepareAsync());
709 return MSERR_OK;
710 }
711
Pause(MessageParcel &data, MessageParcel &reply)712 int32_t PlayerServiceStub::Pause(MessageParcel &data, MessageParcel &reply)
713 {
714 (void)data;
715 reply.WriteInt32(Pause());
716 return MSERR_OK;
717 }
718
Stop(MessageParcel &data, MessageParcel &reply)719 int32_t PlayerServiceStub::Stop(MessageParcel &data, MessageParcel &reply)
720 {
721 (void)data;
722 reply.WriteInt32(Stop());
723 return MSERR_OK;
724 }
725
Reset(MessageParcel &data, MessageParcel &reply)726 int32_t PlayerServiceStub::Reset(MessageParcel &data, MessageParcel &reply)
727 {
728 (void)data;
729 reply.WriteInt32(Reset());
730 return MSERR_OK;
731 }
732
Release(MessageParcel &data, MessageParcel &reply)733 int32_t PlayerServiceStub::Release(MessageParcel &data, MessageParcel &reply)
734 {
735 (void)data;
736 reply.WriteInt32(Release());
737 return MSERR_OK;
738 }
739
SetVolume(MessageParcel &data, MessageParcel &reply)740 int32_t PlayerServiceStub::SetVolume(MessageParcel &data, MessageParcel &reply)
741 {
742 float leftVolume = data.ReadFloat();
743 float rightVolume = data.ReadFloat();
744 reply.WriteInt32(SetVolume(leftVolume, rightVolume));
745 return MSERR_OK;
746 }
747
Seek(MessageParcel &data, MessageParcel &reply)748 int32_t PlayerServiceStub::Seek(MessageParcel &data, MessageParcel &reply)
749 {
750 int32_t mSeconds = data.ReadInt32();
751 int32_t mode = data.ReadInt32();
752 reply.WriteInt32(Seek(mSeconds, static_cast<PlayerSeekMode>(mode)));
753 return MSERR_OK;
754 }
755
GetCurrentTime(MessageParcel &data, MessageParcel &reply)756 int32_t PlayerServiceStub::GetCurrentTime(MessageParcel &data, MessageParcel &reply)
757 {
758 (void)data;
759 int32_t currentTime = -1;
760 int32_t ret = GetCurrentTime(currentTime);
761 reply.WriteInt32(currentTime);
762 reply.WriteInt32(ret);
763 return MSERR_OK;
764 }
765
GetPlaybackPosition(MessageParcel &data, MessageParcel &reply)766 int32_t PlayerServiceStub::GetPlaybackPosition(MessageParcel &data, MessageParcel &reply)
767 {
768 (void)data;
769 int32_t currentTime = -1;
770 int32_t ret = GetPlaybackPosition(currentTime);
771 reply.WriteInt32(currentTime);
772 reply.WriteInt32(ret);
773 return MSERR_OK;
774 }
775
GetVideoTrackInfo(MessageParcel &data, MessageParcel &reply)776 int32_t PlayerServiceStub::GetVideoTrackInfo(MessageParcel &data, MessageParcel &reply)
777 {
778 (void)data;
779 std::vector<Format> videoTrack;
780 int32_t ret = GetVideoTrackInfo(videoTrack);
781 reply.WriteInt32(static_cast<int32_t>(videoTrack.size()));
782 for (auto iter = videoTrack.begin(); iter != videoTrack.end(); iter++) {
783 (void)MediaParcel::Marshalling(reply, *iter);
784 }
785 reply.WriteInt32(ret);
786
787 return MSERR_OK;
788 }
789
GetPlaybackInfo(MessageParcel &data, MessageParcel &reply)790 int32_t PlayerServiceStub::GetPlaybackInfo(MessageParcel &data, MessageParcel &reply)
791 {
792 (void)data;
793 Format playbackInfo;
794 int32_t ret = GetPlaybackInfo(playbackInfo);
795 (void)MediaParcel::Marshalling(reply, playbackInfo);
796 reply.WriteInt32(ret);
797
798 return MSERR_OK;
799 }
800
GetAudioTrackInfo(MessageParcel &data, MessageParcel &reply)801 int32_t PlayerServiceStub::GetAudioTrackInfo(MessageParcel &data, MessageParcel &reply)
802 {
803 (void)data;
804 std::vector<Format> audioTrack;
805 int32_t ret = GetAudioTrackInfo(audioTrack);
806 reply.WriteInt32(static_cast<int32_t>(audioTrack.size()));
807 for (auto iter = audioTrack.begin(); iter != audioTrack.end(); iter++) {
808 (void)MediaParcel::Marshalling(reply, *iter);
809 }
810 reply.WriteInt32(ret);
811
812 return MSERR_OK;
813 }
814
GetSubtitleTrackInfo(MessageParcel &data, MessageParcel &reply)815 int32_t PlayerServiceStub::GetSubtitleTrackInfo(MessageParcel &data, MessageParcel &reply)
816 {
817 (void)data;
818 std::vector<Format> subtitleTrack;
819 int32_t ret = GetSubtitleTrackInfo(subtitleTrack);
820 reply.WriteInt32(static_cast<int32_t>(subtitleTrack.size()));
821 for (auto iter = subtitleTrack.begin(); iter != subtitleTrack.end(); iter++) {
822 (void)MediaParcel::Marshalling(reply, *iter);
823 }
824 reply.WriteInt32(ret);
825
826 return MSERR_OK;
827 }
828
GetVideoWidth(MessageParcel &data, MessageParcel &reply)829 int32_t PlayerServiceStub::GetVideoWidth(MessageParcel &data, MessageParcel &reply)
830 {
831 (void)data;
832 int32_t witdh = GetVideoWidth();
833 reply.WriteInt32(witdh);
834
835 return MSERR_OK;
836 }
837
GetVideoHeight(MessageParcel &data, MessageParcel &reply)838 int32_t PlayerServiceStub::GetVideoHeight(MessageParcel &data, MessageParcel &reply)
839 {
840 (void)data;
841 int32_t height = GetVideoHeight();
842 reply.WriteInt32(height);
843
844 return MSERR_OK;
845 }
846
GetDuration(MessageParcel &data, MessageParcel &reply)847 int32_t PlayerServiceStub::GetDuration(MessageParcel &data, MessageParcel &reply)
848 {
849 (void)data;
850 int32_t duration = -1;
851 int32_t ret = GetDuration(duration);
852 reply.WriteInt32(duration);
853 reply.WriteInt32(ret);
854 return MSERR_OK;
855 }
856
SetPlaybackSpeed(MessageParcel &data, MessageParcel &reply)857 int32_t PlayerServiceStub::SetPlaybackSpeed(MessageParcel &data, MessageParcel &reply)
858 {
859 int32_t mode = data.ReadInt32();
860 reply.WriteInt32(SetPlaybackSpeed(static_cast<PlaybackRateMode>(mode)));
861 return MSERR_OK;
862 }
863
SetMediaSource(MessageParcel &data, MessageParcel &reply)864 int32_t PlayerServiceStub::SetMediaSource(MessageParcel &data, MessageParcel &reply)
865 {
866 std::string url = data.ReadString();
867 auto mapSize = data.ReadUint32();
868 std::map<std::string, std::string> header;
869 if (mapSize >= MAX_MAP_SIZE) {
870 MEDIA_LOGI("Exceeded maximum table size limit");
871 return MSERR_INVALID_OPERATION;
872 }
873 for (size_t i = 0; i < mapSize; i++) {
874 auto kstr = data.ReadString();
875 auto vstr = data.ReadString();
876 header.emplace(kstr, vstr);
877 }
878 std::string mimeType = data.ReadString();
879
880 std::shared_ptr<AVMediaSource> mediaSource = std::make_shared<AVMediaSource>(url, header);
881 mediaSource->SetMimeType(mimeType);
882
883 int32_t fd = -1;
884 if (mimeType == AVMimeType::APPLICATION_M3U8) {
885 fd = data.ReadFileDescriptor();
886 MEDIA_LOGI("fd : %d", fd);
887 }
888 std::string uri = mediaSource->url;
889 size_t fdHeadPos = uri.find("fd://");
890 size_t fdTailPos = uri.find("?");
891 if (mimeType == AVMimeType::APPLICATION_M3U8 && fdHeadPos != std::string::npos &&
892 fdTailPos != std::string::npos) {
893 std::string temp = uri.substr(fdTailPos);
894 std::string newUrl = "fd://" + std::to_string(fd) + temp;
895 mediaSource->url = newUrl;
896 }
897
898 struct AVPlayStrategy strategy;
899 strategy.preferredWidth = data.ReadUint32();
900 strategy.preferredHeight = data.ReadUint32();
901 strategy.preferredBufferDuration = data.ReadUint32();
902 strategy.preferredHdr = data.ReadBool();
903 strategy.preferredAudioLanguage = data.ReadString();
904 strategy.preferredSubtitleLanguage = data.ReadString();
905 reply.WriteInt32(SetMediaSource(mediaSource, strategy));
906 if (mimeType == AVMimeType::APPLICATION_M3U8) {
907 (void)::close(fd);
908 }
909 return MSERR_OK;
910 }
911
GetPlaybackSpeed(MessageParcel &data, MessageParcel &reply)912 int32_t PlayerServiceStub::GetPlaybackSpeed(MessageParcel &data, MessageParcel &reply)
913 {
914 (void)data;
915 PlaybackRateMode mode = SPEED_FORWARD_1_00_X;
916 int32_t ret = GetPlaybackSpeed(mode);
917 reply.WriteInt32(mode);
918 reply.WriteInt32(ret);
919 return MSERR_OK;
920 }
921
SelectBitRate(MessageParcel &data, MessageParcel &reply)922 int32_t PlayerServiceStub::SelectBitRate(MessageParcel &data, MessageParcel &reply)
923 {
924 int32_t bitrate = data.ReadInt32();
925 reply.WriteInt32(SelectBitRate(static_cast<uint32_t>(bitrate)));
926 return MSERR_OK;
927 }
928
929 #ifdef SUPPORT_VIDEO
SetVideoSurface(MessageParcel &data, MessageParcel &reply)930 int32_t PlayerServiceStub::SetVideoSurface(MessageParcel &data, MessageParcel &reply)
931 {
932 sptr<IRemoteObject> object = data.ReadRemoteObject();
933 CHECK_AND_RETURN_RET_LOG(object != nullptr, MSERR_NO_MEMORY, "object is nullptr");
934
935 sptr<IBufferProducer> producer = iface_cast<IBufferProducer>(object);
936 CHECK_AND_RETURN_RET_LOG(producer != nullptr, MSERR_NO_MEMORY, "failed to convert object to producer");
937
938 sptr<Surface> surface = Surface::CreateSurfaceAsProducer(producer);
939 CHECK_AND_RETURN_RET_LOG(surface != nullptr, MSERR_NO_MEMORY, "failed to create surface");
940
941 std::string format = data.ReadString();
942 MEDIA_LOGI("0x%{public}06" PRIXPTR " surfaceFormat is %{public}s!", FAKE_POINTER(this), format.c_str());
943 (void)surface->SetUserData("SURFACE_FORMAT", format);
944 reply.WriteInt32(SetVideoSurface(surface));
945 return MSERR_OK;
946 }
947 #endif
948
SetDecryptConfig(MessageParcel &data, MessageParcel &reply)949 int32_t PlayerServiceStub::SetDecryptConfig(MessageParcel &data, MessageParcel &reply)
950 {
951 MEDIA_LOGI("PlayerServiceStub SetDecryptConfig");
952 #ifdef SUPPORT_AVPLAYER_DRM
953 sptr<IRemoteObject> object = data.ReadRemoteObject();
954 CHECK_AND_RETURN_RET_LOG(object != nullptr, MSERR_NO_MEMORY, "KeySessionServiceProxy object is nullptr");
955 bool svp = data.ReadBool();
956
957 sptr<DrmStandard::MediaKeySessionServiceProxy> keySessionServiceProxy =
958 iface_cast<DrmStandard::MediaKeySessionServiceProxy>(object);
959 if (keySessionServiceProxy != nullptr) {
960 MEDIA_LOGD("And it's count is: %{public}d", keySessionServiceProxy->GetSptrRefCount());
961 reply.WriteInt32(SetDecryptConfig(keySessionServiceProxy, svp));
962 return MSERR_OK;
963 }
964 MEDIA_LOGE("PlayerServiceStub keySessionServiceProxy is nullptr!");
965 return MSERR_INVALID_VAL;
966 #else
967 (void)data;
968 (void)reply;
969 return 0;
970 #endif
971 }
972
IsPlaying(MessageParcel &data, MessageParcel &reply)973 int32_t PlayerServiceStub::IsPlaying(MessageParcel &data, MessageParcel &reply)
974 {
975 (void)data;
976 reply.WriteBool(IsPlaying());
977 return MSERR_OK;
978 }
979
IsLooping(MessageParcel &data, MessageParcel &reply)980 int32_t PlayerServiceStub::IsLooping(MessageParcel &data, MessageParcel &reply)
981 {
982 (void)data;
983 reply.WriteBool(IsLooping());
984 return MSERR_OK;
985 }
986
SetLooping(MessageParcel &data, MessageParcel &reply)987 int32_t PlayerServiceStub::SetLooping(MessageParcel &data, MessageParcel &reply)
988 {
989 bool loop = data.ReadBool();
990 reply.WriteInt32(SetLooping(loop));
991 return MSERR_OK;
992 }
993
SetParameter(MessageParcel &data, MessageParcel &reply)994 int32_t PlayerServiceStub::SetParameter(MessageParcel &data, MessageParcel &reply)
995 {
996 Format param;
997 (void)MediaParcel::Unmarshalling(data, param);
998
999 reply.WriteInt32(SetParameter(param));
1000
1001 return MSERR_OK;
1002 }
1003
DestroyStub(MessageParcel &data, MessageParcel &reply)1004 int32_t PlayerServiceStub::DestroyStub(MessageParcel &data, MessageParcel &reply)
1005 {
1006 (void)data;
1007 reply.WriteInt32(DestroyStub());
1008 return MSERR_OK;
1009 }
1010
SetPlayerCallback(MessageParcel &data, MessageParcel &reply)1011 int32_t PlayerServiceStub::SetPlayerCallback(MessageParcel &data, MessageParcel &reply)
1012 {
1013 (void)data;
1014 reply.WriteInt32(SetPlayerCallback());
1015 return MSERR_OK;
1016 }
1017
SelectTrack(MessageParcel &data, MessageParcel &reply)1018 int32_t PlayerServiceStub::SelectTrack(MessageParcel &data, MessageParcel &reply)
1019 {
1020 int32_t index = data.ReadInt32();
1021 int32_t mode = data.ReadInt32();
1022 reply.WriteInt32(SelectTrack(index, static_cast<PlayerSwitchMode>(mode)));
1023 return MSERR_OK;
1024 }
1025
DeselectTrack(MessageParcel &data, MessageParcel &reply)1026 int32_t PlayerServiceStub::DeselectTrack(MessageParcel &data, MessageParcel &reply)
1027 {
1028 int32_t index = data.ReadInt32();
1029 reply.WriteInt32(DeselectTrack(index));
1030 return MSERR_OK;
1031 }
1032
GetCurrentTrack(MessageParcel &data, MessageParcel &reply)1033 int32_t PlayerServiceStub::GetCurrentTrack(MessageParcel &data, MessageParcel &reply)
1034 {
1035 int32_t trackType = data.ReadInt32();
1036 int32_t index = -1;
1037 int32_t ret = GetCurrentTrack(trackType, index);
1038 reply.WriteInt32(index);
1039 reply.WriteInt32(ret);
1040 return MSERR_OK;
1041 }
1042
SetMediaMuted(MessageParcel &data, MessageParcel &reply)1043 int32_t PlayerServiceStub::SetMediaMuted(MessageParcel &data, MessageParcel &reply)
1044 {
1045 int32_t mediaType = data.ReadInt32();
1046 bool isMuted = data.ReadBool();
1047 int32_t ret = SetMediaMuted(static_cast<MediaType>(mediaType), isMuted);
1048 reply.WriteInt32(ret);
1049 return MSERR_OK;
1050 }
1051
SetMediaMuted(MediaType mediaType, bool isMuted)1052 int32_t PlayerServiceStub::SetMediaMuted(MediaType mediaType, bool isMuted)
1053 {
1054 MediaTrace trace("PlayerServiceStub::SetMediaMuted");
1055 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
1056 return playerServer_->SetMediaMuted(mediaType, isMuted);
1057 }
1058
SetPlaybackStrategy(MessageParcel &data, MessageParcel &reply)1059 int32_t PlayerServiceStub::SetPlaybackStrategy(MessageParcel &data, MessageParcel &reply)
1060 {
1061 struct AVPlayStrategy avPlaybackStrategy = {
1062 .preferredWidth = data.ReadUint32(),
1063 .preferredHeight = data.ReadUint32(),
1064 .preferredBufferDuration = data.ReadUint32(),
1065 .preferredHdr = data.ReadBool(),
1066 .mutedMediaType = static_cast<OHOS::Media::MediaType>(data.ReadInt32())
1067 };
1068 reply.WriteInt32(SetPlaybackStrategy(avPlaybackStrategy));
1069 return MSERR_OK;
1070 }
1071
SetPlaybackStrategy(AVPlayStrategy playbackStrategy)1072 int32_t PlayerServiceStub::SetPlaybackStrategy(AVPlayStrategy playbackStrategy)
1073 {
1074 MediaTrace trace("PlayerServiceStub::SetPlaybackStrategy");
1075 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
1076 return playerServer_->SetPlaybackStrategy(playbackStrategy);
1077 }
1078
SetMaxAmplitudeCbStatus(bool status)1079 int32_t PlayerServiceStub::SetMaxAmplitudeCbStatus(bool status)
1080 {
1081 MediaTrace trace("PlayerServiceStub::SetMaxAmplitudeCbStatus");
1082 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
1083 return playerServer_->SetMaxAmplitudeCbStatus(status);
1084 }
1085
SetMaxAmplitudeCbStatus(MessageParcel &data, MessageParcel &reply)1086 int32_t PlayerServiceStub::SetMaxAmplitudeCbStatus(MessageParcel &data, MessageParcel &reply)
1087 {
1088 bool status = data.ReadInt32();
1089 reply.WriteInt32(SetMaxAmplitudeCbStatus(status));
1090 return MSERR_OK;
1091 }
1092
SetDeviceChangeCbStatus(bool status)1093 int32_t PlayerServiceStub::SetDeviceChangeCbStatus(bool status)
1094 {
1095 MediaTrace trace("PlayerServiceStub::SetDeviceChangeCbStatus");
1096 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
1097 return playerServer_->SetDeviceChangeCbStatus(status);
1098 }
1099
SetDeviceChangeCbStatus(MessageParcel &data, MessageParcel &reply)1100 int32_t PlayerServiceStub::SetDeviceChangeCbStatus(MessageParcel &data, MessageParcel &reply)
1101 {
1102 bool status = data.ReadInt32();
1103 reply.WriteInt32(SetDeviceChangeCbStatus(status));
1104 return MSERR_OK;
1105 }
1106
StartReportStatus()1107 int32_t PlayerServiceStub::StartReportStatus()
1108 {
1109 MEDIA_LOGI("StartReportStatus begin");
1110 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
1111 auto playerServer = std::static_pointer_cast<PlayerServer>(playerServer_);
1112 playerServer->StartReportStatus();
1113 MEDIA_LOGI("StartReportStatus end!");
1114 return MSERR_OK;
1115 }
1116
StopReportStatus()1117 int32_t PlayerServiceStub::StopReportStatus()
1118 {
1119 MEDIA_LOGI("StopReportStatus begin");
1120 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
1121 auto playerServer = std::static_pointer_cast<PlayerServer>(playerServer_);
1122 playerServer->StopReportStatus();
1123 MEDIA_LOGI("StopReportStatus end!");
1124 return MSERR_OK;
1125 }
1126
HandleActive()1127 int32_t PlayerServiceStub::HandleActive()
1128 {
1129 MEDIA_LOGI("PlayerServiceStub HandleActive begin!");
1130 (void)RegisterMonitor(appPid_);
1131 StopBufferring(false);
1132 StartReportStatus();
1133 MEDIA_LOGI("PlayerServiceStub HandleActive end!");
1134 return MSERR_OK;
1135 }
1136
HandleFrozen()1137 int32_t PlayerServiceStub::HandleFrozen()
1138 {
1139 MEDIA_LOGI("PlayerServiceStub HandleFrozen begin!");
1140 (void)CancellationMonitor(appPid_);
1141 StopReportStatus();
1142 StopBufferring(true);
1143 MEDIA_LOGI("PlayerServiceStub HandleFrozen end!");
1144 return MSERR_OK;
1145 }
1146
GetUid()1147 int32_t PlayerServiceStub::GetUid()
1148 {
1149 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
1150 auto playerServer = std::static_pointer_cast<PlayerServer>(playerServer_);
1151 return playerServer->GetUid();
1152 }
1153
IsPlayerRunning()1154 bool PlayerServiceStub::IsPlayerRunning()
1155 {
1156 CHECK_AND_RETURN_RET_LOG(playerServer_ != nullptr, MSERR_NO_MEMORY, "player server is nullptr");
1157 auto playerServer = std::static_pointer_cast<PlayerServer>(playerServer_);
1158 return playerServer->IsPlayerRunning();
1159 }
1160
1161 } // namespace Media
1162 } // namespace OHOS
1163