-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to detect if camera is being used by other applications? #15
Comments
@geocine Sorry for the delay . In the current version, there is no direct way to check if it is open or not. (If an error is detected, it is possible that an exception will be raised.) Maybe there is a mistake in your error checking, or perhaps you need to check in a different way... |
Correct, I'm on Windows. I'm using the demo in this repo to reproduce issue. |
(This report contains with #16 ) I was able to reproduce your problem and have investigated. Unfortunately, it seems that the DirectShow filter graph cannot fully determine that you have entered this state. The above memoized claims that it can be detected by having the filter graph play and examining its status. However, when I run playback with the capture device bound, DirectShow becomes unresponsive at that point.
In the latter case, it is possible to recover (if another application stops) by monitoring it with an interval timer, etc. Furthermore, I did a little research to see how other applications (e.g. Windows Camera, maybe UWP based) get around this. It seems that those applications use at least one method that is not DirectShow. Either way, DirectShow is positioned by MS itself as an API of the past, so don't be surprised if corner case support is flawed, although it may be preferable for FlashCap to move to the Media Foundation API. It may take some time to address this, as we have no experience with the Media Foundation API. |
Thank your for investigating |
I too find this issue very disappointing, and I find the API design that does not attempt to address it offensive, considering that even though DirectShow is an old technology, it is still used in a wide variety of applications ☹ |
事实上 在实际使用时在启动时就判断设备是否被占用意义并不大 3~5帧的时间非常短暂,对于用户来说可能也就是眨个眼的时间,前端页面甚至连连接中的动画都不用做 对UsbCamera进行改造后的例子 private bool _hadLinked = false;
/// <summary>
/// 是否已连接成功(获取成功一次图像)
/// </summary>
/// <returns></returns>
public bool HadLinked()
{
return _hadLinked;
}
public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
{
lock (_bufferLocker)
{
// 重连完成
IsRestarting = false;
}
if (!_hadLinked)
{
_hadLinked = true;
}
return 0;
} 前端调用 bool canGrab = false;
int frameNum = 0;
{
if (_UsbCamera != null)
{
_UsbCamera.Start();
while (!canGrab
&& frameNum<5)
{
Thread.Sleep(_usbCameraTimePerFrame);
canGrab = _UsbCamera.HadLinked();
frameNum++;
}
}
Debug.WriteLine("canGrab:" + canGrab);
} |
Thanks for the useful suggestions! |
The only method I could think of is this pseudocode. Is there a more reliable/better way to do this?
I also need to know why the Camera is unable to start
The text was updated successfully, but these errors were encountered: