audioencoders: add streamheader helper utility

This commit is contained in:
Mark Nauwelaerts 2011-02-18 16:38:37 +01:00 committed by Tim-Philipp Müller
parent 80241fde8d
commit ef92c7438d
2 changed files with 53 additions and 0 deletions

View file

@ -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;
}

View file

@ -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__ */