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 | |
5 | #ifndef QGSTREAMERENCODERCONTROL_H |
6 | #define QGSTREAMERENCODERCONTROL_H |
7 | |
8 | // |
9 | // W A R N I N G |
10 | // ------------- |
11 | // |
12 | // This file is not part of the Qt API. It exists purely as an |
13 | // implementation detail. This header file may change from version to |
14 | // version without notice, or even be removed. |
15 | // |
16 | // We mean it. |
17 | // |
18 | |
19 | #include <private/qplatformmediarecorder_p.h> |
20 | #include "qgstreamermediacapture_p.h" |
21 | #include "qgstreamermetadata_p.h" |
22 | |
23 | #include <QtCore/qurl.h> |
24 | #include <QtCore/qdir.h> |
25 | #include <qelapsedtimer.h> |
26 | #include <qtimer.h> |
27 | |
28 | QT_BEGIN_NAMESPACE |
29 | |
30 | class QMediaMetaData; |
31 | class QGstreamerMessage; |
32 | |
33 | class QGstreamerMediaEncoder : public QPlatformMediaRecorder, QGstreamerBusMessageFilter |
34 | { |
35 | public: |
36 | QGstreamerMediaEncoder(QMediaRecorder *parent); |
37 | virtual ~QGstreamerMediaEncoder(); |
38 | |
39 | bool isLocationWritable(const QUrl &sink) const override; |
40 | |
41 | qint64 duration() const override; |
42 | |
43 | void record(QMediaEncoderSettings &settings) override; |
44 | void pause() override; |
45 | void resume() override; |
46 | void stop() override; |
47 | |
48 | void setMetaData(const QMediaMetaData &) override; |
49 | QMediaMetaData metaData() const override; |
50 | |
51 | void setCaptureSession(QPlatformMediaCaptureSession *session); |
52 | |
53 | QGstElement getEncoder() { return gstEncoder; } |
54 | private: |
55 | bool processBusMessage(const QGstreamerMessage& message) override; |
56 | |
57 | private: |
58 | struct PauseControl { |
59 | PauseControl(QPlatformMediaRecorder &encoder) : encoder(encoder) {} |
60 | |
61 | GstPadProbeReturn processBuffer(QGstPad pad, GstPadProbeInfo *info); |
62 | void installOn(QGstPad pad); |
63 | void reset(); |
64 | |
65 | QPlatformMediaRecorder &encoder; |
66 | GstClockTime pauseOffsetPts = 0; |
67 | std::optional<GstClockTime> pauseStartPts; |
68 | std::optional<GstClockTime> firstBufferPts; |
69 | qint64 duration = 0; |
70 | }; |
71 | |
72 | PauseControl audioPauseControl; |
73 | PauseControl videoPauseControl; |
74 | |
75 | void handleSessionError(QMediaRecorder::Error code, const QString &description); |
76 | void finalize(); |
77 | |
78 | QGstreamerMediaCapture *m_session = nullptr; |
79 | QGstreamerMetaData m_metaData; |
80 | QTimer signalDurationChangedTimer; |
81 | |
82 | QGstPipeline gstPipeline; |
83 | QGstBin gstEncoder; |
84 | QGstElement gstFileSink; |
85 | |
86 | bool m_finalizing = false; |
87 | }; |
88 | |
89 | QT_END_NAMESPACE |
90 | |
91 | #endif // QGSTREAMERENCODERCONTROL_H |
92 |