summaryrefslogtreecommitdiffstats
path: root/src/plugins/directshow/camera/dscamerasession.cpp
diff options
context:
space:
mode:
authorVal Doroshchuk <valentyn.doroshchuk@qt.io>2017-11-14 13:47:09 +0100
committerVaL Doroshchuk <valentyn.doroshchuk@qt.io>2018-03-21 12:56:02 +0000
commit485cb9cec54ee3b9466e730037e7480296e2ecd0 (patch)
tree79291abe5b16739070bf911e9ea818bff89b7982 /src/plugins/directshow/camera/dscamerasession.cpp
parent204b623a8cfe2b2c9fb95fcf7b71fe0f183a5302 (diff)
DirectShow: Emit an error if QCamera::start() fails
If a camera is not started successfully, then an error() should be emitted. After an error the camera's state will be QCamera::UnloadedState and status will be QCamera::UnloadedStatus. The error signal is handled when the camera is unable to set following states: QCamera::UnloadedState, QCamera::LoadedState or QCamera::LoadingState. Thus additionally to QCamera::start() an error can be emitted even when QCamera::load(), QCamera::unload(), or QCamera::stop() is called. Task-number: QTBUG-51825 Change-Id: Ib5ea08ed7983ea49a7bf8c0321cc5266a68d9144 Reviewed-by: Christian Stromme <christian.stromme@qt.io>
Diffstat (limited to 'src/plugins/directshow/camera/dscamerasession.cpp')
-rw-r--r--src/plugins/directshow/camera/dscamerasession.cpp38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/plugins/directshow/camera/dscamerasession.cpp b/src/plugins/directshow/camera/dscamerasession.cpp
index 9b642872a..ca3c47cb8 100644
--- a/src/plugins/directshow/camera/dscamerasession.cpp
+++ b/src/plugins/directshow/camera/dscamerasession.cpp
@@ -441,30 +441,33 @@ bool DSCameraSession::startPreview()
setStatus(QCamera::StartingStatus);
+ QString errorString;
HRESULT hr = S_OK;
IMediaControl* pControl = 0;
if (!configurePreviewFormat()) {
- qWarning() << "Failed to configure preview format";
+ errorString = tr("Failed to configure preview format");
goto failed;
}
- if (!connectGraph())
+ if (!connectGraph()) {
+ errorString = tr("Failed to connect graph");
goto failed;
+ }
if (m_surface)
m_surface->start(m_previewSurfaceFormat);
hr = m_filterGraph->QueryInterface(IID_IMediaControl, (void**)&pControl);
if (FAILED(hr)) {
- qWarning() << "failed to get stream control";
+ errorString = tr("Failed to get stream control");
goto failed;
}
hr = pControl->Run();
pControl->Release();
if (FAILED(hr)) {
- qWarning() << "failed to start";
+ errorString = tr("Failed to start");
goto failed;
}
@@ -477,7 +480,7 @@ failed:
if (m_surface && m_surface->isActive())
m_surface->stop();
disconnectGraph();
- setStatus(QCamera::LoadedStatus);
+ setError(QCamera::CameraError, errorString);
return false;
}
@@ -491,17 +494,18 @@ bool DSCameraSession::stopPreview()
if (m_previewSampleGrabber)
m_previewSampleGrabber->stop();
+ QString errorString;
IMediaControl* pControl = 0;
HRESULT hr = m_filterGraph->QueryInterface(IID_IMediaControl, (void**)&pControl);
if (FAILED(hr)) {
- qWarning() << "failed to get stream control";
+ errorString = tr("Failed to get stream control");
goto failed;
}
hr = pControl->Stop();
pControl->Release();
if (FAILED(hr)) {
- qWarning() << "failed to stop";
+ errorString = tr("Failed to stop");
goto failed;
}
@@ -514,10 +518,16 @@ bool DSCameraSession::stopPreview()
return true;
failed:
- setStatus(QCamera::ActiveStatus);
+ setError(QCamera::CameraError, errorString);
return false;
}
+void DSCameraSession::setError(int error, const QString &errorString)
+{
+ emit cameraError(error, errorString);
+ setStatus(QCamera::UnloadedStatus);
+}
+
void DSCameraSession::setStatus(QCamera::Status status)
{
if (m_status == status)
@@ -668,6 +678,7 @@ bool DSCameraSession::createFilterGraph()
// Previously containered in <qedit.h>.
static const CLSID cLSID_NullRenderer = { 0xC1F400A4, 0x3F08, 0x11d3, { 0x9F, 0x0B, 0x00, 0x60, 0x08, 0x03, 0x9E, 0x37 } };
+ QString errorString;
HRESULT hr;
IMoniker* pMoniker = NULL;
ICreateDevEnum* pDevEnum = NULL;
@@ -677,7 +688,7 @@ bool DSCameraSession::createFilterGraph()
hr = CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC,
IID_IGraphBuilder, (void**)&m_filterGraph);
if (FAILED(hr)) {
- qWarning() << "failed to create filter graph";
+ errorString = tr("Failed to create filter graph");
goto failed;
}
@@ -685,14 +696,14 @@ bool DSCameraSession::createFilterGraph()
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC,
IID_ICaptureGraphBuilder2, (void**)&m_graphBuilder);
if (FAILED(hr)) {
- qWarning() << "failed to create graph builder";
+ errorString = tr("Failed to create graph builder");
goto failed;
}
// Attach the filter graph to the capture graph
hr = m_graphBuilder->SetFiltergraph(m_filterGraph);
if (FAILED(hr)) {
- qWarning() << "failed to connect capture graph and filter graph";
+ errorString = tr("Failed to connect capture graph and filter graph");
goto failed;
}
@@ -762,7 +773,7 @@ bool DSCameraSession::createFilterGraph()
}
if (!m_sourceFilter) {
- qWarning() << "No capture device found";
+ errorString = tr("No capture device found");
goto failed;
}
@@ -779,7 +790,7 @@ bool DSCameraSession::createFilterGraph()
hr = CoCreateInstance(cLSID_NullRenderer, NULL, CLSCTX_INPROC,
IID_IBaseFilter, (void**)&m_nullRendererFilter);
if (FAILED(hr)) {
- qWarning() << "failed to create null renderer";
+ errorString = tr("Failed to create null renderer");
goto failed;
}
@@ -793,6 +804,7 @@ failed:
SAFE_RELEASE(m_nullRendererFilter);
SAFE_RELEASE(m_filterGraph);
SAFE_RELEASE(m_graphBuilder);
+ setError(QCamera::CameraError, errorString);
return false;
}