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 #include "avsession_sysevent.h"
24 #include "avsession_trace.h"
25 #include "avsession_radar.h"
26
27 using namespace OHOS::CastEngine;
28
29 namespace OHOS::AVSession {
~HwCastStreamPlayer()30 HwCastStreamPlayer::~HwCastStreamPlayer()
31 {
32 SLOGI("destruct the HwCastStreamPlayer without release");
33 }
34
Init()35 int32_t HwCastStreamPlayer::Init()
36 {
37 SLOGI("Init the HwCastStreamPlayer");
38 std::lock_guard lockGuard(streamPlayerLock_);
39 if (streamPlayer_) {
40 SLOGI("register self in streamPlayer");
41 return streamPlayer_->RegisterListener(shared_from_this());
42 }
43 return AVSESSION_ERROR;
44 }
45
Release()46 void HwCastStreamPlayer::Release()
47 {
48 SLOGI("Release the HwCastStreamPlayer");
49
50 std::lock_guard lockGuard(streamPlayerLock_);
51 if (streamPlayer_) {
52 streamPlayer_->UnregisterListener();
53 streamPlayer_->Release();
54 streamPlayer_ = nullptr;
55 }
56
57 std::lock_guard playerListLockGuard(streamPlayerListenerListLock_);
58 streamPlayerListenerList_.clear();
59 SLOGI("Release the HwCastStreamPlayer done");
60 }
61
CheckCastTime(int32_t castTime)62 int32_t HwCastStreamPlayer::CheckCastTime(int32_t castTime)
63 {
64 if (castTime < castMinTime) {
65 return castMinTime * castTime;
66 } else {
67 return castTime;
68 }
69 }
70
SendControlCommand(const AVCastControlCommand castControlCommand)71 void HwCastStreamPlayer::SendControlCommand(const AVCastControlCommand castControlCommand)
72 {
73 int32_t commandNum = castControlCommand.GetCommand();
74 SLOGI("send command to streamPlayer %{public}d", static_cast<int32_t>(commandNum));
75 std::lock_guard lockGuard(streamPlayerLock_);
76 if (!streamPlayer_) {
77 SLOGE("streamPlayer is nullptr");
78 HISYSEVENT_FAULT("REMOTE_CONTROL_FAILED",
79 "SESSION_TYPE", "cast",
80 "ERROR_TYPE", "INNER_ERROR",
81 "ERROR_INFO", "streamPlayer is nullptr");
82 AVSessionRadarInfo info("HwCastStreamPlayer::SendControlCommand");
83 info.errorCode_ = AVSessionRadar::GetRadarErrorCode(ERR_REMOTE_CONNECTION_NOT_EXIST);
84 AVSessionRadar::GetInstance().FailToSendControlCommand(info);
85 return;
86 }
87 switch (castControlCommand.GetCommand()) {
88 case AVCastControlCommand::CAST_CONTROL_CMD_PLAY:
89 streamPlayer_->Play();
90 break;
91 case AVCastControlCommand::CAST_CONTROL_CMD_PAUSE:
92 streamPlayer_->Pause();
93 break;
94 case AVCastControlCommand::CAST_CONTROL_CMD_STOP:
95 streamPlayer_->Stop();
96 break;
97 case AVCastControlCommand::CAST_CONTROL_CMD_PLAY_NEXT:
98 streamPlayer_->Next();
99 break;
100 case AVCastControlCommand::CAST_CONTROL_CMD_PLAY_PREVIOUS:
101 streamPlayer_->Previous();
102 break;
103 default:
104 SendControlCommandWithParams(castControlCommand);
105 break;
106 }
107 }
108
SendControlCommandWithParams(const AVCastControlCommand castControlCommand)109 void HwCastStreamPlayer::SendControlCommandWithParams(const AVCastControlCommand castControlCommand)
110 {
111 std::lock_guard lockGuard(streamPlayerLock_);
112 int32_t timeParam;
113 switch (castControlCommand.GetCommand()) {
114 case AVCastControlCommand::CAST_CONTROL_CMD_FAST_FORWARD:
115 castControlCommand.GetForwardTime(timeParam);
116 streamPlayer_->FastForward(CheckCastTime(timeParam));
117 break;
118 case AVCastControlCommand::CAST_CONTROL_CMD_REWIND:
119 castControlCommand.GetRewindTime(timeParam);
120 streamPlayer_->FastRewind(CheckCastTime(timeParam));
121 break;
122 case AVCastControlCommand::CAST_CONTROL_CMD_SEEK:
123 castControlCommand.GetSeekTime(timeParam);
124 streamPlayer_->Seek(timeParam);
125 break;
126 case AVCastControlCommand::CAST_CONTROL_CMD_SET_VOLUME:
127 int32_t volume;
128 castControlCommand.GetVolume(volume);
129 streamPlayer_->SetVolume(volume);
130 break;
131 case AVCastControlCommand::CAST_CONTROL_CMD_SET_SPEED:
132 int32_t speed;
133 castControlCommand.GetSpeed(speed);
134 streamPlayer_->SetSpeed(static_cast<CastEngine::PlaybackSpeed>(speed));
135 break;
136 case AVCastControlCommand::CAST_CONTROL_CMD_SET_LOOP_MODE:
137 int32_t loopMode;
138 castControlCommand.GetLoopMode(loopMode);
139 if (intLoopModeToCastPlus_.count(loopMode) != 0) {
140 SLOGD("SetLoopMode int: %{public}d", loopMode);
141 streamPlayer_->SetLoopMode(intLoopModeToCastPlus_[loopMode]);
142 } else {
143 SLOGE("invalid LoopMode: %{public}d", loopMode);
144 }
145 break;
146 case AVCastControlCommand::CAST_CONTROL_CMD_TOGGLE_FAVORITE:
147 break;
148 case AVCastControlCommand::CAST_CONTROL_CMD_TOGGLE_MUTE:
149 bool enableMute;
150 streamPlayer_->GetMute(enableMute);
151 streamPlayer_->SetMute(!enableMute);
152 break;
153 default:
154 SLOGE("invalid command");
155 HISYSEVENT_FAULT("REMOTE_CONTROL_FAILED", "ERROR_TYPE", "INNER_ERROR", "ERROR_INFO", "invalid command");
156 break;
157 }
158 }
159
GetCurrentItem()160 AVQueueItem HwCastStreamPlayer::GetCurrentItem()
161 {
162 SLOGI("Received GetCurrentItem request");
163 // do not place streamPlayerLock_ in side of curItemLock_
164 std::lock_guard lockGuard(curItemLock_);
165 return currentAVQueueItem_;
166 }
167
RefreshCurrentAVQueueItem(const AVQueueItem & avQueueItem)168 int32_t HwCastStreamPlayer::RefreshCurrentAVQueueItem(const AVQueueItem& avQueueItem)
169 {
170 std::lock_guard lockGuard(curItemLock_);
171 currentAVQueueItem_ = avQueueItem;
172 return AVSESSION_SUCCESS;
173 }
174
Start(const AVQueueItem & avQueueItem)175 int32_t HwCastStreamPlayer::Start(const AVQueueItem& avQueueItem)
176 {
177 CastEngine::MediaInfo mediaInfo;
178 std::shared_ptr<AVMediaDescription> mediaDescription = avQueueItem.GetDescription();
179 mediaInfo.mediaId = mediaDescription->GetMediaId();
180 mediaInfo.mediaName = mediaDescription->GetTitle();
181 mediaInfo.mediaUrl = mediaDescription->GetMediaUri();
182 if (mediaDescription->GetMediaUri() == "") {
183 if (mediaDescription->GetFdSrc().fd_ == 0) {
184 SLOGW("No media id and fd src");
185 mediaInfo.mediaUrl = "http:";
186 } else {
187 mediaInfo.mediaUrl = std::to_string(mediaDescription->GetFdSrc().fd_);
188 }
189 }
190 mediaInfo.mediaType = mediaDescription->GetMediaType();
191 mediaInfo.mediaSize = static_cast<uint32_t>(mediaDescription->GetMediaSize());
192 mediaInfo.startPosition = static_cast<uint32_t>(mediaDescription->GetStartPosition() < 0 ?
193 0 : mediaDescription->GetStartPosition());
194 mediaInfo.duration = static_cast<uint32_t>(mediaDescription->GetDuration());
195 mediaInfo.closingCreditsPosition = static_cast<uint32_t>(mediaDescription->GetCreditsPosition());
196 mediaInfo.albumCoverUrl = mediaDescription->GetIconUri() == "" ?
197 mediaDescription->GetAlbumCoverUri() : mediaDescription->GetIconUri();
198 mediaInfo.albumTitle = mediaDescription->GetAlbumTitle();
199 mediaInfo.mediaArtist = mediaDescription->GetArtist();
200 mediaInfo.lrcUrl = mediaDescription->GetLyricUri();
201 mediaInfo.appIconUrl = mediaDescription->GetIconUri();
202 mediaInfo.appName = mediaDescription->GetAppName();
203 mediaInfo.drmType = mediaDescription->GetDrmScheme();
204
205 AVDataSrcDescriptor dataSrc = mediaDescription->GetDataSrc();
206 SLOGI("has dataSrc hasCallback %{public}d", dataSrc.hasCallback);
207 if (dataSrc.hasCallback) {
208 if (castDataSrc_ == nullptr) {
209 castDataSrc_ = std::make_shared<AVSession::HwCastDataSourceDescriptor>();
210 }
211 castDataSrc_->SetCallback(dataSrc.callback_);
212 castDataSrc_->SetSize(dataSrc.fileSize);
213 mediaInfo.mediaUrl = "/file";
214 mediaInfo.dataSrc = castDataSrc_;
215 }
216
217 std::lock_guard lockGuard(streamPlayerLock_);
218 if (!streamPlayer_) {
219 SLOGE("Set media info and start failed");
220 return AVSESSION_ERROR;
221 }
222 std::shared_ptr<AVMediaDescription> originMediaDescription = nullptr;
223 {
224 std::lock_guard lockGuard(curItemLock_);
225 originMediaDescription = currentAVQueueItem_.GetDescription();
226 }
227 if (originMediaDescription && originMediaDescription->GetMediaUri() != "http:" &&
228 originMediaDescription->GetMediaId() == mediaInfo.mediaId) {
229 CHECK_AND_RETURN_RET_LOG(streamPlayer_->Play() == AVSESSION_SUCCESS, AVSESSION_ERROR, "Set play failed");
230 } else if (streamPlayer_->Play(mediaInfo) != AVSESSION_SUCCESS) {
231 SLOGE("Set media info and start failed");
232 return AVSESSION_ERROR;
233 }
234 RefreshCurrentAVQueueItem(avQueueItem);
235 SLOGI("Set media info and start successfully");
236 return AVSESSION_SUCCESS;
237 }
238
RepeatPrepare(std::shared_ptr<AVMediaDescription> & mediaDescription)239 bool HwCastStreamPlayer::RepeatPrepare(std::shared_ptr<AVMediaDescription>& mediaDescription)
240 {
241 std::lock_guard lockGuard(curItemLock_);
242 if (mediaDescription != nullptr && currentAVQueueItem_.GetDescription() != nullptr &&
243 mediaDescription->GetIconUri() == "URI_CACHE" && mediaDescription->GetIcon() != nullptr) {
244 currentAVQueueItem_.GetDescription()->SetIcon(mediaDescription->GetIcon());
245 SLOGI("Repeat Prepare only setIcon");
246 return true;
247 }
248 return false;
249 }
250
Prepare(const AVQueueItem & avQueueItem)251 int32_t HwCastStreamPlayer::Prepare(const AVQueueItem& avQueueItem)
252 {
253 CastEngine::MediaInfo mediaInfo;
254 std::shared_ptr<AVMediaDescription> mediaDescription = avQueueItem.GetDescription();
255 if (RepeatPrepare(mediaDescription)) {
256 return AVSESSION_SUCCESS;
257 }
258 mediaInfo.mediaId = mediaDescription->GetMediaId();
259 mediaInfo.mediaName = mediaDescription->GetTitle();
260 SLOGI("do Prepare with mediaId %{public}s | title %{public}s",
261 mediaInfo.mediaId.c_str(), mediaInfo.mediaName.c_str());
262 if (mediaDescription->GetMediaUri() == "") {
263 if (mediaDescription->GetFdSrc().fd_ == 0) {
264 SLOGW("No media id and fd src");
265 mediaInfo.mediaUrl = "http:";
266 avQueueItem.GetDescription()->SetMediaUri("http:");
267 } else {
268 mediaInfo.mediaUrl = std::to_string(mediaDescription->GetFdSrc().fd_);
269 }
270 } else {
271 mediaInfo.mediaUrl = mediaDescription->GetMediaUri();
272 }
273 mediaInfo.mediaType = mediaDescription->GetMediaType();
274 mediaInfo.mediaSize = static_cast<uint32_t>(mediaDescription->GetMediaSize());
275 mediaInfo.startPosition = static_cast<uint32_t>(mediaDescription->GetStartPosition() < 0 ?
276 0 : mediaDescription->GetStartPosition());
277 mediaInfo.duration = static_cast<uint32_t>(mediaDescription->GetDuration());
278 mediaInfo.closingCreditsPosition = static_cast<uint32_t>(mediaDescription->GetCreditsPosition());
279 if (mediaDescription->GetIconUri() == "") {
280 mediaInfo.albumCoverUrl = mediaDescription->GetAlbumCoverUri();
281 } else {
282 mediaInfo.albumCoverUrl = mediaDescription->GetIconUri();
283 }
284 mediaInfo.albumTitle = mediaDescription->GetAlbumTitle();
285 mediaInfo.mediaArtist = mediaDescription->GetArtist();
286 mediaInfo.lrcUrl = mediaDescription->GetLyricUri();
287 mediaInfo.appIconUrl = mediaDescription->GetIconUri();
288 mediaInfo.appName = mediaDescription->GetAppName();
289 mediaInfo.drmType = mediaDescription->GetDrmScheme();
290
291 AVDataSrcDescriptor dataSrc = mediaDescription->GetDataSrc();
292 SLOGI("has dataSrc hasCallback %{public}d", dataSrc.hasCallback);
293 if (dataSrc.hasCallback) {
294 if (castDataSrc_ == nullptr) {
295 castDataSrc_ = std::make_shared<AVSession::HwCastDataSourceDescriptor>();
296 }
297 castDataSrc_->SetCallback(dataSrc.callback_);
298 castDataSrc_->SetSize(dataSrc.fileSize);
299 mediaInfo.mediaUrl = "/file";
300 mediaInfo.dataSrc = castDataSrc_;
301 }
302
303 std::lock_guard lockGuard(streamPlayerLock_);
304 SLOGI("pass playerlock, check item lock, mediaInfo mediaUrl and albumCoverUrl");
305 if (streamPlayer_ && streamPlayer_->Load(mediaInfo) == AVSESSION_SUCCESS) {
306 std::lock_guard lockGuard(curItemLock_);
307 SLOGI("Set media info and prepare with curItemLock successed");
308 currentAVQueueItem_ = avQueueItem;
309 return AVSESSION_SUCCESS;
310 }
311 SLOGE("Set media info and prepare failed");
312 return AVSESSION_ERROR;
313 }
314
GetDuration(int32_t & duration)315 int32_t HwCastStreamPlayer::GetDuration(int32_t& duration)
316 {
317 SLOGI("GetDuration begin");
318 std::lock_guard lockGuard(streamPlayerLock_);
319 if (!streamPlayer_) {
320 SLOGE("streamPlayer is nullptr");
321 return AVSESSION_ERROR;
322 }
323 streamPlayer_->GetDuration(duration);
324 SLOGI("GetDuration successed");
325 return AVSESSION_SUCCESS;
326 }
327
GetCastAVPlaybackState(AVPlaybackState & avPlaybackState)328 int32_t HwCastStreamPlayer::GetCastAVPlaybackState(AVPlaybackState& avPlaybackState)
329 {
330 SLOGI("GetCastAVPlaybackState begin");
331 std::lock_guard lockGuard(streamPlayerLock_);
332 if (!streamPlayer_) {
333 SLOGE("streamPlayer is nullptr");
334 return AVSESSION_ERROR;
335 }
336 CastEngine::PlayerStates castPlayerStates;
337 streamPlayer_->GetPlayerStatus(castPlayerStates);
338 if (castPlusStateToString_.count(castPlayerStates) != 0) {
339 avPlaybackState.SetState(castPlusStateToString_[castPlayerStates]);
340 }
341 CastEngine::PlaybackSpeed castPlaybackSpeed;
342 streamPlayer_->GetPlaySpeed(castPlaybackSpeed);
343 if (castPlusSpeedToDouble_.count(castPlaybackSpeed) != 0) {
344 avPlaybackState.SetSpeed(castPlusSpeedToDouble_[castPlaybackSpeed]);
345 }
346 int castPosition;
347 streamPlayer_->GetPosition(castPosition);
348 AVPlaybackState::Position position;
349 position.elapsedTime_ = static_cast<int64_t>(castPosition);
350 avPlaybackState.SetPosition(position);
351 CastEngine::LoopMode castLoopMode;
352 streamPlayer_->GetLoopMode(castLoopMode);
353 if (castPlusLoopModeToInt_.count(castLoopMode) != 0) {
354 avPlaybackState.SetLoopMode(castPlusLoopModeToInt_[castLoopMode]);
355 }
356 int32_t castVolume;
357 int32_t maxCastVolume;
358 streamPlayer_->GetVolume(castVolume, maxCastVolume);
359 avPlaybackState.SetVolume(castVolume);
360
361 std::shared_ptr<AAFwk::WantParams> wantParams = std::make_shared<AAFwk::WantParams>();
362 sptr<AAFwk::IInterface> intIt = AAFwk::Integer::Box(maxCastVolume);
363 if (wantParams == nullptr || intIt == nullptr) {
364 return AVSESSION_ERROR;
365 }
366 wantParams->SetParam("maxCastVolume", intIt);
367 avPlaybackState.SetExtras(wantParams);
368
369 SLOGI("GetCastAVPlaybackState successed with state: %{public}d", avPlaybackState.GetState());
370 return AVSESSION_SUCCESS;
371 }
372
GetMediaCapabilitiesOfVideo(nlohmann::json & videoValue)373 void HwCastStreamPlayer::GetMediaCapabilitiesOfVideo(nlohmann::json& videoValue)
374 {
375 if (videoValue.contains(decodeTypeStr_)) {
376 for (auto decodeType : videoValue[decodeTypeStr_]) {
377 CHECK_AND_CONTINUE(decodeType.is_string());
378 std::string str = decodeType;
379 SLOGI("get %{public}s is %{public}s", decodeTypeStr_.c_str(), str.c_str());
380 jsonCapabilitiesSptr_->decoderTypes_.emplace_back(decodeType);
381 }
382 }
383 if (videoValue.contains(decodeSupportResolutionStr_)) {
384 if (videoValue[decodeSupportResolutionStr_].contains(decodeOfVideoHevcStr_)) {
385 ResolutionLevel resolutionLevel = videoValue[decodeSupportResolutionStr_][decodeOfVideoHevcStr_];
386 std::map<std::string, ResolutionLevel> decodeToResolution = {{decodeOfVideoHevcStr_, resolutionLevel}};
387 jsonCapabilitiesSptr_->decoderSupportResolutions_.emplace_back(decodeToResolution);
388 }
389 if (videoValue[decodeSupportResolutionStr_].contains(decodeOfVideoAvcStr_)) {
390 ResolutionLevel resolutionLevel = videoValue[decodeSupportResolutionStr_][decodeOfVideoAvcStr_];
391 std::map<std::string, ResolutionLevel> decodeToResolution = {{decodeOfVideoAvcStr_, resolutionLevel}};
392 jsonCapabilitiesSptr_->decoderSupportResolutions_.emplace_back(decodeToResolution);
393 }
394 } else {
395 SLOGI("%{public}s of %{public}s no contains", videoStr_.c_str(), decodeSupportResolutionStr_.c_str());
396 }
397 if (videoValue.contains(hdrFormatStr_)) {
398 for (auto hdrFormat: videoValue[hdrFormatStr_]) {
399 CHECK_AND_CONTINUE(hdrFormat.is_number());
400 int num = hdrFormat;
401 SLOGI("get %{public}s is %{public}d", hdrFormatStr_.c_str(), num);
402 jsonCapabilitiesSptr_->hdrFormats_.emplace_back(hdrFormat);
403 }
404 } else {
405 SLOGI("%{public}s of %{public}s no contains", videoStr_.c_str(), hdrFormatStr_.c_str());
406 }
407 }
408
GetMediaCapabilitiesOfAudio(nlohmann::json & audioValue)409 void HwCastStreamPlayer::GetMediaCapabilitiesOfAudio(nlohmann::json& audioValue)
410 {
411 if (audioValue.contains(decodeTypeStr_)) {
412 CHECK_AND_BREAK(audioValue[decodeTypeStr_].is_string());
413 std::string str = audioValue[decodeTypeStr_];
414 SLOGI("%{public}s of %{public}s", decodeTypeStr_.c_str(), str.c_str());
415 jsonCapabilitiesSptr_->decoderTypes_.emplace_back(audioValue[decodeTypeStr_]);
416 }
417 }
418
GetMediaCapabilities()419 int32_t HwCastStreamPlayer::GetMediaCapabilities()
420 {
421 SLOGI("GetMediaCapabilities begin");
422 std::lock_guard lockGuard(streamPlayerLock_);
423 CHECK_AND_RETURN_RET_LOG(streamPlayer_, AVSESSION_ERROR, "streamPlayer_ is nullptr");
424 CHECK_AND_RETURN_RET_LOG(jsonCapabilitiesSptr_, AVSESSION_ERROR, "jsonCapabilitiesSptr_ is nullptr");
425 std::string supportCapabilities;
426 streamPlayer_->GetMediaCapabilities(supportCapabilities);
427 nlohmann::json value = nlohmann::json::parse(supportCapabilities);
428 CHECK_AND_RETURN_RET_LOG(!value.is_null() && !value.is_discarded(), AVSESSION_ERROR, "GetMediaCapabilities fail");
429 if (value.contains(videoStr_)) {
430 GetMediaCapabilitiesOfVideo(value[videoStr_]);
431 } else if (value.contains(audioStr_)) {
432 GetMediaCapabilitiesOfAudio(value[audioStr_]);
433 }
434 if (value.contains(speedStr_)) {
435 for (auto speed : value[speedStr_]) {
436 CHECK_AND_CONTINUE(speed.is_number());
437 float num = speed;
438 SLOGI("support play speed is %{public}f", num);
439 jsonCapabilitiesSptr_->playSpeeds_.emplace_back(speed);
440 }
441 }
442 return AVSESSION_SUCCESS;
443 }
444
GetSupportedDecoders(std::vector<std::string> & decoderTypes)445 int32_t HwCastStreamPlayer::GetSupportedDecoders(std::vector<std::string>& decoderTypes)
446 {
447 SLOGI("enter GetSupportedDecoders");
448 std::lock_guard lockGuard(streamPlayerLock_);
449 CHECK_AND_RETURN_RET_LOG(jsonCapabilitiesSptr_, AVSESSION_ERROR, "jsonCapabilitiesSptr_ is nullptr");
450 if (jsonCapabilitiesSptr_->decoderTypes_.empty()) {
451 GetMediaCapabilities();
452 }
453 decoderTypes = jsonCapabilitiesSptr_->decoderTypes_;
454 return AVSESSION_SUCCESS;
455 }
456
GetRecommendedResolutionLevel(std::string & decoderType,ResolutionLevel & resolutionLevel)457 int32_t HwCastStreamPlayer::GetRecommendedResolutionLevel(std::string& decoderType, ResolutionLevel& resolutionLevel)
458 {
459 SLOGI("enter GetRecommendedResolutionLevel");
460 std::lock_guard lockGuard(streamPlayerLock_);
461 CHECK_AND_RETURN_RET_LOG(jsonCapabilitiesSptr_, AVSESSION_ERROR, "jsonCapabilitiesSptr_ is nullptr");
462 if (jsonCapabilitiesSptr_->decoderSupportResolutions_.empty()) {
463 GetMediaCapabilities();
464 }
465 for (auto& map: jsonCapabilitiesSptr_->decoderSupportResolutions_) {
466 auto it = map.find(decoderType);
467 if (it != map.end()) {
468 SLOGI("find %{public}s map to %{public}d", decoderType.c_str(), static_cast<int32_t>(it->second));
469 resolutionLevel = it->second;
470 } else {
471 SLOGI("no find %{public}s map to resolutionLevel", decoderType.c_str());
472 return AVSESSION_ERROR;
473 }
474 }
475 return AVSESSION_SUCCESS;
476 }
477
GetSupportedHdrCapabilities(std::vector<HDRFormat> & hdrFormats)478 int32_t HwCastStreamPlayer::GetSupportedHdrCapabilities(std::vector<HDRFormat>& hdrFormats)
479 {
480 SLOGI("enter GetSupportedHdrCapabilities");
481 std::lock_guard lockGuard(streamPlayerLock_);
482 CHECK_AND_RETURN_RET_LOG(jsonCapabilitiesSptr_, AVSESSION_ERROR, "jsonCapabilitiesSptr_ is nullptr");
483 if (jsonCapabilitiesSptr_->hdrFormats_.empty()) {
484 GetMediaCapabilities();
485 }
486 hdrFormats = jsonCapabilitiesSptr_->hdrFormats_;
487 return AVSESSION_SUCCESS;
488 }
489
GetSupportedPlaySpeeds(std::vector<float> & playSpeeds)490 int32_t HwCastStreamPlayer::GetSupportedPlaySpeeds(std::vector<float>& playSpeeds)
491 {
492 SLOGI("enter GetSupportedDecoders");
493 std::lock_guard lockGuard(streamPlayerLock_);
494 CHECK_AND_RETURN_RET_LOG(jsonCapabilitiesSptr_, AVSESSION_ERROR, "jsonCapabilitiesSptr_ is nullptr");
495 if (jsonCapabilitiesSptr_->playSpeeds_.empty()) {
496 GetMediaCapabilities();
497 }
498 playSpeeds = jsonCapabilitiesSptr_->playSpeeds_;
499 return AVSESSION_SUCCESS;
500 }
501
SetDisplaySurface(std::string & surfaceId)502 int32_t HwCastStreamPlayer::SetDisplaySurface(std::string &surfaceId)
503 {
504 SLOGI("SetDisplaySurface begin");
505 std::lock_guard lockGuard(streamPlayerLock_);
506 if (!streamPlayer_) {
507 SLOGE("streamPlayer is nullptr");
508 return AVSESSION_ERROR;
509 }
510 streamPlayer_->SetSurface(surfaceId);
511 SLOGI("SetDisplaySurface successed");
512 return AVSESSION_SUCCESS;
513 }
514
ProcessMediaKeyResponse(const std::string & assetId,const std::vector<uint8_t> & response)515 int32_t HwCastStreamPlayer::ProcessMediaKeyResponse(const std::string& assetId, const std::vector<uint8_t>& response)
516 {
517 SLOGI("ProcessMediaKeyResponse begin");
518 std::lock_guard lockGuard(streamPlayerLock_);
519 if (!streamPlayer_) {
520 SLOGE("streamPlayer is nullptr");
521 return AVSESSION_ERROR;
522 }
523 streamPlayer_->ProvideKeyResponse(assetId, response);
524 SLOGI("ProcessMediaKeyResponse successed");
525 return AVSESSION_SUCCESS;
526 }
527
RegisterControllerListener(std::shared_ptr<IAVCastControllerProxyListener> listener)528 int32_t HwCastStreamPlayer::RegisterControllerListener(std::shared_ptr<IAVCastControllerProxyListener> listener)
529 {
530 SLOGI("RegisterControllerListener begin");
531 if (listener == nullptr) {
532 SLOGE("RegisterControllerListener failed for the listener is nullptr");
533 return AVSESSION_ERROR;
534 }
535
536 std::lock_guard playerListLockGuard(streamPlayerListenerListLock_);
537 if (find(streamPlayerListenerList_.begin(), streamPlayerListenerList_.end(), listener)
538 != streamPlayerListenerList_.end()) {
539 SLOGE("listener is already in streamPlayerListenerList_");
540 return AVSESSION_ERROR;
541 }
542 SLOGI("RegisterControllerListener successed, and add it to streamPlayerListenerList_");
543 streamPlayerListenerList_.emplace_back(listener);
544 SLOGI("RegisterControllerListener done with size %{public}d", static_cast<int>(streamPlayerListenerList_.size()));
545 return AVSESSION_SUCCESS;
546 }
547
UnRegisterControllerListener(std::shared_ptr<IAVCastControllerProxyListener> listener)548 int32_t HwCastStreamPlayer::UnRegisterControllerListener(std::shared_ptr<IAVCastControllerProxyListener> listener)
549 {
550 if (listener == nullptr) {
551 SLOGE("UnRegisterCastSessionStateListener failed for the listener is nullptr");
552 return AVSESSION_ERROR;
553 }
554
555 std::lock_guard playerListLockGuard(streamPlayerListenerListLock_);
556 for (auto iter = streamPlayerListenerList_.begin(); iter != streamPlayerListenerList_.end();) {
557 if (*iter == listener) {
558 streamPlayerListenerList_.erase(iter);
559 SLOGI("UnRegisterControllerListener successed, and erase it from streamPlayerListenerList_");
560 return AVSESSION_SUCCESS;
561 } else {
562 ++iter;
563 }
564 }
565 SLOGE("listener is not found in streamPlayerListenerList_, so UnRegisterControllerListener failed");
566
567 return AVSESSION_ERROR;
568 }
569
GetValidAbility(std::vector<int32_t> & validCmdList)570 int32_t HwCastStreamPlayer::GetValidAbility(std::vector<int32_t>& validCmdList)
571 {
572 SLOGI("GetValidAbility in");
573 if (streamPlayer_ == nullptr) {
574 SLOGE("streamPlayer is nullptr");
575 return AVSESSION_ERROR;
576 }
577 CastEngine::StreamCapability streamCapability;
578 streamPlayer_->GetAvailableCapability(streamCapability);
579 checkCmdsFromAbility(streamCapability, validCmdList);
580 return AVSESSION_SUCCESS;
581 }
582
SetValidAbility(const std::vector<int32_t> & validCmdList)583 int32_t HwCastStreamPlayer::SetValidAbility(const std::vector<int32_t>& validCmdList)
584 {
585 SLOGI("SetValidAbility begin");
586 if (streamPlayer_ == nullptr) {
587 SLOGE("streamPlayer is nullptr");
588 return AVSESSION_ERROR;
589 }
590 CastEngine::StreamCapability streamCapability;
591 checkAbilityFromCmds(validCmdList, streamCapability);
592 streamPlayer_->SetAvailableCapability(streamCapability);
593 return AVSESSION_SUCCESS;
594 }
595
OnStateChanged(const CastEngine::PlayerStates playbackState,bool isPlayWhenReady)596 void HwCastStreamPlayer::OnStateChanged(const CastEngine::PlayerStates playbackState, bool isPlayWhenReady)
597 {
598 AVPlaybackState avCastPlaybackState;
599 if (castPlusStateToString_.count(playbackState) == 0) {
600 SLOGE("current playbackState status is not exist in castPlusStateToString_");
601 avCastPlaybackState.SetState(AVPlaybackState::PLAYBACK_STATE_ERROR);
602 } else {
603 SLOGD("On state changed, get state %{public}d", castPlusStateToString_[playbackState]);
604 avCastPlaybackState.SetState(castPlusStateToString_[playbackState]);
605 }
606 std::lock_guard playerListLockGuard(streamPlayerListenerListLock_);
607 for (auto listener : streamPlayerListenerList_) {
608 if (listener != nullptr) {
609 SLOGI("trigger the OnCastPlaybackStateChange for registered listeners");
610 listener->OnCastPlaybackStateChange(avCastPlaybackState);
611 }
612 }
613 SLOGI("on cast state change done");
614 }
615
OnPositionChanged(int position,int bufferPosition,int duration)616 void HwCastStreamPlayer::OnPositionChanged(int position, int bufferPosition, int duration)
617 {
618 if (position == -1 && bufferPosition == -1 && duration == -1) { // -1 is invalid(default) value
619 SLOGW("Invalid position change callback");
620 return;
621 }
622 AVPlaybackState avCastPlaybackState;
623 if (position != -1) { // -1 is invalid position
624 AVPlaybackState::Position castPosition;
625 castPosition.elapsedTime_ = position;
626 avCastPlaybackState.SetPosition(castPosition);
627 SLOGD("Received elapsedTime: %{public}d", position);
628 }
629 if (bufferPosition != -1) { // -1 is invalid buffer position
630 avCastPlaybackState.SetBufferedTime(bufferPosition);
631 SLOGD("Received bufferPosition: %{public}d", bufferPosition);
632 }
633 if (duration != -1) {
634 std::shared_ptr<AAFwk::WantParams> wantParams = std::make_shared<AAFwk::WantParams>();
635 sptr<AAFwk::IInterface> intIt = AAFwk::Integer::Box(duration);
636 wantParams->SetParam("duration", intIt);
637 avCastPlaybackState.SetExtras(wantParams);
638 SLOGD("Received duration: %{public}d", duration);
639 }
640 std::lock_guard playerListLockGuard(streamPlayerListenerListLock_);
641 for (auto listener : streamPlayerListenerList_) {
642 if (listener != nullptr) {
643 SLOGD("trigger the OnPositionChange");
644 listener->OnCastPlaybackStateChange(avCastPlaybackState);
645 }
646 }
647 SLOGI("on cast position change done");
648 }
649
OnMediaItemChanged(const CastEngine::MediaInfo & mediaInfo)650 void HwCastStreamPlayer::OnMediaItemChanged(const CastEngine::MediaInfo& mediaInfo)
651 {
652 SLOGD("Stream player received mediaItemChanged event");
653 std::shared_ptr<AVMediaDescription> mediaDescription = std::make_shared<AVMediaDescription>();
654 mediaDescription->SetMediaId(mediaInfo.mediaId);
655 mediaDescription->SetTitle(mediaInfo.mediaName);
656 mediaDescription->SetMediaUri(mediaInfo.mediaUrl);
657 mediaDescription->SetMediaType(mediaInfo.mediaType);
658 mediaDescription->SetMediaSize(mediaInfo.mediaSize);
659 mediaDescription->SetStartPosition(static_cast<uint32_t>(mediaInfo.startPosition));
660 mediaDescription->SetDuration(static_cast<uint32_t>(mediaInfo.duration));
661 mediaDescription->SetCreditsPosition(static_cast<int32_t>(mediaInfo.closingCreditsPosition));
662 mediaDescription->SetAlbumCoverUri(mediaInfo.albumCoverUrl);
663 mediaDescription->SetAlbumTitle(mediaInfo.albumTitle);
664 mediaDescription->SetArtist(mediaInfo.mediaArtist);
665 mediaDescription->SetLyricUri(mediaInfo.lrcUrl);
666 mediaDescription->SetIconUri(mediaInfo.appIconUrl);
667 mediaDescription->SetAppName(mediaInfo.appName);
668 mediaDescription->SetDrmScheme(mediaInfo.drmType);
669 AVQueueItem queueItem;
670 queueItem.SetDescription(mediaDescription);
671 {
672 std::lock_guard playerListLockGuard(streamPlayerListenerListLock_);
673 for (auto listener : streamPlayerListenerList_) {
674 if (listener != nullptr) {
675 SLOGI("trigger the OnMediaItemChange for registered listeners");
676 listener->OnMediaItemChange(queueItem);
677 }
678 }
679 }
680 {
681 std::lock_guard lockGuard(curItemLock_);
682 currentAVQueueItem_ = queueItem;
683 }
684
685 SLOGI("StreamPlayer received mediaItemChanged event done");
686 }
687
OnNextRequest()688 void HwCastStreamPlayer::OnNextRequest()
689 {
690 SLOGD("StreamPlayer received next request");
691 std::lock_guard playerListLockGuard(streamPlayerListenerListLock_);
692 for (auto listener : streamPlayerListenerList_) {
693 if (listener != nullptr) {
694 SLOGI("trigger the OnPlayNext for registered listeners");
695 listener->OnPlayNext();
696 }
697 }
698 SLOGI("StreamPlayer received next request done");
699 }
700
OnPreviousRequest()701 void HwCastStreamPlayer::OnPreviousRequest()
702 {
703 SLOGD("StreamPlayer received previous request");
704 std::lock_guard playerListLockGuard(streamPlayerListenerListLock_);
705 for (auto listener : streamPlayerListenerList_) {
706 if (listener != nullptr) {
707 SLOGI("trigger the OnPlayPrevious for registered listeners");
708 listener->OnPlayPrevious();
709 }
710 }
711 SLOGI("StreamPlayer received previous request done");
712 }
713
OnVolumeChanged(int volume,int maxVolume)714 void HwCastStreamPlayer::OnVolumeChanged(int volume, int maxVolume)
715 {
716 SLOGD("StreamPlayer received volume changed event: %{public}d", volume);
717 AVPlaybackState avCastPlaybackState;
718 avCastPlaybackState.SetVolume(volume);
719
720 std::shared_ptr<AAFwk::WantParams> wantParams = std::make_shared<AAFwk::WantParams>();
721 sptr<AAFwk::IInterface> intIt = AAFwk::Integer::Box(maxVolume);
722 if (wantParams == nullptr || intIt == nullptr) {
723 return;
724 }
725 wantParams->SetParam("maxCastVolume", intIt);
726 avCastPlaybackState.SetExtras(wantParams);
727
728 std::lock_guard playerListLockGuard(streamPlayerListenerListLock_);
729 for (auto listener : streamPlayerListenerList_) {
730 if (listener != nullptr) {
731 SLOGI("trigger the OnVolumeChanged for registered listeners");
732 listener->OnCastPlaybackStateChange(avCastPlaybackState);
733 }
734 }
735 SLOGI("StreamPlayer received volume changed event done: %{public}d", volume);
736 }
737
OnLoopModeChanged(const CastEngine::LoopMode loopMode)738 void HwCastStreamPlayer::OnLoopModeChanged(const CastEngine::LoopMode loopMode)
739 {
740 AVPlaybackState avCastPlaybackState;
741 if (castPlusLoopModeToInt_.count(loopMode) == 0) {
742 SLOGE("current playbackState status is not exist in castPlusStateToString_");
743 } else {
744 SLOGD("StreamPlayer received loop mode changed event: %{public}d", castPlusLoopModeToInt_[loopMode]);
745 avCastPlaybackState.SetLoopMode(castPlusLoopModeToInt_[loopMode]);
746 }
747 std::lock_guard playerListLockGuard(streamPlayerListenerListLock_);
748 for (auto listener : streamPlayerListenerList_) {
749 if (listener != nullptr) {
750 SLOGI("trigger the OnLoopModeChanged for registered listeners");
751 listener->OnCastPlaybackStateChange(avCastPlaybackState);
752 }
753 }
754 SLOGI("loop mode changed event done: %{public}d", castPlusLoopModeToInt_[loopMode]);
755 }
756
OnPlaySpeedChanged(const CastEngine::PlaybackSpeed speed)757 void HwCastStreamPlayer::OnPlaySpeedChanged(const CastEngine::PlaybackSpeed speed)
758 {
759 AVPlaybackState avCastPlaybackState;
760 if (castPlusSpeedToDouble_.count(speed) == 0) {
761 SLOGE("current speed is not exist in castPlusSpeedToDouble_");
762 return;
763 }
764 SLOGD("StreamPlayer received play speed changed event: %{public}f", castPlusSpeedToDouble_[speed]);
765 avCastPlaybackState.SetSpeed(castPlusSpeedToDouble_[speed]);
766 std::lock_guard playerListLockGuard(streamPlayerListenerListLock_);
767 for (auto listener : streamPlayerListenerList_) {
768 if (listener != nullptr) {
769 SLOGI("trigger the OnPositionChange for registered listeners");
770 listener->OnCastPlaybackStateChange(avCastPlaybackState);
771 }
772 }
773 SLOGI("play speed changed event done: %{public}f", castPlusSpeedToDouble_[speed]);
774 }
775
OnPlayerError(int errorCode,const std::string & errorMsg)776 void HwCastStreamPlayer::OnPlayerError(int errorCode, const std::string &errorMsg)
777 {
778 SLOGD("StreamPlayer received error event, code: %{public}d, message: %{public}s", errorCode, errorMsg.c_str());
779 std::lock_guard playerListLockGuard(streamPlayerListenerListLock_);
780 for (auto listener : streamPlayerListenerList_) {
781 if (listener != nullptr) {
782 SLOGI("trigger the OnPlayerError for registered listeners");
783 listener->OnPlayerError(errorCode, errorMsg);
784 }
785 }
786 SLOGI("error event done, code: %{public}d, message: %{public}s", errorCode, errorMsg.c_str());
787 }
788
OnSeekDone(int32_t seekNumber)789 void HwCastStreamPlayer::OnSeekDone(int32_t seekNumber)
790 {
791 SLOGD("StreamPlayer received seek done event: %{public}d", seekNumber);
792 std::lock_guard playerListLockGuard(streamPlayerListenerListLock_);
793 for (auto listener : streamPlayerListenerList_) {
794 if (listener != nullptr) {
795 SLOGI("trigger the OnSeekDone for registered listeners");
796 listener->OnSeekDone(seekNumber);
797 }
798 }
799 SLOGI("StreamPlayer received seek done event done with: %{public}d", seekNumber);
800 }
801
OnVideoSizeChanged(int width,int height)802 void HwCastStreamPlayer::OnVideoSizeChanged(int width, int height)
803 {
804 SLOGD("StreamPlayer received video size change event, width: %{public}d, height: %{public}d", width, height);
805 std::lock_guard playerListLockGuard(streamPlayerListenerListLock_);
806 for (auto listener : streamPlayerListenerList_) {
807 if (listener != nullptr) {
808 SLOGI("trigger the OnVideoSizeChange for registered listeners");
809 listener->OnVideoSizeChange(width, height);
810 }
811 }
812 SLOGI("video size change event done, width: %{public}d, height: %{public}d", width, height);
813 }
814
OnEndOfStream(int isLooping)815 void HwCastStreamPlayer::OnEndOfStream(int isLooping)
816 {
817 SLOGD("Received EndOfStream callback, value is %{public}d", isLooping);
818 std::lock_guard playerListLockGuard(streamPlayerListenerListLock_);
819 for (auto listener : streamPlayerListenerList_) {
820 if (listener != nullptr) {
821 SLOGI("trigger the OnEndOfStream for registered listeners");
822 listener->OnEndOfStream(isLooping);
823 }
824 }
825
826 AVPlaybackState avCastPlaybackState;
827 std::shared_ptr<AAFwk::WantParams> wantParams = std::make_shared<AAFwk::WantParams>();
828 sptr<AAFwk::IInterface> intIt = AAFwk::Integer::Box(isLooping);
829 if (wantParams == nullptr || intIt == nullptr) {
830 return;
831 }
832 wantParams->SetParam("endofstream", intIt);
833 avCastPlaybackState.SetExtras(wantParams);
834 SLOGD("Received end of stream event: %{public}d", isLooping);
835
836 for (auto listener : streamPlayerListenerList_) {
837 if (listener != nullptr) {
838 SLOGI("trigger the OnEndOfStream for registered listeners");
839 listener->OnCastPlaybackStateChange(avCastPlaybackState);
840 }
841 }
842 SLOGI("Received EndOfStream callback done, value is %{public}d", isLooping);
843 }
844
OnPlayRequest(const CastEngine::MediaInfo & mediaInfo)845 void HwCastStreamPlayer::OnPlayRequest(const CastEngine::MediaInfo& mediaInfo)
846 {
847 SLOGI("Stream player received PlayRequest event");
848 std::shared_ptr<AVMediaDescription> mediaDescription = std::make_shared<AVMediaDescription>();
849 mediaDescription->SetMediaId(mediaInfo.mediaId);
850 mediaDescription->SetTitle(mediaInfo.mediaName);
851 mediaDescription->SetMediaUri(mediaInfo.mediaUrl);
852 mediaDescription->SetMediaType(mediaInfo.mediaType);
853 mediaDescription->SetMediaSize(mediaInfo.mediaSize);
854 mediaDescription->SetStartPosition(static_cast<uint32_t>(mediaInfo.startPosition));
855 mediaDescription->SetDuration(static_cast<uint32_t>(mediaInfo.duration));
856 mediaDescription->SetCreditsPosition(static_cast<int32_t>(mediaInfo.closingCreditsPosition));
857 mediaDescription->SetAlbumCoverUri(mediaInfo.albumCoverUrl);
858 mediaDescription->SetAlbumTitle(mediaInfo.albumTitle);
859 mediaDescription->SetArtist(mediaInfo.mediaArtist);
860 mediaDescription->SetLyricUri(mediaInfo.lrcUrl);
861 mediaDescription->SetIconUri(mediaInfo.appIconUrl);
862 mediaDescription->SetAppName(mediaInfo.appName);
863 mediaDescription->SetDrmScheme(mediaInfo.drmType);
864 AVQueueItem queueItem;
865 queueItem.SetDescription(mediaDescription);
866 std::lock_guard playerListLockGuard(streamPlayerListenerListLock_);
867 for (auto listener : streamPlayerListenerList_) {
868 if (listener != nullptr) {
869 SLOGI("trigger the OnPlayRequest for registered listeners");
870 listener->OnPlayRequest(queueItem);
871 }
872 }
873 SLOGI("Stream player received PlayRequest event done");
874 }
875
OnImageChanged(std::shared_ptr<Media::PixelMap> pixelMap)876 void HwCastStreamPlayer::OnImageChanged(std::shared_ptr<Media::PixelMap> pixelMap)
877 {
878 SLOGD("Stream player received ImageChanged event");
879 }
880
OnAlbumCoverChanged(std::shared_ptr<Media::PixelMap> pixelMap)881 void HwCastStreamPlayer::OnAlbumCoverChanged(std::shared_ptr<Media::PixelMap> pixelMap)
882 {
883 SLOGI("Received AlbumCoverChanged callback");
884 if (pixelMap == nullptr) {
885 SLOGE("Invalid pixelMap null");
886 return;
887 }
888 std::shared_ptr<AVSessionPixelMap> innerPixelMap =
889 AVSessionPixelMapAdapter::ConvertToInnerWithLimitedSize(pixelMap);
890 if (innerPixelMap == nullptr) {
891 SLOGE("Invalid innerPixelMap null");
892 return;
893 }
894
895 std::shared_ptr<AVMediaDescription> mediaDescription = nullptr;
896 {
897 std::lock_guard lockGuard(curItemLock_);
898 mediaDescription = currentAVQueueItem_.GetDescription();
899 }
900 if (mediaDescription == nullptr) {
901 SLOGE("OnAlbumCoverChanged with nullptr mediaDescription, return with default");
902 return;
903 }
904 mediaDescription->SetIcon(innerPixelMap);
905 AVQueueItem queueItem;
906 queueItem.SetDescription(mediaDescription);
907 {
908 std::lock_guard playerListLockGuard(streamPlayerListenerListLock_);
909 for (auto listener : streamPlayerListenerList_) {
910 if (listener != nullptr) {
911 SLOGI("trigger the OnMediaItemChange for registered listeners on Album change");
912 listener->OnMediaItemChange(queueItem);
913 }
914 }
915 }
916 {
917 std::lock_guard lockGuard(curItemLock_);
918 currentAVQueueItem_ = queueItem;
919 }
920 SLOGI("Received AlbumCoverChanged callback done");
921 }
922
OnAvailableCapabilityChanged(const CastEngine::StreamCapability & streamCapability)923 void HwCastStreamPlayer::OnAvailableCapabilityChanged(const CastEngine::StreamCapability &streamCapability)
924 {
925 SLOGE("Received OnAvailableCapabilityChanged callback");
926 std::vector<int32_t> supportedCastCmds;
927 checkCmdsFromAbility(streamCapability, supportedCastCmds);
928 for (auto listener : streamPlayerListenerList_) {
929 if (listener != nullptr) {
930 SLOGI("trigger the OnValidCommandChange for registered listeners");
931 listener->OnValidCommandChange(supportedCastCmds);
932 }
933 }
934 }
935
OnKeyRequest(const std::string & assetId,const std::vector<uint8_t> & keyRequestData)936 void HwCastStreamPlayer::OnKeyRequest(const std::string& assetId, const std::vector<uint8_t>& keyRequestData)
937 {
938 SLOGD("Stream player received keyRequest event");
939 std::lock_guard playerListLockGuard(streamPlayerListenerListLock_);
940 for (auto listener : streamPlayerListenerList_) {
941 if (listener != nullptr) {
942 SLOGI("trigger the OnKeyRequest for registered listeners");
943 listener->OnKeyRequest(assetId, keyRequestData);
944 }
945 }
946 SLOGI("Stream player received keyRequest event done");
947 }
948
checkCmdsFromAbility(const CastEngine::StreamCapability & streamCapability,std::vector<int32_t> & supportedCastCmds)949 void HwCastStreamPlayer::checkCmdsFromAbility(
950 const CastEngine::StreamCapability& streamCapability, std::vector<int32_t>& supportedCastCmds)
951 {
952 if (streamCapability.isPlaySupported) {
953 supportedCastCmds.push_back(AVCastControlCommand::CAST_CONTROL_CMD_PLAY);
954 }
955 if (streamCapability.isPauseSupported) {
956 supportedCastCmds.push_back(AVCastControlCommand::CAST_CONTROL_CMD_PAUSE);
957 }
958 if (streamCapability.isStopSupported) {
959 supportedCastCmds.push_back(AVCastControlCommand::CAST_CONTROL_CMD_STOP);
960 }
961 if (streamCapability.isNextSupported) {
962 supportedCastCmds.push_back(AVCastControlCommand::CAST_CONTROL_CMD_PLAY_NEXT);
963 }
964 if (streamCapability.isPreviousSupported) {
965 supportedCastCmds.push_back(AVCastControlCommand::CAST_CONTROL_CMD_PLAY_PREVIOUS);
966 }
967 if (streamCapability.isSeekSupported) {
968 supportedCastCmds.push_back(AVCastControlCommand::CAST_CONTROL_CMD_SEEK);
969 }
970 if (streamCapability.isFastForwardSupported) {
971 supportedCastCmds.push_back(AVCastControlCommand::CAST_CONTROL_CMD_FAST_FORWARD);
972 }
973 if (streamCapability.isFastRewindSupported) {
974 supportedCastCmds.push_back(AVCastControlCommand::CAST_CONTROL_CMD_REWIND);
975 }
976 if (streamCapability.isLoopModeSupported) {
977 supportedCastCmds.push_back(AVCastControlCommand::CAST_CONTROL_CMD_SET_LOOP_MODE);
978 }
979 if (streamCapability.isSetVolumeSupported) {
980 supportedCastCmds.push_back(AVCastControlCommand::CAST_CONTROL_CMD_SET_VOLUME);
981 }
982 }
983
checkAbilityFromCmds(const std::vector<int32_t> & supportedCastCmds,CastEngine::StreamCapability & streamCapability)984 void HwCastStreamPlayer::checkAbilityFromCmds(
985 const std::vector<int32_t>& supportedCastCmds, CastEngine::StreamCapability& streamCapability)
986 {
987 for (const int32_t cmd : supportedCastCmds) {
988 switch (cmd) {
989 case AVCastControlCommand::CAST_CONTROL_CMD_PLAY:
990 streamCapability.isPlaySupported = true;
991 break;
992 case AVCastControlCommand::CAST_CONTROL_CMD_PAUSE:
993 streamCapability.isPauseSupported = true;
994 break;
995 case AVCastControlCommand::CAST_CONTROL_CMD_STOP:
996 streamCapability.isStopSupported = true;
997 break;
998 case AVCastControlCommand::CAST_CONTROL_CMD_PLAY_NEXT:
999 streamCapability.isNextSupported = true;
1000 break;
1001 case AVCastControlCommand::CAST_CONTROL_CMD_PLAY_PREVIOUS:
1002 streamCapability.isPreviousSupported = true;
1003 break;
1004 case AVCastControlCommand::CAST_CONTROL_CMD_SEEK:
1005 streamCapability.isSeekSupported = true;
1006 break;
1007 case AVCastControlCommand::CAST_CONTROL_CMD_FAST_FORWARD:
1008 streamCapability.isFastForwardSupported = true;
1009 break;
1010 case AVCastControlCommand::CAST_CONTROL_CMD_REWIND:
1011 streamCapability.isFastRewindSupported = true;
1012 break;
1013 case AVCastControlCommand::CAST_CONTROL_CMD_SET_LOOP_MODE:
1014 streamCapability.isLoopModeSupported = true;
1015 break;
1016 case AVCastControlCommand::CAST_CONTROL_CMD_SET_VOLUME:
1017 streamCapability.isSetVolumeSupported = true;
1018 break;
1019 default:
1020 break;
1021 }
1022 }
1023 streamCapability.isToggleFavoriteSupported = false;
1024 }
1025 } // namespace OHOS::AVSession
1026