Disabled special Blackmagic capture card support by default.
This commit is contained in:
parent
ce81d244e9
commit
b9d8c555ff
3 changed files with 61 additions and 44 deletions
|
|
@ -181,8 +181,6 @@ public class OpenSeeWebcamInfo : MonoBehaviour {
|
||||||
|
|
||||||
public List<OpenSeeWebcam> cameras;
|
public List<OpenSeeWebcam> cameras;
|
||||||
|
|
||||||
private bool initialized = false;
|
|
||||||
|
|
||||||
static private string ListCameraDetails_x64() {
|
static private string ListCameraDetails_x64() {
|
||||||
System.IntPtr cap = create_capture_x64();
|
System.IntPtr cap = create_capture_x64();
|
||||||
int length = get_json_length_x64(cap);
|
int length = get_json_length_x64(cap);
|
||||||
|
|
@ -215,35 +213,36 @@ public class OpenSeeWebcamInfo : MonoBehaviour {
|
||||||
return buffer.ToString();
|
return buffer.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
static public List<OpenSeeWebcam> ListCameraDetails() {
|
static public List<OpenSeeWebcam> ListCameraDetails(bool includeBlackMagic) {
|
||||||
string jsonData;
|
string jsonData = null;
|
||||||
string bmJsonData;
|
string bmJsonData = null;
|
||||||
if (Environment.Is64BitProcess) {
|
if (Environment.Is64BitProcess) {
|
||||||
jsonData = ListCameraDetails_x64();
|
jsonData = ListCameraDetails_x64();
|
||||||
bmJsonData = ListBlackMagicDetails_x64();
|
if (includeBlackMagic)
|
||||||
|
bmJsonData = ListBlackMagicDetails_x64();
|
||||||
} else {
|
} else {
|
||||||
jsonData = ListCameraDetails_x86();
|
jsonData = ListCameraDetails_x86();
|
||||||
bmJsonData = ListBlackMagicDetails_x86();
|
if (includeBlackMagic)
|
||||||
|
bmJsonData = ListBlackMagicDetails_x86();
|
||||||
}
|
}
|
||||||
List<OpenSeeWebcam> details = JsonConvert.DeserializeObject<List<OpenSeeWebcam>>(jsonData);
|
List<OpenSeeWebcam> details = JsonConvert.DeserializeObject<List<OpenSeeWebcam>>(jsonData);
|
||||||
foreach (var cam in details)
|
foreach (var cam in details)
|
||||||
cam.type = OpenSeeWebcamType.DirectShow;
|
cam.type = OpenSeeWebcamType.DirectShow;
|
||||||
List<OpenSeeWebcam> bmDetails = JsonConvert.DeserializeObject<List<OpenSeeWebcam>>(bmJsonData);
|
if (includeBlackMagic) {
|
||||||
foreach (var cam in bmDetails)
|
List<OpenSeeWebcam> bmDetails = JsonConvert.DeserializeObject<List<OpenSeeWebcam>>(bmJsonData);
|
||||||
cam.type = OpenSeeWebcamType.Blackmagic;
|
foreach (var cam in bmDetails)
|
||||||
details.AddRange(bmDetails);
|
cam.type = OpenSeeWebcamType.Blackmagic;
|
||||||
|
details.AddRange(bmDetails);
|
||||||
|
}
|
||||||
return details;
|
return details;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Start() {
|
void Start() {
|
||||||
Initialize();
|
Initialize(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initialize() {
|
public void Initialize(bool includeBlackMagic) {
|
||||||
if (initialized)
|
cameras = ListCameraDetails(includeBlackMagic);
|
||||||
return;
|
|
||||||
initialized = true;
|
|
||||||
cameras = ListCameraDetails();
|
|
||||||
foreach (var camera in cameras)
|
foreach (var camera in cameras)
|
||||||
camera.GetPrettyCapabilities();
|
camera.GetPrettyCapabilities();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,11 @@ def resolve(name):
|
||||||
lib = None
|
lib = None
|
||||||
bm_lib = None
|
bm_lib = None
|
||||||
bm_options = None
|
bm_options = None
|
||||||
|
bm_enabled = False
|
||||||
|
|
||||||
|
def set_bm_enabled(v):
|
||||||
|
global bm_enabled
|
||||||
|
bm_enabled = v
|
||||||
|
|
||||||
def set_options(str):
|
def set_options(str):
|
||||||
global bm_options
|
global bm_options
|
||||||
|
|
@ -29,17 +34,20 @@ class DShowCapture():
|
||||||
global lib
|
global lib
|
||||||
global bm_lib
|
global bm_lib
|
||||||
global bm_options
|
global bm_options
|
||||||
|
global bm_enabled
|
||||||
if lib is None or bm_lib is None:
|
if lib is None or bm_lib is None:
|
||||||
if platform.architecture()[0] == '32bit':
|
if platform.architecture()[0] == '32bit':
|
||||||
dll_path = resolve(os.path.join("dshowcapture", "dshowcapture_x86.dll"))
|
dll_path = resolve(os.path.join("dshowcapture", "dshowcapture_x86.dll"))
|
||||||
lib = cdll.LoadLibrary(dll_path)
|
lib = cdll.LoadLibrary(dll_path)
|
||||||
dll_path = resolve(os.path.join("dshowcapture", "libminibmcapture32.dll"))
|
if bm_enabled:
|
||||||
bm_lib = cdll.LoadLibrary(dll_path)
|
dll_path = resolve(os.path.join("dshowcapture", "libminibmcapture32.dll"))
|
||||||
|
bm_lib = cdll.LoadLibrary(dll_path)
|
||||||
else:
|
else:
|
||||||
dll_path = resolve(os.path.join("dshowcapture", "dshowcapture_x64.dll"))
|
dll_path = resolve(os.path.join("dshowcapture", "dshowcapture_x64.dll"))
|
||||||
lib = cdll.LoadLibrary(dll_path)
|
lib = cdll.LoadLibrary(dll_path)
|
||||||
dll_path = resolve(os.path.join("dshowcapture", "libminibmcapture64.dll"))
|
if bm_enabled:
|
||||||
bm_lib = cdll.LoadLibrary(dll_path)
|
dll_path = resolve(os.path.join("dshowcapture", "libminibmcapture64.dll"))
|
||||||
|
bm_lib = cdll.LoadLibrary(dll_path)
|
||||||
|
|
||||||
# DirectShow
|
# DirectShow
|
||||||
lib.create_capture.restype = c_void_p
|
lib.create_capture.restype = c_void_p
|
||||||
|
|
@ -63,16 +71,18 @@ class DShowCapture():
|
||||||
lib.destroy_capture.argtypes = [c_void_p]
|
lib.destroy_capture.argtypes = [c_void_p]
|
||||||
|
|
||||||
# Blackmagic
|
# Blackmagic
|
||||||
bm_lib.start_capture_single.argtypes = [c_int, c_int, c_void_p]
|
if bm_enabled:
|
||||||
bm_lib.read_frame_bgra32_blocking.argtypes = [c_char_p, c_int]
|
bm_lib.start_capture_single.argtypes = [c_int, c_int, c_void_p]
|
||||||
bm_lib.stop_capture_single.argtypes = []
|
bm_lib.read_frame_bgra32_blocking.argtypes = [c_char_p, c_int]
|
||||||
bm_lib.get_json_length.argtypes = []
|
bm_lib.stop_capture_single.argtypes = []
|
||||||
bm_lib.get_json.argtypes = [c_char_p, c_int]
|
bm_lib.get_json_length.argtypes = []
|
||||||
if not bm_options is None:
|
bm_lib.get_json.argtypes = [c_char_p, c_int]
|
||||||
bm_lib.set_options.argtypes = [c_char_p]
|
if not bm_options is None:
|
||||||
bm_lib.set_options(bm_options.encode())
|
bm_lib.set_options.argtypes = [c_char_p]
|
||||||
|
bm_lib.set_options(bm_options.encode())
|
||||||
self.lib = lib
|
self.lib = lib
|
||||||
self.bm_lib = bm_lib
|
if bm_enabled:
|
||||||
|
self.bm_lib = bm_lib
|
||||||
self.cap = lib.create_capture()
|
self.cap = lib.create_capture()
|
||||||
self.name_buffer = create_string_buffer(255);
|
self.name_buffer = create_string_buffer(255);
|
||||||
self.buffer = None
|
self.buffer = None
|
||||||
|
|
@ -98,6 +108,7 @@ class DShowCapture():
|
||||||
return name_str
|
return name_str
|
||||||
|
|
||||||
def get_info(self):
|
def get_info(self):
|
||||||
|
global bm_enabled
|
||||||
# DirectShow
|
# DirectShow
|
||||||
json_length = self.lib.get_json_length(self.cap);
|
json_length = self.lib.get_json_length(self.cap);
|
||||||
json_buffer = create_string_buffer(json_length)
|
json_buffer = create_string_buffer(json_length)
|
||||||
|
|
@ -109,16 +120,17 @@ class DShowCapture():
|
||||||
cam["index"] = cam["id"]
|
cam["index"] = cam["id"]
|
||||||
|
|
||||||
# Blackmagic
|
# Blackmagic
|
||||||
json_length = self.bm_lib.get_json_length();
|
if bm_enabled:
|
||||||
json_buffer = create_string_buffer(json_length)
|
json_length = self.bm_lib.get_json_length();
|
||||||
self.bm_lib.get_json(json_buffer, json_length);
|
json_buffer = create_string_buffer(json_length)
|
||||||
json_text = str(json_buffer.value.decode('utf8'))
|
self.bm_lib.get_json(json_buffer, json_length);
|
||||||
bm_info = json.loads(json_text)
|
json_text = str(json_buffer.value.decode('utf8'))
|
||||||
dshow_len = len(self.info)
|
bm_info = json.loads(json_text)
|
||||||
for cam in bm_info:
|
dshow_len = len(self.info)
|
||||||
cam["type"] = "Blackmagic"
|
for cam in bm_info:
|
||||||
cam["index"] = cam["id"] + dshow_len
|
cam["type"] = "Blackmagic"
|
||||||
self.info.extend(bm_info)
|
cam["index"] = cam["id"] + dshow_len
|
||||||
|
self.info.extend(bm_info)
|
||||||
|
|
||||||
return self.info
|
return self.info
|
||||||
|
|
||||||
|
|
@ -142,6 +154,7 @@ class DShowCapture():
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
def capture_device_by_dcap(self, cam, dcap, width, height, fps):
|
def capture_device_by_dcap(self, cam, dcap, width, height, fps):
|
||||||
|
global bm_enabled
|
||||||
if not self.have_devices:
|
if not self.have_devices:
|
||||||
self.get_devices()
|
self.get_devices()
|
||||||
if self.info is None:
|
if self.info is None:
|
||||||
|
|
@ -150,7 +163,7 @@ class DShowCapture():
|
||||||
ret = False
|
ret = False
|
||||||
if self.info[cam]['type'] == "DirectShow":
|
if self.info[cam]['type'] == "DirectShow":
|
||||||
ret = self.lib.capture_device_by_dcap(self.cap, cam, dcap, width, height, fps) == 1
|
ret = self.lib.capture_device_by_dcap(self.cap, cam, dcap, width, height, fps) == 1
|
||||||
elif self.info[cam]['type'] == "Blackmagic":
|
elif bm_enabled and self.info[cam]['type'] == "Blackmagic":
|
||||||
ret = self.bm_lib.start_capture_single(self.info[cam]['id'], self.info[cam]['caps'][dcap]['bmModecode'], None) == 1
|
ret = self.bm_lib.start_capture_single(self.info[cam]['id'], self.info[cam]['caps'][dcap]['bmModecode'], None) == 1
|
||||||
if ret:
|
if ret:
|
||||||
self.type = self.info[cam]['type']
|
self.type = self.info[cam]['type']
|
||||||
|
|
@ -163,7 +176,7 @@ class DShowCapture():
|
||||||
self.colorspace_internal = self.get_colorspace_internal()
|
self.colorspace_internal = self.get_colorspace_internal()
|
||||||
self.size = self.width * self.height * 4 * 4
|
self.size = self.width * self.height * 4 * 4
|
||||||
self.buffer = create_frame_buffer(self.width, self.height, 4)
|
self.buffer = create_frame_buffer(self.width, self.height, 4)
|
||||||
elif self.type == "Blackmagic":
|
elif bm_enabled and self.type == "Blackmagic":
|
||||||
self.width = self.info[cam]['caps'][dcap]['minCX']
|
self.width = self.info[cam]['caps'][dcap]['minCX']
|
||||||
self.height = self.info[cam]['caps'][dcap]['minCY']
|
self.height = self.info[cam]['caps'][dcap]['minCY']
|
||||||
self.fps = int(10000000 / self.info[cam]['caps'][dcap]['minInterval'])
|
self.fps = int(10000000 / self.info[cam]['caps'][dcap]['minInterval'])
|
||||||
|
|
@ -224,11 +237,12 @@ class DShowCapture():
|
||||||
return self.lib.capturing(self.cap) == 1
|
return self.lib.capturing(self.cap) == 1
|
||||||
|
|
||||||
def get_frame(self, timeout):
|
def get_frame(self, timeout):
|
||||||
|
global bm_enabled
|
||||||
if self.size is None:
|
if self.size is None:
|
||||||
return None
|
return None
|
||||||
if self.type == "DirectShow":
|
if self.type == "DirectShow":
|
||||||
self.real_size = self.lib.get_frame(self.cap, timeout, self.buffer, self.size)
|
self.real_size = self.lib.get_frame(self.cap, timeout, self.buffer, self.size)
|
||||||
elif self.type == "Blackmagic":
|
elif bm_enabled and self.type == "Blackmagic":
|
||||||
self.bm_lib.read_frame_bgra32_blocking(self.buffer, self.size)
|
self.bm_lib.read_frame_bgra32_blocking(self.buffer, self.size)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
@ -266,11 +280,12 @@ class DShowCapture():
|
||||||
return img
|
return img
|
||||||
|
|
||||||
def stop_capture(self):
|
def stop_capture(self):
|
||||||
|
global bm_enabled
|
||||||
self.size = None
|
self.size = None
|
||||||
self.real_size = None
|
self.real_size = None
|
||||||
if self.type == "DirectShow":
|
if self.type == "DirectShow":
|
||||||
return self.lib.stop_capture(self.cap)
|
return self.lib.stop_capture(self.cap)
|
||||||
elif self.type == "Blackmagic":
|
elif bm_enabled and self.type == "Blackmagic":
|
||||||
return self.bm_lib.stop_capture_single() != 0
|
return self.bm_lib.stop_capture_single() != 0
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ if os.name == 'nt':
|
||||||
parser.add_argument("-H", "--height", type=int, help="Set camera and raw RGB height", default=360)
|
parser.add_argument("-H", "--height", type=int, help="Set camera and raw RGB height", default=360)
|
||||||
parser.add_argument("-F", "--fps", type=int, help="Set camera frames per second", default=24)
|
parser.add_argument("-F", "--fps", type=int, help="Set camera frames per second", default=24)
|
||||||
parser.add_argument("-D", "--dcap", type=int, help="Set which device capability line to use or -1 to use the default camera settings", default=None)
|
parser.add_argument("-D", "--dcap", type=int, help="Set which device capability line to use or -1 to use the default camera settings", default=None)
|
||||||
|
parser.add_argument("-B", "--blackmagic", type=int, help="When set to 1, special support for Blackmagic devices is enabled", default=0)
|
||||||
else:
|
else:
|
||||||
parser.add_argument("-W", "--width", type=int, help="Set raw RGB width", default=640)
|
parser.add_argument("-W", "--width", type=int, help="Set raw RGB width", default=640)
|
||||||
parser.add_argument("-H", "--height", type=int, help="Set raw RGB height", default=360)
|
parser.add_argument("-H", "--height", type=int, help="Set raw RGB height", default=360)
|
||||||
|
|
@ -73,6 +74,8 @@ sys.stderr = OutputLog(output_logfile, sys.stderr)
|
||||||
|
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
import dshowcapture
|
import dshowcapture
|
||||||
|
if args.blackmagic == 1:
|
||||||
|
dshowcapture.set_bm_enabled(True)
|
||||||
if not args.blackmagic_options is None:
|
if not args.blackmagic_options is None:
|
||||||
dshowcapture.set_options(args.blackmagic_options)
|
dshowcapture.set_options(args.blackmagic_options)
|
||||||
if not args.priority is None:
|
if not args.priority is None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue