summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2021-10-05 13:28:03 +0200
committerLars Knoll <lars.knoll@qt.io>2021-10-05 13:50:10 +0200
commit16bcd8bcd3e1b5df5db00695b6013608a2c05407 (patch)
treeea03a4e85029edb223c068cfc2b74ebc9736d37b
parent1b667b9927fd07b37c1a1c62c6858b5381ad595b (diff)
Fix crashes in tst_qmediacapturesession
There are still quite a few test failures left, but at least the test now runs through. Pick-to: 6.2 Change-Id: Ic750cf619bb2992daf620cd2a6b4038ffec9abb3 Reviewed-by: Doris Verria <doris.verria@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
-rw-r--r--src/multimedia/platform/darwin/avfvideosink_p.h2
-rw-r--r--src/multimedia/platform/darwin/camera/avfmediaencoder.mm26
2 files changed, 19 insertions, 9 deletions
diff --git a/src/multimedia/platform/darwin/avfvideosink_p.h b/src/multimedia/platform/darwin/avfvideosink_p.h
index d25efdfc7..85295e4c2 100644
--- a/src/multimedia/platform/darwin/avfvideosink_p.h
+++ b/src/multimedia/platform/darwin/avfvideosink_p.h
@@ -105,7 +105,7 @@ public:
void updateLayerBounds();
void nativeSizeChanged() { updateLayerBounds(); }
- QSize nativeSize() const { return m_sink->nativeSize(); }
+ QSize nativeSize() const { return m_sink ? m_sink->nativeSize() : QSize(); }
CVMetalTextureCacheRef cvMetalTextureCache = nullptr;
#if defined(Q_OS_MACOS)
diff --git a/src/multimedia/platform/darwin/camera/avfmediaencoder.mm b/src/multimedia/platform/darwin/camera/avfmediaencoder.mm
index 6761c1d8d..2e081108e 100644
--- a/src/multimedia/platform/darwin/camera/avfmediaencoder.mm
+++ b/src/multimedia/platform/darwin/camera/avfmediaencoder.mm
@@ -305,6 +305,12 @@ NSDictionary *avfVideoSettings(QMediaEncoderSettings &encoderSettings, AVCapture
dim = CMVideoFormatDescriptionGetDimensions(formatDesc);
}
+ if (w < 0 || h < 0) {
+ w = dim.width;
+ h = dim.height;
+ }
+
+
if (w > 0 && h > 0) {
// Make sure the recording resolution has the same aspect ratio as the device's
// current resolution
@@ -403,6 +409,8 @@ NSDictionary *avfVideoSettings(QMediaEncoderSettings &encoderSettings, AVCapture
void AVFMediaEncoder::applySettings(QMediaEncoderSettings &settings)
{
+ unapplySettings();
+
AVFCameraSession *session = m_service->session();
// audio settings
@@ -601,20 +609,22 @@ void AVFMediaEncoder::assetWriterStarted()
void AVFMediaEncoder::assetWriterFinished()
{
- Q_ASSERT(m_service && m_service->session());
- AVFCameraSession *session = m_service->session();
const QMediaRecorder::RecorderState lastState = m_state;
unapplySettings();
- if (session->videoOutput()) {
- session->videoOutput()->resetCaptureDelegate();
- }
- if (session->audioPreviewDelegate()) {
- [session->audioPreviewDelegate() resetAudioPreviewDelegate];
+ if (m_service) {
+ AVFCameraSession *session = m_service->session();
+
+ if (session->videoOutput()) {
+ session->videoOutput()->resetCaptureDelegate();
+ }
+ if (session->audioPreviewDelegate()) {
+ [session->audioPreviewDelegate() resetAudioPreviewDelegate];
+ }
+ [session->captureSession() startRunning];
}
- [session->captureSession() startRunning];
m_state = QMediaRecorder::StoppedState;
if (m_state != lastState)