|
Packit Service |
963350 |
/* GStreamer
|
|
Packit Service |
963350 |
* Copyright (C) 2011 Wim Taymans <wim.taymans@gmail.com>
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* gstsample.c: media sample
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
963350 |
* modify it under the terms of the GNU Library General Public
|
|
Packit Service |
963350 |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
963350 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
963350 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
963350 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
963350 |
* Library General Public License for more details.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* You should have received a copy of the GNU Library General Public
|
|
Packit Service |
963350 |
* License along with this library; if not, write to the
|
|
Packit Service |
963350 |
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
Packit Service |
963350 |
* Boston, MA 02110-1301, USA.
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/**
|
|
Packit Service |
963350 |
* SECTION:gstsample
|
|
Packit Service |
963350 |
* @title: GstSample
|
|
Packit Service |
963350 |
* @short_description: A media sample
|
|
Packit Service |
963350 |
* @see_also: #GstBuffer, #GstCaps, #GstSegment
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* A #GstSample is a small object containing data, a type, timing and
|
|
Packit Service |
963350 |
* extra arbitrary information.
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
#include "gst_private.h"
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
#include "gstsample.h"
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
GST_DEBUG_CATEGORY_STATIC (gst_sample_debug);
|
|
Packit Service |
963350 |
#define GST_CAT_DEFAULT gst_sample_debug
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
struct _GstSample
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstMiniObject mini_object;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
GstBuffer *buffer;
|
|
Packit Service |
963350 |
GstCaps *caps;
|
|
Packit Service |
963350 |
GstSegment segment;
|
|
Packit Service |
963350 |
GstStructure *info;
|
|
Packit Service |
963350 |
GstBufferList *buffer_list;
|
|
Packit Service |
963350 |
};
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
GType _gst_sample_type = 0;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
GST_DEFINE_MINI_OBJECT_TYPE (GstSample, gst_sample);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
void
|
|
Packit Service |
963350 |
_priv_gst_sample_initialize (void)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
_gst_sample_type = gst_sample_get_type ();
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
GST_DEBUG_CATEGORY_INIT (gst_sample_debug, "sample", 0, "GstSample debug");
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static GstSample *
|
|
Packit Service |
963350 |
_gst_sample_copy (GstSample * sample)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstSample *copy;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
copy = gst_sample_new (sample->buffer, sample->caps, &sample->segment,
|
|
Packit Service |
963350 |
(sample->info) ? gst_structure_copy (sample->info) : NULL);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
if (sample->buffer_list)
|
|
Packit Service |
963350 |
copy->buffer_list = (GstBufferList *)
|
|
Packit Service |
963350 |
gst_mini_object_ref (GST_MINI_OBJECT_CAST (sample->buffer_list));
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
return copy;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static void
|
|
Packit Service |
963350 |
_gst_sample_free (GstSample * sample)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GST_LOG ("free %p", sample);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
if (sample->buffer)
|
|
Packit Service |
963350 |
gst_buffer_unref (sample->buffer);
|
|
Packit Service |
963350 |
if (sample->caps)
|
|
Packit Service |
963350 |
gst_caps_unref (sample->caps);
|
|
Packit Service |
963350 |
if (sample->info) {
|
|
Packit Service |
963350 |
gst_structure_set_parent_refcount (sample->info, NULL);
|
|
Packit Service |
963350 |
gst_structure_free (sample->info);
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
if (sample->buffer_list)
|
|
Packit Service |
963350 |
gst_mini_object_unref (GST_MINI_OBJECT_CAST (sample->buffer_list));
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
g_slice_free1 (sizeof (GstSample), sample);
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/**
|
|
Packit Service |
963350 |
* gst_sample_new:
|
|
Packit Service |
963350 |
* @buffer: (transfer none) (allow-none): a #GstBuffer, or %NULL
|
|
Packit Service |
963350 |
* @caps: (transfer none) (allow-none): a #GstCaps, or %NULL
|
|
Packit Service |
963350 |
* @segment: (transfer none) (allow-none): a #GstSegment, or %NULL
|
|
Packit Service |
963350 |
* @info: (transfer full) (allow-none): a #GstStructure, or %NULL
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Create a new #GstSample with the provided details.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Free-function: gst_sample_unref
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Returns: (transfer full): the new #GstSample. gst_sample_unref()
|
|
Packit Service |
963350 |
* after usage.
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
GstSample *
|
|
Packit Service |
963350 |
gst_sample_new (GstBuffer * buffer, GstCaps * caps, const GstSegment * segment,
|
|
Packit Service |
963350 |
GstStructure * info)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstSample *sample;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
sample = g_slice_new0 (GstSample);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
GST_LOG ("new %p", sample);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
gst_mini_object_init (GST_MINI_OBJECT_CAST (sample), 0, _gst_sample_type,
|
|
Packit Service |
963350 |
(GstMiniObjectCopyFunction) _gst_sample_copy, NULL,
|
|
Packit Service |
963350 |
(GstMiniObjectFreeFunction) _gst_sample_free);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
sample->buffer = buffer ? gst_buffer_ref (buffer) : NULL;
|
|
Packit Service |
963350 |
sample->caps = caps ? gst_caps_ref (caps) : NULL;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
if (segment)
|
|
Packit Service |
963350 |
gst_segment_copy_into (segment, &sample->segment);
|
|
Packit Service |
963350 |
else
|
|
Packit Service |
963350 |
gst_segment_init (&sample->segment, GST_FORMAT_TIME);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
if (info) {
|
|
Packit Service |
963350 |
if (!gst_structure_set_parent_refcount (info,
|
|
Packit Service |
963350 |
&sample->mini_object.refcount))
|
|
Packit Service |
963350 |
goto had_parent;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
sample->info = info;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
return sample;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/* ERRORS */
|
|
Packit Service |
963350 |
had_parent:
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
gst_sample_unref (sample);
|
|
Packit Service |
963350 |
g_warning ("structure is already owned by another object");
|
|
Packit Service |
963350 |
return NULL;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/**
|
|
Packit Service |
963350 |
* gst_sample_get_buffer:
|
|
Packit Service |
963350 |
* @sample: a #GstSample
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Get the buffer associated with @sample
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Returns: (transfer none) (nullable): the buffer of @sample or %NULL
|
|
Packit Service |
963350 |
* when there is no buffer. The buffer remains valid as long as
|
|
Packit Service |
963350 |
* @sample is valid. If you need to hold on to it for longer than
|
|
Packit Service |
963350 |
* that, take a ref to the buffer with gst_buffer_ref().
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
GstBuffer *
|
|
Packit Service |
963350 |
gst_sample_get_buffer (GstSample * sample)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
g_return_val_if_fail (GST_IS_SAMPLE (sample), NULL);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
return sample->buffer;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/**
|
|
Packit Service |
963350 |
* gst_sample_get_caps:
|
|
Packit Service |
963350 |
* @sample: a #GstSample
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Get the caps associated with @sample
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Returns: (transfer none) (nullable): the caps of @sample or %NULL
|
|
Packit Service |
963350 |
* when there is no caps. The caps remain valid as long as @sample is
|
|
Packit Service |
963350 |
* valid. If you need to hold on to the caps for longer than that,
|
|
Packit Service |
963350 |
* take a ref to the caps with gst_caps_ref().
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
GstCaps *
|
|
Packit Service |
963350 |
gst_sample_get_caps (GstSample * sample)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
g_return_val_if_fail (GST_IS_SAMPLE (sample), NULL);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
return sample->caps;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/**
|
|
Packit Service |
963350 |
* gst_sample_get_segment:
|
|
Packit Service |
963350 |
* @sample: a #GstSample
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Get the segment associated with @sample
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Returns: (transfer none): the segment of @sample.
|
|
Packit Service |
963350 |
* The segment remains valid as long as @sample is valid.
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
GstSegment *
|
|
Packit Service |
963350 |
gst_sample_get_segment (GstSample * sample)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
g_return_val_if_fail (GST_IS_SAMPLE (sample), NULL);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
return &sample->segment;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/**
|
|
Packit Service |
963350 |
* gst_sample_get_info:
|
|
Packit Service |
963350 |
* @sample: a #GstSample
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Get extra information associated with @sample.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Returns: (transfer none) (nullable): the extra info of @sample.
|
|
Packit Service |
963350 |
* The info remains valid as long as @sample is valid.
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
const GstStructure *
|
|
Packit Service |
963350 |
gst_sample_get_info (GstSample * sample)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
g_return_val_if_fail (GST_IS_SAMPLE (sample), NULL);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
return sample->info;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/**
|
|
Packit Service |
963350 |
* gst_sample_get_buffer_list:
|
|
Packit Service |
963350 |
* @sample: a #GstSample
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Get the buffer list associated with @sample
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Returns: (transfer none) (nullable): the buffer list of @sample or %NULL
|
|
Packit Service |
963350 |
* when there is no buffer list. The buffer list remains valid as long as
|
|
Packit Service |
963350 |
* @sample is valid. If you need to hold on to it for longer than
|
|
Packit Service |
963350 |
* that, take a ref to the buffer list with gst_mini_object_ref ().
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Since: 1.6
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
GstBufferList *
|
|
Packit Service |
963350 |
gst_sample_get_buffer_list (GstSample * sample)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
g_return_val_if_fail (GST_IS_SAMPLE (sample), NULL);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
return sample->buffer_list;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/**
|
|
Packit Service |
963350 |
* gst_sample_set_buffer_list:
|
|
Packit Service |
963350 |
* @sample: a #GstSample
|
|
Packit Service |
963350 |
* @buffer_list: a #GstBufferList
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Set the buffer list associated with @sample
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Since: 1.6
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
void
|
|
Packit Service |
963350 |
gst_sample_set_buffer_list (GstSample * sample, GstBufferList * buffer_list)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstBufferList *old = NULL;
|
|
Packit Service |
963350 |
g_return_if_fail (GST_IS_SAMPLE (sample));
|
|
Packit Service |
963350 |
old = sample->buffer_list;
|
|
Packit Service |
963350 |
sample->buffer_list = (GstBufferList *)
|
|
Packit Service |
963350 |
gst_mini_object_ref (GST_MINI_OBJECT_CAST (buffer_list));
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
if (old)
|
|
Packit Service |
963350 |
gst_mini_object_unref (GST_MINI_OBJECT_CAST (old));
|
|
Packit Service |
963350 |
}
|