Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2b503d

Browse files
committed
Fix screen capture switch
1 parent 3691b10 commit d2b503d

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

webrtc-android-framework/src/main/java/org/webrtc/ScreenCapturerAndroid.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*/
3838
public class ScreenCapturerAndroid implements VideoCapturer, VideoSink {
3939
private static final int DISPLAY_FLAGS =
40-
DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC | DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION;
40+
DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC | DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION;
4141
// DPI for VirtualDisplay, does not seem to matter for us.
4242
public static final int VIRTUAL_DISPLAY_DPI = 400;
4343

@@ -50,15 +50,14 @@ public class ScreenCapturerAndroid implements VideoCapturer, VideoSink {
5050
@Nullable private SurfaceTextureHelper surfaceTextureHelper;
5151
@Nullable private CapturerObserver capturerObserver;
5252
private long numCapturedFrames;
53-
54-
@Nullable public MediaProjection mediaProjection;
55-
@Nullable public MediaProjectionManager mediaProjectionManager;
56-
53+
@Nullable private MediaProjection mediaProjection;
5754
private boolean isDisposed;
5855
private WindowManager windowManager;
5956
private int deviceRotation = 0;
6057
private static final String TAG = ScreenCapturerAndroid.class.getSimpleName();
6158

59+
@Nullable private MediaProjectionManager mediaProjectionManager;
60+
6261
/**
6362
* Constructs a new Screen Capturer.
6463
*
@@ -68,9 +67,8 @@ public class ScreenCapturerAndroid implements VideoCapturer, VideoSink {
6867
* @param mediaProjectionCallback MediaProjection callback to implement application specific
6968
* logic in events such as when the user revokes a previously granted capture permission.
7069
**/
71-
public ScreenCapturerAndroid(MediaProjection mediaProjection, Intent mediaProjectionPermissionResultData,
70+
public ScreenCapturerAndroid(Intent mediaProjectionPermissionResultData,
7271
MediaProjection.Callback mediaProjectionCallback) {
73-
this.mediaProjection = mediaProjection;
7472
this.mediaProjectionPermissionResultData = mediaProjectionPermissionResultData;
7573
this.mediaProjectionCallback = mediaProjectionCallback;
7674
}
@@ -94,7 +92,7 @@ public MediaProjection getMediaProjection() {
9492
// TODO(bugs.webrtc.org/8491): Remove NoSynchronizedMethodCheck suppression.
9593
@SuppressWarnings("NoSynchronizedMethodCheck")
9694
public synchronized void initialize(final SurfaceTextureHelper surfaceTextureHelper,
97-
final Context applicationContext, final CapturerObserver capturerObserver) {
95+
final Context applicationContext, final CapturerObserver capturerObserver) {
9896
checkNotDisposed();
9997

10098
if (capturerObserver == null) {
@@ -121,17 +119,14 @@ public void setMediaProjection(@Nullable MediaProjection mediaProjection) {
121119
// TODO(bugs.webrtc.org/8491): Remove NoSynchronizedMethodCheck suppression.
122120
@SuppressWarnings("NoSynchronizedMethodCheck")
123121
public synchronized void startCapture(
124-
final int width, final int height, final int ignoredFramerate) {
122+
final int width, final int height, final int ignoredFramerate) {
125123
checkNotDisposed();
126124

127125
this.width = width;
128126
this.height = height;
129127

130-
// It means that it will use old method(without running in MediaProjectionService)
131-
if(mediaProjection == null){
132-
mediaProjection = mediaProjectionManager.getMediaProjection(
133-
Activity.RESULT_OK, mediaProjectionPermissionResultData);
134-
}
128+
mediaProjection = mediaProjectionManager.getMediaProjection(
129+
Activity.RESULT_OK, mediaProjectionPermissionResultData);
135130

136131
// Let MediaProjection callback use the SurfaceTextureHelper thread.
137132
mediaProjection.registerCallback(mediaProjectionCallback, surfaceTextureHelper.getHandler());
@@ -172,6 +167,7 @@ public void run() {
172167
// TODO(bugs.webrtc.org/8491): Remove NoSynchronizedMethodCheck suppression.
173168
@SuppressWarnings("NoSynchronizedMethodCheck")
174169
public synchronized void dispose() {
170+
Log.i(TAG, "ScreenCapturer is disposed");
175171
isDisposed = true;
176172
}
177173

@@ -187,7 +183,7 @@ public synchronized void dispose() {
187183
// TODO(bugs.webrtc.org/8491): Remove NoSynchronizedMethodCheck suppression.
188184
@SuppressWarnings("NoSynchronizedMethodCheck")
189185
public synchronized void changeCaptureFormat(
190-
final int width, final int height, final int ignoredFramerate) {
186+
final int width, final int height, final int ignoredFramerate) {
191187
checkNotDisposed();
192188

193189
this.width = width;
@@ -213,8 +209,8 @@ public void run() {
213209
private void createVirtualDisplay() {
214210
surfaceTextureHelper.setTextureSize(width, height);
215211
virtualDisplay = mediaProjection.createVirtualDisplay("WebRTC_ScreenCapture", width, height,
216-
VIRTUAL_DISPLAY_DPI, DISPLAY_FLAGS, new Surface(surfaceTextureHelper.getSurfaceTexture()),
217-
null /* callback */, null /* callback handler */);
212+
VIRTUAL_DISPLAY_DPI, DISPLAY_FLAGS, new Surface(surfaceTextureHelper.getSurfaceTexture()),
213+
null /* callback */, null /* callback handler */);
218214
}
219215

220216
// This is called on the internal looper thread of {@Code SurfaceTextureHelper}.

0 commit comments

Comments
 (0)