[chronojump] webcam better parse of devices on win and mac
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] webcam better parse of devices on win and mac
- Date: Fri, 5 Apr 2019 15:40:29 +0000 (UTC)
commit 05dc499b061eaefabeab54865004bc5971cc2d84
Author: Xavier de Blas <xaviblas gmail com>
Date: Fri Apr 5 17:39:49 2019 +0200
webcam better parse of devices on win and mac
src/webcamFfmpegDevices.cs | 54 +++++++++++++++++++++++++++++++++++++++-------
1 file changed, 46 insertions(+), 8 deletions(-)
---
diff --git a/src/webcamFfmpegDevices.cs b/src/webcamFfmpegDevices.cs
index c7ab69aa..341c483c 100644
--- a/src/webcamFfmpegDevices.cs
+++ b/src/webcamFfmpegDevices.cs
@@ -225,27 +225,30 @@ public abstract class WebcamFfmpegGetDevicesWinMac : WebcamFfmpegGetDevices
StringSplitOptions.None
);
+ bool started = false;
foreach(string l in lines)
{
LogB.Information("line: " + l);
- foreach(Match match in Regex.Matches(l, "\"([^\"]*)\""))
- {
- //remove quotes from the match (at beginning and end) to add it in SQL
- string s = match.ToString().Substring(1, match.ToString().Length -2);
- LogB.Information("add match: " + s);
- if(s.Length < 3)
- break;
+ //devices start after the videoDevString line
+ if(! started)
+ {
+ if(l.Contains(videoDevString))
+ started = true;
- wd_list.Add(new WebcamDevice(s[1].ToString(), s)); //code will be char 1:
"[0] my device"
+ continue;
}
+ parseMatch(l);
+
//after the list of video devices comes the list of audio devices, skip it
if(l.Contains(audioDevString))
break;
}
}
+ protected abstract void parseMatch(string l);
+
protected bool executableExists()
{
return File.Exists(executable);
@@ -278,6 +281,21 @@ public class WebcamFfmpegGetDevicesWindows : WebcamFfmpegGetDevicesWinMac
return parameters;
}
+
+ protected override void parseMatch(string l)
+ {
+ foreach(Match match in Regex.Matches(l, "\"([^\"]*)\""))
+ {
+ //remove quotes from the match (at beginning and end) to add it in SQL
+ string s = match.ToString().Substring(1, match.ToString().Length -2);
+
+ LogB.Information("add match: " + s);
+ if(s.Length < 3)
+ break;
+
+ wd_list.Add(new WebcamDevice(s[1].ToString(), s)); //code will be char 1: "[0] my
device"
+ }
+ }
}
public class WebcamFfmpegGetDevicesMac : WebcamFfmpegGetDevicesWinMac
@@ -306,4 +324,24 @@ public class WebcamFfmpegGetDevicesMac : WebcamFfmpegGetDevicesWinMac
return parameters;
}
+
+ protected override void parseMatch(string l)
+ {
+ if(! l.Contains("AVFoundation input device"))
+ return;
+
+ int firstBracketEnd = l.IndexOf(']');
+ if(firstBracketEnd > 0 && l.Length > firstBracketEnd + 2)
+ {
+ string s = l.Substring(firstBracketEnd);
+ int secondBracketStart = s.IndexOf('[');
+
+ if(secondBracketStart > 0 && s.Length > secondBracketStart + 2)
+ {
+ s = s.Substring(secondBracketStart);
+ LogB.Information("MAC matchPARSE: ***" + s + "***");
+ wd_list.Add(new WebcamDevice(s[1].ToString(), s));
+ }
+ }
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]