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#include "qgstreameraudiodevice_p.h"
5
6#include <qgstutils_p.h>
7#include <private/qplatformmediaintegration_p.h>
8
9QT_BEGIN_NAMESPACE
10
11QGStreamerAudioDeviceInfo::QGStreamerAudioDeviceInfo(GstDevice *d, const QByteArray &device, QAudioDevice::Mode mode)
12 : QAudioDevicePrivate(device, mode),
13 gstDevice(d)
14{
15 Q_ASSERT(gstDevice);
16 gst_object_ref(object: gstDevice);
17
18 auto *n = gst_device_get_display_name(device: gstDevice);
19 description = QString::fromUtf8(utf8: n);
20 g_free(mem: n);
21
22 auto caps = QGstCaps(gst_device_get_caps(device: gstDevice),QGstCaps::HasRef);
23 int size = caps.size();
24 for (int i = 0; i < size; ++i) {
25 auto c = caps.at(index: i);
26 if (c.name() == "audio/x-raw") {
27 auto rate = c["rate"].toIntRange();
28 if (rate) {
29 minimumSampleRate = rate->min;
30 maximumSampleRate = rate->max;
31 }
32 auto channels = c["channels"].toIntRange();
33 if (channels) {
34 minimumChannelCount = channels->min;
35 maximumChannelCount = channels->max;
36 }
37 supportedSampleFormats = c["format"].getSampleFormats();
38 }
39 }
40
41 preferredFormat.setChannelCount(qBound(min: minimumChannelCount, val: 2, max: maximumChannelCount));
42 preferredFormat.setSampleRate(qBound(min: minimumSampleRate, val: 48000, max: maximumSampleRate));
43 QAudioFormat::SampleFormat f = QAudioFormat::Int16;
44 if (!supportedSampleFormats.contains(t: f))
45 f = supportedSampleFormats.value(i: 0, defaultValue: QAudioFormat::Unknown);
46 preferredFormat.setSampleFormat(f);
47}
48
49QGStreamerAudioDeviceInfo::~QGStreamerAudioDeviceInfo()
50{
51 if (gstDevice)
52 gst_object_unref(object: gstDevice);
53}
54
55QT_END_NAMESPACE
56

source code of qtmultimedia/src/plugins/multimedia/gstreamer/audio/qgstreameraudiodevice.cpp