1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "hw_cast_stream_player.h"
17 #include "int_wrapper.h"
18 #include "avsession_log.h"
19 #include "avcast_player_state.h"
20 #include "avqueue_item.h"
21 #include "avmedia_description.h"
22 #include "avsession_errors.h"
23
24 using namespace OHOS::CastEngine;
25
26 namespace OHOS::AVSession {
~HwCastStreamPlayer()27 HwCastStreamPlayer::~HwCastStreamPlayer()
28 {
29 SLOGI("destruct the HwCastStreamPlayer");
30 Release();
31 }
32
Init()33 void HwCastStreamPlayer::Init()
34 {
35 SLOGI("Init the HwCastStreamPlayer");
36 std::lock_guard lockGuard(streamPlayerLock_);
37 if (streamPlayer_) {
38 SLOGI("register self in streamPlayer");
39 streamPlayer_->RegisterListener(shared_from_this());
40 }
41 }
42
Release()43 void HwCastStreamPlayer::Release()
44 {
45 SLOGI("Release the HwCastStreamPlayer");
46 std::lock_guard lockGuard(streamPlayerLock_);
47 if (streamPlayer_) {
48 streamPlayer_->UnregisterListener();
49 streamPlayer_->Release();
50 streamPlayer_ = nullptr;
51 }
52 streamPlayerListenerList_.clear();
53 }
54
SendControlCommand(const AVCastControlCommand castControlCommand)55 void HwCastStreamPlayer::SendControlCommand(const AVCastControlCommand castControlCommand)
56 {
57 SLOGI("send command to streamPlayer");
58 std::lock_guard lockGuard(streamPlayerLock_);
59 if (!streamPlayer_) {
60 SLOGE("streamPlayer is nullptr");
61 return;
62 }
63 switch (castControlCommand.GetCommand()) {
64 case AVCastControlCommand::CAST_CONTROL_CMD_PLAY:
65 streamPlayer_->Play();
66 break;
67 case AVCastControlCommand::CAST_CONTROL_CMD_PAUSE:
68 streamPlayer_->Pause();
69 break;
70 case AVCastControlCommand::CAST_CONTROL_CMD_STOP:
71 streamPlayer_->Stop();
72 break;
73 case AVCastControlCommand::CAST_CONTROL_CMD_PLAY_NEXT:
74 streamPlayer_->Next();
75 break;
76 case AVCastControlCommand::CAST_CONTROL_CMD_PLAY_PREVIOUS:
77 streamPlayer_->Previous();
78 break;
79 default:
80 SendControlCommandWithParams(castControlCommand);
81 break;
82 }
83 }
84
SendControlCommandWithParams(const AVCastControlCommand castControlCommand)85 void HwCastStreamPlayer::SendControlCommandWithParams(const AVCastControlCommand castControlCommand)
86 {
87 int32_t currentPosition = 0;
88 std::lock_guard lockGuard(streamPlayerLock_);
89 switch (castControlCommand.GetCommand()) {
90 case AVCastControlCommand::CAST_CONTROL_CMD_FAST_FORWARD:
91 streamPlayer_->GetPosition(currentPosition);
92 int32_t forwardTime;
93 castControlCommand.GetForwardTime(forwardTime);
94 streamPlayer_->Seek(currentPosition + forwardTime);
95 break;
96 case AVCastControlCommand::CAST_CONTROL_CMD_REWIND:
97 streamPlayer_->GetPosition(currentPosition);
98 int32_t rewindTime;
99 castControlCommand.GetRewindTime(rewindTime);
100 streamPlayer_->Seek(rewindTime > currentPosition ? 0 : currentPosition - rewindTime);
101 break;
102 case AVCastControlCommand::CAST_CONTROL_CMD_SEEK:
103 int32_t seekTime;
104 castControlCommand.GetSeekTime(seekTime);
105 streamPlayer_->Seek(seekTime);
106 break;
107 case AVCastControlCommand::CAST_CONTROL_CMD_SET_VOLUME:
108 int32_t volume;
109 castControlCommand.GetVolume(volume);
110 streamPlayer_->SetVolume(volume);
111 break;
112 case AVCastControlCommand::CAST_CONTROL_CMD_SET_SPEED:
113 int32_t speed;
114 castControlCommand.GetSpeed(speed);
115 streamPlayer_->SetSpeed(static_cast<CastEngine::PlaybackSpeed>(speed));
116 break;
117 case AVCastControlCommand::CAST_CONTROL_CMD_SET_LOOP_MODE:
118 int32_t loopMode;
119 castControlCommand.GetLoopMode(loopMode);
120 streamPlayer_->SetLoopMode(static_cast<CastEngine::LoopMode>(loopMode + 1)); // Convert loop mode
121 break;
122 case AVCastControlCommand::CAST_CONTROL_CMD_TOGGLE_FAVORITE:
123 break;
124 default:
125 SLOGE("invalid command");
126 break;
127 }
128 }
129
GetCurrentItem()130 AVQueueItem HwCastStreamPlayer::GetCurrentItem()
131 {
132 std::lock_guard lockGuard(streamPlayerLock_);
133 return currentAVQueueItem_;
134 }
135
Start(const AVQueueItem & avQueueItem)136 int32_t HwCastStreamPlayer::Start(const AVQueueItem& avQueueItem)
137 {
138 CastEngine::MediaInfo mediaInfo;
139 std::shared_ptr<AVMediaDescription> mediaDescription = avQueueItem.GetDescription();
140 mediaInfo.mediaId = mediaDescription->GetMediaId();
141 mediaInfo.mediaName = mediaDescription->GetTitle();
142 if (mediaDescription->GetMediaUri() == "") {
143 if (mediaDescription->GetFdSrc().fd_ == 0) {
144 SLOGW("No media id and fd src");
145 mediaInfo.mediaUrl = "http:";
146 } else {
147 mediaInfo.mediaUrl = std::to_string(mediaDescription->GetFdSrc().fd_);
148 }
149 } else {
150 mediaInfo.mediaUrl = mediaDescription->GetMediaUri();
151 }
152 mediaInfo.mediaType = mediaDescription->GetMediaType();
153 mediaInfo.mediaSize = mediaDescription->GetMediaSize();
154 mediaInfo.startPosition = static_cast<uint32_t>(mediaDescription->GetStartPosition());
155 mediaInfo.duration = static_cast<uint32_t>(mediaDescription->GetDuration());
156 mediaInfo.closingCreditsPosition = static_cast<uint32_t>(mediaDescription->GetCreditsPosition());
157 if (mediaDescription->GetIconUri() == "") {
158 mediaInfo.albumCoverUrl = mediaDescription->GetAlbumCoverUri();
159 } else {
160 mediaInfo.albumCoverUrl = mediaDescription->GetIconUri();
161 }
162 mediaInfo.albumTitle = mediaDescription->GetAlbumTitle();
163 mediaInfo.mediaArtist = mediaDescription->GetArtist();
164 mediaInfo.lrcUrl = mediaDescription->GetLyricUri();
165 mediaInfo.appIconUrl = mediaDescription->GetIconUri();
166 mediaInfo.appName = mediaDescription->GetAppName();
167 SLOGD("mediaInfo albumCoverUrl is %{public}s", mediaInfo.albumCoverUrl.c_str());
168 std::lock_guard lockGuard(streamPlayerLock_);
169 if (!streamPlayer_) {
170 SLOGE("Set media info and start failed");
171 return AVSESSION_ERROR;
172 }
173 if (currentAVQueueItem_.GetDescription() && currentAVQueueItem_.GetDescription()->GetMediaUri() != "http:" &&
174 currentAVQueueItem_.GetDescription()->GetMediaId() == mediaInfo.mediaId) {
175 if (streamPlayer_->Play() != AVSESSION_SUCCESS) {
176 SLOGE("Set media info and start failed");
177 return AVSESSION_ERROR;
178 }
179 } else if (streamPlayer_->Play(mediaInfo) != AVSESSION_SUCCESS) {
180 SLOGE("Set media info and start failed");
181 return AVSESSION_ERROR;
182 }
183 currentAVQueueItem_ = avQueueItem;
184 SLOGI("Set media info and start successfully");
185 return AVSESSION_SUCCESS;
186 }
187
Prepare(const AVQueueItem & avQueueItem)188 int32_t HwCastStreamPlayer::Prepare(const AVQueueItem& avQueueItem)
189 {
190 CastEngine::MediaInfo mediaInfo;
191 std::shared_ptr<AVMediaDescription> mediaDescription = avQueueItem.GetDescription();
192 mediaInfo.mediaId = mediaDescription->GetMediaId();
193 mediaInfo.mediaName = mediaDescription->GetTitle();
194 if (mediaDescription->GetMediaUri() == "") {
195 if (mediaDescription->GetFdSrc().fd_ == 0) {
196 SLOGW("No media id and fd src");
197 mediaInfo.mediaUrl = "http:";
198 avQueueItem.GetDescription()->SetMediaUri("http:");
199 } else {
200 mediaInfo.mediaUrl = std::to_string(mediaDescription->GetFdSrc().fd_);
201 }
202 } else {
203 mediaInfo.mediaUrl = mediaDescription->GetMediaUri();
204 }
205 mediaInfo.mediaType = mediaDescription->GetMediaType();
206 mediaInfo.mediaSize = mediaDescription->GetMediaSize();
207 mediaInfo.startPosition = static_cast<uint32_t>(mediaDescription->GetStartPosition());
208 mediaInfo.duration = static_cast<uint32_t>(mediaDescription->GetDuration());
209 mediaInfo.closingCreditsPosition = static_cast<uint32_t>(mediaDescription->GetCreditsPosition());
210 if (mediaDescription->GetIconUri() == "") {
211 mediaInfo.albumCoverUrl = mediaDescription->GetAlbumCoverUri();
212 } else {
213 mediaInfo.albumCoverUrl = mediaDescription->GetIconUri();
214 }
215 mediaInfo.albumTitle = mediaDescription->GetAlbumTitle();
216 mediaInfo.mediaArtist = mediaDescription->GetArtist();
217 mediaInfo.lrcUrl = mediaDescription->GetLyricUri();
218 mediaInfo.appIconUrl = mediaDescription->GetIconUri();
219 mediaInfo.appName = mediaDescription->GetAppName();
220
221 std::lock_guard lockGuard(streamPlayerLock_);
222 if (streamPlayer_ && streamPlayer_->Load(mediaInfo) == AVSESSION_SUCCESS) {
223 SLOGI("Set media info and prepare successed");
224 currentAVQueueItem_ = avQueueItem;
225 return AVSESSION_SUCCESS;
226 }
227 SLOGE("Set media info and prepare failed");
228 return AVSESSION_ERROR;
229 }
230
GetDuration(int32_t & duration)231 int32_t HwCastStreamPlayer::GetDuration(int32_t& duration)
232 {
233 SLOGI("GetDuration begin");
234 std::lock_guard lockGuard(streamPlayerLock_);
235 if (!streamPlayer_) {
236 SLOGE("streamPlayer is nullptr");
237 return AVSESSION_ERROR;
238 }
239 streamPlayer_->GetDuration(duration);
240 SLOGI("GetDuration successed");
241 return AVSESSION_SUCCESS;
242 }
243
GetCastAVPlaybackState(AVPlaybackState & avPlaybackState)244 int32_t HwCastStreamPlayer::GetCastAVPlaybackState(AVPlaybackState& avPlaybackState)
245 {
246 SLOGI("GetCastAVPlaybackState begin");
247 std::lock_guard lockGuard(streamPlayerLock_);
248 if (!streamPlayer_) {
249 SLOGE("streamPlayer is nullptr");
250 return AVSESSION_ERROR;
251 }
252 CastEngine::PlayerStates castPlayerStates;
253 streamPlayer_->GetPlayerStatus(castPlayerStates);
254 if (castPlusStateToString_.count(castPlayerStates) != 0) {
255 avPlaybackState.SetState(castPlusStateToString_[castPlayerStates]);
256 }
257 CastEngine::PlaybackSpeed castPlaybackSpeed;
258 streamPlayer_->GetPlaySpeed(castPlaybackSpeed);
259 if (castPlusSpeedToDouble_.count(castPlaybackSpeed) != 0) {
260 avPlaybackState.SetSpeed(castPlusSpeedToDouble_[castPlaybackSpeed]);
261 }
262 int castPosition;
263 streamPlayer_->GetPosition(castPosition);
264 AVPlaybackState::Position position;
265 position.updateTime_ = static_cast<int64_t>(castPosition);
266 avPlaybackState.SetPosition(position);
267 CastEngine::LoopMode castLoopMode;
268 streamPlayer_->GetLoopMode(castLoopMode);
269 if (castPlusLoopModeToInt_.count(castLoopMode) != 0) {
270 avPlaybackState.SetLoopMode(castPlusLoopModeToInt_[castLoopMode]);
271 }
272 int32_t castVolume;
273 int32_t maxCastVolume;
274 streamPlayer_->GetVolume(castVolume, maxCastVolume);
275 avPlaybackState.SetVolume(castVolume);
276
277 std::shared_ptr<AAFwk::WantParams> wantParams = std::make_shared<AAFwk::WantParams>();
278 sptr<AAFwk::IInterface> intIt = AAFwk::Integer::Box(maxCastVolume);
279 if (wantParams == nullptr || intIt == nullptr) {
280 return AVSESSION_ERROR;
281 }
282 wantParams->SetParam("maxCastVolume", intIt);
283 avPlaybackState.SetExtras(wantParams);
284
285 SLOGI("GetCastAVPlaybackState successed");
286 return AVSESSION_SUCCESS;
287 }
288
SetDisplaySurface(std::string & surfaceId)289 int32_t HwCastStreamPlayer::SetDisplaySurface(std::string &surfaceId)
290 {
291 SLOGI("SetDisplaySurface begin");
292 std::lock_guard lockGuard(streamPlayerLock_);
293 if (!streamPlayer_) {
294 SLOGE("streamPlayer is nullptr");
295 return AVSESSION_ERROR;
296 }
297 streamPlayer_->SetSurface(surfaceId);
298 SLOGI("SetDisplaySurface successed");
299 return AVSESSION_SUCCESS;
300 }
301
RegisterControllerListener(std::shared_ptr<IAVCastControllerProxyListener> listener)302 int32_t HwCastStreamPlayer::RegisterControllerListener(std::shared_ptr<IAVCastControllerProxyListener> listener)
303 {
304 SLOGI("RegisterControllerListener begin");
305 if (listener == nullptr) {
306 SLOGE("RegisterControllerListener failed for the listener is nullptr");
307 return AVSESSION_ERROR;
308 }
309 std::lock_guard lockGuard(streamPlayerLock_);
310 if (find(streamPlayerListenerList_.begin(), streamPlayerListenerList_.end(), listener)
311 != streamPlayerListenerList_.end()) {
312 SLOGE("listener is already in streamPlayerListenerList_");
313 return AVSESSION_ERROR;
314 }
315 SLOGI("RegisterControllerListener successed, and add it to streamPlayerListenerList_");
316 streamPlayerListenerList_.emplace_back(listener);
317
318 return AVSESSION_SUCCESS;
319 }
320
UnRegisterControllerListener(std::shared_ptr<IAVCastControllerProxyListener> listener)321 int32_t HwCastStreamPlayer::UnRegisterControllerListener(std::shared_ptr<IAVCastControllerProxyListener> listener)
322 {
323 if (listener == nullptr) {
324 SLOGE("UnRegisterCastSessionStateListener failed for the listener is nullptr");
325 return AVSESSION_ERROR;
326 }
327 std::lock_guard lockGuard(streamPlayerLock_);
328 for (auto iter = streamPlayerListenerList_.begin(); iter != streamPlayerListenerList_.end();) {
329 if (*iter == listener) {
330 streamPlayerListenerList_.erase(iter);
331 SLOGI("UnRegisterControllerListener successed, and erase it from streamPlayerListenerList_");
332 return AVSESSION_SUCCESS;
333 } else {
334 ++iter;
335 }
336 }
337 SLOGE("listener is not found in streamPlayerListenerList_, so UnRegisterControllerListener failed");
338
339 return AVSESSION_ERROR;
340 }
341
OnStateChanged(const CastEngine::PlayerStates playbackState,bool isPlayWhenReady)342 void HwCastStreamPlayer::OnStateChanged(const CastEngine::PlayerStates playbackState, bool isPlayWhenReady)
343 {
344 AVPlaybackState avCastPlaybackState;
345 if (castPlusStateToString_.count(playbackState) == 0) {
346 SLOGE("current playbackState status is not exist in castPlusStateToString_");
347 avCastPlaybackState.SetState(AVPlaybackState::PLAYBACK_STATE_ERROR);
348 } else {
349 SLOGD("On state changed, get state %{public}d", castPlusStateToString_[playbackState]);
350 avCastPlaybackState.SetState(castPlusStateToString_[playbackState]);
351 }
352 for (auto listener : streamPlayerListenerList_) {
353 if (listener != nullptr) {
354 SLOGI("trigger the OnCastPlaybackStateChange for registered listeners");
355 listener->OnCastPlaybackStateChange(avCastPlaybackState);
356 }
357 }
358 }
359
OnPositionChanged(int position,int bufferPosition,int duration)360 void HwCastStreamPlayer::OnPositionChanged(int position, int bufferPosition, int duration)
361 {
362 if (position == -1 && bufferPosition == -1 && duration == -1) { // -1 is invalid(default) value
363 SLOGW("Invalid position change callback");
364 return;
365 }
366 AVPlaybackState avCastPlaybackState;
367 if (position != -1) { // -1 is invalid position
368 AVPlaybackState::Position castPosition;
369 castPosition.elapsedTime_ = position;
370 avCastPlaybackState.SetPosition(castPosition);
371 SLOGD("Received elapsedTime: %{public}d", position);
372 }
373 if (bufferPosition != -1) { // -1 is invalid buffer position
374 avCastPlaybackState.SetBufferedTime(bufferPosition);
375 SLOGD("Received bufferPosition: %{public}d", bufferPosition);
376 }
377 if (duration != -1) {
378 std::shared_ptr<AAFwk::WantParams> wantParams = std::make_shared<AAFwk::WantParams>();
379 sptr<AAFwk::IInterface> intIt = AAFwk::Integer::Box(duration);
380 wantParams->SetParam("duration", intIt);
381 avCastPlaybackState.SetExtras(wantParams);
382 SLOGD("Received duration: %{public}d", duration);
383 }
384 for (auto listener : streamPlayerListenerList_) {
385 if (listener != nullptr) {
386 SLOGI("trigger the OnPositionChange for registered listeners");
387 listener->OnCastPlaybackStateChange(avCastPlaybackState);
388 }
389 }
390 }
391
OnMediaItemChanged(const CastEngine::MediaInfo & mediaInfo)392 void HwCastStreamPlayer::OnMediaItemChanged(const CastEngine::MediaInfo& mediaInfo)
393 {
394 SLOGD("Stream player received mediaItemChanged event");
395 std::shared_ptr<AVMediaDescription> mediaDescription = std::make_shared<AVMediaDescription>();
396 mediaDescription->SetMediaId(mediaInfo.mediaId);
397 mediaDescription->SetTitle(mediaInfo.mediaName);
398 mediaDescription->SetMediaUri(mediaInfo.mediaUrl);
399 mediaDescription->SetMediaType(mediaInfo.mediaType);
400 mediaDescription->SetMediaSize(mediaInfo.mediaSize);
401 mediaDescription->SetStartPosition(static_cast<uint32_t>(mediaInfo.startPosition));
402 mediaDescription->SetDuration(static_cast<uint32_t>(mediaInfo.duration));
403 mediaDescription->SetCreditsPosition(static_cast<int32_t>(mediaInfo.closingCreditsPosition));
404 mediaDescription->SetAlbumCoverUri(mediaInfo.albumCoverUrl);
405 mediaDescription->SetAlbumTitle(mediaInfo.albumTitle);
406 mediaDescription->SetArtist(mediaInfo.mediaArtist);
407 mediaDescription->SetLyricUri(mediaInfo.lrcUrl);
408 mediaDescription->SetIconUri(mediaInfo.appIconUrl);
409 mediaDescription->SetAppName(mediaInfo.appName);
410 AVQueueItem queueItem;
411 queueItem.SetDescription(mediaDescription);
412 for (auto listener : streamPlayerListenerList_) {
413 if (listener != nullptr) {
414 SLOGI("trigger the OnMediaItemChange for registered listeners");
415 listener->OnMediaItemChange(queueItem);
416 }
417 }
418 std::lock_guard lockGuard(streamPlayerLock_);
419 currentAVQueueItem_ = queueItem;
420 }
421
OnNextRequest()422 void HwCastStreamPlayer::OnNextRequest()
423 {
424 SLOGD("StreamPlayer received next request");
425 for (auto listener : streamPlayerListenerList_) {
426 if (listener != nullptr) {
427 SLOGI("trigger the OnPlayNext for registered listeners");
428 listener->OnPlayNext();
429 }
430 }
431 }
432
OnPreviousRequest()433 void HwCastStreamPlayer::OnPreviousRequest()
434 {
435 SLOGD("StreamPlayer received previous request");
436 for (auto listener : streamPlayerListenerList_) {
437 if (listener != nullptr) {
438 SLOGI("trigger the OnPlayPrevious for registered listeners");
439 listener->OnPlayPrevious();
440 }
441 }
442 }
443
OnVolumeChanged(int volume,int maxVolume)444 void HwCastStreamPlayer::OnVolumeChanged(int volume, int maxVolume)
445 {
446 SLOGD("StreamPlayer received volume changed event: %{public}d", volume);
447 AVPlaybackState avCastPlaybackState;
448 avCastPlaybackState.SetVolume(volume);
449
450 std::shared_ptr<AAFwk::WantParams> wantParams = std::make_shared<AAFwk::WantParams>();
451 sptr<AAFwk::IInterface> intIt = AAFwk::Integer::Box(maxVolume);
452 if (wantParams == nullptr || intIt == nullptr) {
453 return;
454 }
455 wantParams->SetParam("maxCastVolume", intIt);
456 avCastPlaybackState.SetExtras(wantParams);
457
458 for (auto listener : streamPlayerListenerList_) {
459 if (listener != nullptr) {
460 SLOGI("trigger the OnVolumeChanged for registered listeners");
461 listener->OnCastPlaybackStateChange(avCastPlaybackState);
462 }
463 }
464 }
465
OnLoopModeChanged(const CastEngine::LoopMode loopMode)466 void HwCastStreamPlayer::OnLoopModeChanged(const CastEngine::LoopMode loopMode)
467 {
468 AVPlaybackState avCastPlaybackState;
469 if (castPlusLoopModeToInt_.count(loopMode) == 0) {
470 SLOGE("current playbackState status is not exist in castPlusStateToString_");
471 } else {
472 SLOGD("StreamPlayer received loop mode changed event: %{public}d", castPlusLoopModeToInt_[loopMode]);
473 avCastPlaybackState.SetLoopMode(castPlusLoopModeToInt_[loopMode]);
474 }
475 for (auto listener : streamPlayerListenerList_) {
476 if (listener != nullptr) {
477 SLOGI("trigger the OnLoopModeChanged for registered listeners");
478 listener->OnCastPlaybackStateChange(avCastPlaybackState);
479 }
480 }
481 }
482
OnPlaySpeedChanged(const CastEngine::PlaybackSpeed speed)483 void HwCastStreamPlayer::OnPlaySpeedChanged(const CastEngine::PlaybackSpeed speed)
484 {
485 AVPlaybackState avCastPlaybackState;
486 if (castPlusSpeedToDouble_.count(speed) == 0) {
487 SLOGE("current speed is not exist in castPlusSpeedToDouble_");
488 return;
489 }
490 SLOGD("StreamPlayer received play speed changed event: %{public}f", castPlusSpeedToDouble_[speed]);
491 avCastPlaybackState.SetSpeed(castPlusSpeedToDouble_[speed]);
492 for (auto listener : streamPlayerListenerList_) {
493 if (listener != nullptr) {
494 SLOGI("trigger the OnPositionChange for registered listeners");
495 listener->OnCastPlaybackStateChange(avCastPlaybackState);
496 }
497 }
498 }
499
OnPlayerError(int errorCode,const std::string & errorMsg)500 void HwCastStreamPlayer::OnPlayerError(int errorCode, const std::string &errorMsg)
501 {
502 SLOGD("StreamPlayer received error event, code: %{public}d, message: %{public}s", errorCode, errorMsg.c_str());
503 for (auto listener : streamPlayerListenerList_) {
504 if (listener != nullptr) {
505 SLOGI("trigger the OnPlayerError for registered listeners");
506 listener->OnPlayerError(errorCode, errorMsg);
507 }
508 }
509 }
510
OnSeekDone(int32_t seekNumber)511 void HwCastStreamPlayer::OnSeekDone(int32_t seekNumber)
512 {
513 SLOGD("StreamPlayer received seek done event: %{public}d", seekNumber);
514 for (auto listener : streamPlayerListenerList_) {
515 if (listener != nullptr) {
516 SLOGI("trigger the OnSeekDone for registered listeners");
517 listener->OnSeekDone(seekNumber);
518 }
519 }
520 }
521
OnVideoSizeChanged(int width,int height)522 void HwCastStreamPlayer::OnVideoSizeChanged(int width, int height)
523 {
524 SLOGD("StreamPlayer received video size change event, width: %{public}d, height: %{public}d", width, height);
525 for (auto listener : streamPlayerListenerList_) {
526 if (listener != nullptr) {
527 SLOGI("trigger the OnVideoSizeChange for registered listeners");
528 listener->OnVideoSizeChange(width, height);
529 }
530 }
531 }
532
OnEndOfStream(int isLooping)533 void HwCastStreamPlayer::OnEndOfStream(int isLooping)
534 {
535 SLOGD("Received EndOfStream callback, value is %{public}d", isLooping);
536 for (auto listener : streamPlayerListenerList_) {
537 if (listener != nullptr) {
538 SLOGI("trigger the OnEndOfStream for registered listeners");
539 listener->OnEndOfStream(isLooping);
540 }
541 }
542
543 AVPlaybackState avCastPlaybackState;
544 std::shared_ptr<AAFwk::WantParams> wantParams = std::make_shared<AAFwk::WantParams>();
545 sptr<AAFwk::IInterface> intIt = AAFwk::Integer::Box(isLooping);
546 if (wantParams == nullptr || intIt == nullptr) {
547 return;
548 }
549 wantParams->SetParam("endofstream", intIt);
550 avCastPlaybackState.SetExtras(wantParams);
551 SLOGD("Received end of stream event: %{public}d", isLooping);
552
553 for (auto listener : streamPlayerListenerList_) {
554 if (listener != nullptr) {
555 SLOGI("trigger the OnEndOfStream for registered listeners");
556 listener->OnCastPlaybackStateChange(avCastPlaybackState);
557 }
558 }
559 }
560 } // namespace OHOS::AVSession
561