簡體   English   中英

Qt和Gstreamer的交互出現問題

[英]Trouble with an interaction of Qt and Gstreamer

我在Qt中有我的GUI,並且有一個Gstreamer管道,可以從電視FM卡中提取音頻並將其寫入文件。 我想在管道中添加一個level元素,因為我想使用Qt ProgressBar顯示當前的音頻級別。 我只是不知道如何將值從GLib contexto傳遞到Qt GUI上下文。

我在一段代碼中添加了公交車看台(在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);
    ...
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM