From b2e8f0ecfd4a35c62b3feb65d01ded8c25990a3e Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 12 Jan 2004 19:35:54 +0000 Subject: adding structure setters matching the templates for audio Original commit message from CVS: adding structure setters matching the templates for audio --- gst-libs/gst/audio/audio.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'gst-libs/gst/audio/audio.c') diff --git a/gst-libs/gst/audio/audio.c b/gst-libs/gst/audio/audio.c index e1d59220..d467af49 100644 --- a/gst-libs/gst/audio/audio.c +++ b/gst-libs/gst/audio/audio.c @@ -23,6 +23,8 @@ #include "audio.h" +#include + int gst_audio_frame_byte_size (GstPad* pad) { @@ -185,6 +187,81 @@ gst_audio_is_buffer_framed (GstPad* pad, GstBuffer* buf) return FALSE; } +/* _getcaps helper functions + * sets structure fields to default for audio type + * flag determines which structure fields to set to default + * keep these functions in sync with the templates in audio.h + */ + +/* private helper function + * sets a list on the structure + * pass in structure, fieldname for the list, type of the list values, + * number of list values, and each of the values, terminating with NULL + */ +static void +_gst_audio_structure_set_list (GstStructure *structure, const gchar *fieldname, + GType type, int number, ...) +{ + va_list varargs; + GValue value = { 0 }; + GArray *array; + int j; + + g_return_if_fail (structure != NULL); + + g_value_init (&value, GST_TYPE_LIST); + array = g_value_peek_pointer (&value); + + va_start (varargs, number); + + for (j = 0; j < number; ++j) + { + int i; + gboolean b; + + GValue list_value = { 0 }; + + switch (type) + { + case G_TYPE_INT: + i = va_arg (varargs, int); + g_value_init (&list_value, G_TYPE_INT); + g_value_set_int (&list_value, i); + break; + case G_TYPE_BOOLEAN: + b = va_arg (varargs, gboolean); + g_value_init (&list_value, G_TYPE_BOOLEAN); + g_value_set_boolean (&list_value, b); + break; + default: + g_warning ("_gst_audio_structure_set_list: LIST of given type not implemented."); + } + g_array_append_val (array, list_value); + + } + gst_structure_set_value (structure, fieldname, &value); + va_end (varargs); +} + +void +gst_audio_structure_set_int (GstStructure *structure, GstAudioFieldFlag flag) +{ + if (flag & GST_AUDIO_FIELD_RATE) + gst_structure_set (structure, "rate", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL); + if (flag & GST_AUDIO_FIELD_CHANNELS) + gst_structure_set (structure, "channels", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL); + if (flag & GST_AUDIO_FIELD_ENDIANNESS) + _gst_audio_structure_set_list (structure, "endianness", G_TYPE_INT, 2, G_LITTLE_ENDIAN, G_BIG_ENDIAN, NULL); + if (flag & GST_AUDIO_FIELD_WIDTH) + _gst_audio_structure_set_list (structure, "width", G_TYPE_INT, 3, 8, 16, 32, NULL); + if (flag & GST_AUDIO_FIELD_DEPTH) + gst_structure_set (structure, "depth", GST_TYPE_INT_RANGE, 1, 32, NULL); + if (flag & GST_AUDIO_FIELD_SIGNED) + _gst_audio_structure_set_list (structure, "signed", G_TYPE_BOOLEAN, 2, TRUE, FALSE, NULL); + if (flag & GST_AUDIO_FIELD_BUFFER_FRAMES) + gst_structure_set (structure, "buffer-frames", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL); +} + static gboolean plugin_init (GstPlugin *plugin) { -- cgit v1.2.1