Explorar el Código

fix #4974: migrate conversation GST helpers to new MST API

Christian Grothoff hace 7 años
padre
commit
802f89d297

+ 1 - 1
src/conversation/Makefile.am

@@ -138,7 +138,7 @@ gnunet_helper_audio_record_CFLAGS = \
  $(GST_CFLAGS)
 
 gnunet_helper_audio_playback_SOURCES = \
-    gnunet_gst_test.c gnunet_gst.c
+    gnunet-helper-audio-playback-gst.c
 gnunet_helper_audio_playback_LDADD = \
   $(top_builddir)/src/util/libgnunetutil.la \
   $(GST_LIBS) \

+ 35 - 34
src/conversation/gnunet-helper-audio-playback-gst.c

@@ -56,7 +56,7 @@
 /**
  * Tokenizer for the data we get from stdin
  */
-struct GNUNET_SERVER_MessageStreamTokenizer *stdin_mst;
+struct GNUNET_MessageStreamTokenizer *stdin_mst;
 
 /**
  * Main pipeline.
@@ -82,20 +82,20 @@ static int abort_read;
 
 static void
 sink_child_added (GstChildProxy *child_proxy,
-		  GObject *object, 
+		  GObject *object,
 		  gchar *name,
 		  gpointer user_data)
 {
   if (GST_IS_AUDIO_BASE_SRC (object))
     g_object_set (object,
-		  "buffer-time", (gint64) BUFFER_TIME, 
+		  "buffer-time", (gint64) BUFFER_TIME,
 		  "latency-time", (gint64) LATENCY_TIME,
 		  NULL);
 }
 
 
 static void
-ogg_pad_added (GstElement *element, 
+ogg_pad_added (GstElement *element,
 	       GstPad *pad,
 	       gpointer data)
 {
@@ -127,7 +127,7 @@ quit ()
 static gboolean
 bus_call (GstBus *bus, GstMessage *msg, gpointer data)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
 	      "Bus message\n");
   switch (GST_MESSAGE_TYPE (msg))
   {
@@ -141,15 +141,15 @@ bus_call (GstBus *bus, GstMessage *msg, gpointer data)
     {
       gchar  *debug;
       GError *error;
-      
+
       gst_message_parse_error (msg, &error, &debug);
       g_free (debug);
-      
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
-		  "Error: %s\n", 
+
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+		  "Error: %s\n",
 		  error->message);
       g_error_free (error);
-      
+
       quit ();
       break;
     }
@@ -196,7 +196,7 @@ feed_buffer_to_gst (const char *audio, size_t b_len)
   switch (flow)
   {
   case GST_FLOW_OK:
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
 		"Fed %u bytes to the pipeline\n",
 		(unsigned int) b_len);
     break;
@@ -207,7 +207,7 @@ feed_buffer_to_gst (const char *audio, size_t b_len)
     break;
   case GST_FLOW_EOS:
     /* end of stream */
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
 		"EOS\n");
     break;
   default:
@@ -224,7 +224,6 @@ feed_buffer_to_gst (const char *audio, size_t b_len)
  */
 static int
 stdin_receiver (void *cls,
-		void *client,
 		const struct GNUNET_MessageHeader *msg)
 {
   struct AudioMessage *audio;
@@ -253,21 +252,21 @@ main (int argc, char **argv)
   uint64_t toff;
 
   typedef void (*SignalHandlerPointer) (int);
- 
+
   SignalHandlerPointer inthandler, termhandler;
 #ifdef DEBUG_READ_PURE_OGG
   int read_pure_ogg = getenv ("GNUNET_READ_PURE_OGG") ? 1 : 0;
 #endif
 
-  inthandler = signal (SIGINT, 
+  inthandler = signal (SIGINT,
 		       &signalhandler);
-  termhandler = signal (SIGTERM, 
+  termhandler = signal (SIGTERM,
 			&signalhandler);
-  
+
 #ifdef WINDOWS
   setmode (0, _O_BINARY);
 #endif
-  
+
   /* Initialisation */
   gst_init (&argc, &argv);
 
@@ -275,13 +274,13 @@ main (int argc, char **argv)
 		 GNUNET_log_setup ("gnunet-helper-audio-playback-gst",
 				   "WARNING",
 				   NULL));
-  
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
 	      "Audio sink starts\n");
-  
-  stdin_mst = GNUNET_SERVER_mst_create (&stdin_receiver, 
-					NULL);
-  
+
+  stdin_mst = GNUNET_MST_create (&stdin_receiver,
+                                 NULL);
+
   /* Create gstreamer elements */
   pipeline = gst_pipeline_new ("audio-player");
   source   = gst_element_factory_make ("appsrc",        "audio-input");
@@ -298,13 +297,13 @@ main (int argc, char **argv)
     return -1;
   }
 
