| 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 <private/qplatformmediacapture_p.h> | 
| 19 | #include <private/qplatformmediaintegration_p.h> | 
| 20 | |
| 21 | #include <common/qgst_bus_observer_p.h> | 
| 22 | #include <common/qgst_p.h> | 
| 23 | #include <common/qgstpipeline_p.h> | 
| 24 | |
| 25 | QT_BEGIN_NAMESPACE | 
| 26 | |
| 27 | class QGstreamerCameraBase; | 
| 28 | class QGstreamerImageCapture; | 
| 29 | class QGstreamerMediaRecorder; | 
| 30 | class QGstreamerAudioInput; | 
| 31 | class QGstreamerAudioOutput; | 
| 32 | class QGstreamerVideoOutput; | 
| 33 | class QGstreamerVideoSink; | 
| 34 | |
| 35 | class QGstreamerMediaCaptureSession final : public QPlatformMediaCaptureSession, | 
| 36 | QGstreamerBusMessageFilter | 
| 37 | { | 
| 38 | public: | 
| 39 | static QMaybe<QPlatformMediaCaptureSession *> create(); | 
| 40 | ~QGstreamerMediaCaptureSession() override; | 
| 41 | |
| 42 | QPlatformCamera *camera() override; | 
| 43 | void setCamera(QPlatformCamera *camera) override; | 
| 44 | |
| 45 | QPlatformImageCapture *imageCapture() override; | 
| 46 | void setImageCapture(QPlatformImageCapture *imageCapture) override; | 
| 47 | |
| 48 | QPlatformMediaRecorder *mediaRecorder() override; | 
| 49 | void setMediaRecorder(QPlatformMediaRecorder *recorder) override; | 
| 50 | |
| 51 | void setAudioInput(QPlatformAudioInput *input) override; | 
| 52 | QGstreamerAudioInput *audioInput() { return gstAudioInput; } | 
| 53 | |
| 54 | void setVideoPreview(QVideoSink *sink) override; | 
| 55 | void setAudioOutput(QPlatformAudioOutput *output) override; | 
| 56 | |
| 57 | const QGstPipeline &pipeline() const; | 
| 58 | |
| 59 | QGstreamerVideoSink *gstreamerVideoSink() const; | 
| 60 | |
| 61 | struct RecorderElements | 
| 62 | { | 
| 63 | QGstBin encodeBin; | 
| 64 | QGstElement fileSink; | 
| 65 | |
| 66 | QGstPad audioSink; | 
| 67 | QGstPad videoSink; | 
| 68 | }; | 
| 69 | void linkAndStartEncoder(RecorderElements, const QMediaMetaData &); | 
| 70 | void unlinkRecorder(); | 
| 71 | void finalizeRecorder(); | 
| 72 | |
| 73 | private: | 
| 74 | bool processBusMessage(const QGstreamerMessage &) override; | 
| 75 | bool processBusMessageError(const QGstreamerMessage &); | 
| 76 | bool processBusMessageLatency(const QGstreamerMessage &); | 
| 77 | |
| 78 | void setCameraActive(bool activate); | 
| 79 | |
| 80 | explicit QGstreamerMediaCaptureSession(QGstreamerVideoOutput *videoOutput); | 
| 81 | |
| 82 | friend QGstreamerMediaRecorder; | 
| 83 | // Gst elements | 
| 84 | QGstPipeline capturePipeline; | 
| 85 | |
| 86 | QGstreamerAudioInput *gstAudioInput = nullptr; | 
| 87 | QGstreamerCameraBase *gstCamera = nullptr; | 
| 88 | QMetaObject::Connection gstCameraActiveConnection; | 
| 89 | |
| 90 | QGstElement gstAudioTee; | 
| 91 | QGstPad audioSrcPadForEncoder; | 
| 92 | QGstPad audioSrcPadForOutput; | 
| 93 | |
| 94 | QGstElement gstVideoTee; | 
| 95 | QGstPad videoSrcPadForEncoder; | 
| 96 | QGstPad videoSrcPadForOutput; | 
| 97 | QGstPad videoSrcPadForImageCapture; | 
| 98 | |
| 99 | QGstElement encoderVideoCapsFilter; | 
| 100 | QGstElement encoderAudioCapsFilter; | 
| 101 | |
| 102 | QGstPad imageCaptureSink(); | 
| 103 | QGstPad videoOutputSink(); | 
| 104 | QGstPad audioOutputSink(); | 
| 105 | |
| 106 | std::optional<RecorderElements> m_currentRecorderState; | 
| 107 | |
| 108 | QGstreamerAudioOutput *gstAudioOutput = nullptr; | 
| 109 | QGstreamerVideoOutput *gstVideoOutput = nullptr; | 
| 110 | |
| 111 | QGstreamerMediaRecorder *m_mediaRecorder = nullptr; | 
| 112 | QGstreamerImageCapture *m_imageCapture = nullptr; | 
| 113 | }; | 
| 114 | |
| 115 | QT_END_NAMESPACE | 
| 116 | |
| 117 | #endif // QGSTREAMERMEDIACAPTURESESSION_H | 
| 118 | 
