c++ - Qt 和 Gstreamer 交互的问题

标签 c++ qt gstreamer

我在 Qt 中有我的 GUI,我有一个 Gstreamer 管道,它从电视 FM 卡中获取音频并将其写入文件。我在管道中添加了一个级别元素,因为我想使用 Qt ProgressBar 显示当前的音频级别。我只是不知道如何将值从 GLib contexto 传递到 Qt GUI 上下文。

我的一段代码,我在其中添加了一个总线 watch (在 Qt 插槽内)

gst_bin_add_many(GST_BIN(pline2), alsasrc, audioconvert, level, audioresample, wavenc, filesink, NULL);
gst_element_link_many(alsasrc, audioconvert, level, audioresample, wavenc, filesink, NULL);
bus = gst_pipeline_get_bus(GST_PIPELINE(pline2));
guint watch_id = gst_bus_add_watch (bus, message_handler, NULL);
gst_bus_add_watch(bus, bus_call, loop2);
gst_object_unref(bus);

这是我获得音频电平的地方

static gboolean message_handler (GstBus * bus, GstMessage * message, gpointer data)
{
    if (message->type == GST_MESSAGE_ELEMENT) {
        const GstStructure *s = gst_message_get_structure (message);
        const gchar *name = gst_structure_get_name (s);
        if (strcmp (name, "level") == 0) {
            gint channels;
            GstClockTime endtime;
            gdouble rms_dB, peak_dB, decay_dB;
            gdouble rms;
            const GValue *array_val;
            const GValue *value;
            GValueArray *rms_arr, *peak_arr, *decay_arr;
            gint i;
            if (!gst_structure_get_clock_time (s, "endtime", &endtime))
                g_warning ("Could not parse endtime");
            /* the values are packed into GValueArrays with the value per channel */
            array_val = gst_structure_get_value (s, "rms");
            rms_arr = (GValueArray *) g_value_get_boxed (array_val);
            array_val = gst_structure_get_value (s, "peak");
            peak_arr = (GValueArray *) g_value_get_boxed (array_val);
            array_val = gst_structure_get_value (s, "decay");
            decay_arr = (GValueArray *) g_value_get_boxed (array_val);
            /* we can get the number of channels as the length of any of the value
                   * arrays */
            channels = rms_arr->n_values;
            g_print ("endtime: %" GST_TIME_FORMAT ", channels: %d\n",
                      GST_TIME_ARGS (endtime), channels);
            for (i = 0; i < channels; ++i) {
                g_print ("channel %d\n", i);
                value = g_value_array_get_nth (rms_arr, i);
                rms_dB = g_value_get_double (value);
                value = g_value_array_get_nth (peak_arr, i);
                peak_dB = g_value_get_double (value);
                value = g_value_array_get_nth (decay_arr, i);
                decay_dB = g_value_get_double (value);
                //g_print ("    RMS: %f dB, peak: %f dB, decay: %f dB\n", rms_dB, peak_dB, decay_dB);
                /* converting from dB to normal gives us a value between 0.0 and 1.0 */
                rms = pow (10, rms_dB / 20);
                //g_print ("    normalized rms value: %f\n", rms);


            }
        }
    }
    return TRUE;
}

例如,我如何显示 rms_dB 值?也许有人可以给我一个提示。谢谢。

最佳答案

您可以将进度条指针作为参数传递给 gst_bus_add_watch:

QProgressBar* progressBar = ...;
...
guint watch_id = gst_bus_add_watch (bus, message_handler, (gpointer)progressBar);
...
static gboolean message_handler (GstBus * bus, GstMessage * message, gpointer data)
{
    ...
    QProgressBar* progressBar = static_cast<QProgressBar*>(data);
    progressBar->setValue(rms_dB);
    ...
 }

关于c++ - Qt 和 Gstreamer 交互的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46237188/

相关文章:

android - 关于android上JNI中C++全局变量的问题

c++ - __attribute __((__ packed__))有什么区别;和#pragma pack(1)

c++ - Sailfish OS下的Gstreamer没有输出声音

qt - 使用 Qt 录制和播放音频流

windows - GStreamer Qt WINDOWS

c++ - GStreamer 在 Qt5 树莓派中遇到一般流错误

c++ - 变换反馈的完整设置(openGL)

c++ - 如何使用 Boost 在 C++ 中制作代理服务器

sqlite - 为设备选择嵌入式Linux

qt - 为什么 QML ScrollView 在 QtQuick.Controls 2.0 中不可用?