-  g_signal_connect (sink, 
+  g_signal_connect (sink,
 		    "child-added",
-		    G_CALLBACK (sink_child_added), 
+		    G_CALLBACK (sink_child_added),
 		    NULL);
-  g_signal_connect (demuxer, 
+  g_signal_connect (demuxer,
 		    "pad-added",
-		    G_CALLBACK (ogg_pad_added), 
+		    G_CALLBACK (ogg_pad_added),
 		    decoder);
 
   /* Keep a reference to it, we operate on it */
@@ -362,7 +361,7 @@ main (int argc, char **argv)
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
 		"Received %d bytes of audio data (total: %llu)\n",
 		(int) ret,
-		toff);
+		(unsigned long long) toff);
     if (0 == ret)
       break;
 #ifdef DEBUG_READ_PURE_OGG
@@ -372,20 +371,22 @@ main (int argc, char **argv)
     }
     else
 #endif
-    GNUNET_SERVER_mst_receive (stdin_mst, NULL,
-			       readbuf, ret,
-			       GNUNET_NO, GNUNET_NO);
+    GNUNET_MST_from_buffer (stdin_mst,
+                            readbuf,
+                            ret,
+                            GNUNET_NO,
+                            GNUNET_NO);
   }
-  GNUNET_SERVER_mst_destroy (stdin_mst);
+  GNUNET_MST_destroy (stdin_mst);
 
   signal (SIGINT, inthandler);
   signal (SIGINT, termhandler);
 
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
 	      "Returned, stopping playback\n");
   quit ();
 
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
 	      "Deleting pipeline\n");
   gst_object_unref (GST_OBJECT (source));
   source = NULL;

+ 6 - 3
src/conversation/gnunet-helper-audio-record-gst.c

@@ -352,9 +352,12 @@ main (int argc, char **argv)
         {
           if (-1 == ret)
             GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Failed to write %u bytes at offset %u (total %u) in phase %d: %s\n",
-                (unsigned int) to_send - offset, (unsigned int) offset,
-                (unsigned int) (to_send + offset), phase, strerror (errno));
+                        "Failed to write %u bytes at offset %u (total %u) in phase %d: %s\n",
+                        (unsigned int) (to_send - offset),
+                        (unsigned int) offset,
+                        (unsigned int) (to_send + offset),
+                        phase,
+                        strerror (errno));
           abort_send = 1;
           break;
         }

+ 26 - 28
src/conversation/gnunet_gst.c

@@ -29,6 +29,7 @@
  */
 static struct GNUNET_CONFIGURATION_Handle *cfg;
 
+
 void
 dump_buffer(unsigned n, const unsigned char* buf)
 {
@@ -61,15 +62,13 @@ BREAKOUT:
 /***
  * load gnunet configuration
  */
-  void
+void
 gg_load_configuration(GNUNET_gstData * d)
 {
   char *audiobackend_string;
   cfg =  GNUNET_CONFIGURATION_create();
   GNUNET_CONFIGURATION_load(cfg, "mediahelper.conf");
 
-  char *section = "MEDIAHELPER";
-
   GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "JACK_PP_IN", &d->jack_pp_in);
   GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "JACK_PP_OUT", &d->jack_pp_out);
 
@@ -77,19 +76,19 @@ gg_load_configuration(GNUNET_gstData * d)
 
  // printf("abstring: %s \n", audiobackend_string);
 
-  if ( audiobackend_string == "AUTO" )
+  if (0 == strcasecmp (audiobackend_string, "AUTO"))
   {
     d->audiobackend = AUTO;
-  } else if ( audiobackend_string = "JACK" )
+  } else if (0 == strcasecmp (audiobackend_string, "JACK"))
   {
     d->audiobackend = JACK;
-  } else if ( audiobackend_string = "ALSA" )
+  } else if (0 == strcasecmp (audiobackend_string, "ALSA"))
   {
     d->audiobackend = ALSA;
-  } else if ( audiobackend_string = "FAKE" )
+  } else if (0 == strcasecmp (audiobackend_string, "FAKE"))
   {
     d->audiobackend = FAKE;
-  } else if ( audiobackend_string = "TEST" )
+  } else if (0 == strcasecmp (audiobackend_string, "TEST"))
   {
     d->audiobackend = TEST;
   } else
