Giter Site home page Giter Site logo

Comments (8)

geocine avatar geocine commented on May 24, 2024 1

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.

kekyo avatar kekyo commented on May 24, 2024 1

(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.

geocine avatar geocine commented on May 24, 2024 1

Thank your for investigating

from flashcap.

yangjieshao avatar yangjieshao commented on May 24, 2024 1

事实上 在实际使用时在启动时就判断设备是否被占用意义并不大
只需要由前端程序判断 在启动相机后连续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.

kekyo avatar kekyo commented on May 24, 2024

@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.

kekyo avatar kekyo commented on May 24, 2024

Memoized:

from flashcap.

kekyo avatar kekyo commented on May 24, 2024

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.

kekyo avatar kekyo commented on May 24, 2024

Thanks for the useful suggestions!

from flashcap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.