4#include <QtCore/qcoreapplication.h>
5#include <QtCore/qdebug.h>
6#include <QtCore/qmath.h>
7#include <QtMultimedia/private/qaudiohelpers_p.h>
27 qRegisterMetaType<GstSample *>();
37 if (m_errorState ==
error)
51 if (m_deviceState ==
state)
54 m_deviceState =
state;
120bool QGStreamerAudioSource::open()
126 if (!deviceInfo->gstDevice) {
141 if (gstCaps.isNull()) {
150 qDebug() <<
"Caps: " << gst_caps_to_string(gstCaps);
155 auto *gstBus = gst_pipeline_get_bus(gstPipeline.
pipeline());
156 gst_bus_add_watch(gstBus, &QGStreamerAudioSource::busMessage,
this);
157 gst_object_unref (gstBus);
159 gstAppSink = createAppSink();
160 gstAppSink.set(
"caps", gstCaps);
166 gstVolume.
set(
"volume", m_volume);
168 gstPipeline.
add(gstInput, gstVolume, conv, gstAppSink);
171 gstPipeline.
setState(GST_STATE_PLAYING);
176 m_elapsedTimeOffset = 0;
182void QGStreamerAudioSource::close()
187 gstPipeline.
setState(GST_STATE_NULL);
193 if (!m_pullMode && m_audioSink) {
196 m_audioSink =
nullptr;
200gboolean QGStreamerAudioSource::busMessage(GstBus *, GstMessage *msg, gpointer
user_data)
203 switch (GST_MESSAGE_TYPE (msg)) {
204 case GST_MESSAGE_EOS:
207 case GST_MESSAGE_ERROR: {
220 return m_buffer.
size();
226 gstPipeline.
setState(GST_STATE_PLAYING);
239 gstVolume.
set(
"volume", vol);
249 m_bufferSize =
value;
268 gstPipeline.
setState(GST_STATE_PAUSED);
280QGstAppSink QGStreamerAudioSource::createAppSink()
282 QGstAppSink
sink = QGstAppSink::create(
"appsink");
289 gst_base_sink_set_sync(
sink.baseSink(), FALSE);
297 GstBuffer *
buffer = gst_sample_get_buffer(sample.
get());
299 gst_buffer_map(
buffer, &mapInfo, GST_MAP_READ);
300 const char *bufferData = (
const char*)mapInfo.data;
312 gst_buffer_unmap(
buffer, &mapInfo);
316GstFlowReturn QGStreamerAudioSource::new_sample(GstAppSink *
sink, gpointer
user_data)
322 gst_app_sink_pull_sample(
sink),
327 control->newDataAvailable(std::move(sample));
333void QGStreamerAudioSource::eos(GstAppSink *, gpointer
user_data)
341 m_audioDevice = audio;
349 m_audioDevice->m_bytesWritten += bytes;
362 return m_audioDevice->m_buffer.
size();
IOBluetoothDevice * device
The QAudioDevice class provides an information about audio devices and their functionality.
const QAudioDevicePrivate * handle() const
void stateChanged(QAudio::State state)
void errorChanged(QAudio::Error error)
qint64 restart() noexcept
Restarts the timer and returns the number of milliseconds elapsed since the previous start.
qsizetype bufferSize() const override
void setFormat(const QAudioFormat &format) override
void setBufferSize(qsizetype value) override
qsizetype bytesReady() const override
QAudioFormat format() const override
qreal volume() const override
qint64 processedUSecs() const override
void setVolume(qreal volume) override
friend class GStreamerInputPrivate
QAudio::State state() const override
QIODevice * start() override
QGStreamerAudioSource(const QAudioDevice &device, QObject *parent)
QAudio::Error error() const override
std::enable_if_t<(std::is_base_of_v< QGstElement, Ts > &&...), void add)(const Ts &...ts)
static QGstElement createFromDevice(const QGstDeviceHandle &, const char *name=nullptr)
static QGstElement createFromFactory(const char *factory, const char *name=nullptr)
void set(const char *property, const char *str)
GstStateChangeReturn setState(GstState state)
GstPipeline * pipeline() const
static QGstPipeline create(const char *name)
\inmodule QtCore \reentrant
virtual bool open(QIODeviceBase::OpenMode mode)
Opens the device and sets its OpenMode to mode.
void readyRead()
This signal is emitted once every time new data is available for reading from the device's current re...
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Q_CORE_EXPORT void append(const char *data, qint64 size)
Q_CORE_EXPORT void clear()
Q_CORE_EXPORT qint64 read(char *data, qint64 maxLength)
static QTime currentTime()
Returns the current time as reported by the system clock.
QGstCaps capsForAudioFormat(const QAudioFormat &format)
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void * user_data
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
std::enable_if_t<(std::is_base_of_v< QGstElement, Ts > &&...), void qLinkGstElements)(const Ts &...ts)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei GLsizei GLenum format
GLsizei GLenum GLboolean sink
GLenum GLenum GLenum input
PromiseCallbacks callbacks
Type get() const noexcept