@@ -147,8 +146,6 @@ write_data (const char *ptr, size_t msg_size)
 extern GstFlowReturn
 on_appsink_new_sample (GstElement * element, GNUNET_gstData * d)
 {
-  static unsigned long long toff;
-
   //size of message including gnunet header
   size_t msg_size;
 
@@ -161,7 +158,6 @@ on_appsink_new_sample (GstElement * element, GNUNET_gstData * d)
   GstCaps *s_caps;
   char *caps_str;
 */
-  (d->audio_message)->header.size = htons ((uint16_t) msg_size);
 
   if (gst_app_sink_is_eos(GST_APP_SINK(element)))
     return GST_FLOW_OK;
@@ -197,13 +193,7 @@ on_appsink_new_sample (GstElement * element, GNUNET_gstData * d)
 
   // copy the data into audio_message
   GNUNET_memcpy (((char *) &(d->audio_message)[1]), map.data, len);
-/*
-  toff += msg_size;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Sending %u bytes of audio data (total: %llu)\n",
-              (unsigned int) msg_size,
-              toff);
-*/
+  (d->audio_message)->header.size = htons ((uint16_t) msg_size);
   if (d->pure_ogg)
     // write the audio_message without the gnunet headers
     write_data ((const char *) &(d->audio_message)[1], len);
@@ -589,14 +579,15 @@ autoaudiosource_child_added (GstChildProxy *child_proxy, GObject *object, gchar
     g_object_set (object, "buffer-time", (gint64) BUFFER_TIME, "latency-time", (gint64) LATENCY_TIME, NULL);
 }
 
+
 GstElement *
 get_pipeline(GstElement *element)
 {
   GstPipeline *p;
 
-  p = gst_object_get_parent(element);
+  p = GST_PIPELINE (gst_object_get_parent(GST_OBJECT (element)));
 
-  return p;
+  return GST_ELEMENT (p);
 }
 
   static void
@@ -617,6 +608,7 @@ decoder_ogg_pad_added (GstElement *element,
   gst_object_unref (sinkpad);
 }
 
+
 int
 gnunet_read (GNUNET_gstData * d)
 {
@@ -646,10 +638,13 @@ gnunet_read (GNUNET_gstData * d)
      else
      {
   //#endif
-  GNUNET_SERVER_mst_receive (d->stdin_mst, NULL,
-      readbuf, ret,
-      GNUNET_NO, GNUNET_NO);
+  GNUNET_MST_from_buffer (d->stdin_mst,
+                          readbuf,
+                          ret,
+                          GNUNET_NO,
+                          GNUNET_NO);
      }
+     return 0;
 }
 
 /**
@@ -657,13 +652,14 @@ gnunet_read (GNUNET_gstData * d)
  */
 static int
 stdin_receiver (void *cls,
-		void *client,
 		const struct GNUNET_MessageHeader *msg)
 {
   struct AudioMessage *audio;
   size_t b_len;
+
   printf("stdin receiver \n ");
-  dump_buffer(sizeof(msg), msg);
+  dump_buffer (sizeof(msg),
+               (const unsigned char *) msg);
 
   switch (ntohs (msg->type))
   {
@@ -711,7 +707,7 @@ get_app(GNUNET_gstData *d, int type)
  //d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
 
 
-    d->stdin_mst = GNUNET_SERVER_mst_create (&stdin_receiver, d);
+    d->stdin_mst = GNUNET_MST_create (&stdin_receiver, d);
 
     if ( d->stdin_mst == NULL)
      printf("stdin_mst = NULL");
@@ -768,7 +764,7 @@ get_coder(GNUNET_gstData *d , int type)
 {
   GstBin *bin;
   GstPad *srcpad, *sinkpad, *srcghostpad, *sinkghostpad;
-  GstCaps *caps, *rtpcaps;
+  GstCaps *rtpcaps;
   GstElement *encoder, *muxer, *decoder, *demuxer, *jitterbuffer, *rtpcapsfilter;
 
   if ( d->usertp == TRUE )
@@ -892,7 +888,9 @@ get_coder(GNUNET_gstData *d , int type)
 
   return bin;
 }
-  extern GstBin *
+
+
+extern GstBin *
 get_audiobin(GNUNET_gstData *d , int type)
 {
   GstBin *bin;

+ 1 - 1
src/conversation/gnunet_gst_def.h

@@ -94,7 +94,7 @@ struct GNUNET_gstData {
 
   // things
   struct AudioMessage *audio_message;
-  struct GNUNET_SERVER_MessageStreamTokenizer *stdin_mst;
+  struct GNUNET_MessageStreamTokenizer *stdin_mst;
   GstElement *appsrc;
   GstElement *appsink;
   //settings

+ 3 - 4
src/conversation/gnunet_gst_test.c

@@ -18,7 +18,7 @@
   Boston, MA 02110-1301, USA.
 */
 /**
- * @file conversation/gnunet_gst.c
+ * @file conversation/gnunet_gst_test.c
  * @brief FIXME
  * @author Hark
  */
@@ -30,8 +30,7 @@ int
 main (int argc, char *argv[])
 {
   struct GNUNET_gstData *gst;
-  GstBus *bus;
-  GstMessage *msg;
+  // GstBus *bus;
   GstElement *gnunetsrc, *gnunetsink, *source, *sink, *encoder, *decoder;
 
 
@@ -137,7 +136,7 @@ main (int argc, char *argv[])
  }
   g_print ("Returned, stopping playback\n");
 
-  gst_object_unref (bus);
+  // gst_object_unref (bus);
   gst_element_set_state (GST_ELEMENT(gst->pipeline), GST_STATE_NULL);
   gst_object_unref (gst->pipeline);