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 QGSTAPPSRC_H
5#define QGSTAPPSRC_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/qtmultimediaglobal_p.h>
19#include <private/qmultimediautils_p.h>
20#include <qaudioformat.h>
21
22#include <QtCore/qobject.h>
23#include <QtCore/qiodevice.h>
24#include <QtCore/private/qringbuffer_p.h>
25#include <QtCore/qatomic.h>
26
27#include <qgst_p.h>
28#include <gst/app/gstappsrc.h>
29
30QT_BEGIN_NAMESPACE
31
32class QNetworkReply;
33
34class Q_MULTIMEDIA_EXPORT QGstAppSrc : public QObject
35{
36 Q_OBJECT
37public:
38 static QMaybe<QGstAppSrc *> create(QObject *parent = nullptr);
39 ~QGstAppSrc();
40
41 bool setup(QIODevice *stream = nullptr, qint64 offset = 0);
42 void setAudioFormat(const QAudioFormat &f);
43
44 void setExternalAppSrc(const QGstElement &appsrc);
45 QGstElement element();
46
47 void write(const char *data, qsizetype size);
48
49 bool canAcceptMoreData() { return m_noMoreData || m_dataRequestSize != 0; }
50
51 void suspend() { m_suspended = true; }
52 void resume() { m_suspended = false; m_noMoreData = true; }
53
54Q_SIGNALS:
55 void bytesProcessed(int bytes);
56 void noMoreData();
57
58private Q_SLOTS:
59 void pushData();
60 bool doSeek(qint64);
61 void onDataReady();
62
63 void streamDestroyed();
64private:
65 QGstAppSrc(QGstElement appsrc, QObject *parent);
66
67 bool setStream(QIODevice *, qint64 offset);
68 bool isStreamValid() const
69 {
70 return m_stream != nullptr && m_stream->isOpen();
71 }
72
73 static gboolean on_seek_data(GstAppSrc *element, guint64 arg0, gpointer userdata);
74 static void on_enough_data(GstAppSrc *element, gpointer userdata);
75 static void on_need_data(GstAppSrc *element, uint arg0, gpointer userdata);
76
77 void sendEOS();
78 void eosOrIdle();
79
80 QIODevice *m_stream = nullptr;
81 QNetworkReply *m_networkReply = nullptr;
82 QRingBuffer m_buffer;
83 QAudioFormat m_format;
84
85 QGstElement m_appSrc;
86 bool m_sequential = true;
87 bool m_suspended = false;
88 bool m_noMoreData = false;
89 GstAppStreamType m_streamType = GST_APP_STREAM_TYPE_RANDOM_ACCESS;
90 qint64 m_offset = 0;
91 qint64 m_maxBytes = 0;
92 qint64 bytesReadSoFar = 0;
93 QAtomicInteger<unsigned int> m_dataRequestSize = 0;
94 int streamedSamples = 0;
95};
96
97QT_END_NAMESPACE
98
99#endif
100

source code of qtmultimedia/src/plugins/multimedia/gstreamer/common/qgstappsrc_p.h