@@ -750,6 +750,97 @@ static public String[] list() {
750750 return out ;
751751 }
752752
753+ // This is a temporary addition until it's decided how to bring back resolution/framerate caps to the official API.
754+ // The old way of doing things is still listed in the video tutorial:
755+ // https://processing.org/tutorials/video
756+ static public String [] getCapabilities (String device ) {
757+ for (int i =0 ; i < devices .size (); i ++) {
758+ String deviceName = assignDisplayName (devices .get (i ), i );
759+ if (devices .get (i ).getDisplayName ().equals (device ) || devices .get (i ).getName ().equals (device ) || deviceName .equals (device )) {
760+ return parseCaps (devices .get (i ));
761+ }
762+ }
763+ return new String []{};
764+ }
765+
766+ static private String [] parseCaps (Device dev ) {
767+ String [] caps = dev .getCaps ().toString ().split (";" );
768+ ArrayList <String > devCaps = new ArrayList <String >();
769+
770+ for (String cap : caps ) {
771+ if (cap .indexOf ("video/x-raw," ) == -1 ) continue ; // Looking for raw caps (excluding GLMemory stuff)
772+
773+ int indexWidth = cap .indexOf ("width" );
774+ int indexHeight = cap .indexOf ("height" );
775+ int indexFramerate = cap .indexOf ("framerate" );
776+
777+ String stringWidth = "" ;
778+ String stringHeight = "" ;
779+ String stringFramerate = "" ;
780+
781+ if (0 < indexWidth && 0 < indexHeight && 0 < indexFramerate ) {
782+ stringWidth = cap .substring (indexWidth , cap .indexOf (',' , indexWidth ));
783+ stringHeight = cap .substring (indexHeight , cap .indexOf (", format" , indexHeight ));
784+ stringFramerate = cap .substring (indexFramerate , cap .indexOf (']' , indexFramerate ));
785+ }
786+ // PApplet.println("=======>", cap);
787+ if (0 < stringHeight .indexOf ("{" )) {
788+ // A list of heights... something like "height=(int){ 448, 600 }
789+ stringHeight = stringHeight .substring (13 , stringHeight .length () - 1 );
790+ String [] values = stringHeight .split ("," );
791+ for (String value : values ) {
792+ stringHeight = "height=(int)" + value .trim ();
793+ addCapStringsToList (stringWidth , stringHeight , stringFramerate , devCaps );
794+ }
795+ } else {
796+ addCapStringsToList (stringWidth , stringHeight , stringFramerate , devCaps );
797+ }
798+ }
799+
800+ String [] out = new String [0 ];
801+ return devCaps .toArray (out );
802+ }
803+
804+ static private void addCapStringsToList (String stringWidth , String stringHeight , String stringFramerate , ArrayList <String > devCaps ) {
805+ if (0 < stringWidth .split ("=" ).length ) { // Expecting a string of the form "width=(int)1600"
806+ stringWidth = stringWidth .substring (11 );
807+ try {
808+ Integer .parseInt (stringWidth );
809+ } catch (NumberFormatException ex ) {
810+ stringHeight = "" ;
811+ }
812+ }
813+ if (0 < stringHeight .split ("=" ).length ) { // Expecting a string of the form "height=(int)896"
814+ stringHeight = stringHeight .substring (12 );
815+ try {
816+ Integer .parseInt (stringHeight );
817+ } catch (NumberFormatException ex ) {
818+ stringHeight = "" ;
819+ }
820+ }
821+ if (0 < stringFramerate .split ("=," ).length ) { // Expecting a string of the form "framerate=(fraction)[ 5/1, 10000000/333333"
822+ stringFramerate = stringFramerate .substring (stringFramerate .indexOf ("=" ));
823+ String [] fpsParts = stringFramerate .split ("," );
824+ if (1 < fpsParts .length ) {
825+ stringFramerate = fpsParts [1 ].trim ();
826+ fpsParts = stringFramerate .split ("/" );
827+ if (fpsParts .length == 2 ) {
828+ try {
829+ int fpsNumerator = Integer .parseInt (fpsParts [0 ]);
830+ int fpsDenominator = Integer .parseInt (fpsParts [1 ]);
831+ int fps = fpsNumerator / fpsDenominator ;
832+ stringFramerate = String .valueOf (fps );
833+ } catch (NumberFormatException ex ) {
834+ stringFramerate = "" ;
835+ }
836+ }
837+ }
838+ }
839+ if (!stringWidth .equals ("" ) && !stringHeight .equals ("" ) && !stringFramerate .equals ("" )) {
840+ devCaps .add ("size=" + stringWidth + "x" + stringHeight + ",fps=" + stringFramerate );
841+ }
842+ }
843+
753844 static private String assignDisplayName (Device d , int pos ) {
754845 String s = "" ;
755846 int count = 1 ;
0 commit comments