4#include <common/qgstutils_p.h>
5#include <common/qgst_p.h>
7#include <QtMultimedia/qaudioformat.h>
17#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
33 for (
int i = 1; i < QAudioFormat::NSampleFormats; ++i) {
34 if (strcmp(fmt, audioSampleFormatNames[i]))
36 return QAudioFormat::SampleFormat(i);
39 return QAudioFormat::Unknown;
45
46
47
50 auto caps = QGstCaps(gst_sample_get_caps(sample), QGstCaps::NeedsRef);
53 return audioFormatForCaps(caps);
60 if (s.name() !=
"audio/x-raw")
63 auto rate = s
["rate"].toInt();
64 auto channels = s
["channels"].toInt();
65 QAudioFormat::SampleFormat fmt = gstSampleFormatToSampleFormat(s[
"format"].toString());
66 if (!rate || !channels || fmt == QAudioFormat::Unknown)
69 format.setSampleRate(*rate);
70 format.setChannelCount(*channels);
71 format.setSampleFormat(fmt);
77
78
79
80
81
85 if (!format.isValid())
88 auto sampleFormat = format.sampleFormat();
89 auto caps = gst_caps_new_simple(
91 "format" , G_TYPE_STRING, audioSampleFormatNames[sampleFormat],
92 "rate" , G_TYPE_INT , format.sampleRate(),
93 "channels", G_TYPE_INT , format.channelCount(),
94 "layout" , G_TYPE_STRING,
"interleaved",
97 return QGstCaps(caps, QGstCaps::HasRef);
102 if (!GST_VALUE_HOLDS_LIST(value))
105 QList<QAudioFormat::SampleFormat> formats;
106 guint nFormats = gst_value_list_get_size(value);
107 for (guint f = 0; f < nFormats; ++f) {
108 QGValue v = QGValue{ gst_value_list_get_value(value, f) };
110 QAudioFormat::SampleFormat fmt = gstSampleFormatToSampleFormat(name);
111 if (fmt == QAudioFormat::Unknown)
120 using namespace std::chrono;
121 using namespace std::chrono_literals;
124 nanoseconds startTime{ GST_BUFFER_TIMESTAMP(buffer) };
125 if (startTime >= 0ns) {
126 frame->setStartTime(floor<microseconds>(startTime).count());
128 nanoseconds duration{ GST_BUFFER_DURATION(buffer) };
130 frame->setEndTime(floor<microseconds>(startTime + duration).count());
136 return gst_element_factory_list_get_elements(GST_ELEMENT_FACTORY_TYPE_SINK
137 | GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO,
143 return QLocale::codeToLanguage(QString::fromUtf8(lang), QLocale::AnyLanguageCode);
QList< QAudioFormat::SampleFormat > getSampleFormats() const
const char * toString() const
QGstStructureView at(int index) const
QGValue operator[](const char *fieldname) const
QLocale::Language codeToLanguage(const gchar *)
QGstCaps capsForAudioFormat(const QAudioFormat &format)
QAudioFormat audioFormatForCaps(const QGstCaps &caps)
void setFrameTimeStampsFromBuffer(QVideoFrame *frame, GstBuffer *buffer)
QAudioFormat audioFormatForSample(GstSample *sample)
const char * audioSampleFormatNames[QAudioFormat::NSampleFormats]
QAudioFormat::SampleFormat gstSampleFormatToSampleFormat(const char *fmt)
GList * qt_gst_video_sinks()