@@ -88,7 +88,7 @@ class GetUserMediaImpl {
88
88
private static final String PERMISSION_AUDIO = Manifest .permission .RECORD_AUDIO ;
89
89
private static final String PERMISSION_VIDEO = Manifest .permission .CAMERA ;
90
90
private static final String PERMISSION_SCREEN = "android.permission.MediaProjection" ;
91
- private static int CAPTURE_PERMISSION_REQUEST_CODE = 1 ;
91
+ private static final int CAPTURE_PERMISSION_REQUEST_CODE = 1 ;
92
92
private static final String GRANT_RESULTS = "GRANT_RESULT" ;
93
93
private static final String PERMISSIONS = "PERMISSION" ;
94
94
private static final String PROJECTION_DATA = "PROJECTION_DATA" ;
@@ -103,8 +103,6 @@ class GetUserMediaImpl {
103
103
private final Context applicationContext ;
104
104
105
105
static final int minAPILevel = Build .VERSION_CODES .LOLLIPOP ;
106
- private MediaProjectionManager mProjectionManager = null ;
107
- private static MediaProjection sMediaProjection = null ;
108
106
109
107
final AudioSamplesInterceptor inputSamplesInterceptor = new AudioSamplesInterceptor ();
110
108
private OutputAudioSamplesInterceptor outputSamplesInterceptor = null ;
@@ -351,23 +349,6 @@ private AudioTrack getUserAudio(ConstraintsMap constraints) {
351
349
void getUserMedia (
352
350
final ConstraintsMap constraints , final Result result , final MediaStream mediaStream ) {
353
351
354
- // TODO: change getUserMedia constraints format to support new syntax
355
- // constraint format seems changed, and there is no mandatory any more.
356
- // and has a new syntax/attrs to specify resolution
357
- // should change `parseConstraints()` according
358
- // see: https://www.w3.org/TR/mediacapture-streams/#idl-def-MediaTrackConstraints
359
-
360
- ConstraintsMap videoConstraintsMap = null ;
361
- ConstraintsMap videoConstraintsMandatory = null ;
362
-
363
- if (constraints .getType ("video" ) == ObjectType .Map ) {
364
- videoConstraintsMap = constraints .getMap ("video" );
365
- if (videoConstraintsMap .hasKey ("mandatory" )
366
- && videoConstraintsMap .getType ("mandatory" ) == ObjectType .Map ) {
367
- videoConstraintsMandatory = videoConstraintsMap .getMap ("mandatory" );
368
- }
369
- }
370
-
371
352
final ArrayList <String > requestPermissions = new ArrayList <>();
372
353
373
354
if (constraints .hasKey ("audio" )) {
@@ -441,18 +422,6 @@ public void invoke(Object... args) {
441
422
442
423
void getDisplayMedia (
443
424
final ConstraintsMap constraints , final Result result , final MediaStream mediaStream ) {
444
- ConstraintsMap videoConstraintsMap = null ;
445
- ConstraintsMap videoConstraintsMandatory = null ;
446
-
447
- if (constraints .getType ("video" ) == ObjectType .Map ) {
448
- videoConstraintsMap = constraints .getMap ("video" );
449
- if (videoConstraintsMap .hasKey ("mandatory" )
450
- && videoConstraintsMap .getType ("mandatory" ) == ObjectType .Map ) {
451
- videoConstraintsMandatory = videoConstraintsMap .getMap ("mandatory" );
452
- }
453
- }
454
-
455
- final ConstraintsMap videoConstraintsMandatory2 = videoConstraintsMandatory ;
456
425
457
426
screenRequestPremissions (
458
427
new ResultReceiver (new Handler (Looper .getMainLooper ())) {
@@ -640,6 +609,34 @@ private void getUserMedia(
640
609
641
610
private boolean isFacing = true ;
642
611
612
+ /**
613
+ * @return Returns the integer at the key, or the `ideal` property if it is a map.
614
+ */
615
+ @ Nullable
616
+ private Integer getConstrainInt (@ Nullable ConstraintsMap constraintsMap , String key ) {
617
+ if (constraintsMap == null ){
618
+ return null ;
619
+ }
620
+
621
+ if (constraintsMap .getType (key ) == ObjectType .Number ) {
622
+ try {
623
+ return constraintsMap .getInt (key );
624
+ } catch (Exception e ) {
625
+ // Could be a double instead
626
+ return (int ) Math .round (constraintsMap .getDouble (key ));
627
+ }
628
+ }
629
+
630
+ if (constraintsMap .getType (key ) == ObjectType .Map ) {
631
+ ConstraintsMap innerMap = constraintsMap .getMap (key );
632
+ if (constraintsMap .getType ("ideal" ) == ObjectType .Number ) {
633
+ return innerMap .getInt ("ideal" );
634
+ }
635
+ }
636
+
637
+ return null ;
638
+ }
639
+
643
640
private VideoTrack getUserVideo (ConstraintsMap constraints ) {
644
641
ConstraintsMap videoConstraintsMap = null ;
645
642
ConstraintsMap videoConstraintsMandatory = null ;
@@ -651,6 +648,7 @@ private VideoTrack getUserVideo(ConstraintsMap constraints) {
651
648
}
652
649
}
653
650
651
+
654
652
Log .i (TAG , "getUserMedia(video): " + videoConstraintsMap );
655
653
656
654
// NOTE: to support Camera2, the device should:
@@ -688,16 +686,25 @@ private VideoTrack getUserVideo(ConstraintsMap constraints) {
688
686
surfaceTextureHelper , applicationContext , videoSource .getCapturerObserver ());
689
687
690
688
VideoCapturerInfo info = new VideoCapturerInfo ();
691
- info .width =
692
- videoConstraintsMandatory != null && videoConstraintsMandatory .hasKey ("minWidth" )
689
+
690
+ Integer videoWidth = getConstrainInt (videoConstraintsMap , "width" );
691
+ info .width = videoWidth != null
692
+ ? videoWidth
693
+ : videoConstraintsMandatory != null && videoConstraintsMandatory .hasKey ("minWidth" )
693
694
? videoConstraintsMandatory .getInt ("minWidth" )
694
695
: DEFAULT_WIDTH ;
695
- info .height =
696
- videoConstraintsMandatory != null && videoConstraintsMandatory .hasKey ("minHeight" )
696
+
697
+ Integer videoHeight = getConstrainInt (videoConstraintsMap , "height" );
698
+ info .height = videoHeight != null
699
+ ? videoHeight
700
+ : videoConstraintsMandatory != null && videoConstraintsMandatory .hasKey ("minHeight" )
697
701
? videoConstraintsMandatory .getInt ("minHeight" )
698
702
: DEFAULT_HEIGHT ;
699
- info .fps =
700
- videoConstraintsMandatory != null && videoConstraintsMandatory .hasKey ("minFrameRate" )
703
+
704
+ Integer videoFrameRate = getConstrainInt (videoConstraintsMap , "frameRate" );
705
+ info .fps = videoFrameRate != null
706
+ ? videoFrameRate
707
+ : videoConstraintsMandatory != null && videoConstraintsMandatory .hasKey ("minFrameRate" )
701
708
? videoConstraintsMandatory .getInt ("minFrameRate" )
702
709
: DEFAULT_FPS ;
703
710
info .capturer = videoCapturer ;
0 commit comments