2017-09-15 3 views
0

J'ai mon interface graphique en Qt et j'ai un pipeline Gstreamer qui récupère l'audio d'une carte TV FM et l'écrit dans un fichier. J'ai ajouté un élément de niveau dans le pipeline parce que je veux montrer le niveau audio actuel en utilisant un Qt ProgressBar. Je n'arrive pas à comprendre comment passer une valeur de GLib contexto dans le contexte Qt GUI.Problème avec une interaction de Qt et Gstreamer

Un morceau de mon code où j'ajoute une montre de bus (dans une fente 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); 

Et voici où je reçois le niveau audio

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; 
} 

Comment pourrais-je afficher, pour exemple, valeur rms_dB? Peut-être que quelqu'un pourrait me donner un indice. Je vous remercie.

Répondre

1

Vous pouvez passer un pointeur de barre de progression comme argument pour 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); 
    ... 
} 
+0

Voici ce que je reçois: erreur: pas de fonction concordante pour appel à 'qobject_cast (void * &)' QProgressBar * progressBar = qobject_cast (données); – alexanderk409

+0

QProgressBar * progressBar = static_cast (data) ;, car ce n'est pas un pointeur QObject qobject_cast ne peut pas fonctionner. –

+0

Merci beaucoup. Solution brillante. Ça marche. – alexanderk409