2017-09-15 4 views
0

Qt에 GUI가 있고 TV FM 카드에서 오디오를 가져 와서 파일에 쓰는 Gstreamer 파이프 라인이 있습니다. Qt ProgressBar를 사용하여 현재 오디오 레벨을 보여주기 때문에 레벨 요소를 파이프 라인에 추가했습니다. GLib 컨텍스트에서 Qt GUI 컨텍스트로 값을 전달하는 방법을 알 수 없습니다.Qt와 Gstreamer의 상호 작용에 문제가 있습니다.

I의 (a 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 값? 아마 누군가 나에게 힌트를 줄 수있을거야. 고맙습니다.

답변

1

당신은 gst_bus_add_watch 인수로 진행 표시 줄 포인터를 전달할 수 있습니다 : 오류 : 님의 호출에 대한 일치 기능 'qobject_cast (무효 *)' QProgressBar *의 ProgressBar =을

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

이 내가 무엇을 얻을 qobject_cast (데이터); – alexanderk409

+0

QProgressBar * progressBar = static_cast (데이터); QObject 포인터가 없으므로 qobject_cast가 작동하지 않습니다. –

+0

정말 고마워요. 뛰어난 솔루션. 그것은 작동합니다. – alexanderk409

관련 문제