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