summaryrefslogtreecommitdiffstats
path: root/src/plugins/directshow/camera/dscamerasession.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/directshow/camera/dscamerasession.cpp')
-rw-r--r--src/plugins/directshow/camera/dscamerasession.cpp83
1 files changed, 55 insertions, 28 deletions
diff --git a/src/plugins/directshow/camera/dscamerasession.cpp b/src/plugins/directshow/camera/dscamerasession.cpp
index c309359ed..8d0c72057 100644
--- a/src/plugins/directshow/camera/dscamerasession.cpp
+++ b/src/plugins/directshow/camera/dscamerasession.cpp
@@ -130,30 +130,28 @@ void DSCameraSession::setViewfinderSettings(const QCameraViewfinderSettings &set
qreal DSCameraSession::scaledImageProcessingParameterValue(
const ImageProcessingParameterInfo &sourceValueInfo)
{
- if (sourceValueInfo.currentValue == sourceValueInfo.defaultValue) {
+ if (sourceValueInfo.currentValue == sourceValueInfo.defaultValue)
return 0.0f;
- } else if (sourceValueInfo.currentValue < sourceValueInfo.defaultValue) {
+ if (sourceValueInfo.currentValue < sourceValueInfo.defaultValue) {
return ((sourceValueInfo.currentValue - sourceValueInfo.minimumValue)
/ qreal(sourceValueInfo.defaultValue - sourceValueInfo.minimumValue))
+ (-1.0f);
- } else {
- return ((sourceValueInfo.currentValue - sourceValueInfo.defaultValue)
- / qreal(sourceValueInfo.maximumValue - sourceValueInfo.defaultValue));
}
+ return ((sourceValueInfo.currentValue - sourceValueInfo.defaultValue)
+ / qreal(sourceValueInfo.maximumValue - sourceValueInfo.defaultValue));
}
qint32 DSCameraSession::sourceImageProcessingParameterValue(
qreal scaledValue, const ImageProcessingParameterInfo &valueRange)
{
- if (qFuzzyIsNull(scaledValue)) {
+ if (qFuzzyIsNull(scaledValue))
return valueRange.defaultValue;
- } else if (scaledValue < 0.0f) {
+ if (scaledValue < 0.0f) {
return ((scaledValue - (-1.0f)) * (valueRange.defaultValue - valueRange.minimumValue))
+ valueRange.minimumValue;
- } else {
- return (scaledValue * (valueRange.maximumValue - valueRange.defaultValue))
- + valueRange.defaultValue;
}
+ return (scaledValue * (valueRange.maximumValue - valueRange.defaultValue))
+ + valueRange.defaultValue;
}
static QCameraImageProcessingControl::ProcessingParameter searchRelatedResultingParameter(
@@ -482,7 +480,7 @@ bool DSCameraSession::startPreview()
if (m_surface)
m_surface->start(m_previewSurfaceFormat);
- hr = m_filterGraph->QueryInterface(IID_IMediaControl, (void**)&pControl);
+ hr = m_filterGraph->QueryInterface(IID_IMediaControl, reinterpret_cast<void**>(&pControl));
if (FAILED(hr)) {
errorString = tr("Failed to get stream control");
goto failed;
@@ -520,7 +518,8 @@ bool DSCameraSession::stopPreview()
QString errorString;
IMediaControl* pControl = 0;
- HRESULT hr = m_filterGraph->QueryInterface(IID_IMediaControl, (void**)&pControl);
+ HRESULT hr = m_filterGraph->QueryInterface(IID_IMediaControl,
+ reinterpret_cast<void**>(&pControl));
if (FAILED(hr)) {
errorString = tr("Failed to get stream control");
goto failed;
@@ -585,10 +584,13 @@ int DSCameraSession::captureImage(const QString &fileName)
return m_imageIdCounter;
}
+ const QString ext = !m_imageEncoderSettings.codec().isEmpty()
+ ? m_imageEncoderSettings.codec().toLower()
+ : QLatin1String("jpg");
m_imageCaptureFileName = m_fileNameGenerator.generateFileName(fileName,
QMediaStorageLocation::Pictures,
QLatin1String("IMG_"),
- QLatin1String("jpg"));
+ ext);
updateReadyForCapture();
@@ -688,8 +690,9 @@ void DSCameraSession::processCapturedImage(int id,
const QImage &image,
const QString &path)
{
+ const QString format = m_imageEncoderSettings.codec();
if (captureDestinations & QCameraImageCapture::CaptureToFile) {
- if (image.save(path, "JPG")) {
+ if (image.save(path, !format.isEmpty() ? format.toUtf8().constData() : "JPG")) {
Q_EMIT imageSaved(id, path);
} else {
Q_EMIT captureError(id, QCameraImageCapture::ResourceError,
@@ -714,7 +717,7 @@ bool DSCameraSession::createFilterGraph()
// Create the filter graph
hr = CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC,
- IID_IGraphBuilder, (void**)&m_filterGraph);
+ IID_IGraphBuilder, reinterpret_cast<void**>(&m_filterGraph));
if (FAILED(hr)) {
errorString = tr("Failed to create filter graph");
goto failed;
@@ -722,7 +725,8 @@ bool DSCameraSession::createFilterGraph()
// Create the capture graph builder
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC,
- IID_ICaptureGraphBuilder2, (void**)&m_graphBuilder);
+ IID_ICaptureGraphBuilder2,
+ reinterpret_cast<void**>(&m_graphBuilder));
if (FAILED(hr)) {
errorString = tr("Failed to create graph builder");
goto failed;
@@ -756,7 +760,8 @@ bool DSCameraSession::createFilterGraph()
QString output = QString::fromWCharArray(strName);
mallocInterface->Free(strName);
if (m_sourceDeviceName.contains(output)) {
- hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&m_sourceFilter);
+ hr = pMoniker->BindToObject(nullptr, nullptr, IID_IBaseFilter,
+ reinterpret_cast<void**>(&m_sourceFilter));
if (SUCCEEDED(hr)) {
pMoniker->Release();
break;
@@ -775,7 +780,8 @@ bool DSCameraSession::createFilterGraph()
while (pEnum->Next(1, &pMoniker, NULL) == S_OK) {
IPropertyBag *pPropBag = 0;
- hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void**)(&pPropBag));
+ hr = pMoniker->BindToStorage(nullptr, nullptr, IID_IPropertyBag,
+ reinterpret_cast<void**>(&pPropBag));
if (FAILED(hr)) {
pMoniker->Release();
continue; // Don't panic yet
@@ -783,7 +789,8 @@ bool DSCameraSession::createFilterGraph()
// No need to get the description, just grab it
- hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&m_sourceFilter);
+ hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter,
+ reinterpret_cast<void**>(&m_sourceFilter));
pPropBag->Release();
pMoniker->Release();
if (SUCCEEDED(hr)) {
@@ -841,9 +848,11 @@ bool DSCameraSession::configurePreviewFormat()
{
// Resolve viewfinder settings
int settingsIndex = 0;
+ const QSize captureResolution = m_imageEncoderSettings.resolution();
+ const QSize resolution = captureResolution.isValid() ? captureResolution : m_viewfinderSettings.resolution();
QCameraViewfinderSettings resolvedViewfinderSettings;
for (const QCameraViewfinderSettings &s : qAsConst(m_supportedViewfinderSettings)) {
- if ((m_viewfinderSettings.resolution().isEmpty() || m_viewfinderSettings.resolution() == s.resolution())
+ if ((resolution.isEmpty() || resolution == s.resolution())
&& (qFuzzyIsNull(m_viewfinderSettings.minimumFrameRate()) || qFuzzyCompare((float)m_viewfinderSettings.minimumFrameRate(), (float)s.minimumFrameRate()))
&& (qFuzzyIsNull(m_viewfinderSettings.maximumFrameRate()) || qFuzzyCompare((float)m_viewfinderSettings.maximumFrameRate(), (float)s.maximumFrameRate()))
&& (m_viewfinderSettings.pixelFormat() == QVideoFrame::Format_Invalid || m_viewfinderSettings.pixelFormat() == s.pixelFormat())
@@ -887,10 +896,9 @@ bool DSCameraSession::configurePreviewFormat()
HRESULT hr;
IAMStreamConfig* pConfig = 0;
- hr = m_graphBuilder->FindInterface(&PIN_CATEGORY_CAPTURE,
- &MEDIATYPE_Video,
- m_sourceFilter,
- IID_IAMStreamConfig, (void**)&pConfig);
+ hr = m_graphBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
+ m_sourceFilter, IID_IAMStreamConfig,
+ reinterpret_cast<void**>(&pConfig));
if (FAILED(hr)) {
qWarning() << "Failed to get config for capture device";
return false;
@@ -1064,8 +1072,8 @@ void DSCameraSession::updateSourceCapabilities()
IAMVideoControl *pVideoControl = 0;
hr = m_graphBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
- m_sourceFilter,
- IID_IAMVideoControl, (void**)&pVideoControl);
+ m_sourceFilter, IID_IAMVideoControl,
+ reinterpret_cast<void**>(&pVideoControl));
if (FAILED(hr)) {
qWarning() << "Failed to get the video control";
} else {
@@ -1091,8 +1099,8 @@ void DSCameraSession::updateSourceCapabilities()
}
hr = m_graphBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
- m_sourceFilter,
- IID_IAMStreamConfig, (void**)&pConfig);
+ m_sourceFilter, IID_IAMStreamConfig,
+ reinterpret_cast<void**>(&pConfig));
if (FAILED(hr)) {
qWarning() << "failed to get config on capture device";
return;
@@ -1169,4 +1177,23 @@ void DSCameraSession::updateSourceCapabilities()
updateImageProcessingParametersInfos();
}
+QList<QSize> DSCameraSession::supportedResolutions(bool *continuous) const
+{
+ if (continuous)
+ *continuous = false;
+
+ QList<QSize> res;
+ for (auto &settings : m_supportedViewfinderSettings) {
+ auto size = settings.resolution();
+ if (!res.contains(size))
+ res << size;
+ }
+
+ std::sort(res.begin(), res.end(), [](const QSize &r1, const QSize &r2) {
+ return qlonglong(r1.width()) * r1.height() < qlonglong(r2.width()) * r2.height();
+ });
+
+ return res;
+}
+
QT_END_NAMESPACE