Split out documentation into subfolders.
[platform/upstream/gstreamer.git] / examples / tutorials / basic-tutorial-8.c
similarity index 98%
rename from tutorials/basic-tutorial-8.c
rename to examples/tutorials/basic-tutorial-8.c
index 2ddeaa7..558ac2d 100644 (file)
@@ -1,24 +1,24 @@
 #include <gst/gst.h>
 #include <gst/audio/audio.h>
 #include <string.h>
-  
+
 #define CHUNK_SIZE 1024   /* Amount of bytes we are sending in each buffer */
 #define SAMPLE_RATE 44100 /* Samples per second we are sending */
-  
+
 /* Structure to contain all our information, so we can pass it to callbacks */
 typedef struct _CustomData {
   GstElement *pipeline, *app_source, *tee, *audio_queue, *audio_convert1, *audio_resample, *audio_sink;
   GstElement *video_queue, *audio_convert2, *visual, *video_convert, *video_sink;
   GstElement *app_queue, *app_sink;
-  
+
   guint64 num_samples;   /* Number of samples generated so far (for timestamp generation) */
   gfloat a, b, c, d;     /* For waveform generation */
-  
+
   guint sourceid;        /* To control the GSource */
-  
+
   GMainLoop *main_loop;  /* GLib's Main Loop */
 } CustomData;
-  
+
 /* This method is called by the idle GSource in the mainloop, to feed CHUNK_SIZE bytes into appsrc.
  * The idle handler is added to the mainloop when appsrc requests us to start sending data (need-data signal)
  * and is removed when appsrc has enough data (enough-data signal).
@@ -31,14 +31,14 @@ static gboolean push_data (CustomData *data) {
   gint16 *raw;
   gint num_samples = CHUNK_SIZE / 2; /* Because each sample is 16 bits */
   gfloat freq;
-  
+
   /* Create a new empty buffer */
   buffer = gst_buffer_new_and_alloc (CHUNK_SIZE);
-  
+
   /* Set its timestamp and duration */
   GST_BUFFER_TIMESTAMP (buffer) = gst_util_uint64_scale (data->num_samples, GST_SECOND, SAMPLE_RATE);
   GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale (CHUNK_SIZE, GST_SECOND, SAMPLE_RATE);
-  
+
   /* Generate some psychodelic waveforms */
   gst_buffer_map (buffer, &map, GST_MAP_WRITE);
   raw = (gint16 *)map.data;
@@ -52,21 +52,21 @@ static gboolean push_data (CustomData *data) {
   }
   gst_buffer_unmap (buffer, &map);
   data->num_samples += num_samples;
-  
+
   /* Push the buffer into the appsrc */
   g_signal_emit_by_name (data->app_source, "push-buffer", buffer, &ret);
-  
+
   /* Free the buffer now that we are done with it */
   gst_buffer_unref (buffer);
-  
+
   if (ret != GST_FLOW_OK) {
     /* We got some error, stop sending data */
     return FALSE;
   }
-  
+
   return TRUE;
 }
-  
+
 /* This signal callback triggers when appsrc needs data. Here, we add an idle handler
  * to the mainloop to start pushing data into the appsrc */
 static void start_feed (GstElement *source, guint size, CustomData *data) {
@@ -75,7 +75,7 @@ static void start_feed (GstElement *source, guint size, CustomData *data) {
     data->sourceid = g_idle_add ((GSourceFunc) push_data, data);
   }
 }
-  
+
 /* This callback triggers when appsrc has enough data and we can stop sending.
  * We remove the idle handler from the mainloop */
 static void stop_feed (GstElement *source, CustomData *data) {
@@ -85,11 +85,11 @@ static void stop_feed (GstElement *source, CustomData *data) {
     data->sourceid = 0;
   }
 }
-  
+
 /* The appsink has received a buffer */
 static void new_sample (GstElement *sink, CustomData *data) {
   GstSample *sample;
-  
+
   /* Retrieve the buffer */
   g_signal_emit_by_name (sink, "pull-sample", &sample);
   if (sample) {
@@ -98,22 +98,22 @@ static void new_sample (GstElement *sink, CustomData *data) {
     gst_sample_unref (sample);
   }
 }
-  
+
 /* This function is called when an error message is posted on the bus */
 static void error_cb (GstBus *bus, GstMessage *msg, CustomData *data) {
   GError *err;
   gchar *debug_info;
-  
+
   /* Print error details on the screen */
   gst_message_parse_error (msg, &err, &debug_info);
   g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message);
   g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none");
   g_clear_error (&err);
   g_free (debug_info);
-  
+
   g_main_loop_quit (data->main_loop);
 }
