/* * Copyright (C) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "player_impl.h" #include "i_media_service.h" #include "media_log.h" #include "media_errors.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_PLAYER, "PlayerImpl"}; constexpr int32_t API_VERSION_14 = 14; static int32_t apiVersion_ = -1; } namespace OHOS { namespace Media { std::shared_ptr PlayerFactory::CreatePlayer() { MEDIA_LOGD("PlayerImpl: CreatePlayer in"); std::shared_ptr impl = std::make_shared(); CHECK_AND_RETURN_RET_LOG(impl != nullptr, nullptr, "failed to new PlayerImpl"); int32_t ret = impl->Init(); CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, nullptr, "failed to init PlayerImpl"); return impl; } int32_t PlayerImpl::Init() { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " Init in", FAKE_POINTER(this)); HiviewDFX::HiTraceChain::SetId(traceId_); playerService_ = MediaServiceFactory::GetInstance().CreatePlayerService(); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_UNKNOWN, "failed to create player service"); return MSERR_OK; } PlayerImpl::PlayerImpl() { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this)); ResetSeekVariables(); traceId_ = HiviewDFX::HiTraceChain::Begin("PlayerImpl", HITRACE_FLAG_DEFAULT); } PlayerImpl::~PlayerImpl() { if (playerService_ != nullptr) { (void)MediaServiceFactory::GetInstance().DestroyPlayerService(playerService_); playerService_ = nullptr; } ResetSeekVariables(); HiviewDFX::HiTraceChain::End(traceId_); MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this)); } void PlayerImpl::ResetSeekVariables() { mCurrentPosition = INT32_MIN; mCurrentSeekMode = PlayerSeekMode::SEEK_PREVIOUS_SYNC; mSeekPosition = INT32_MIN; mSeekMode = PlayerSeekMode::SEEK_PREVIOUS_SYNC; isSeeking_ = false; } int32_t PlayerImpl::SetMediaMuted(OHOS::Media::MediaType mediaType, bool isMuted) { CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_INVALID_VAL, "playerService_ not exist"); return playerService_->SetMediaMuted(mediaType, isMuted); } int32_t PlayerImpl::SetSource(const std::shared_ptr &dataSrc) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " SetSource in(dataSrc)", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(dataSrc != nullptr, MSERR_INVALID_VAL, "failed to create data source"); return playerService_->SetSource(dataSrc); } int32_t PlayerImpl::SetSource(const std::string &url) { MEDIA_LOGD("PlayerImpl:0x%{private}06" PRIXPTR " SetSource in(url): %{private}s", FAKE_POINTER(this), url.c_str()); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); CHECK_AND_RETURN_RET_LOG(!url.empty(), MSERR_INVALID_VAL, "url is empty.."); return playerService_->SetSource(url); } int32_t PlayerImpl::SetSource(int32_t fd, int64_t offset, int64_t size) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " SetSource in(fd)", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->SetSource(fd, offset, size); } int32_t PlayerImpl::AddSubSource(const std::string &url) { MEDIA_LOGD("PlayerImpl:0x%{private}06" PRIXPTR " AddSubSource in(url): %{private}s", FAKE_POINTER(this), url.c_str()); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); CHECK_AND_RETURN_RET_LOG(!url.empty(), MSERR_INVALID_VAL, "url is empty.."); return playerService_->AddSubSource(url); } int32_t PlayerImpl::AddSubSource(int32_t fd, int64_t offset, int64_t size) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " AddSubSource in(fd)", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->AddSubSource(fd, offset, size); } int32_t PlayerImpl::Play() { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " Play in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->Play(); } int32_t PlayerImpl::SetPlayRange(int64_t start, int64_t end) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " SetPlayRange in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->SetPlayRange(start, end); } int32_t PlayerImpl::SetPlayRangeWithMode(int64_t start, int64_t end, PlayerSeekMode mode) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " SetPlayRangeWithMode in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->SetPlayRangeWithMode(start, end, mode); } int32_t PlayerImpl::Prepare() { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " Prepare in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->Prepare(); } int32_t PlayerImpl::SetRenderFirstFrame(bool display) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " SetRenderFirstFrame in, display %{public}d", FAKE_POINTER(this), display); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->SetRenderFirstFrame(display); } int32_t PlayerImpl::PrepareAsync() { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " PrepareAsync in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->PrepareAsync(); } int32_t PlayerImpl::Pause() { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " Pause in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->Pause(); } int32_t PlayerImpl::Stop() { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " Stop in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); ResetSeekVariables(); return playerService_->Stop(); } int32_t PlayerImpl::Reset() { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " Reset in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); ResetSeekVariables(); return playerService_->Reset(); } int32_t PlayerImpl::Release() { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " Release in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); (void)playerService_->Release(); (void)MediaServiceFactory::GetInstance().DestroyPlayerService(playerService_); playerService_ = nullptr; return MSERR_OK; } int32_t PlayerImpl::ReleaseSync() { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " ReleaseSync in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); (void)playerService_->ReleaseSync(); (void)MediaServiceFactory::GetInstance().DestroyPlayerService(playerService_); playerService_ = nullptr; return MSERR_OK; } int32_t PlayerImpl::SetVolume(float leftVolume, float rightVolume) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " SetVolume(%{public}f, %{public}f) in", FAKE_POINTER(this), leftVolume, rightVolume); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->SetVolume(leftVolume, rightVolume); } int32_t PlayerImpl::Seek(int32_t mSeconds, PlayerSeekMode mode) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " Seek in, seek to %{public}d ms, mode is %{public}d", FAKE_POINTER(this), mSeconds, mode); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); std::unique_lock lock(recMutex_); // SEEK_CONTINOUS is usually called in batches, and will not report seek done event. if (mode == PlayerSeekMode::SEEK_CONTINOUS) { return playerService_->Seek(mSeconds, mode); } mCurrentPosition = mSeconds; mCurrentSeekMode = mode; if ((mSeekPosition != mCurrentPosition || mSeekMode != mCurrentSeekMode) && !isSeeking_) { MEDIA_LOGI("Start seek once."); isSeeking_ = true; mSeekPosition = mSeconds; mSeekMode = mode; auto retCode = playerService_->Seek(mSeconds, mode); if (retCode != MSERR_OK) { ResetSeekVariables(); } MEDIA_LOGI("Start seek once end"); return retCode; } else { MEDIA_LOGE("Seeking not completed, need wait the lastest seek end, then seek again."); } MEDIA_LOGI("Seeking task end. %{public}d ms, mode is %{public}d", mSeconds, mode); return MSERR_OK; } void PlayerImpl::HandleSeekDoneInfo(PlayerOnInfoType type, int32_t extra) { if (type == INFO_TYPE_SEEKDONE) { MEDIA_LOGI("HandleSeekDoneInfo entered"); CHECK_AND_RETURN_LOG(playerService_ != nullptr, "player service does not exist.."); if (extra == -1) { MEDIA_LOGI("seek error, need reset seek variables"); ResetSeekVariables(); return; } std::unique_lock lock(recMutex_); if (mSeekPosition != mCurrentPosition || mSeekMode != mCurrentSeekMode) { MEDIA_LOGI("Start seek again (%{public}d, %{public}d)", mCurrentPosition, mCurrentSeekMode); mSeekPosition = mCurrentPosition; mSeekMode = mCurrentSeekMode; playerService_->Seek(mCurrentPosition, mCurrentSeekMode); } else { MEDIA_LOGI("All seeks complete - return to regularly scheduled program"); ResetSeekVariables(); } MEDIA_LOGI("HandleSeekDoneInfo end seekTo(%{public}d, %{public}d)", mCurrentPosition, mCurrentSeekMode); } } void PlayerImpl::OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody) { HandleSeekDoneInfo(type, extra); std::shared_ptr callback; { std::unique_lock lock(cbMutex_); callback = callback_; } CHECK_AND_RETURN_LOG(callback != nullptr, "callback is nullptr."); if (type == INFO_TYPE_SEEKDONE) { if (extra == -1) { MEDIA_LOGI("seek done error callback, no need report"); return; } if (!isSeeking_) { callback->OnInfo(type, extra, infoBody); } else { MEDIA_LOGD("Is seeking to (%{public}d, %{public}d), not update now", mCurrentPosition, mCurrentSeekMode); } } else { callback->OnInfo(type, extra, infoBody); } } int32_t PlayerImpl::GetCurrentTime(int32_t ¤tTime) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " GetCurrentTime in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->GetCurrentTime(currentTime); } int32_t PlayerImpl::GetVideoTrackInfo(std::vector &videoTrack) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " GetVideoTrackInfo in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->GetVideoTrackInfo(videoTrack); } int32_t PlayerImpl::GetPlaybackInfo(Format &playbackInfo) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " GetPlaybackInfo in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->GetPlaybackInfo(playbackInfo); } int32_t PlayerImpl::GetAudioTrackInfo(std::vector &audioTrack) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " GetAudioTrackInfo in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->GetAudioTrackInfo(audioTrack); } int32_t PlayerImpl::GetSubtitleTrackInfo(std::vector &subtitleTrack) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " GetSubtitleTrackInfo in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->GetSubtitleTrackInfo(subtitleTrack); } int32_t PlayerImpl::GetVideoWidth() { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " GetVideoWidth in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->GetVideoWidth(); } int32_t PlayerImpl::GetVideoHeight() { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " GetVideoHeight in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->GetVideoHeight(); } int32_t PlayerImpl::SetPlaybackSpeed(PlaybackRateMode mode) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " SetPlaybackSpeed in, mode is %{public}d", FAKE_POINTER(this), mode); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->SetPlaybackSpeed(mode); } int32_t PlayerImpl::SetMediaSource(const std::shared_ptr &mediaSource, AVPlayStrategy strategy) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " SetMediaSource in(dataSrc)", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(mediaSource != nullptr, MSERR_INVALID_VAL, "mediaSource is nullptr!"); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->SetMediaSource(mediaSource, strategy); } int32_t PlayerImpl::GetPlaybackSpeed(PlaybackRateMode &mode) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " GetPlaybackSpeed in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->GetPlaybackSpeed(mode); } int32_t PlayerImpl::SelectBitRate(uint32_t bitRate) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " SelectBitRate(%{public}d) in", FAKE_POINTER(this), bitRate); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->SelectBitRate(bitRate); } int32_t PlayerImpl::GetDuration(int32_t &duration) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " GetDuration in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->GetDuration(duration); } int32_t PlayerImpl::GetApiVersion(int32_t &apiVersion) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " GetApiVersion in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->GetApiVersion(apiVersion); } #ifdef SUPPORT_VIDEO int32_t PlayerImpl::SetVideoSurface(sptr surface) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " SetVideoSurface in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); CHECK_AND_RETURN_RET_LOG(surface != nullptr, MSERR_INVALID_VAL, "surface is nullptr"); surface_ = surface; return playerService_->SetVideoSurface(surface); } #endif bool PlayerImpl::IsPlaying() { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " IsPlaying in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, false, "player service does not exist.."); return playerService_->IsPlaying(); } bool PlayerImpl::IsLooping() { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " IsLooping in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, false, "player service does not exist.."); return playerService_->IsLooping(); } int32_t PlayerImpl::SetLooping(bool loop) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " SetLooping in, loop %{public}d", FAKE_POINTER(this), loop); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->SetLooping(loop); } int32_t PlayerImpl::SetPlayerCallback(const std::shared_ptr &callback) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " SetPlayerCallback in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); CHECK_AND_RETURN_RET_LOG(callback != nullptr, MSERR_INVALID_VAL, "callback is nullptr"); { std::unique_lock lock(cbMutex_); callback_ = callback; } std::shared_ptr playerCb = std::make_shared(callback, shared_from_this()); return playerService_->SetPlayerCallback(playerCb); } int32_t PlayerImpl::SetParameter(const Format ¶m) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " SetParameter in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->SetParameter(param); } int32_t PlayerImpl::SelectTrack(int32_t index, PlayerSwitchMode mode) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " SelectTrack in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); if (index == prevTrackIndex_) { MEDIA_LOGI("Select the same track, index: %{public}d", index); return 0; } prevTrackIndex_ = index; return playerService_->SelectTrack(index, mode); } int32_t PlayerImpl::DeselectTrack(int32_t index) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " DeselectTrack in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->DeselectTrack(index); } int32_t PlayerImpl::GetCurrentTrack(int32_t trackType, int32_t &index) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " GetCurrentTrack in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->GetCurrentTrack(trackType, index); } int32_t PlayerImpl::SetDecryptConfig(const sptr &keySessionProxy, bool svp) { MEDIA_LOGI("PlayerImpl DRM SetDecryptConfig"); #ifdef SUPPORT_AVPLAYER_DRM CHECK_AND_RETURN_RET_LOG(keySessionProxy != nullptr, MSERR_INVALID_VAL, "keysessionproxy is nullptr"); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); MEDIA_LOGD("And it's count is: %{public}d in PlayerImpl", keySessionProxy->GetSptrRefCount()); return playerService_->SetDecryptConfig(keySessionProxy, svp); #else (void)keySessionProxy; (void)svp; return 0; #endif } int32_t PlayerImpl::SetDeviceChangeCbStatus(bool status) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " SetDeviceChangeCbStatus in, status is %{public}d", FAKE_POINTER(this), status); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist."); return playerService_->SetDeviceChangeCbStatus(status); } int32_t PlayerImpl::SetPlaybackStrategy(AVPlayStrategy playbackStrategy) { MEDIA_LOGD("Set playback strategy"); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist.."); return playerService_->SetPlaybackStrategy(playbackStrategy); } int32_t PlayerImpl::SetMaxAmplitudeCbStatus(bool status) { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " SetMaxAmplitudeCbStatus in, status is %{public}d", FAKE_POINTER(this), status); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist."); return playerService_->SetMaxAmplitudeCbStatus(status); } bool PlayerImpl::IsSeekContinuousSupported() { MEDIA_LOGD("PlayerImpl:0x%{public}06" PRIXPTR " IsSeekContinuousSupported in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(playerService_ != nullptr, MSERR_SERVICE_DIED, "player service does not exist."); return playerService_->IsSeekContinuousSupported(); } PlayerImplCallback::PlayerImplCallback(const std::shared_ptr playerCb, std::shared_ptr player) { playerCb_ = playerCb; player_ = player; } void PlayerImplCallback::OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody) { auto player = player_.lock(); CHECK_AND_RETURN_LOG(player != nullptr, "player does not exist.."); player->OnInfo(type, extra, infoBody); } void PlayerImplCallback::OnError(int32_t errorCode, const std::string &errorMsg) { std::shared_ptr playerCb; { std::unique_lock lock(playerImplCbMutex_); playerCb = playerCb_; } auto player = player_.lock(); if (player != nullptr && getApiVersionFlag_) { player->GetApiVersion(apiVersion_); getApiVersionFlag_ = false; } MEDIA_LOGI("PlayerImplCallback apiVersion %{public}d", apiVersion_); if (apiVersion_ < API_VERSION_14) { if (IsAPI14IOError(static_cast(errorCode))) { errorCode = MSERR_DATA_SOURCE_IO_ERROR; } } CHECK_AND_RETURN_LOG(playerCb != nullptr, "playerCb does not exist.."); playerCb->OnError(errorCode, errorMsg); } } // namespace Media } // namespace OHOS