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 QGSTREAMERAUDIODECODERCONTROL_H
5#define QGSTREAMERAUDIODECODERCONTROL_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 <QtMultimedia/private/qtmultimediaglobal_p.h>
19#include <QObject>
20#include <QtCore/qmutex.h>
21#include <QtCore/qurl.h>
22
23#include <private/qplatformaudiodecoder_p.h>
24#include <private/qmultimediautils_p.h>
25#include <qgstpipeline_p.h>
26#include "qaudiodecoder.h"
27
28#if QT_CONFIG(gstreamer_app)
29#include <qgstappsrc_p.h>
30#endif
31
32#include <qgst_p.h>
33#include <gst/app/gstappsink.h>
34
35QT_BEGIN_NAMESPACE
36
37class QGstreamerMessage;
38
39class QGstreamerAudioDecoder
40 : public QPlatformAudioDecoder,
41 public QGstreamerBusMessageFilter
42{
43 Q_OBJECT
44
45public:
46 static QMaybe<QPlatformAudioDecoder *> create(QAudioDecoder *parent);
47 virtual ~QGstreamerAudioDecoder();
48
49 QUrl source() const override;
50 void setSource(const QUrl &fileName) override;
51
52 QIODevice *sourceDevice() const override;
53 void setSourceDevice(QIODevice *device) override;
54
55 void start() override;
56 void stop() override;
57
58 QAudioFormat audioFormat() const override;
59 void setAudioFormat(const QAudioFormat &format) override;
60
61 QAudioBuffer read() override;
62 bool bufferAvailable() const override;
63
64 qint64 position() const override;
65 qint64 duration() const override;
66
67 // GStreamerBusMessageFilter interface
68 bool processBusMessage(const QGstreamerMessage &message) override;
69
70#if QT_CONFIG(gstreamer_app)
71 QGstAppSrc *appsrc() const { return m_appSrc; }
72 static void configureAppSrcElement(GObject*, GObject*, GParamSpec*, QGstreamerAudioDecoder *_this);
73#endif
74
75 static GstFlowReturn new_sample(GstAppSink *sink, gpointer user_data);
76
77private slots:
78 void updateDuration();
79
80private:
81 QGstreamerAudioDecoder(QGstPipeline playbin, QGstElement audioconvert, QAudioDecoder *parent);
82
83 void setAudioFlags(bool wantNativeAudio);
84 void addAppSink();
85 void removeAppSink();
86
87 void processInvalidMedia(QAudioDecoder::Error errorCode, const QString& errorString);
88 static qint64 getPositionFromBuffer(GstBuffer* buffer);
89
90 QGstPipeline m_playbin;
91 QGstBin m_outputBin;
92 QGstElement m_audioConvert;
93 GstAppSink *m_appSink = nullptr;
94 QGstAppSrc *m_appSrc = nullptr;
95
96 QUrl mSource;
97 QIODevice *mDevice = nullptr;
98 QAudioFormat mFormat;
99
100 mutable QMutex m_buffersMutex;
101 int m_buffersAvailable = 0;
102
103 qint64 m_position = -1;
104 qint64 m_duration = -1;
105
106 int m_durationQueries = 0;
107};
108
109QT_END_NAMESPACE
110
111#endif // QGSTREAMERPLAYERSESSION_H
112

source code of qtmultimedia/src/plugins/multimedia/gstreamer/audio/qgstreameraudiodecoder_p.h