Comments (8)
Are you saying that if the camera device is already in use, it will open successfully but not call back?
Correct, I'm on Windows. I'm using the demo in this repo to reproduce issue.
from flashcap.
(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.
Later, when I checked the status, I found that there is the following division of cases:
- After execution of FlashCap, another application uses the same camera: Filter graph status is continue "playing".
- Before execution of FlashCap, another application uses the same camera: Filter graph status is "stopped".
In the latter case, it is possible to recover (if another application stops) by monitoring it with an interval timer, etc.
And forcing the filter graph to stop and then play. However, in the end, I don't think this hack is appealing because it doesn't solve the former problem.
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.
I have seen error codes defined in the Media Foundation API (MF_E_HW_MFT_FAILED_START_STREAMING
), which is the oldest, but newer than DirectShow. Perhaps the UWP and other high-level APIs have this under the hood.
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.
from flashcap.
Thank your for investigating
from flashcap.
事实上 在实际使用时在启动时就判断设备是否被占用意义并不大
只需要由前端程序判断 在启动相机后连续3~5帧的时间内没有帧数据返回就可以认为相机异常了
异常包括被占用或者播放到一半相机被移除
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);
}
from flashcap.
@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.)
Are you saying that if the camera device is already in use, it will open successfully but not call back?
Maybe there is a mistake in your error checking, or perhaps you need to check in a different way...
Is your environment Windows or Linux?
from flashcap.
Memoized:
- https://stackoverflow.com/questions/8655951/get-webcam-status-using-c-sharp
- https://stackoverflow.com/questions/9060480/how-in-directshow-to-know-if-the-webcam-is-used
from flashcap.
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 ☹
from flashcap.
Thanks for the useful suggestions!
from flashcap.
Related Issues (20)
- run wpf sample app HOT 3
- Avalonia 11: MVVM Community Toolkit: ObservableCollection<CaptureDeviceDescriptor> is null HOT 2
- Added ShowPropertyPage method to DirectShowDevice class HOT 1
- Need support with Avalonia Sample HOT 9
- Is there any way to set camera parameters like white balance, exposure on linux? HOT 1
- Blue screen error without stopping HOT 1
- Capture Error event handler HOT 1
- SET the power line frequency property HOT 1
- After running StartAsync() on linux, executing StopAsync() and then StartAsync(), pixelBufferArrived will not be executed again. HOT 4
- VideoCharacteristics not detected HOT 17
- Typo in Linux device enumeration HOT 3
- Reversed logic when enumerating Linux device capabilities HOT 3
- 执行OpenAsync时发生异常 HOT 1
- Elgato CamLink 4K DirectShow Pixel Format HOT 4
- Capture works first time on Linux, but not subsequent times HOT 4
- How to do shrink memory when capturing from WebCam to WPF HOT 2
- Avalonia aot 启动失败
- Is there a camera snapshot event handler? HOT 1
- AutoPixelBufferScope set PixelBuffer to null, cause allocate new PixelBuffer for every frame HOT 3
- Possible leaks in AsyncLock HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flashcap.