4#include <QtCore/qcoreapplication.h>
5#include <QtCore/qdebug.h>
6#include <QtCore/qmath.h>
7#include <private/qaudiohelpers_p.h>
25 qRegisterMetaType<GstSample *>();
35 if (m_errorState ==
error)
49 if (m_deviceState ==
state)
52 m_deviceState =
state;
118bool QGStreamerAudioSource::open()
124 if (!deviceInfo->gstDevice) {
130 gstInput =
QGstElement(gst_device_create_element(deviceInfo->gstDevice,
nullptr));
139 if (gstCaps.isNull()) {
148 qDebug() <<
"Caps: " << gst_caps_to_string(gstCaps);
153 auto *gstBus = gst_pipeline_get_bus(gstPipeline.
pipeline());
154 gst_bus_add_watch(gstBus, &QGStreamerAudioSource::busMessage,
this);
155 gst_object_unref (gstBus);
157 gstAppSink = createAppSink();
158 gstAppSink.
set(
"caps", gstCaps);
164 gstVolume.
set(
"volume", m_volume);
166 gstPipeline.
add(gstInput, gstVolume, conv, gstAppSink);
167 gstInput.
link(gstVolume, conv, gstAppSink);
169 gstPipeline.
setState(GST_STATE_PLAYING);
174 m_elapsedTimeOffset = 0;
180void QGStreamerAudioSource::close()
185 gstPipeline.
setState(GST_STATE_NULL);
191 if (!m_pullMode && m_audioSink) {
194 m_audioSink =
nullptr;
198gboolean QGStreamerAudioSource::busMessage(GstBus *, GstMessage *msg, gpointer
user_data)
201 switch (GST_MESSAGE_TYPE (msg)) {
202 case GST_MESSAGE_EOS:
205 case GST_MESSAGE_ERROR: {
210 gst_message_parse_error (msg, &
error, &
debug);
214 g_error_free (
error);
226 return m_buffer.
size();
232 gstPipeline.
setState(GST_STATE_PLAYING);
245 gstVolume.
set(
"volume", vol);
255 m_bufferSize =
value;
274 gstPipeline.
setState(GST_STATE_PAUSED);
289 GstAppSink *appSink =
reinterpret_cast<GstAppSink *
>(
sink.element());
295 gst_app_sink_set_callbacks(appSink, &
callbacks,
this,
nullptr);
297 gst_base_sink_set_sync(GST_BASE_SINK(appSink), FALSE);
302void QGStreamerAudioSource::newDataAvailable(GstSample *sample)
305 GstBuffer *
buffer = gst_sample_get_buffer(sample);
307 gst_buffer_map(
buffer, &mapInfo, GST_MAP_READ);
308 const char *bufferData = (
const char*)mapInfo.data;
320 gst_buffer_unmap(
buffer, &mapInfo);
323 gst_sample_unref(sample);
326GstFlowReturn QGStreamerAudioSource::new_sample(GstAppSink *
sink, gpointer
user_data)
331 GstSample *sample = gst_app_sink_pull_sample(
sink);
337void QGStreamerAudioSource::eos(GstAppSink *, gpointer
user_data)
345 m_audioDevice = qobject_cast<QGStreamerAudioSource*>(audio);
353 m_audioDevice->m_bytesWritten += bytes;
366 return m_audioDevice->m_buffer.
size();
372#include "moc_qgstreameraudiosource_p.cpp"
IOBluetoothDevice * device
The QAudioDevice class provides an information about audio devices and their functionality.
const QAudioDevicePrivate * handle() const
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
void add(const QGstElement &element)
bool link(const QGstElement &next)
void set(const char *property, const char *str)
GstStateChangeReturn setState(GstState state)
GstPipeline * pipeline() const
\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.
State
\value ActiveState Audio data is being processed, this state is set after start() is called and while...
Error
\value NoError No errors have occurred \value OpenError An error occurred opening the audio device \v...
Q_MULTIMEDIA_EXPORT 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]
#define Q_ARG(Type, data)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei GLsizei GLenum format
GLsizei GLenum GLboolean sink
GLenum GLenum GLenum input
PromiseCallbacks callbacks
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent