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