X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gst%2Fgstsample.c;h=143215f591fda9378ca940213db8e81669b00ac5;hb=ed5d888ba5ffcaa9561e60c6b237bcf4a9ca3853;hp=4ceb436e6b92982b3b9b75b35360b1c4b9b0674a;hpb=666c8c11c65399ea920d00f1547f59dc3c657cb7;p=platform%2Fupstream%2Fgstreamer.git diff --git a/gst/gstsample.c b/gst/gstsample.c index 4ceb436..143215f 100644 --- a/gst/gstsample.c +++ b/gst/gstsample.c @@ -21,18 +21,20 @@ /** * SECTION:gstsample + * @title: GstSample * @short_description: A media sample * @see_also: #GstBuffer, #GstCaps, #GstSegment * * A #GstSample is a small object containing data, a type, timing and * extra arbitrary information. - * - * Last reviewed on 2012-03-29 (0.11.3) */ #include "gst_private.h" #include "gstsample.h" +GST_DEBUG_CATEGORY_STATIC (gst_sample_debug); +#define GST_CAT_DEFAULT gst_sample_debug + struct _GstSample { GstMiniObject mini_object; @@ -41,6 +43,7 @@ struct _GstSample GstCaps *caps; GstSegment segment; GstStructure *info; + GstBufferList *buffer_list; }; GType _gst_sample_type = 0; @@ -51,6 +54,8 @@ void _priv_gst_sample_initialize (void) { _gst_sample_type = gst_sample_get_type (); + + GST_DEBUG_CATEGORY_INIT (gst_sample_debug, "sample", 0, "GstSample debug"); } static GstSample * @@ -61,6 +66,10 @@ _gst_sample_copy (GstSample * sample) copy = gst_sample_new (sample->buffer, sample->caps, &sample->segment, (sample->info) ? gst_structure_copy (sample->info) : NULL); + if (sample->buffer_list) + copy->buffer_list = (GstBufferList *) + gst_mini_object_ref (GST_MINI_OBJECT_CAST (sample->buffer_list)); + return copy; } @@ -77,15 +86,18 @@ _gst_sample_free (GstSample * sample) gst_structure_set_parent_refcount (sample->info, NULL); gst_structure_free (sample->info); } + if (sample->buffer_list) + gst_mini_object_unref (GST_MINI_OBJECT_CAST (sample->buffer_list)); + g_slice_free1 (sizeof (GstSample), sample); } /** * gst_sample_new: - * @buffer: (transfer none) (allow-none): a #GstBuffer, or NULL - * @caps: (transfer none) (allow-none): a #GstCaps, or NULL - * @segment: (transfer none) (allow-none): a #GstSegment, or NULL - * @info: (transfer full) (allow-none): a #GstStructure, or NULL + * @buffer: (transfer none) (allow-none): a #GstBuffer, or %NULL + * @caps: (transfer none) (allow-none): a #GstCaps, or %NULL + * @segment: (transfer none) (allow-none): a #GstSegment, or %NULL + * @info: (transfer full) (allow-none): a #GstStructure, or %NULL * * Create a new #GstSample with the provided details. * @@ -111,6 +123,7 @@ gst_sample_new (GstBuffer * buffer, GstCaps * caps, const GstSegment * segment, sample->buffer = buffer ? gst_buffer_ref (buffer) : NULL; sample->caps = caps ? gst_caps_ref (caps) : NULL; + /* FIXME 2.0: initialize with GST_FORMAT_UNDEFINED by default */ if (segment) gst_segment_copy_into (segment, &sample->segment); else @@ -140,8 +153,10 @@ had_parent: * * Get the buffer associated with @sample * - * Returns: (transfer none): the buffer of @sample or NULL when there - * is no buffer. The buffer remains valid as long as @sample is valid. + * Returns: (transfer none) (nullable): the buffer of @sample or %NULL + * when there is no buffer. The buffer remains valid as long as + * @sample is valid. If you need to hold on to it for longer than + * that, take a ref to the buffer with gst_buffer_ref(). */ GstBuffer * gst_sample_get_buffer (GstSample * sample) @@ -157,8 +172,10 @@ gst_sample_get_buffer (GstSample * sample) * * Get the caps associated with @sample * - * Returns: (transfer none): the caps of @sample or NULL when there - * is no caps. The caps remain valid as long as @sample is valid. + * Returns: (transfer none) (nullable): the caps of @sample or %NULL + * when there is no caps. The caps remain valid as long as @sample is + * valid. If you need to hold on to the caps for longer than that, + * take a ref to the caps with gst_caps_ref(). */ GstCaps * gst_sample_get_caps (GstSample * sample) @@ -191,7 +208,7 @@ gst_sample_get_segment (GstSample * sample) * * Get extra information associated with @sample. * - * Returns: (transfer none): the extra info of @sample. + * Returns: (transfer none) (nullable): the extra info of @sample. * The info remains valid as long as @sample is valid. */ const GstStructure * @@ -201,3 +218,134 @@ gst_sample_get_info (GstSample * sample) return sample->info; } + +/** + * gst_sample_get_buffer_list: + * @sample: a #GstSample + * + * Get the buffer list associated with @sample + * + * Returns: (transfer none) (nullable): the buffer list of @sample or %NULL + * when there is no buffer list. The buffer list remains valid as long as + * @sample is valid. If you need to hold on to it for longer than + * that, take a ref to the buffer list with gst_mini_object_ref (). + * + * Since: 1.6 + */ +GstBufferList * +gst_sample_get_buffer_list (GstSample * sample) +{ + g_return_val_if_fail (GST_IS_SAMPLE (sample), NULL); + + return sample->buffer_list; +} + +/** + * gst_sample_set_buffer_list: + * @sample: a #GstSample + * @buffer_list: a #GstBufferList + * + * Set the buffer list associated with @sample. @sample must be writable. + * + * Since: 1.6 + */ +void +gst_sample_set_buffer_list (GstSample * sample, GstBufferList * buffer_list) +{ + GstBufferList *old = NULL; + g_return_if_fail (GST_IS_SAMPLE (sample)); + g_return_if_fail (gst_sample_is_writable (sample)); + + old = sample->buffer_list; + sample->buffer_list = buffer_list ? (GstBufferList *) + gst_mini_object_ref (GST_MINI_OBJECT_CAST (buffer_list)) : NULL; + + if (old) + gst_mini_object_unref (GST_MINI_OBJECT_CAST (old)); +} + +/** + * gst_sample_set_buffer: + * + * Set the buffer associated with @sample. @sample must be writable. + * + * Since: 1.16 + */ +void +gst_sample_set_buffer (GstSample * sample, GstBuffer * buffer) +{ + g_return_if_fail (GST_IS_SAMPLE (sample)); + g_return_if_fail (gst_sample_is_writable (sample)); + + gst_buffer_replace (&sample->buffer, buffer); +} + +/** + * gst_sample_set_caps: + * + * Set the caps associated with @sample. @sample must be writable. + * + * Since: 1.16 + */ +void +gst_sample_set_caps (GstSample * sample, GstCaps * caps) +{ + g_return_if_fail (GST_IS_SAMPLE (sample)); + g_return_if_fail (gst_sample_is_writable (sample)); + + gst_caps_replace (&sample->caps, caps); +} + +/** + * gst_sample_set_segment: + * + * Set the segment associated with @sample. @sample must be writable. + * + * Since: 1.16 + */ +void +gst_sample_set_segment (GstSample * sample, const GstSegment * segment) +{ + g_return_if_fail (GST_IS_SAMPLE (sample)); + g_return_if_fail (gst_sample_is_writable (sample)); + + /* FIXME 2.0: initialize with GST_FORMAT_UNDEFINED by default */ + if (segment) + gst_segment_copy_into (segment, &sample->segment); + else + gst_segment_init (&sample->segment, GST_FORMAT_TIME); +} + +/** + * gst_sample_set_info: + * + * Set the info structure associated with @sample. @sample must be writable, + * and @info must not have a parent set already. + * + * Since: 1.16 + */ +gboolean +gst_sample_set_info (GstSample * sample, GstStructure * info) +{ + g_return_val_if_fail (GST_IS_SAMPLE (sample), FALSE); + g_return_val_if_fail (gst_sample_is_writable (sample), FALSE); + + if (info) { + if (!gst_structure_set_parent_refcount (info, + &sample->mini_object.refcount)) + goto had_parent; + } + + if (sample->info) { + gst_structure_set_parent_refcount (sample->info, NULL); + gst_structure_free (sample->info); + } + + sample->info = info; + + return TRUE; + +had_parent: + g_warning ("structure is already owned by another object"); + return FALSE; +}