手机miracast投屏到ops设备没有画面随机问题分析

📅 2026/7/3 13:14:44 👁️ 阅读次数 📝 编程学习
手机miracast投屏到ops设备没有画面随机问题分析

问题

手机Miracast投屏至OPS设备时有弹窗,无视频画面,手机端显示连接投屏成功。

问题根因

随机出现无视频画面是因为下面两个函数调用的时序不稳定,可能会导致sharedDecoder_->Start没有被调用。
sharedDecoder_ 对象是在AppendSurface接口里面创建的,如果start比AppendSurface先调用,则sharedDecoder_ 没有创建,isPlaying_ 不会置为true,等AppendSurface调用时isPlaying_的值为false,也不会调用sharedDecoder_->Start。

voidMediaController::Start(){SHARING_LOGI("tttt MediaController::Start.");automediaChannel=mediaChannel_.lock();RETURN_IF_NULL(mediaChannel);autodispatcher=mediaChannel->GetDispatcher();RETURN_IF_NULL(dispatcher);{std::lock_guard<std::mutex>lock(playAudioMutex_);if(nullptr!=audioPlayController_){if(audioPlayController_->Start(dispatcher)){isPlaying_=true;}}}{std::lock_guard<std::mutex>lock(playVideoMutex_);if(sharedDecoder_&&sharedDecoder_->SurfaceCount()>0){if(sharedDecoder_->Start(dispatcher)){isPlaying_=true;}}}SHARING_LOGI("tttt MediaController::Start end.");}
boolMediaController::AppendSurface(sptr<Surface>surface,SceneType sceneType){RETURN_FALSE_IF_NULL(surface);SHARING_LOGI("tttt MediaController::AppendSurface.");std::lock_guard<std::mutex>lock(playVideoMutex_);if(!EnsureSharedDecoder()){SHARING_LOGE("cannot create shared decoder, mediachannelId: %{public}u.",mediachannelId_);returnfalse;}uint64_tsurfaceId=surface->GetUniqueId();if(sharedDecoder_->HasSurface(surfaceId)){SHARING_LOGE("surface is in use, %{public}"PRIx64".",surfaceId);returnfalse;}if(!sharedDecoder_->AddSurface(surface,sceneType)){SHARING_LOGE("AddSurface failed, mediachannelId: %{public}u.",mediachannelId_);returnfalse;}SHARING_LOGI("tttt MediaController::AppendSurface, isPlaying_=%{public}d",isPlaying_.load());if(isPlaying_){automediaChannel=mediaChannel_.lock();if(mediaChannel){autodispatcher=mediaChannel->GetDispatcher();if(dispatcher){sharedDecoder_->Start(dispatcher);}}}returntrue;}

解决方法

AppendSurface调用时,每次都调用sharedDecoder_->Start。

@@-139,6+143,7@@boolMediaController::AppendSurface(sptr<Surface>surface,SceneType sceneType){RETURN_FALSE_IF_NULL(surface);+SHARING_LOGI("tttt MediaController::AppendSurface.");std::lock_guard<std::mutex>lock(playVideoMutex_);if(!EnsureSharedDecoder()){SHARING_LOGE("cannot create shared decoder, mediachannelId: %{public}u.",mediachannelId_);@@-156,12+161,15@@boolMediaController::AppendSurface(sptr<Surface>surface,SceneType sceneType)returnfalse;}-if(isPlaying_){+SHARING_LOGI("tttt MediaController::AppendSurface, isPlaying_=%{public}d",isPlaying_.load());+//if (isPlaying_) {+if(true){automediaChannel=mediaChannel_.lock();if(mediaChannel){autodispatcher=mediaChannel->GetDispatcher();if(dispatcher){sharedDecoder_->Start(dispatcher);+isPlaying_=true;}}}