From ef92c7438d564691780b392ebdb5b8cf180e1e6e Mon Sep 17 00:00:00 2001 From: Mark Nauwelaerts Date: Fri, 18 Feb 2011 16:38:37 +0100 Subject: [PATCH] audioencoders: add streamheader helper utility --- gst-libs/gst/audio/gstbaseaudioencoder.c | 50 ++++++++++++++++++++++++++++++++ gst-libs/gst/audio/gstbaseaudioencoder.h | 3 ++ 2 files changed, 53 insertions(+) diff --git a/gst-libs/gst/audio/gstbaseaudioencoder.c b/gst-libs/gst/audio/gstbaseaudioencoder.c index f539ebd..b6b6c1f 100644 --- a/gst-libs/gst/audio/gstbaseaudioencoder.c +++ b/gst-libs/gst/audio/gstbaseaudioencoder.c @@ -1591,3 +1591,53 @@ gst_base_audio_encoder_sink_activate_push (GstPad * pad, gboolean active) gst_object_unref (enc); return result; } + +/** gst_base_audio_encoder_add_streamheader: + * @caps: a #GstCaps + * @buf: header buffers + * + * Adds given buffers to an array of buffers set as streamheader field + * on the given @caps. List of buffer arguments must be NULL-terminated. + * + * Returns: input caps with a streamheader field added, or NULL if some error + */ +GstCaps * +gst_base_audio_encoder_add_streamheader (GstCaps * caps, GstBuffer * buf, ...) +{ + GstStructure *structure = NULL; + va_list va; + GValue array = { 0 }; + GValue value = { 0 }; + + g_return_val_if_fail (caps != NULL, NULL); + g_return_val_if_fail (gst_caps_is_fixed (caps), NULL); + + caps = gst_caps_make_writable (caps); + structure = gst_caps_get_structure (caps, 0); + + g_value_init (&array, GST_TYPE_ARRAY); + + va_start (va, buf); + /* put buffers in a fixed list */ + while (buf) { + g_assert (gst_buffer_is_metadata_writable (buf)); + + /* mark buffer */ + GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_IN_CAPS); + + g_value_init (&value, GST_TYPE_BUFFER); + buf = gst_buffer_copy (buf); + GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_IN_CAPS); + gst_value_set_buffer (&value, buf); + gst_buffer_unref (buf); + gst_value_array_append_value (&array, &value); + g_value_unset (&value); + + buf = va_arg (va, GstBuffer *); + } + + gst_structure_set_value (structure, "streamheader", &array); + g_value_unset (&array); + + return caps; +} diff --git a/gst-libs/gst/audio/gstbaseaudioencoder.h b/gst-libs/gst/audio/gstbaseaudioencoder.h index 27c1ba0..457a2e5 100644 --- a/gst-libs/gst/audio/gstbaseaudioencoder.h +++ b/gst-libs/gst/audio/gstbaseaudioencoder.h @@ -246,6 +246,9 @@ GstFlowReturn gst_base_audio_encoder_finish_frame (GstBaseAudioEncoder * enc, GstCaps * gst_base_audio_encoder_proxy_getcaps (GstBaseAudioEncoder * enc, GstCaps * caps); +GstCaps * gst_base_audio_encoder_add_streamheader (GstCaps * caps, + GstBuffer * buf, ...); + G_END_DECLS #endif /* __GST_BASE_AUDIO_ENCODER_H__ */ -- 2.7.4