# AVCastFlowChart **Repository Path**: devil_red/AVCastFlowChart ## Basic Information - **Project Name**: AVCastFlowChart - **Description**: OH播控框架avsession投播流程图 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-04-07 - **Last Updated**: 2025-04-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 应用发起投播 StartCast 首次发起投播: ```mermaid sequenceDiagram participant CollaborationManager participant AVSessionService participant AVSessionItem participant AVRouterImpl participant HwCastProvider participant HwCastProviderSession participant CastSessionManager participant ICastSession participant ICastSessionManagerListener participant ICastSessionListener participant HwCastStreamPlayer(sink) participant HwCastProviderSession(sink) participant HwCastProvider(sink) participant AVRouterImpl(sink) participant AVSessionItem(sink) participant AVSessionService(sink) AVSessionService->>AVSessionItem:StartCast() AVSessionItem->>CollaborationManager:ListenCollaborationApplyResult() AVSessionItem->>+CollaborationManager:ApplyAdvancedResource() CollaborationManager->>AVSessionItem:serviceCollaborationCallback()[max:10s] CollaborationManager->>-AVSessionItem:serviceCollaborationCallback()[max:60s] Note over AVSessionItem,CollaborationManager:投播接入协同框架 AVSessionItem->>AVRouterImpl:StartCast() AVRouterImpl->>HwCastProvider:StartCastSession() HwCastProvider->>CastSessionManager:CreateCastSession() ICastSession->>HwCastProvider:ICastSession HwCastProvider->>HwCastProviderSession:Init() HwCastProviderSession->>ICastSession:RegisterListener() Note over AVRouterImpl,HwCastProviderSession:AVRouter::GetInstance().StartCast() ICastSessionManagerListener-->>HwCastProvider(sink):OnSessionCreated() HwCastProvider(sink)-->>AVRouterImpl(sink):ReleaseCurrentCastSession() AVRouterImpl(sink)->>AVSessionService(sink):ReleaseCastSession() AVSessionService(sink)->>AVSessionItem(sink):UnRegisterDeviceStateCallback() AVSessionItem(sink)->>AVRouterImpl(sink):UnRegisterCallback() AVRouterImpl(sink)->>HwCastProvider(sink):UnRegisterCastSessionStateListener() HwCastProvider(sink)->>HwCastProviderSession(sink):UnRegisterCastSessionStateListener() Note over HwCastProviderSession(sink),AVSessionItem(sink):AVSessionItem::UnRegisterDeviceStateCallback() / AVRouter::GetInstance().UnRegisterCallback() AVSessionService(sink)->>AVSessionItem(sink):StopCastSession() AVSessionItem(sink)->>AVRouterImpl(sink):StopCastSession() AVRouterImpl(sink)->>HwCastProvider(sink):StopCastSession() opt hwCastStreamPlayer HwCastProvider(sink)->>HwCastStreamPlayer(sink):Release() HwCastStreamPlayer(sink)->>CastSessionManager:UnregisterListener() HwCastStreamPlayer(sink)->>CastSessionManager:Release() end AVSessionItem(sink)->>AVSessionItem(sink):DoContinuousTaskUnregister() Note over CastSessionManager,AVSessionItem(sink):AVSessionItem::StopCastSession() AVSessionService(sink)->>AVSessionItem(sink):ReleaseAVCastControllerInner() AVSessionService(sink)->>AVSessionService(sink):HandleSessionRelease() AVSessionService(sink)->>AVSessionItem(sink):DestroyTask() AVSessionItem(sink)->>AVSessionItem(sink):ReleaseAVCastControllerInner() AVSessionItem(sink)->>AVSessionItem(sink):StopCastDisplayListener() AVSessionService(sink)->>AVSessionService(sink):UpdateFrontSession() Note over AVSessionItem(sink),AVSessionService(sink):AVSessionService::HandleSessionRelease() ICastSessionManagerListener-->>HwCastProvider(sink):ICastSession HwCastProvider(sink)->>HwCastProviderSession(sink):Init() HwCastProvider(sink)->>HwCastProviderSession(sink):CreateStreamPlayer() HwCastProvider(sink)->>HwCastStreamPlayer(sink):Init() HwCastProvider(sink)->>AVRouterImpl(sink):OnCastSessionCreated() AVRouterImpl(sink)->>AVSessionService(sink):CreateSessionByCast() AVSessionService(sink)->>AVSessionService(sink):CreateSessionInner() AVSessionService(sink)->>AVSessionItem(sink):SetCastHandle() AVSessionService(sink)->>AVSessionItem(sink):RegisterDeviceStateCallback() AVSessionItem(sink)->>AVRouterImpl(sink):RegisterCallback() Note over AVRouterImpl(sink),HwCastProviderSession(sink):AVRouter::GetInstance().RegisterCallback() Note over CastSessionManager,AVSessionService(sink):HwCastProvider::OnSessionCreated() AVSessionItem->>AVRouterImpl:RegisterCallback() AVRouterImpl->>HwCastProvider:RegisterCastSessionStateListener() HwCastProvider->>HwCastProviderSession:RegisterCastSessionStateListener() opt stashDeviceState_ > 0 HwCastProviderSession->>AVRouterImpl:OnCastStateChange() AVRouterImpl-->>AVSessionItem:OnCastStateChange() AVSessionItem->>AVSessionItem:DealCollaborationPublishState() alt connectStateFromCast_ AVSessionItem->>CollaborationManager:PublishServiceState(SCM_CONNECTED) else disconnectStateFromCast_ AVSessionItem->>CollaborationManager:PublishServiceState(SCM_IDLE) AVSessionItem->>AVRouterImpl:UnRegisterCallback() AVSessionItem->>AVRouterImpl:StopCastSession() AVSessionItem->>AVSessionItem:DoContinuousTaskUnregister() end AVSessionItem->>CollaborationManager:SendCollaborationOnStop(AVSessionItem::StopCast) AVSessionItem->>AVSessionItem:HandleOutputDeviceChange() end Note over AVRouterImpl,HwCastProviderSession:AVRouter::GetInstance().RegisterCallback() AVSessionItem->>AVRouterImpl:AddDevice() AVRouterImpl->>HwCastProvider:AddDevice() HwCastProvider->>HwCastProviderSession:AddDevice() HwCastProviderSession->>ICastSession:AddDevice() Note over AVRouterImpl,ICastSession:AVRouter::GetInstance().AddDevice() AVSessionItem->>AVSessionItem:DoContinuousTaskRegister() Note over AVSessionItem,ICastSession:AVSessionItem::SubStartCast() ICastSessionListener-->>HwCastProviderSession(sink):OnDeviceState() HwCastProviderSession(sink)->>AVRouterImpl(sink):OnCastStateChange() AVRouterImpl(sink)-->>AVSessionItem(sink):OnCastStateChange() AVSessionItem(sink)->>AVSessionItem(sink):DealCollaborationPublishState() alt connectStateFromCast_ AVSessionItem(sink)->>CollaborationManager:PublishServiceState(SCM_CONNECTED) AVSessionItem(sink)->>AVSessionService(sink):HandleCallStartEvent() else disconnectStateFromCast_ AVSessionItem(sink)->>CollaborationManager:PublishServiceState(SCM_IDLE) AVSessionItem(sink)->>AVRouterImpl(sink):UnRegisterCallback() AVSessionItem(sink)->>AVRouterImpl(sink):StopCastSession() AVSessionItem(sink)->>AVSessionItem(sink):DoContinuousTaskUnregister() AVSessionItem(sink)->>AVSessionItem(sink):Destroy() end AVSessionItem(sink)->>CollaborationManager:SendCollaborationOnStop(AVRouter::GetInstance().StopCastSession) AVSessionItem(sink)->>AVSessionItem(sink):HandleOutputDeviceChange() Note over HwCastStreamPlayer(sink),HwCastStreamPlayer(sink):SetDisplaySurface() ICastSessionListener-->>HwCastProviderSession:OnDeviceState() HwCastProviderSession->>AVRouterImpl:OnCastStateChange() AVRouterImpl-->>AVSessionItem:OnCastStateChange() AVSessionItem->>AVSessionItem:DealCollaborationPublishState() alt connectStateFromCast_ AVSessionItem->>CollaborationManager:PublishServiceState(SCM_CONNECTED) AVSessionItem->>AVSessionService:HandleCallStartEvent() else disconnectStateFromCast_ AVSessionItem->>CollaborationManager:PublishServiceState(SCM_IDLE) AVSessionItem->>AVRouterImpl:UnRegisterCallback() AVSessionItem->>AVRouterImpl:StopCastSession() AVSessionItem->>AVSessionItem:DoContinuousTaskUnregister() end AVSessionItem->>CollaborationManager:SendCollaborationOnStop(AVSessionItem::StopCast) AVSessionItem->>AVSessionItem:HandleOutputDeviceChange() ``` ### 关键日志 直接搜索: enter CastAddToCollaboration:投播接入协同框架流程 enter ListenCollaborationApplyResult:给协同框架注册ApplyResult回调 ApplyResult can cast:协同框架投播回调PASS ​ :AVRouterImpl开始投播流程 StartCastSession begin:HwCastProvider开始投播流程 StartCastSession check lock:cast+创建session成功 CastSession init successed:HwCastProviderSession创建成功 StartCastSession successed and return the castId is:AVRouterImpl StartCast成功,获取castHandle成功 Add device process:AVSessionItem开始增加设备 AVRouterImpl register IAVRouterListener callback to provider:AVRouterImpl开始注册回调 register castsession state listener check lock with castId:HwCastProvider传递注册AVRouterImpl回调 RegisterCastSessionStateListener:HwCastProviderSession注册AVRouterImpl回调 register listener finished with size:HwCastProviderSession成功注册AVRouterImpl回调 AVRouterImpl AddDevice process:AVRouterImpl开始增加设备 AddCastDevice with config castSession and corresonding castId is:HwCastProvider开始增加设备 AddDevice in HwCastProviderSession:HwCastProviderSession开始增加设备 AddDevice in HwCastProviderSession with ret:cast+结束增加设备 Add device process with ret:AVSessionItem结束增加设备 reportContinuousTaskEventEx done, result:长时任务注册成功