mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 929431 - Don't reinitialize DirectShow if it's not actually needed. r=jesup
This commit is contained in:
parent
94d8b1868c
commit
18c8edb589
@ -132,7 +132,7 @@ int32_t VideoCaptureDS::Init(const int32_t id, const char* deviceUniqueIdUTF8)
|
||||
|
||||
// Temporary connect here.
|
||||
// This is done so that no one else can use the capture device.
|
||||
if (SetCameraOutput(_requestedCapability) != 0)
|
||||
if (SetCameraOutputIfNeeded(_requestedCapability) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -154,15 +154,11 @@ int32_t VideoCaptureDS::StartCapture(
|
||||
{
|
||||
CriticalSectionScoped cs(&_apiCs);
|
||||
|
||||
if (capability != _requestedCapability)
|
||||
if (SetCameraOutputIfNeeded(capability) != 0)
|
||||
{
|
||||
DisconnectGraph();
|
||||
|
||||
if (SetCameraOutput(capability) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
HRESULT hr = _mediaControl->Run();
|
||||
if (FAILED(hr))
|
||||
{
|
||||
@ -186,6 +182,7 @@ int32_t VideoCaptureDS::StopCapture()
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool VideoCaptureDS::CaptureStarted()
|
||||
{
|
||||
OAFilterState state = 0;
|
||||
@ -200,6 +197,7 @@ bool VideoCaptureDS::CaptureStarted()
|
||||
return state == State_Running;
|
||||
|
||||
}
|
||||
|
||||
int32_t VideoCaptureDS::CaptureSettings(
|
||||
VideoCaptureCapability& settings)
|
||||
{
|
||||
@ -207,16 +205,13 @@ int32_t VideoCaptureDS::CaptureSettings(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t VideoCaptureDS::SetCameraOutput(
|
||||
const VideoCaptureCapability& requestedCapability)
|
||||
int32_t VideoCaptureDS::SetCameraOutputIfNeeded(
|
||||
const VideoCaptureCapability& requestedCapability)
|
||||
{
|
||||
|
||||
// Get the best matching capability
|
||||
VideoCaptureCapability capability;
|
||||
int32_t capabilityIndex;
|
||||
|
||||
// Store the new requested size
|
||||
_requestedCapability = requestedCapability;
|
||||
// Match the requested capability with the supported.
|
||||
if ((capabilityIndex = _dsInfo.GetBestMatchedCapability(_deviceUniqueId,
|
||||
_requestedCapability,
|
||||
@ -224,6 +219,16 @@ int32_t VideoCaptureDS::SetCameraOutput(
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (capability != _activeCapability) {
|
||||
DisconnectGraph();
|
||||
// Store the new mode the camera actually selected
|
||||
_activeCapability = capability;
|
||||
} else {
|
||||
// Camera selected the same mode, nothing to do
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Reduce the frame rate if possible.
|
||||
if (capability.maxFPS > requestedCapability.maxFPS)
|
||||
{
|
||||
@ -232,9 +237,17 @@ int32_t VideoCaptureDS::SetCameraOutput(
|
||||
{
|
||||
capability.maxFPS = 30;
|
||||
}
|
||||
|
||||
// Store the new expected capture delay
|
||||
_captureDelay = capability.expectedCaptureDelay;
|
||||
|
||||
return SetCameraOutput(capability, capabilityIndex);
|
||||
}
|
||||
|
||||
int32_t VideoCaptureDS::SetCameraOutput(
|
||||
const VideoCaptureCapability& capability,
|
||||
int32_t capabilityIndex)
|
||||
{
|
||||
// Convert it to the windows capability index since they are not nexessary
|
||||
// the same
|
||||
VideoCaptureCapabilityWindows windowsCapability;
|
||||
|
@ -53,13 +53,17 @@ protected:
|
||||
virtual ~VideoCaptureDS();
|
||||
|
||||
// Help functions
|
||||
|
||||
int32_t
|
||||
SetCameraOutput(const VideoCaptureCapability& requestedCapability);
|
||||
SetCameraOutputIfNeeded(const VideoCaptureCapability& requestedCapability);
|
||||
int32_t
|
||||
SetCameraOutput(const VideoCaptureCapability& requestedCapability,
|
||||
int32_t capabilityIndex);
|
||||
|
||||
int32_t DisconnectGraph();
|
||||
HRESULT VideoCaptureDS::ConnectDVCamera();
|
||||
|
||||
DeviceInfoDS _dsInfo;
|
||||
VideoCaptureCapability _activeCapability;
|
||||
|
||||
IBaseFilter* _captureFilter;
|
||||
IGraphBuilder* _graphBuilder;
|
||||
|
Loading…
Reference in New Issue
Block a user