AVCaptureDeviceFormat - avoid duplicates (OS X/iOS)

Excluding video range (iOS) is not the right way to avoid "duplicates" - with
other devices there can be also duplicates (formats with the same resolutions),
but completely different pixel formats. Since we do not know what they will be in advance,
we take the media subtype from the initial preset for a capture device and use it
as a filter. Update viewfinder and image encoder settings controls.

Change-Id: If20aea24b19b43574d5c3e9bf2ba85f50fc08916
Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
This commit is contained in:
Timur Pocheptsov
2015-03-04 16:34:32 +01:00
parent dbcf44247d
commit f839f9e3eb
6 changed files with 141 additions and 94 deletions

View File

@@ -41,6 +41,7 @@
#include "avfmediavideoprobecontrol.h"
#include "avfcameraviewfindersettingscontrol.h"
#include "avfimageencodercontrol.h"
#include "avfcamerautility.h"
#include <CoreFoundation/CoreFoundation.h>
#include <Foundation/Foundation.h>
@@ -143,6 +144,7 @@ AVFCameraSession::AVFCameraSession(AVFCameraService *service, QObject *parent)
, m_active(false)
, m_videoInput(nil)
, m_audioInput(nil)
, m_defaultCodec(0)
{
m_captureSession = [[AVCaptureSession alloc] init];
m_observer = [[AVFCameraSessionObserver alloc] initWithCameraSession:this];
@@ -277,6 +279,8 @@ void AVFCameraSession::setState(QCamera::State newState)
Q_EMIT readyToConfigureConnections();
[m_captureSession commitConfiguration];
[m_captureSession startRunning];
m_defaultCodec = 0;
defaultCodec();
applyImageEncoderSettings();
applyViewfinderSettings();
}
@@ -407,6 +411,25 @@ void AVFCameraSession::removeProbe(AVFMediaVideoProbeControl *probe)
m_videoProbesMutex.unlock();
}
FourCharCode AVFCameraSession::defaultCodec()
{
if (!m_defaultCodec) {
#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0)
if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_7, QSysInfo::MV_IOS_7_0)) {
if (AVCaptureDevice *device = videoCaptureDevice()) {
AVCaptureDeviceFormat *format = device.activeFormat;
if (!format || !format.formatDescription)
return m_defaultCodec;
m_defaultCodec = CMVideoFormatDescriptionGetCodecType(format.formatDescription);
}
}
#else
// TODO: extract media subtype.
#endif
}
return m_defaultCodec;
}
void AVFCameraSession::onCameraFrameFetched(const QVideoFrame &frame)
{
m_videoProbesMutex.lock();