public static bool IsVideoDeviceConnected(string altname) { if (string.IsNullOrEmpty(altname)) { return(true); // NONE selected - don't show watermark in this case. } int success = DirectShowDevices.buildDeviceNamesFind(DirectShowDevices.DEVICETYPE.VideoCaptureDevice, altname); return(success == 0); }
public static void BuildDeviceList() { devices.Clear(); IntPtr devCtx = DirectShowDevices.buildDeviceList(DirectShowDevices.DEVICETYPE.AudioCaptureDevice); int numDevices = DirectShowDevices.getNumberDevices(devCtx); if (numDevices == 0) { DirectShowDevices.freeDeviceList(DirectShowDevices.DEVICETYPE.AudioCaptureDevice, devCtx); return; } string tmpStrAltName = string.Empty; string tmpName = string.Empty; for (int i = 0; i < numDevices; i++) { DeviceInfo devInfo = new DeviceInfo(); //save the friendly name DirectShowDevices.getDeviceNameFromStr(devCtx, out tmpName, i); devInfo.name = tmpName; //save the alternative name DirectShowDevices.getDeviceAltNameFromStr(devCtx, out tmpStrAltName, i); devInfo.altname = tmpStrAltName.ToString(); //set the device index from built list devInfo.deviceIndex = i; devInfo.outputs.Clear(); int numStreams = DirectShowDevices.getNumStreamParamsInDeviceFromIndex(devCtx, i); List <AudioInfo> checkDuplicates = new List <AudioInfo>(); for (int j = 0; j < numStreams; j++) { DirectShowDevices.AudioStreamParams tmpParams = new DirectShowDevices.AudioStreamParams(); AudioInfo outputInfo = new AudioInfo(); DirectShowDevices.getAudioStreamParamsInDeviceFromIndex(devCtx, out tmpParams, i, j); outputInfo.channel = tmpParams.nChannels; outputInfo.samplingRate = tmpParams.nSamplesPerSec; outputInfo.avgBytesPerSec = tmpParams.nAvgBytesPerSec; outputInfo.blockAlign = tmpParams.nBlockAlign; outputInfo.bitPerSample = tmpParams.wBitsPerSample; //check duplicates bool found = false; //find duplicate resolutions, and remove the lower framerate ones, first by producing a list of them foreach (var a in checkDuplicates) { if (a.channel == outputInfo.channel && a.samplingRate == outputInfo.samplingRate && a.avgBytesPerSec == tmpParams.nAvgBytesPerSec && a.blockAlign == tmpParams.nBlockAlign) { found = true; //found first occurence, we can get out of here break; } } if (found == false) { checkDuplicates.Add(outputInfo); } AddOutputEntry(devInfo, outputInfo); } //add this device to the list along with its stream info if (devInfo.outputs.Count > 0) { devInfo.outputs.Sort(SortEntriesDescendingBytesPerSec); devices.Add(devInfo); } tmpStrAltName = null; } DirectShowDevices.freeDeviceList(DirectShowDevices.DEVICETYPE.AudioCaptureDevice, devCtx); RebuildMixCastAudioDevices(44100); }
public static void BuildDeviceList() { devices.Clear(); IntPtr devCtx = DirectShowDevices.buildDeviceList(DirectShowDevices.DEVICETYPE.VideoCaptureDevice); int numDevices = DirectShowDevices.getNumberDevices(devCtx); if (numDevices == 0) { DirectShowDevices.freeDeviceList(DirectShowDevices.DEVICETYPE.VideoCaptureDevice, devCtx); return; } string tmpStrAltName = string.Empty; string tmpName = string.Empty; for (int i = 0; i < numDevices; i++) { DeviceInfo devInfo = new DeviceInfo(); //save the friendly name DirectShowDevices.getDeviceNameFromStr(devCtx, out tmpName, i); devInfo.name = tmpName; //Filter out StarGazer's other sensors "Intel(R) RealSense(TM) Camera SR300" other than the RGB if (devInfo.name.ToLower().Contains("sr300") && !devInfo.name.ToLower().Contains("rgb")) { continue; } //save the alternative name DirectShowDevices.getDeviceAltNameFromStr(devCtx, out tmpStrAltName, i); devInfo.altname = tmpStrAltName; //set the device index from built list devInfo.deviceIndex = i; devInfo.outputs.Clear(); int numStreams = DirectShowDevices.getNumStreamParamsInDeviceFromIndex(devCtx, i); List <OutputInfo> checkDuplicates = new List <OutputInfo>(); List <OutputInfo> removeTheseDuplicates = new List <OutputInfo>(); for (int j = 0; j < numStreams; j++) { DirectShowDevices.VideoStreamParams tmpParams = new DirectShowDevices.VideoStreamParams(); StringBuilder tmpPixelFormat = new StringBuilder(50); OutputInfo outputInfo = new OutputInfo(); DirectShowDevices.getVideoStreamParamsInDeviceFromIndex(devCtx, out tmpParams, i, j); outputInfo.bitrate = tmpParams.bitrate; outputInfo.height = tmpParams.height; outputInfo.width = tmpParams.width; outputInfo.framerate = tmpParams.framerate; outputInfo.numPlanes = tmpParams.numPlanes; outputInfo.bitsPerPixel = tmpParams.bitsPerPixel; DirectShowDevices.avPixFmtToString(tmpParams.pixFmt, tmpPixelFormat); outputInfo.pixelFormat = tmpPixelFormat.ToString(); if (outputInfo.width == 0 || outputInfo.height == 0) { continue; } //check duplicates bool found = false; //find duplicate resolutions, and remove the lower framerate ones, first by producing a list of them foreach (var a in checkDuplicates) { if (a.width == outputInfo.width && a.height == outputInfo.height && a.pixelFormat == outputInfo.pixelFormat) { found = true; //if the stored info has higher framerate if (a.framerate > outputInfo.framerate) { //keep the stored one and remove the one we just used to compare, outputInfo removeTheseDuplicates.Add(outputInfo); } else if (a.framerate < outputInfo.framerate) { //keep the new one and remove the old one removeTheseDuplicates.Add(a); checkDuplicates.Remove(a); checkDuplicates.Add(outputInfo); } //found first occurence, we can get out of here break; } } if (found == false) { checkDuplicates.Add(outputInfo); } AddOutputEntry(devInfo, outputInfo); } //remove the lower framerates of duplicate resolutions and pixel format if (devInfo.outputs.Count > 0) { foreach (var a in removeTheseDuplicates) { devInfo.outputs.Remove(a); } } //add this device to the list along with its stream info if (devInfo.outputs.Count > 0) { devices.Add(devInfo); } removeTheseDuplicates.Clear(); checkDuplicates.Clear(); removeTheseDuplicates = null; checkDuplicates = null; } tmpStrAltName = null; DirectShowDevices.freeDeviceList(DirectShowDevices.DEVICETYPE.VideoCaptureDevice, devCtx); ProcessRealSenseInput(); }