Skip to content

Commit

Permalink
fix: fix crash of AgoraVideoView with flutter texture rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
littleGnAl committed Mar 2, 2023
1 parent 13397da commit f9fdca7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/src/impl/global_video_view_controller.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:convert';

import 'package:agora_rtc_engine/src/impl/video_view_controller_impl.dart';
Expand All @@ -17,6 +18,9 @@ class GlobalVideoViewController {
int _videoFrameBufferManagerIntPtr = 0;
int get videoFrameBufferManagerIntPtr => _videoFrameBufferManagerIntPtr;

final Map<int, Completer<void>> _destroyTextureRenderCompleters = {};
bool _isDetachVFBMing = false;

Future<void> attachVideoFrameBufferManager(int irisRtcEngineIntPtr) async {
if (_videoFrameBufferManagerIntPtr != 0) {
return;
Expand All @@ -35,6 +39,20 @@ class GlobalVideoViewController {
if (_videoFrameBufferManagerIntPtr == 0) {
return;
}

_isDetachVFBMing = true;

// Need wait for all `destroyTextureRender` functions are called completed before
// `FreeIrisVideoFrameBufferManager`, if not, the `destroyTextureRender`(call
// `IrisVideoFrameBufferManager.DisableVideoFrameBuffer` in native side) and
// `FreeIrisVideoFrameBufferManager` will be called parallelly, which will cause crash.
for (final completer in _destroyTextureRenderCompleters.values) {
if (!completer.isCompleted) {
await completer.future;
}
}
_destroyTextureRenderCompleters.clear();

await irisMethodChannel.invokeMethod(IrisMethodCall(
'FreeIrisVideoFrameBufferManager',
jsonEncode({
Expand Down Expand Up @@ -89,7 +107,17 @@ class GlobalVideoViewController {
});
}

/// Call `IrisVideoFrameBufferManager.DisableVideoFrameBuffer` in the native side
Future<void> destroyTextureRender(int textureId) async {
_destroyTextureRenderCompleters.putIfAbsent(
textureId, () => Completer<void>());

await methodChannel.invokeMethod('destroyTextureRender', textureId);

_destroyTextureRenderCompleters[textureId]?.complete(null);

if (!_isDetachVFBMing) {
_destroyTextureRenderCompleters.remove(textureId);
}
}
}

0 comments on commit f9fdca7

Please sign in to comment.