disposeRenderInternal method

  1. @protected
Future<void> disposeRenderInternal()
inherited

Implementation

@protected
Future<void> disposeRenderInternal() async {
  if (shouldUseFlutterTexture) {
    // Stop performance monitoring for this texture
    if (_textureId != kTextureNotInit) {
      _unregisterPerformanceStats(_textureId);
    }

    await rtcEngine.globalVideoViewController
        ?.destroyTextureRender(getTextureId());
    _textureId = kTextureNotInit;
    if (connection != null) {
      PerformanceDataCollector.instance.clearChannelData(
          connection!.channelId ?? '',
          connection!.localUid ?? 0,
          VideoSourceTypeExt.fromValue(getVideoSourceType()));
    }
    return;
  }

  // Pass view handle with kNullViewHandle will clear all setup renderers,
  // since we decide to use VideoViewSetupMode.videoViewSetupRemove to remove
  // the renderers, we should return directly here.
  if (_viewHandle != kNullViewHandle) {
    VideoCanvas newCanvas = VideoCanvas(
      view: _viewHandle,
      renderMode: canvas.renderMode,
      mirrorMode: canvas.mirrorMode,
      uid: canvas.uid,
      sourceType: canvas.sourceType,
      cropArea: canvas.cropArea,
      setupMode: VideoViewSetupMode.videoViewSetupRemove,
      mediaPlayerId: canvas.mediaPlayerId,
    );

    await rtcEngine.globalVideoViewController
        ?.setupVideoView(_viewHandle, newCanvas, connection: connection);

    _viewHandle = kNullViewHandle;
  }

  // We need to ensure the platform view is valid before calling setupVideoView since
  // we use VideoViewSetupMode.videoViewSetupRemove to remove renderers. This is important
  // because the platform view is shared between the app and native side via a GlobalRef address.
  if (_platformViewId != kInvalidPlatformViewId) {
    await dePlatformRenderRef(_platformViewId);
    _platformViewId = kInvalidPlatformViewId;
  }

  if (connection?.channelId != null && connection?.localUid != null) {
    PerformanceDataCollector.instance.clearChannelData(
        connection!.channelId ?? '',
        connection!.localUid ?? 0,
        VideoSourceTypeExt.fromValue(getVideoSourceType()));
  }
}