1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qmediarecorder_p.h"
5
6#include <private/qplatformmediarecorder_p.h>
7#include <qaudiodevice.h>
8#include <qcamera.h>
9#include <qscreencapture.h>
10#include <qwindowcapture.h>
11#include <qmediacapturesession.h>
12#include <private/qplatformcamera_p.h>
13#include <private/qplatformsurfacecapture_p.h>
14#include <private/qplatformmediaintegration_p.h>
15#include <private/qplatformmediacapture_p.h>
16
17#include <QtCore/qdebug.h>
18#include <QtCore/qurl.h>
19#include <QtCore/qstringlist.h>
20#include <QtCore/qmetaobject.h>
21#include <QtCore/qtimer.h>
22
23#include <qaudioformat.h>
24
25QT_BEGIN_NAMESPACE
26
27/*!
28 \class QMediaRecorder
29 \inmodule QtMultimedia
30 \ingroup multimedia
31 \ingroup multimedia_recording
32 \ingroup multimedia_video
33 \ingroup multimedia_audio
34
35 \brief The QMediaRecorder class is used for encoding and recording a capture session.
36
37 The QMediaRecorder class is a class for encoding and recording media generated in a
38 QMediaCaptureSession.
39
40 \snippet multimedia-snippets/media.cpp Media recorder
41*/
42/*!
43 \qmltype MediaRecorder
44 \instantiates QMediaRecorder
45 \brief For encoding and recording media generated in a CaptureSession.
46
47 \inqmlmodule QtMultimedia
48 \ingroup multimedia_qml
49 \ingroup multimedia_audio_qml
50 \ingroup multimedia_video_qml
51
52 The MediaRecorder element can be used within a CaptureSession to record and encode audio and
53 video captured from a microphone and camera
54
55 \since 6.2
56 The code below shows a simple capture session containing a MediaRecorder using the default
57 camera and default audio input.
58
59\qml
60 CaptureSession {
61 id: captureSession
62 camera: Camera {
63 id: camera
64 active: true
65 }
66 audioInput: AudioInput {}
67 recorder: MediaRecorder {
68 id: recorder
69 }
70 }
71\endqml
72
73 The code below shows how the recording can be started and stopped.
74\qml
75 CameraButton {
76 text: "Record"
77 visible: recorder.recorderState !== MediaRecorder.RecordingState
78 onClicked: recorder.record()
79 }
80
81 CameraButton {
82 id: stopButton
83 text: "Stop"
84 visible: recorder.recorderState === MediaRecorder.RecordingState
85 onClicked: recorder.stop()
86 }
87\endqml
88
89 \sa CaptureSession, Camera, AudioInput, ImageCapture
90*/
91QMediaRecorderPrivate::QMediaRecorderPrivate()
92{
93 // Force an early initialization of the mime database
94 // to avoid a delay when recording for the first time.
95 encoderSettings.mimeType();
96}
97
98QString QMediaRecorderPrivate::msgFailedStartRecording()
99{
100 return QMediaRecorder::tr(s: "Failed to start recording");
101}
102
103/*!
104 Constructs a media recorder which records the media produced by a microphone and camera.
105 The media recorder is a child of \a{parent}.
106*/
107
108QMediaRecorder::QMediaRecorder(QObject *parent)
109 : QObject(parent),
110 d_ptr(new QMediaRecorderPrivate)
111{
112 Q_D(QMediaRecorder);
113
114 auto &mediaIntegration = *QPlatformMediaIntegration::instance();
115
116 d->q_ptr = this;
117 auto maybeControl = mediaIntegration.createRecorder(this);
118 if (maybeControl) {
119 // The first format info initialization may take some time,
120 // for users it seems to be more suitable to have a delay on the object construction
121 // rather than on QMediaRecorder::record
122 mediaIntegration.formatInfo();
123
124 d->control = maybeControl.value();
125 } else {
126 d->initErrorMessage = maybeControl.error();
127 qWarning() << "Failed to initialize QMediaRecorder" << maybeControl.error();
128 }
129}
130
131/*!
132 Destroys a media recorder object.
133*/
134
135QMediaRecorder::~QMediaRecorder()
136{
137 if (d_ptr->captureSession)
138 d_ptr->captureSession->setRecorder(nullptr);
139 delete d_ptr->control;
140 delete d_ptr;
141}
142
143/*!
144 \internal
145*/
146QPlatformMediaRecorder *QMediaRecorder::platformRecoder() const
147{
148 return d_ptr->control;
149}
150
151/*!
152 \internal
153*/
154void QMediaRecorder::setCaptureSession(QMediaCaptureSession *session)
155{
156 Q_D(QMediaRecorder);
157 d->captureSession = session;
158}
159/*!
160 \qmlproperty QUrl QtMultimedia::MediaRecorder::outputLocation
161 \brief The destination location of media content.
162
163 Setting the location can fail, for example when the service supports only
164 local file system locations but a network URL was passed. If the operation
165 fails an errorOccured() signal is emitted.
166
167 The location can be relative or empty. If empty the recorder uses the
168 system specific place and file naming scheme.
169
170 \sa errorOccurred()
171*/
172
173/*!
174 \property QMediaRecorder::outputLocation
175 \brief the destination location of media content.
176
177 Setting the location can fail, for example when the service supports only
178 local file system locations but a network URL was passed. If the operation
179 fails an errorOccured() signal is emitted.
180
181 The output location can be relative or empty; in the latter case the recorder
182 uses the system specific place and file naming scheme.
183*/
184
185/*!
186 \qmlproperty QUrl QtMultimedia::MediaRecorder::actualLocation
187 \brief The actual location of the last media content.
188
189 The actual location is usually available after recording starts,
190 and reset when new location is set or new recording starts.
191*/
192
193/*!
194 \property QMediaRecorder::actualLocation
195 \brief The actual location of the last media content.
196
197 The actual location is usually available after recording starts,
198 and reset when new location is set or new recording starts.
199*/
200
201/*!
202 \qmlproperty bool QtMultimedia::MediaRecorder::isAvailable
203 \brief This property holds whether the recorder service is ready to use.
204
205 Returns \c true if media recorder service ready to use.
206*/
207/*!
208 Returns \c true if media recorder service ready to use.
209*/
210bool QMediaRecorder::isAvailable() const
211{
212 return d_func()->control && d_func()->captureSession;
213}
214
215QUrl QMediaRecorder::outputLocation() const
216{
217 return d_func()->control ? d_func()->control->outputLocation() : QUrl();
218}
219
220void QMediaRecorder::setOutputLocation(const QUrl &location)
221{
222 Q_D(QMediaRecorder);
223 if (!d->control) {
224 emit errorOccurred(error: QMediaRecorder::ResourceError, errorString: d->initErrorMessage);
225 return;
226 }
227 d->control->setOutputLocation(location);
228 d->control->clearActualLocation();
229 if (!location.isEmpty() && !d->control->isLocationWritable(location))
230 emit errorOccurred(error: QMediaRecorder::LocationNotWritable, errorString: tr(s: "Output location not writable"));
231}
232
233QUrl QMediaRecorder::actualLocation() const
234{
235 Q_D(const QMediaRecorder);
236 return d->control ? d->control->actualLocation() : QUrl();
237}
238
239/*!
240 Returns the current media recorder state.
241
242 \sa QMediaRecorder::RecorderState
243*/
244
245QMediaRecorder::RecorderState QMediaRecorder::recorderState() const
246{
247 return d_func()->control ? QMediaRecorder::RecorderState(d_func()->control->state()) : StoppedState;
248}
249
250/*!
251 \property QMediaRecorder::error
252
253 Returns the current error state.
254
255 \sa errorString()
256*/
257
258QMediaRecorder::Error QMediaRecorder::error() const
259{
260 Q_D(const QMediaRecorder);
261
262 return d->control ? d->control->error() : QMediaRecorder::ResourceError;
263}
264/*!
265 \qmlproperty string QtMultimedia::MediaRecorder::errorString
266 \brief This property holds a string describing the current error state.
267
268 \sa error
269*/
270/*!
271 \property QMediaRecorder::errorString
272
273 Returns a string describing the current error state.
274
275 \sa error()
276*/
277
278QString QMediaRecorder::errorString() const
279{
280 Q_D(const QMediaRecorder);
281
282 return d->control ? d->control->errorString() : d->initErrorMessage;
283}
284/*!
285 \qmlproperty qint64 QtMultimedia::MediaRecorder::duration
286
287 \brief This property holds the recorded media duration in milliseconds.
288*/
289
290/*!
291 \property QMediaRecorder::duration
292
293 \brief the recorded media duration in milliseconds.
294*/
295
296qint64 QMediaRecorder::duration() const
297{
298 return d_func()->control ? d_func()->control->duration() : 0;
299}
300/*!
301 \fn void QMediaRecorder::encoderSettingsChanged()
302
303 Signals when the encoder settings change.
304*/
305/*!
306 \qmlmethod QtMultimedia::MediaRecorder::record()
307 \brief Starts recording.
308
309 While the recorder state is changed immediately to
310 \c MediaRecorder.RecordingState, recording may start asynchronously.
311
312 If recording fails, the error() signal is emitted with recorder state being
313 reset back to \c{QMediaRecorder.StoppedState}.
314
315 \note On mobile devices, recording will happen in the orientation the
316 device had when calling record and is locked for the duration of the recording.
317 To avoid artifacts on the user interface, we recommend to keep the user interface
318 locked to the same orientation as long as the recording is ongoing using
319 the contentOrientation property of the Window and unlock it again once the recording
320 is finished.
321*/
322/*!
323 Start recording.
324
325 While the recorder state is changed immediately to
326 c\{QMediaRecorder::RecordingState}, recording may start asynchronously.
327
328 If recording fails error() signal is emitted with recorder state being
329 reset back to \c{QMediaRecorder::StoppedState}.
330
331 \note On mobile devices, recording will happen in the orientation the
332 device had when calling record and is locked for the duration of the recording.
333 To avoid artifacts on the user interface, we recommend to keep the user interface
334 locked to the same orientation as long as the recording is ongoing using
335 the contentOrientation property of QWindow and unlock it again once the recording
336 is finished.
337*/
338
339void QMediaRecorder::record()
340{
341 Q_D(QMediaRecorder);
342
343 if (!d->control || !d->captureSession)
344 return;
345
346 if (d->control->state() == QMediaRecorder::PausedState) {
347 d->control->resume();
348 } else {
349 auto oldMediaFormat = d->encoderSettings.mediaFormat();
350
351 auto platformSession = d->captureSession->platformSession();
352 const bool hasVideo = platformSession && !platformSession->activeVideoSources().empty();
353
354 d->encoderSettings.resolveFormat(flags: hasVideo ? QMediaFormat::RequiresVideo : QMediaFormat::NoFlags);
355 d->control->clearActualLocation();
356 d->control->clearError();
357
358 auto settings = d->encoderSettings;
359 d->control->record(settings&: d->encoderSettings);
360
361 if (settings != d->encoderSettings)
362 emit encoderSettingsChanged();
363
364 if (oldMediaFormat != d->encoderSettings.mediaFormat())
365 emit mediaFormatChanged();
366 }
367}
368/*!
369 \qmlmethod QtMultimedia::MediaRecorder::pause()
370 \brief Pauses recording.
371
372 The recorder state is changed to QMediaRecorder.PausedState.
373
374 Depending on the platform, pausing recording may be not supported.
375 In this case the recorder state is unchanged.
376*/
377/*!
378 Pauses recording.
379
380 The recorder state is changed to QMediaRecorder::PausedState.
381
382 Depending on the platform, pausing recording may be not supported.
383 In this case the recorder state is unchanged.
384*/
385
386void QMediaRecorder::pause()
387{
388 Q_D(QMediaRecorder);
389 if (d->control && d->captureSession)
390 d->control->pause();
391}
392/*!
393 \qmlmethod QtMultimedia::MediaRecorder::stop()
394 \brief Stops the recording.
395
396 The recorder will stop the recording. Processing pending video and audio data might
397 however still take some time. The recording is finished, once the state of the media
398 recorder changes to QMediaRecorder::StoppedState.
399*/
400
401/*!
402 The recorder will stop the recording. Processing pending video and audio data might
403 however still take some time. The recording is finished, once the state of the media
404 recorder changes to QMediaRecorder::StoppedState.
405*/
406void QMediaRecorder::stop()
407{
408 Q_D(QMediaRecorder);
409 if (d->control && d->captureSession)
410 d->control->stop();
411}
412/*!
413 \qmlproperty enumeration QtMultimedia::MediaRecorder::recorderState
414 \brief This property holds the current media recorder state.
415
416 The state property represents the user request and is changed synchronously
417 during record(), pause() or stop() calls.
418 RecorderSstate may also change asynchronously when recording fails.
419
420 \value MediaRecorder.StoppedState The recorder is not active.
421 \value MediaRecorder.RecordingState The recording is requested.
422 \value MediaRecorder.PausedState The recorder is pause.
423*/
424/*!
425 \enum QMediaRecorder::RecorderState
426
427 \value StoppedState The recorder is not active.
428 \value RecordingState The recording is requested.
429 \value PausedState The recorder is paused.
430*/
431/*!
432 \qmlproperty enumeration QtMultimedia::MediaRecorder::error
433 \brief This property holds the current media recorder error state.
434
435 \value MediaRecorder.NoError Not in an error state.
436 \value MediaRecorder.ResourceError Not enough system resources
437 \value MediaRecorder.FormatError the current format is not supported.
438 \value MediaRecorder.OutOfSpaceError No space left on device.
439 \value MediaRecorder.LocationNotWriteable The output location is not writable.
440*/
441/*!
442 \enum QMediaRecorder::Error
443
444 \value NoError No Errors.
445 \value ResourceError Device is not ready or not available.
446 \value FormatError Current format is not supported.
447 \value OutOfSpaceError No space left on device.
448 \value LocationNotWritable The output location is not writable.
449*/
450
451/*!
452 \property QMediaRecorder::recorderState
453 \brief The current state of the media recorder.
454
455 The state property represents the user request and is changed synchronously
456 during record(), pause() or stop() calls.
457 Recorder state may also change asynchronously when recording fails.
458*/
459
460/*!
461 \qmlsignal QtMultimedia::MediaRecorder::recorderStateChanged(RecorderState state)
462 \brief Signals that a media recorder's \a state has changed.
463*/
464
465/*!
466 \fn QMediaRecorder::recorderStateChanged(QMediaRecorder::RecorderState state)
467
468 Signals that a media recorder's \a state has changed.
469*/
470
471/*!
472 \qmlsignal QtMultimedia::MediaRecorder::durationChanged(qint64 duration)
473 \brief Signals that the \a duration of the recorded media has changed.
474*/
475
476/*!
477 \fn QMediaRecorder::durationChanged(qint64 duration)
478
479 Signals that the \a duration of the recorded media has changed.
480*/
481/*!
482 \qmlsignal QtMultimedia::MediaRecorder::actualLocationChanged(const QUrl &location)
483 \brief Signals that the actual \a location of the recorded media has changed.
484
485 This signal is usually emitted when recording starts.
486*/
487/*!
488 \fn QMediaRecorder::actualLocationChanged(const QUrl &location)
489
490 Signals that the actual \a location of the recorded media has changed.
491 This signal is usually emitted when recording starts.
492*/
493/*!
494 \qmlsignal QtMultimedia::MediaRecorder::errorOccurred(Error error, const QString &errorString)
495 \brief Signals that an \a error has occurred.
496
497 The \a errorString contains a description of the error.
498*/
499/*!
500 \fn QMediaRecorder::errorOccurred(QMediaRecorder::Error error, const QString &errorString)
501
502 Signals that an \a error has occurred, with \a errorString containing
503 a description of the error.
504*/
505
506/*!
507 \qmlproperty mediaMetaData QtMultimedia::MediaRecorder::metaData
508
509 \brief This property holds meta data associated with the recording.
510
511 When a recording is started, any meta-data assigned will be attached to that
512 recording.
513
514 \note Ensure that meta-data is assigned correctly by assigning it before
515 starting the recording.
516
517 \sa mediaMetaData
518*/
519
520/*!
521 \property QMediaRecorder::metaData
522
523 Returns the metaData associated with the recording.
524*/
525QMediaMetaData QMediaRecorder::metaData() const
526{
527 Q_D(const QMediaRecorder);
528
529 return d->control ? d->control->metaData() : QMediaMetaData{};
530}
531
532/*!
533 Sets the meta data to \a metaData.
534
535 \note To ensure that meta-data is set correctly, it should be set before starting the recording.
536 Once the recording is started, any meta-data set will be attached to the next recording.
537*/
538void QMediaRecorder::setMetaData(const QMediaMetaData &metaData)
539{
540 Q_D(QMediaRecorder);
541
542 if (d->control && d->captureSession)
543 d->control->setMetaData(metaData);
544}
545
546/*!
547 Adds \a metaData to the recorded media.
548*/
549void QMediaRecorder::addMetaData(const QMediaMetaData &metaData)
550{
551 auto data = this->metaData();
552 // merge data
553 for (const auto &k : metaData.keys())
554 data.insert(k, value: metaData.value(k));
555 setMetaData(data);
556}
557/*!
558 \qmlsignal QtMultimedia::MediaRecorder::metaDataChanged()
559
560 \brief Signals that a media object's meta-data has changed.
561
562 If multiple meta-data elements are changed metaDataChanged() is emitted
563 once.
564*/
565/*!
566 \fn QMediaRecorder::metaDataChanged()
567
568 Signals that a media object's meta-data has changed.
569
570 If multiple meta-data elements are changed metaDataChanged() is emitted
571 once.
572*/
573
574/*!
575 Returns the media capture session.
576*/
577QMediaCaptureSession *QMediaRecorder::captureSession() const
578{
579 Q_D(const QMediaRecorder);
580 return d->captureSession;
581}
582/*!
583 \qmlproperty enumeration QtMultimedia::MediaRecorder::quality
584
585 Enumerates quality encoding levels.
586
587 \value MediaRecorder.VeryLowQuality
588 \value MediaRecorder.LowQuality
589 \value MediaRecorder.NormalQuality
590 \value MediaRecorder.HighQuality
591 \value MediaRecorder.VeryHighQuality
592*/
593/*!
594 \enum QMediaRecorder::Quality
595
596 Enumerates quality encoding levels.
597
598 \value VeryLowQuality
599 \value LowQuality
600 \value NormalQuality
601 \value HighQuality
602 \value VeryHighQuality
603*/
604
605/*!
606 \enum QMediaRecorder::EncodingMode
607
608 Enumerates encoding modes.
609
610 \value ConstantQualityEncoding Encoding will aim to have a constant quality, adjusting bitrate to fit.
611 \value ConstantBitRateEncoding Encoding will use a constant bit rate, adjust quality to fit.
612 \value AverageBitRateEncoding Encoding will try to keep an average bitrate setting, but will use
613 more or less as needed.
614 \value TwoPassEncoding The media will first be processed to determine the characteristics,
615 and then processed a second time allocating more bits to the areas
616 that need it.
617*/
618
619/*!
620
621 \qmlproperty MediaFormat QtMultimedia::MediaRecorder::mediaFormat
622
623 \brief This property holds the current MediaFormat of the recorder.
624*/
625/*!
626 \property QMediaRecorder::mediaFormat
627
628 Returns the recording media format.
629*/
630QMediaFormat QMediaRecorder::mediaFormat() const
631{
632 Q_D(const QMediaRecorder);
633 return d->encoderSettings.mediaFormat();
634}
635
636void QMediaRecorder::setMediaFormat(const QMediaFormat &format)
637{
638 Q_D(QMediaRecorder);
639 if (d->encoderSettings.mediaFormat() == format)
640 return;
641 d->encoderSettings.setMediaFormat(format);
642 emit mediaFormatChanged();
643}
644
645/*!
646
647 \qmlproperty enumeration QtMultimedia::MediaRecorder::encodingMode
648 \since 6.6
649 \brief This property holds the encoding mode.
650 \sa QMediaRecorder::EncodingMode
651*/
652
653/*!
654 Returns the encoding mode.
655
656 \sa EncodingMode
657*/
658QMediaRecorder::EncodingMode QMediaRecorder::encodingMode() const
659{
660 Q_D(const QMediaRecorder);
661 return d->encoderSettings.encodingMode();
662}
663
664/*!
665 \fn void QMediaRecorder::encodingModeChanged()
666
667 Signals when the encoding mode changes.
668*/
669/*!
670 Sets the encoding \a mode setting.
671
672 If ConstantQualityEncoding is set, the quality
673 encoding parameter is used and bit rates are ignored,
674 otherwise the bitrates are used.
675
676 \sa encodingMode(), EncodingMode
677*/
678void QMediaRecorder::setEncodingMode(EncodingMode mode)
679{
680 Q_D(QMediaRecorder);
681 if (d->encoderSettings.encodingMode() == mode)
682 return;
683 d->encoderSettings.setEncodingMode(mode);
684 emit encodingModeChanged();
685}
686
687/*!
688 \property QMediaRecorder::quality
689
690 Returns the recording quality.
691*/
692QMediaRecorder::Quality QMediaRecorder::quality() const
693{
694 Q_D(const QMediaRecorder);
695 return d->encoderSettings.quality();
696}
697
698/*!
699 \fn void QMediaRecorder::qualityChanged()
700
701 Signals when the recording quality changes.
702*/
703void QMediaRecorder::setQuality(Quality quality)
704{
705 Q_D(QMediaRecorder);
706 if (d->encoderSettings.quality() == quality)
707 return;
708 d->encoderSettings.setQuality(quality);
709 emit qualityChanged();
710}
711
712/*!
713 \qmlproperty Size QtMultimedia::MediaRecorder::videoResolution
714 \since 6.6
715 \brief This property holds the resolution of the encoded video.
716
717 Set an empty Size to make the recorder choose an optimal resolution based
718 on what is available from the video source and the limitations of the codec.
719*/
720
721
722/*!
723 Returns the resolution of the encoded video.
724*/
725QSize QMediaRecorder::videoResolution() const
726{
727 Q_D(const QMediaRecorder);
728 return d->encoderSettings.videoResolution();
729}
730
731/*!
732 \fn void QMediaRecorder::videoResolutionChanged()
733
734 Signals when the video recording resolution changes.
735*/
736/*!
737 Sets the resolution of the encoded video to \a{size}.
738
739 Pass an empty QSize to make the recorder choose an optimal resolution based
740 on what is available from the video source and the limitations of the codec.
741*/
742void QMediaRecorder::setVideoResolution(const QSize &size)
743{
744 Q_D(QMediaRecorder);
745 if (d->encoderSettings.videoResolution() == size)
746 return;
747 d->encoderSettings.setVideoResolution(size);
748 emit videoResolutionChanged();
749}
750
751/*! \fn void QMediaRecorder::setVideoResolution(int width, int height)
752
753 Sets the \a width and \a height of the resolution of the encoded video.
754
755 \overload
756*/
757
758/*!
759 \qmlproperty real QtMultimedia::MediaRecorder::videoFrameRate
760 \since 6.6
761 \brief This property holds the video frame rate.
762
763 A value of 0 indicates the recorder should make an optimal choice based on what is available
764 from the video source and the limitations of the codec.
765*/
766
767/*!
768 Returns the video frame rate.
769*/
770qreal QMediaRecorder::videoFrameRate() const
771{
772 Q_D(const QMediaRecorder);
773 return d->encoderSettings.videoFrameRate();
774}
775
776/*!
777 \fn void QMediaRecorder::videoFrameRateChanged()
778
779 Signals when the recording video frame rate changes.
780*/
781/*!
782 Sets the video \a frameRate.
783
784 A value of 0 indicates the recorder should make an optimal choice based on what is available
785 from the video source and the limitations of the codec.
786*/
787void QMediaRecorder::setVideoFrameRate(qreal frameRate)
788{
789 Q_D(QMediaRecorder);
790 if (d->encoderSettings.videoFrameRate() == frameRate)
791 return;
792 d->encoderSettings.setVideoFrameRate(frameRate);
793 emit videoFrameRateChanged();
794}
795
796/*!
797 \qmlproperty int QtMultimedia::MediaRecorder::videoBitRate
798 \since 6.6
799 \brief This property holds the bit rate of the compressed video stream in bits per second.
800*/
801
802/*!
803 Returns the bit rate of the compressed video stream in bits per second.
804*/
805int QMediaRecorder::videoBitRate() const
806{
807 Q_D(const QMediaRecorder);
808 return d->encoderSettings.videoBitRate();
809}
810
811/*!
812 \fn void QMediaRecorder::videoBitRateChanged()
813
814 Signals when the recording video bit rate changes.
815*/
816/*!
817 Sets the video \a bitRate in bits per second.
818*/
819void QMediaRecorder::setVideoBitRate(int bitRate)
820{
821 Q_D(QMediaRecorder);
822 if (d->encoderSettings.videoBitRate() == bitRate)
823 return;
824 d->encoderSettings.setVideoBitRate(bitRate);
825 emit videoBitRateChanged();
826}
827
828/*!
829 \qmlproperty int QtMultimedia::MediaRecorder::audioBitRate
830 \since 6.6
831 \brief This property holds the bit rate of the compressed audio stream in bits per second.
832*/
833
834/*!
835 Returns the bit rate of the compressed audio stream in bits per second.
836*/
837int QMediaRecorder::audioBitRate() const
838{
839 Q_D(const QMediaRecorder);
840 return d->encoderSettings.audioBitRate();
841}
842
843/*!
844 \fn void QMediaRecorder::audioBitRateChanged()
845
846 Signals when the recording audio bit rate changes.
847*/
848/*!
849 Sets the audio \a bitRate in bits per second.
850*/
851void QMediaRecorder::setAudioBitRate(int bitRate)
852{
853 Q_D(QMediaRecorder);
854 if (d->encoderSettings.audioBitRate() == bitRate)
855 return;
856 d->encoderSettings.setAudioBitRate(bitRate);
857 emit audioBitRateChanged();
858}
859
860/*!
861 \qmlproperty int QtMultimedia::MediaRecorder::audioChannelCount
862 \since 6.6
863 \brief This property holds the number of audio channels.
864*/
865
866/*!
867 Returns the number of audio channels.
868*/
869int QMediaRecorder::audioChannelCount() const
870{
871 Q_D(const QMediaRecorder);
872 return d->encoderSettings.audioChannelCount();
873}
874
875/*!
876 \fn void QMediaRecorder::audioChannelCountChanged()
877
878 Signals when the recording audio channel count changes.
879*/
880/*!
881 Sets the number of audio \a channels.
882
883 A value of -1 indicates the recorder should make an optimal choice based on
884 what is available from the audio source and the limitations of the codec.
885*/
886void QMediaRecorder::setAudioChannelCount(int channels)
887{
888 Q_D(QMediaRecorder);
889 if (d->encoderSettings.audioChannelCount() == channels)
890 return;
891 d->encoderSettings.setAudioChannelCount(channels);
892 emit audioChannelCountChanged();
893}
894
895/*!
896 \qmlproperty int QtMultimedia::MediaRecorder::audioSampleRate
897 \since 6.6
898 \brief This property holds the audio sample rate in Hz.
899*/
900
901/*!
902 Returns the audio sample rate in Hz.
903*/
904int QMediaRecorder::audioSampleRate() const
905{
906 Q_D(const QMediaRecorder);
907 return d->encoderSettings.audioSampleRate();
908}
909/*!
910 \fn void QMediaRecorder::audioSampleRateChanged()
911
912 Signals when the recording audio sample rate changes.
913*/
914/*!
915 Sets the audio \a sampleRate in Hz.
916
917 A value of \c -1 indicates the recorder should make an optimal choice based
918 on what is available from the audio source, and the limitations of the codec.
919*/
920void QMediaRecorder::setAudioSampleRate(int sampleRate)
921{
922 Q_D(QMediaRecorder);
923 if (d->encoderSettings.audioSampleRate() == sampleRate)
924 return;
925 d->encoderSettings.setAudioSampleRate(sampleRate);
926 emit audioSampleRateChanged();
927}
928
929QT_END_NAMESPACE
930
931#include "moc_qmediarecorder.cpp"
932

source code of qtmultimedia/src/multimedia/recording/qmediarecorder.cpp