summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Vander Stichele <thomas@apestaart.org>2004-01-12 19:35:54 +0000
committerThomas Vander Stichele <thomas@apestaart.org>2004-01-12 19:35:54 +0000
commitb2e8f0ecfd4a35c62b3feb65d01ded8c25990a3e (patch)
treed5d50cf269b4b8288cb033ea98c55e73125597db
parentbb768f388edebc33621e87301dc186f860c83ea0 (diff)
downloadgst-plugins-bad-b2e8f0ecfd4a35c62b3feb65d01ded8c25990a3e.tar.gz
gst-plugins-bad-b2e8f0ecfd4a35c62b3feb65d01ded8c25990a3e.tar.bz2
gst-plugins-bad-b2e8f0ecfd4a35c62b3feb65d01ded8c25990a3e.zip
adding structure setters matching the templates for audio
Original commit message from CVS: adding structure setters matching the templates for audio
-rw-r--r--ChangeLog8
-rw-r--r--gst-libs/gst/audio/audio.c77
-rw-r--r--gst-libs/gst/audio/audio.h13
3 files changed, 98 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 58fe7467..f4b50423 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2004-01-12 Thomas Vander Stichele <thomas at apestaart dot org>
+
+ * gst-libs/gst/audio/audio.c: (_gst_audio_structure_set_list),
+ (gst_audio_structure_set_int):
+ * gst-libs/gst/audio/audio.h:
+ add helper functions for _getcaps matching the standard audio
+ templates
+
2004-01-12 David Schleef <ds@schleef.org>
* gst/audioconvert/gstaudioconvert.c: (gst_audio_convert_link):
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 <gst/gststructure.h>
+
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)
{
diff --git a/gst-libs/gst/audio/audio.h b/gst-libs/gst/audio/audio.h
index 73a4043f..1b761026 100644
--- a/gst-libs/gst/audio/audio.h
+++ b/gst-libs/gst/audio/audio.h
@@ -111,5 +111,18 @@ long gst_audio_highest_sample_value (GstPad* pad);
/* check if the buffer size is a whole multiple of the frame size */
gboolean gst_audio_is_buffer_framed (GstPad* pad, GstBuffer* buf);
+/* functions useful for _getcaps functions */
+typedef enum {
+ GST_AUDIO_FIELD_RATE = (1 << 0),
+ GST_AUDIO_FIELD_CHANNELS = (1 << 1),
+ GST_AUDIO_FIELD_ENDIANNESS = (1 << 2),
+ GST_AUDIO_FIELD_WIDTH = (1 << 3),
+ GST_AUDIO_FIELD_DEPTH = (1 << 4),
+ GST_AUDIO_FIELD_SIGNED = (1 << 5),
+ GST_AUDIO_FIELD_BUFFER_FRAMES = (1 << 6)
+} GstAudioFieldFlag;
+
+void gst_audio_structure_set_int (GstStructure *structure, GstAudioFieldFlag flag);
+
G_END_DECLS