-  
+
 int main(int argc, char *argv[]) {
   CustomData data;
   GstPadTemplate *tee_src_pad_template;
@@ -122,15 +122,15 @@ int main(int argc, char *argv[]) {
   GstAudioInfo info;
   GstCaps *audio_caps;
   GstBus *bus;
-  
+
   /* Initialize cumstom data structure */
   memset (&data, 0, sizeof (data));
   data.b = 1; /* For waveform generation */
   data.d = 1;
-  
+
   /* Initialize GStreamer */
   gst_init (&argc, &argv);
-  
+
   /* Create the elements */
   data.app_source = gst_element_factory_make ("appsrc", "audio_source");
   data.tee = gst_element_factory_make ("tee", "tee");
@@ -145,34 +145,34 @@ int main(int argc, char *argv[]) {
   data.video_sink = gst_element_factory_make ("autovideosink", "video_sink");
   data.app_queue = gst_element_factory_make ("queue", "app_queue");
   data.app_sink = gst_element_factory_make ("appsink", "app_sink");
-  
+
   /* Create the empty pipeline */
   data.pipeline = gst_pipeline_new ("test-pipeline");
-  
+
   if (!data.pipeline || !data.app_source || !data.tee || !data.audio_queue || !data.audio_convert1 ||
       !data.audio_resample || !data.audio_sink || !data.video_queue || !data.audio_convert2 || !data.visual ||
       !data.video_convert || !data.video_sink || !data.app_queue || !data.app_sink) {
     g_printerr ("Not all elements could be created.\n");
     return -1;
   }
-  
+
   /* Configure wavescope */
   g_object_set (data.visual, "shader", 0, "style", 0, NULL);
-  
+
   /* Configure appsrc */
   gst_audio_info_set_format (&info, GST_AUDIO_FORMAT_S16, SAMPLE_RATE, 1, NULL);
   audio_caps = gst_audio_info_to_caps (&info);
   g_object_set (data.app_source, "caps", audio_caps, "format", GST_FORMAT_TIME, NULL);
   g_signal_connect (data.app_source, "need-data", G_CALLBACK (start_feed), &data);
   g_signal_connect (data.app_source, "enough-data", G_CALLBACK (stop_feed), &data);
-  
+
   /* Configure appsink */
   g_object_set (data.app_sink, "emit-signals", TRUE, "caps", audio_caps, NULL);
   g_signal_connect (data.app_sink, "new-sample", G_CALLBACK (new_sample), &data);
   gst_caps_unref (audio_caps);
-  
+
   /* Link all elements that can be automatically linked because they have "Always" pads */
-  gst_bin_add_many (GST_BIN (data.pipeline), data.app_source, data.tee, data.audio_queue, data.audio_convert1, data.audio_resample, 
+  gst_bin_add_many (GST_BIN (data.pipeline), data.app_source, data.tee, data.audio_queue, data.audio_convert1, data.audio_resample,
       data.audio_sink, data.video_queue, data.audio_convert2, data.visual, data.video_convert, data.video_sink, data.app_queue,
       data.app_sink, NULL);
   if (gst_element_link_many (data.app_source, data.tee, NULL) != TRUE ||
@@ -183,7 +183,7 @@ int main(int argc, char *argv[]) {
     gst_object_unref (data.pipeline);
     return -1;
   }
-  
+
   /* Manually link the Tee, which has "Request" pads */
   tee_src_pad_template = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (data.tee), "src_%u");
   tee_audio_pad = gst_element_request_pad (data.tee, tee_src_pad_template, NULL, NULL);
@@ -205,20 +205,20 @@ int main(int argc, char *argv[]) {
   gst_object_unref (queue_audio_pad);
   gst_object_unref (queue_video_pad);
   gst_object_unref (queue_app_pad);
-  
+
   /* Instruct the bus to emit signals for each received message, and connect to the interesting signals */
   bus = gst_element_get_bus (data.pipeline);
   gst_bus_add_signal_watch (bus);
   g_signal_connect (G_OBJECT (bus), "message::error", (GCallback)error_cb, &data);
   gst_object_unref (bus);
-  
+
   /* Start playing the pipeline */
   gst_element_set_state (data.pipeline, GST_STATE_PLAYING);
-  
+
   /* Create a GLib Main Loop and set it to run */
   data.main_loop = g_main_loop_new (NULL, FALSE);
   g_main_loop_run (data.main_loop);
-  
+
   /* Release the request pads from the Tee, and unref them */
   gst_element_release_request_pad (data.tee, tee_audio_pad);
   gst_element_release_request_pad (data.tee, tee_video_pad);
@@ -226,7 +226,7 @@ int main(int argc, char *argv[]) {
   gst_object_unref (tee_audio_pad);
   gst_object_unref (tee_video_pad);
   gst_object_unref (tee_app_pad);
-  
+
   /* Free resources */
   gst_element_set_state (data.pipeline, GST_STATE_NULL);
   gst_object_unref (data.pipeline);