diff --git a/ChangeLog b/ChangeLog index 17541ba9fc..08af99ce7b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-02-12 Sebastian Dröge + + * ext/gio/gstgiostreamsink.c: + * ext/gio/gstgiostreamsrc.c: + Add documentation and example code for giostreamsink/giostreamsrc. + + * tests/check/pipelines/gio.c: (GST_START_TEST): + Ask the GMemoryOutputStream for the data instead of assuming that + the pointer to the data stayed the same. It could've been realloc'ed. + 2008-02-12 Sebastian Dröge * ext/gio/gstgiosink.c: diff --git a/ext/gio/gstgiostreamsink.c b/ext/gio/gstgiostreamsink.c index f27d2990e1..cafea2b04b 100644 --- a/ext/gio/gstgiostreamsink.c +++ b/ext/gio/gstgiostreamsink.c @@ -21,12 +21,45 @@ /** * SECTION:element-giostreamsink + * @short_description: Write to a GIO GOutputStream * * - * Example launch line * + * This plugin writes incoming data to a custom GIO #GOutputStream. + * + * + * It can, for example, be used to write a stream to memory with a + * #GMemoryOuputStream or to write to a file with a #GFileOuputStream. + * + * Example code + * + * The following example writes the received data to a #GMemoryOutputStream. * - * gst-launch audiotestsrc num-buffers=100 ! flacenc ! giosink location=file:///home/foo/bar.flac + +#include <gst/gst.h> +#include <gio/gio.h> + +... + +GstElement *sink; +GMemoryOuputStream *stream; +// out_data will contain the received data +guint8 *out_data; + +... + +stream = G_MEMORY_OUTPUT_STREAM (g_memory_output_stream_new (NULL, 0, + (GReallocFunc) g_realloc, (GDestroyNotify) g_free)); +sink = gst_element_factory_make ("giostreamsink", "sink"); +g_object_set (G_OBJECT (sink), "stream", stream, NULL); + +... + +// after processing get the written data +out_data = g_memory_ouput_stream_get_data (G_MEMORY_OUTPUT_STREAM (stream)); + +... + * * * diff --git a/ext/gio/gstgiostreamsrc.c b/ext/gio/gstgiostreamsrc.c index 3683c980c6..78b78d1cd1 100644 --- a/ext/gio/gstgiostreamsrc.c +++ b/ext/gio/gstgiostreamsrc.c @@ -21,12 +21,45 @@ /** * SECTION:element-giostreamsrc + * @short_description: Reads data from a GIO GInputStream * * - * Example launch line * + * This plugin reads data from a custom GIO #GInputStream. + * + * + * It can, for example, be used to read data from memory with a + * #GMemoryInputStream or to read from a file with a + * #GFileInputStream. + * + * Example code + * + * The following example reads data from a #GMemoryOutputStream. * - * gst-launch giosrc location=file:///home/foo/bar.ext ! fakesink + +#include <gst/gst.h> +#include <gio/gio.h> + +... + +GstElement *src; +GMemoryInputStream *stream; +// in_data will contain the data to send +guint8 *in_data; +gint i; + +... +in_data = g_new (guint8, 512); +for (i = 0; i < 512; i++) + in_data[i] = i % 256; + +stream = G_MEMORY_INPUT_STREAM (g_memory_input_stream_new_from_data (in_data, 512, + (GDestroyNotify) g_free)); +src = gst_element_factory_make ("giostreamsrc", "src"); +g_object_set (G_OBJECT (src), "stream", stream, NULL); + +... + * * * diff --git a/tests/check/pipelines/gio.c b/tests/check/pipelines/gio.c index a28cb7e96b..07ca0136b8 100644 --- a/tests/check/pipelines/gio.c +++ b/tests/check/pipelines/gio.c @@ -86,6 +86,7 @@ GST_START_TEST (test_memory_stream) output = G_MEMORY_OUTPUT_STREAM (g_memory_output_stream_new (out_data, 512, (GReallocFunc) g_realloc, (GDestroyNotify) g_free)); + out_data = NULL; loop = g_main_loop_new (NULL, FALSE); @@ -121,6 +122,8 @@ GST_START_TEST (test_memory_stream) fail_unless (got_eos); + out_data = g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (output)); + for (i = 0; i < 512; i++) fail_unless_equals_int (in_data[i], out_data[i]);