From 434a1b478d38a1cc2ff712edad5b068d9be1fd92 Mon Sep 17 00:00:00 2001 From: littleGnAl Date: Mon, 9 Sep 2024 14:29:40 +0800 Subject: [PATCH 1/4] [example][ScreenSharing] Set the screen-sharing view render mode to RenderModeType.renderModeFit --- example/lib/examples/advanced/screen_sharing/screen_sharing.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/example/lib/examples/advanced/screen_sharing/screen_sharing.dart b/example/lib/examples/advanced/screen_sharing/screen_sharing.dart index 330529124..d8a29a96f 100644 --- a/example/lib/examples/advanced/screen_sharing/screen_sharing.dart +++ b/example/lib/examples/advanced/screen_sharing/screen_sharing.dart @@ -196,6 +196,7 @@ class _State extends State with KeepRemoteVideoViewsMixin { canvas: const VideoCanvas( uid: 0, sourceType: VideoSourceType.videoSourceScreen, + renderMode: RenderModeType.renderModeFit, ), )) : Container( From 666cae9bd213daa54dae1b81da39f06d49d67a48 Mon Sep 17 00:00:00 2001 From: littleGnAl Date: Wed, 22 May 2024 16:58:44 +0800 Subject: [PATCH 2/4] [example][screen_sharing] Allow input the screen capture frame rate by user --- .../screen_sharing/screen_sharing.dart | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/example/lib/examples/advanced/screen_sharing/screen_sharing.dart b/example/lib/examples/advanced/screen_sharing/screen_sharing.dart index d8a29a96f..fb9fec9c5 100644 --- a/example/lib/examples/advanced/screen_sharing/screen_sharing.dart +++ b/example/lib/examples/advanced/screen_sharing/screen_sharing.dart @@ -505,6 +505,8 @@ class _ScreenShareDesktopState extends State List _screenCaptureSourceInfos = []; late ScreenCaptureSourceInfo _selectedScreenCaptureSourceInfo; + late final TextEditingController _screenShareFrameRateController; + @override bool get isScreenShared => widget.isScreenShared; @@ -589,6 +591,8 @@ class _ScreenShareDesktopState extends State void initState() { super.initState(); + _screenShareFrameRateController = TextEditingController(text: '30'); + _initScreenCaptureSourceInfos(); } @@ -599,6 +603,14 @@ class _ScreenShareDesktopState extends State mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ + TextField( + controller: _screenShareFrameRateController, + decoration: + const InputDecoration(hintText: 'Screen Sharing frame rate'), + ), + const SizedBox( + height: 20, + ), _createDropdownButton(), if (_screenCaptureSourceInfos.isNotEmpty) Row( @@ -629,18 +641,18 @@ class _ScreenShareDesktopState extends State await rtcEngine.startScreenCaptureByDisplayId( displayId: sourceId!, regionRect: const Rectangle(x: 0, y: 0, width: 0, height: 0), - captureParams: const ScreenCaptureParameters( + captureParams: ScreenCaptureParameters( captureMouseCursor: true, - frameRate: 30, + frameRate: int.parse(_screenShareFrameRateController.text), )); } else if (_selectedScreenCaptureSourceInfo.type == ScreenCaptureSourceType.screencapturesourcetypeWindow) { await rtcEngine.startScreenCaptureByWindowId( windowId: sourceId!, regionRect: const Rectangle(x: 0, y: 0, width: 0, height: 0), - captureParams: const ScreenCaptureParameters( + captureParams: ScreenCaptureParameters( captureMouseCursor: true, - frameRate: 30, + frameRate: int.parse(_screenShareFrameRateController.text), ), ); } From 07058c1cc1e750733304d28984d6f23899a6889c Mon Sep 17 00:00:00 2001 From: littleGnAl Date: Thu, 12 Sep 2024 15:17:19 +0800 Subject: [PATCH 3/4] [example][screen_sharing] Allow control the preview by user --- .../screen_sharing/screen_sharing.dart | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/example/lib/examples/advanced/screen_sharing/screen_sharing.dart b/example/lib/examples/advanced/screen_sharing/screen_sharing.dart index fb9fec9c5..d6c957240 100644 --- a/example/lib/examples/advanced/screen_sharing/screen_sharing.dart +++ b/example/lib/examples/advanced/screen_sharing/screen_sharing.dart @@ -22,6 +22,7 @@ class ScreenSharing extends StatefulWidget { class _State extends State with KeepRemoteVideoViewsMixin { late final RtcEngineEx _engine; bool _isReadyPreview = false; + bool _isStartedPreview = false; String channelId = config.channelId; bool isJoined = false; late TextEditingController _controller; @@ -99,7 +100,6 @@ class _State extends State with KeepRemoteVideoViewsMixin { _engine.registerEventHandler(_rtcEngineEventHandler); await _engine.enableVideo(); - await _engine.startPreview(); await _engine.setClientRole(role: ClientRoleType.clientRoleBroadcaster); setState(() { @@ -170,7 +170,11 @@ class _State extends State with KeepRemoteVideoViewsMixin { Widget build(BuildContext context) { return ExampleActionsWidget( displayContentBuilder: (context, isLayoutHorizontal) { - if (!_isReadyPreview) return Container(); + if (!_isStartedPreview) { + return const Center( + child: Text('Press the "Start Preview" button to preview'), + ); + } final children = [ Expanded( flex: 1, @@ -277,6 +281,35 @@ class _State extends State with KeepRemoteVideoViewsMixin { const SizedBox( height: 20, ), + Row( + children: [ + Expanded( + flex: 1, + child: ElevatedButton( + onPressed: () { + if (_isStartedPreview) { + _engine.stopPreview(); + _engine.stopPreview( + sourceType: VideoSourceType.videoSourceScreen); + } else { + _engine.startPreview(); + _engine.startPreview( + sourceType: VideoSourceType.videoSourceScreen); + } + + setState(() { + _isStartedPreview = !_isStartedPreview; + }); + }, + child: + Text('${_isStartedPreview ? 'Stop' : 'Start'} Preview'), + ), + ) + ], + ), + const SizedBox( + height: 20, + ), Row( children: [ Expanded( @@ -386,7 +419,6 @@ class _ScreenShareWebState extends State await rtcEngine.startScreenCapture( const ScreenCaptureParameters2(captureAudio: true, captureVideo: true)); - await rtcEngine.startPreview(sourceType: VideoSourceType.videoSourceScreen); onStartScreenShared(); } @@ -459,7 +491,6 @@ class _ScreenShareMobileState extends State await rtcEngine.startScreenCapture( const ScreenCaptureParameters2(captureAudio: true, captureVideo: true)); - await rtcEngine.startPreview(sourceType: VideoSourceType.videoSourceScreen); _showRPSystemBroadcastPickerViewIfNeed(); onStartScreenShared(); } From 3a4b486484cbd507619b4a328d291ff4bcd24a9e Mon Sep 17 00:00:00 2001 From: littleGnAl Date: Thu, 12 Sep 2024 15:56:44 +0800 Subject: [PATCH 4/4] [example][screen_sharing] Set ScreenScenarioType.screenScenarioGaming to enable zero-copy feature --- .../lib/examples/advanced/screen_sharing/screen_sharing.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/example/lib/examples/advanced/screen_sharing/screen_sharing.dart b/example/lib/examples/advanced/screen_sharing/screen_sharing.dart index d6c957240..32b23b8e8 100644 --- a/example/lib/examples/advanced/screen_sharing/screen_sharing.dart +++ b/example/lib/examples/advanced/screen_sharing/screen_sharing.dart @@ -101,6 +101,8 @@ class _State extends State with KeepRemoteVideoViewsMixin { await _engine.enableVideo(); await _engine.setClientRole(role: ClientRoleType.clientRoleBroadcaster); + await _engine + .setScreenCaptureScenario(ScreenScenarioType.screenScenarioGaming); setState(() { _isReadyPreview = true;