From bcaec9624c9124dc256ad963d5735496e219414a Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Tue, 21 Apr 2015 18:07:19 +0200 Subject: AVFoundation: fix microphone permission when using the camera. The microphone permission was always requested when using the camera, even when not actually using the microphone, which can only happen when recording a video. The permission request is triggered by adding an audio AVCaptureDeviceInput to the AVCaptureSession, which was done when setting the camera to LoadedState. This is now done when setting the camera mode to CaptureVideo. Task-number: QTBUG-45659 Change-Id: I3692797128cfb70ba5ccbc7a36b6955471039e80 Reviewed-by: Timur Pocheptsov --- src/plugins/avfoundation/camera/avfcamerasession.h | 3 +- .../avfoundation/camera/avfcamerasession.mm | 38 ++----------- .../avfoundation/camera/avfmediarecordercontrol.h | 5 +- .../avfoundation/camera/avfmediarecordercontrol.mm | 62 +++++++++++++++++++--- 4 files changed, 63 insertions(+), 45 deletions(-) diff --git a/src/plugins/avfoundation/camera/avfcamerasession.h b/src/plugins/avfoundation/camera/avfcamerasession.h index 8ce7461df..0a2ca214c 100644 --- a/src/plugins/avfoundation/camera/avfcamerasession.h +++ b/src/plugins/avfoundation/camera/avfcamerasession.h @@ -92,7 +92,7 @@ Q_SIGNALS: private: static void updateCameraDevices(); - void attachInputDevices(); + void attachVideoInputDevice(); static int m_defaultCameraIndex; static QList m_cameraDevices; @@ -105,7 +105,6 @@ private: AVCaptureSession *m_captureSession; AVCaptureDeviceInput *m_videoInput; - AVCaptureDeviceInput *m_audioInput; AVFCameraSessionObserver *m_observer; }; diff --git a/src/plugins/avfoundation/camera/avfcamerasession.mm b/src/plugins/avfoundation/camera/avfcamerasession.mm index 4d4b2f657..d0bb0e51a 100644 --- a/src/plugins/avfoundation/camera/avfcamerasession.mm +++ b/src/plugins/avfoundation/camera/avfcamerasession.mm @@ -147,7 +147,6 @@ AVFCameraSession::AVFCameraSession(AVFCameraService *service, QObject *parent) , m_state(QCamera::UnloadedState) , m_active(false) , m_videoInput(nil) - , m_audioInput(nil) { m_captureSession = [[AVCaptureSession alloc] init]; m_observer = [[AVFCameraSessionObserver alloc] initWithCameraSession:this]; @@ -163,11 +162,6 @@ AVFCameraSession::~AVFCameraSession() [m_videoInput release]; } - if (m_audioInput) { - [m_captureSession removeInput:m_audioInput]; - [m_audioInput release]; - } - [m_observer release]; [m_captureSession release]; } @@ -286,10 +280,9 @@ void AVFCameraSession::setState(QCamera::State newState) QCamera::State oldState = m_state; m_state = newState; - //attach audio and video inputs during Unloaded->Loaded transition - if (oldState == QCamera::UnloadedState) { - attachInputDevices(); - } + //attach video input during Unloaded->Loaded transition + if (oldState == QCamera::UnloadedState) + attachVideoInputDevice(); if (m_state == QCamera::ActiveState) { Q_EMIT readyToConfigureConnections(); @@ -331,7 +324,7 @@ void AVFCameraSession::processSessionStopped() } } -void AVFCameraSession::attachInputDevices() +void AVFCameraSession::attachVideoInputDevice() { //Attach video input device: if (m_service->videoDeviceControl()->isDirty()) { @@ -359,29 +352,6 @@ void AVFCameraSession::attachInputDevices() } } } - - //Attach audio input device: - if (m_service->audioInputSelectorControl()->isDirty()) { - if (m_audioInput) { - [m_captureSession removeInput:m_audioInput]; - [m_audioInput release]; - m_audioInput = 0; - } - - AVCaptureDevice *audioDevice = m_service->audioInputSelectorControl()->createCaptureDevice(); - - NSError *error = nil; - m_audioInput = [AVCaptureDeviceInput - deviceInputWithDevice:audioDevice - error:&error]; - - if (!m_audioInput) { - qWarning() << "Failed to create audio device input"; - } else { - [m_audioInput retain]; - [m_captureSession addInput:m_audioInput]; - } - } } #include "moc_avfcamerasession.cpp" diff --git a/src/plugins/avfoundation/camera/avfmediarecordercontrol.h b/src/plugins/avfoundation/camera/avfmediarecordercontrol.h index a4c7b7f42..fb181a67b 100644 --- a/src/plugins/avfoundation/camera/avfmediarecordercontrol.h +++ b/src/plugins/avfoundation/camera/avfmediarecordercontrol.h @@ -46,6 +46,7 @@ QT_BEGIN_NAMESPACE class AVFCameraSession; class AVFCameraControl; +class AVFAudioInputSelectorControl; class AVFCameraService; class AVFMediaRecorderControl : public QMediaRecorderControl @@ -78,11 +79,12 @@ public Q_SLOTS: void handleRecordingFailed(const QString &message); private Q_SLOTS: - void reconnectMovieOutput(); + void setupSessionForCapture(); void updateStatus(); private: AVFCameraControl *m_cameraControl; + AVFAudioInputSelectorControl *m_audioInputControl; AVFCameraSession *m_session; bool m_connected; @@ -96,6 +98,7 @@ private: bool m_muted; qreal m_volume; + AVCaptureDeviceInput *m_audioInput; AVCaptureMovieFileOutput *m_movieOutput; AVFMediaRecorderDelegate *m_recorderDelagate; AVFStorageLocation m_storageLocation; diff --git a/src/plugins/avfoundation/camera/avfmediarecordercontrol.mm b/src/plugins/avfoundation/camera/avfmediarecordercontrol.mm index d65d238d9..3e855b46f 100644 --- a/src/plugins/avfoundation/camera/avfmediarecordercontrol.mm +++ b/src/plugins/avfoundation/camera/avfmediarecordercontrol.mm @@ -44,6 +44,7 @@ #include "avfcamerasession.h" #include "avfcameraservice.h" #include "avfcameracontrol.h" +#include "avfaudioinputselectorcontrol.h" #include #include @@ -122,6 +123,7 @@ QT_USE_NAMESPACE AVFMediaRecorderControl::AVFMediaRecorderControl(AVFCameraService *service, QObject *parent) : QMediaRecorderControl(parent) , m_cameraControl(service->cameraControl()) + , m_audioInputControl(service->audioInputSelectorControl()) , m_session(service->session()) , m_connected(false) , m_state(QMediaRecorder::StoppedState) @@ -130,21 +132,29 @@ AVFMediaRecorderControl::AVFMediaRecorderControl(AVFCameraService *service, QObj , m_recordingFinished(false) , m_muted(false) , m_volume(1.0) + , m_audioInput(nil) { m_movieOutput = [[AVCaptureMovieFileOutput alloc] init]; m_recorderDelagate = [[AVFMediaRecorderDelegate alloc] initWithRecorder:this]; connect(m_cameraControl, SIGNAL(stateChanged(QCamera::State)), SLOT(updateStatus())); connect(m_cameraControl, SIGNAL(statusChanged(QCamera::Status)), SLOT(updateStatus())); - connect(m_cameraControl, SIGNAL(captureModeChanged(QCamera::CaptureModes)), SLOT(reconnectMovieOutput())); - - reconnectMovieOutput(); + connect(m_cameraControl, SIGNAL(captureModeChanged(QCamera::CaptureModes)), SLOT(setupSessionForCapture())); + connect(m_session, SIGNAL(readyToConfigureConnections()), SLOT(setupSessionForCapture())); + connect(m_session, SIGNAL(stateChanged(QCamera::State)), SLOT(setupSessionForCapture())); } AVFMediaRecorderControl::~AVFMediaRecorderControl() { - if (m_movieOutput) + if (m_movieOutput) { [m_session->captureSession() removeOutput:m_movieOutput]; + [m_movieOutput release]; + } + + if (m_audioInput) { + [m_session->captureSession() removeInput:m_audioInput]; + [m_audioInput release]; + } [m_recorderDelagate release]; } @@ -315,13 +325,39 @@ void AVFMediaRecorderControl::handleRecordingFailed(const QString &message) Q_EMIT error(QMediaRecorder::ResourceError, message); } -void AVFMediaRecorderControl::reconnectMovieOutput() +void AVFMediaRecorderControl::setupSessionForCapture() { //adding movie output causes high CPU usage even when while recording is not active, - //connect it only while video capture mode is enabled + //connect it only while video capture mode is enabled. + // Similarly, connect the Audio input only in that mode, since it's only necessary + // when recording anyway. Adding an Audio input will trigger the microphone permission + // request on iOS, but it shoudn't do so until we actually try to record. AVCaptureSession *captureSession = m_session->captureSession(); - if (!m_connected && m_cameraControl->captureMode().testFlag(QCamera::CaptureVideo)) { + if (!m_connected + && m_cameraControl->captureMode().testFlag(QCamera::CaptureVideo) + && m_session->state() != QCamera::UnloadedState) { + + // Add audio input + // Allow recording even if something wrong happens with the audio input initialization + AVCaptureDevice *audioDevice = m_audioInputControl->createCaptureDevice(); + if (!audioDevice) { + qWarning("No audio input device available"); + } else { + NSError *error = nil; + m_audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:&error]; + + if (!m_audioInput) { + qWarning() << "Failed to create audio device input"; + } else if (![captureSession canAddInput:m_audioInput]) { + qWarning() << "Could not connect the audio input"; + m_audioInput = 0; + } else { + [m_audioInput retain]; + [captureSession addInput:m_audioInput]; + } + } + if ([captureSession canAddOutput:m_movieOutput]) { [captureSession addOutput:m_movieOutput]; m_connected = true; @@ -329,8 +365,18 @@ void AVFMediaRecorderControl::reconnectMovieOutput() Q_EMIT error(QMediaRecorder::ResourceError, tr("Could not connect the video recorder")); qWarning() << "Could not connect the video recorder"; } - } else if (m_connected && !m_cameraControl->captureMode().testFlag(QCamera::CaptureVideo)) { + } else if (m_connected + && (!m_cameraControl->captureMode().testFlag(QCamera::CaptureVideo) + || m_session->state() != QCamera::ActiveState)) { + [captureSession removeOutput:m_movieOutput]; + + if (m_audioInput) { + [captureSession removeInput:m_audioInput]; + [m_audioInput release]; + m_audioInput = nil; + } + m_connected = false; } -- cgit v1.2.3 From 20dbf8490e8226e96898d9b0ef6edd5f9a87bff2 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Thu, 23 Apr 2015 14:52:55 +0200 Subject: Added 5.4.2 change file. Change-Id: Ib9d829e92343d5230875c37bee7b2bf912b1d304 Reviewed-by: Christian Stromme --- dist/changes-5.4.2 | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 dist/changes-5.4.2 diff --git a/dist/changes-5.4.2 b/dist/changes-5.4.2 new file mode 100644 index 000000000..07e553022 --- /dev/null +++ b/dist/changes-5.4.2 @@ -0,0 +1,64 @@ +Qt 5.4.2 is a bug-fix release. It maintains both forward and backward +compatibility (source and binary) with Qt 5.4.0 and 5.4.1. + +For more details, refer to the online documentation included in this +distribution. The documentation is also available online: + + http://qt-project.org/doc/qt-5.4 + +The Qt version 5.4 series is binary compatible with the 5.3.x series. +Applications compiled for 5.3 will continue to run with 5.4. + +Some of the changes listed in this file include issue tracking numbers +corresponding to tasks in the Qt Bug Tracker: + + http://bugreports.qt-project.org/ + +Each of these identifiers can be entered in the bug tracker to obtain more +information about a particular change. + +**************************************************************************** +* Library * +**************************************************************************** + +QtMultimedia +------------ + + - QCameraInfo::availableCameras() and QtMultimedia.availableCameras (QML) + now return an up-to-date list when a camera is added or removed from the + system. + - Fixed memory leak in QMediaPlaylist::load(). + +**************************************************************************** +* Platform Specific Changes * +**************************************************************************** + +Android +------- + + - [QTBUG-37525] Fixed VideoOutput not working on some devices when used + with a Camera. + - [QTBUG-44383] Fixed setting a URL with special characters on a + MediaPlayer. + +iOS +--- + + - [QTBUG-44790] Fixed crash when using QAudioOutput/QAudioInput on iOS 5. + - [QTBUG-45659] Using QCamera doesn't always prompt for microphone + permission anymore, it now only does so when using the CaptureVideo mode. + +Linux +----- + + - [QTBUG-42326] Fixed regression causing software devices to not be + included in QAudioDeviceInfo::availableDevices() when using the ALSA + backend. + +Windows +------- + + - [QTBUG-32746] QMediaPlayer doesn't resume playback anymore when seeking + an audio media while paused. + - [QTBUG-42648] Greatly improved QAudioDeviceInfo supported formats detection. + - [QTBUG-44305] QAudioDeviceInfo: Fixed memory leak in availableDevices(). -- cgit v1.2.3