2 * Copyright (C) 2011 Wim Taymans <wim.taymans@gmail.com>
4 * gstsample.c: media sample
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
24 * @short_description: A media sample
25 * @see_also: #GstBuffer, #GstCaps, #GstSegment
27 * A #GstSample is a small object containing data, a type, timing and
28 * extra arbitrary information.
30 * Last reviewed on 2012-03-29 (0.11.3)
32 #include "gst_private.h"
34 #include "gstsample.h"
38 GstMiniObject mini_object;
46 GType _gst_sample_type = 0;
48 GST_DEFINE_MINI_OBJECT_TYPE (GstSample, gst_sample);
51 _priv_gst_sample_initialize (void)
53 _gst_sample_type = gst_sample_get_type ();
57 _gst_sample_copy (GstSample * sample)
61 copy = gst_sample_new (sample->buffer, sample->caps, &sample->segment,
62 gst_structure_copy (sample->info));
68 _gst_sample_free (GstSample * sample)
70 GST_LOG ("free %p", sample);
73 gst_buffer_unref (sample->buffer);
75 gst_caps_unref (sample->caps);
77 g_slice_free1 (GST_MINI_OBJECT_SIZE (sample), sample);
82 * @buffer: a #GstBuffer
84 * @segment: a #GstSegment
85 * @info: a #GstStructure
87 * Create a new #GstSample with the provided details.
89 * Free-function: gst_sample_unref
91 * Returns: (transfer full): the new #GstSample. gst_sample_unref()
97 gst_sample_new (GstBuffer * buffer, GstCaps * caps, const GstSegment * segment,
102 sample = g_slice_new0 (GstSample);
104 GST_LOG ("new %p", sample);
106 gst_mini_object_init (GST_MINI_OBJECT_CAST (sample), _gst_sample_type,
109 sample->mini_object.copy = (GstMiniObjectCopyFunction) _gst_sample_copy;
110 sample->mini_object.free = (GstMiniObjectFreeFunction) _gst_sample_free;
112 sample->buffer = buffer ? gst_buffer_ref (buffer) : NULL;
113 sample->caps = caps ? gst_caps_ref (caps) : NULL;
116 gst_segment_copy_into (segment, &sample->segment);
118 gst_segment_init (&sample->segment, GST_FORMAT_TIME);
121 if (!gst_structure_set_parent_refcount (info,
122 &sample->mini_object.refcount))
132 gst_sample_unref (sample);
133 g_warning ("structure is already owned by another object");
139 * gst_sample_get_buffer:
140 * @sample: a #GstSample
142 * Get the buffer associated with @sample
144 * Returns: (transfer none): the buffer of @sample or NULL when there
145 * is no buffer. The buffer remains valid as long as @sample is valid.
148 gst_sample_get_buffer (GstSample * sample)
150 g_return_val_if_fail (GST_IS_SAMPLE (sample), NULL);
152 return sample->buffer;
156 * gst_sample_get_caps:
157 * @sample: a #GstSample
159 * Get the caps associated with @sample
161 * Returns: (transfer none): the caps of @sample or NULL when there
162 * is no caps. The caps remain valid as long as @sample is valid.
165 gst_sample_get_caps (GstSample * sample)
167 g_return_val_if_fail (GST_IS_SAMPLE (sample), NULL);
173 * gst_sample_get_segment:
174 * @sample: a #GstSample
176 * Get the segment associated with @sample
178 * Returns: (transfer none): the segment of @sample.
179 * The segment remains valid as long as @sample is valid.
182 gst_sample_get_segment (GstSample * sample)
184 g_return_val_if_fail (GST_IS_SAMPLE (sample), NULL);
186 return &sample->segment;
190 * gst_sample_get_info:
191 * @sample: a #GstSample
193 * Get extra information associated with @sample.
195 * Returns: (transfer none): the extra info of @sample.
196 * The info remains valid as long as @sample is valid.
199 gst_sample_get_info (GstSample * sample)
201 g_return_val_if_fail (GST_IS_SAMPLE (sample), NULL);