| 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 | #ifndef QGSTREAMERMEDIACAPTURESESSION_H |
| 5 | #define QGSTREAMERMEDIACAPTURESESSION_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtCore/private/qexpected_p.h> |
| 19 | |
| 20 | #include <private/qplatformmediacapture_p.h> |
| 21 | #include <private/qplatformmediaintegration_p.h> |
| 22 | |
| 23 | #include <common/qgst_bus_observer_p.h> |
| 24 | #include <common/qgst_p.h> |
| 25 | #include <common/qgstpipeline_p.h> |
| 26 | |
| 27 | QT_BEGIN_NAMESPACE |
| 28 | |
| 29 | class QGstreamerCameraBase; |
| 30 | class QGstreamerImageCapture; |
| 31 | class QGstreamerMediaRecorder; |
| 32 | class QGstreamerAudioInput; |
| 33 | class QGstreamerAudioOutput; |
| 34 | class QGstreamerVideoOutput; |
| 35 | class QGstreamerVideoSink; |
| 36 | |
| 37 | class QGstreamerMediaCaptureSession final : public QPlatformMediaCaptureSession, |
| 38 | QGstreamerBusMessageFilter |
| 39 | { |
| 40 | public: |
| 41 | static q23::expected<QPlatformMediaCaptureSession *, QString> create(); |
| 42 | ~QGstreamerMediaCaptureSession() override; |
| 43 | |
| 44 | QPlatformCamera *camera() override; |
| 45 | void setCamera(QPlatformCamera *camera) override; |
| 46 | |
| 47 | QPlatformImageCapture *imageCapture() override; |
| 48 | void setImageCapture(QPlatformImageCapture *imageCapture) override; |
| 49 | |
| 50 | QPlatformMediaRecorder *mediaRecorder() override; |
| 51 | void setMediaRecorder(QPlatformMediaRecorder *recorder) override; |
| 52 | |
| 53 | void setAudioInput(QPlatformAudioInput *input) override; |
| 54 | QGstreamerAudioInput *audioInput() { return gstAudioInput; } |
| 55 | |
| 56 | void setVideoPreview(QVideoSink *sink) override; |
| 57 | void setAudioOutput(QPlatformAudioOutput *output) override; |
| 58 | |
| 59 | const QGstPipeline &pipeline() const; |
| 60 | |
| 61 | QGstreamerVideoSink *gstreamerVideoSink() const; |
| 62 | |
| 63 | struct RecorderElements |
| 64 | { |
| 65 | QGstBin encodeBin; |
| 66 | QGstElement fileSink; |
| 67 | |
| 68 | QGstPad audioSink; |
| 69 | QGstPad videoSink; |
| 70 | }; |
| 71 | void linkAndStartEncoder(RecorderElements, const QMediaMetaData &); |
| 72 | void unlinkRecorder(); |
| 73 | void finalizeRecorder(); |
| 74 | |
| 75 | private: |
| 76 | bool processBusMessage(const QGstreamerMessage &) override; |
| 77 | bool processBusMessageError(const QGstreamerMessage &); |
| 78 | bool processBusMessageLatency(const QGstreamerMessage &); |
| 79 | |
| 80 | void setCameraActive(bool activate); |
| 81 | |
| 82 | explicit QGstreamerMediaCaptureSession(QGstreamerVideoOutput *videoOutput); |
| 83 | |
| 84 | friend QGstreamerMediaRecorder; |
| 85 | // Gst elements |
| 86 | QGstPipeline capturePipeline; |
| 87 | |
| 88 | QGstreamerAudioInput *gstAudioInput = nullptr; |
| 89 | QGstreamerCameraBase *gstCamera = nullptr; |
| 90 | QMetaObject::Connection gstCameraActiveConnection; |
| 91 | |
| 92 | QGstElement gstAudioTee; |
| 93 | QGstPad audioSrcPadForEncoder; |
| 94 | QGstPad audioSrcPadForOutput; |
| 95 | |
| 96 | QGstElement gstVideoTee; |
| 97 | QGstPad videoSrcPadForEncoder; |
| 98 | QGstPad videoSrcPadForOutput; |
| 99 | QGstPad videoSrcPadForImageCapture; |
| 100 | |
| 101 | QGstElement encoderVideoCapsFilter; |
| 102 | QGstElement encoderAudioCapsFilter; |
| 103 | |
| 104 | QGstPad imageCaptureSink(); |
| 105 | QGstPad videoOutputSink(); |
| 106 | QGstPad audioOutputSink(); |
| 107 | |
| 108 | std::optional<RecorderElements> m_currentRecorderState; |
| 109 | |
| 110 | QGstreamerAudioOutput *gstAudioOutput = nullptr; |
| 111 | QGstreamerVideoOutput *gstVideoOutput = nullptr; |
| 112 | |
| 113 | QGstreamerMediaRecorder *m_mediaRecorder = nullptr; |
| 114 | QGstreamerImageCapture *m_imageCapture = nullptr; |
| 115 | }; |
| 116 | |
| 117 | QT_END_NAMESPACE |
| 118 | |
| 119 | #endif // QGSTREAMERMEDIACAPTURESESSION_H |
| 120 |
