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 QGSTREAMERMEDIARECORDER_H |
5 | #define QGSTREAMERMEDIARECORDER_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 <mediacapture/qgstreamermediacapturesession_p.h> |
19 | #include <common/qgstreamermetadata_p.h> |
20 | |
21 | #include <QtMultimedia/private/qplatformmediarecorder_p.h> |
22 | #include <QtCore/qurl.h> |
23 | #include <QtCore/qtimer.h> |
24 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | class QMediaMetaData; |
28 | class QGstreamerMessage; |
29 | |
30 | class QGstreamerMediaRecorder : public QPlatformMediaRecorder |
31 | { |
32 | public: |
33 | explicit QGstreamerMediaRecorder(QMediaRecorder *parent); |
34 | virtual ~QGstreamerMediaRecorder(); |
35 | |
36 | bool isLocationWritable(const QUrl &sink) const override; |
37 | |
38 | qint64 duration() const override; |
39 | |
40 | void record(QMediaEncoderSettings &settings) override; |
41 | void pause() override; |
42 | void resume() override; |
43 | void stop() override; |
44 | |
45 | void setMetaData(const QMediaMetaData &) override; |
46 | QMediaMetaData metaData() const override; |
47 | |
48 | void setCaptureSession(QPlatformMediaCaptureSession *session); |
49 | |
50 | void processBusMessage(const QGstreamerMessage &message); |
51 | |
52 | private: |
53 | struct PauseControl { |
54 | explicit PauseControl(QPlatformMediaRecorder &encoder) : encoder(encoder) { } |
55 | |
56 | GstPadProbeReturn processBuffer(QGstPad pad, GstPadProbeInfo *info); |
57 | void installOn(QGstPad pad); |
58 | void reset(); |
59 | |
60 | QPlatformMediaRecorder &encoder; |
61 | GstClockTime pauseOffsetPts = 0; |
62 | std::optional<GstClockTime> pauseStartPts; |
63 | std::optional<GstClockTime> firstBufferPts; |
64 | qint64 duration = 0; |
65 | }; |
66 | |
67 | PauseControl audioPauseControl; |
68 | PauseControl videoPauseControl; |
69 | |
70 | void handleSessionError(QMediaRecorder::Error code, const QString &description); |
71 | void finalize(); |
72 | |
73 | QGstreamerMediaCaptureSession *m_session = nullptr; |
74 | QMediaMetaData m_metaData; |
75 | QTimer signalDurationChangedTimer; |
76 | |
77 | bool m_finalizing = false; |
78 | }; |
79 | |
80 | QT_END_NAMESPACE |
81 | |
82 | #endif // QGSTREAMERMEDIARECORDER_H |
83 |