2 * Copyright (C) 2008 David Schleef <ds@schleef.org>
3 * Copyright (C) 2012 Collabora Ltd.
4 * Author : Edward Hervey <edward@collabora.com>
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.
26 #include "gstvideoutils.h"
30 G_DEFINE_BOXED_TYPE (GstVideoCodecFrame, gst_video_codec_frame,
31 (GBoxedCopyFunc) gst_video_codec_frame_ref,
32 (GBoxedFreeFunc) gst_video_codec_frame_unref);
35 _gst_video_codec_frame_free (GstVideoCodecFrame * frame)
37 g_return_if_fail (frame != NULL);
39 GST_DEBUG ("free frame %p", frame);
41 if (frame->input_buffer) {
42 gst_buffer_unref (frame->input_buffer);
45 if (frame->output_buffer) {
46 gst_buffer_unref (frame->output_buffer);
49 g_list_foreach (frame->events, (GFunc) gst_event_unref, NULL);
50 g_list_free (frame->events);
52 if (frame->user_data_destroy_notify)
53 frame->user_data_destroy_notify (frame->user_data);
55 g_slice_free (GstVideoCodecFrame, frame);
59 * gst_video_codec_frame_set_user_data:
60 * @frame: a #GstVideoCodecFrame
61 * @user_data: private data
62 * @notify: (closure user_data): a #GDestroyNotify
64 * Sets @user_data on the frame and the #GDestroyNotify that will be called when
65 * the frame is freed. Allows to attach private data by the subclass to frames.
67 * If a @user_data was previously set, then the previous set @notify will be called
68 * before the @user_data is replaced.
71 gst_video_codec_frame_set_user_data (GstVideoCodecFrame * frame,
72 gpointer user_data, GDestroyNotify notify)
74 if (frame->user_data_destroy_notify)
75 frame->user_data_destroy_notify (frame->user_data);
77 frame->user_data = user_data;
78 frame->user_data_destroy_notify = notify;
82 * gst_video_codec_frame_get_user_data:
83 * @frame: a #GstVideoCodecFrame
85 * Gets private data set on the frame by the subclass via
86 * gst_video_codec_frame_set_user_data() previously.
88 * Returns: (transfer none): The previously set user_data
91 gst_video_codec_frame_get_user_data (GstVideoCodecFrame * frame)
93 return frame->user_data;
97 * gst_video_codec_frame_ref:
98 * @frame: a #GstVideoCodecFrame
100 * Increases the refcount of the given frame by one.
105 gst_video_codec_frame_ref (GstVideoCodecFrame * frame)
107 g_return_val_if_fail (frame != NULL, NULL);
109 g_atomic_int_inc (&frame->ref_count);
115 * gst_video_codec_frame_unref:
116 * @frame: a #GstVideoCodecFrame
118 * Decreases the refcount of the frame. If the refcount reaches 0, the frame
122 gst_video_codec_frame_unref (GstVideoCodecFrame * frame)
124 g_return_if_fail (frame != NULL);
125 g_return_if_fail (frame->ref_count > 0);
127 if (g_atomic_int_dec_and_test (&frame->ref_count)) {
128 _gst_video_codec_frame_free (frame);
134 * gst_video_codec_state_ref:
135 * @state: a #GstVideoCodecState
137 * Increases the refcount of the given state by one.
142 gst_video_codec_state_ref (GstVideoCodecState * state)
144 g_return_val_if_fail (state != NULL, NULL);
146 g_atomic_int_inc (&state->ref_count);
152 _gst_video_codec_state_free (GstVideoCodecState * state)
155 gst_caps_unref (state->caps);
156 if (state->codec_data)
157 gst_buffer_unref (state->codec_data);
161 * gst_video_codec_state_unref:
162 * @state: a #GstVideoCodecState
164 * Decreases the refcount of the state. If the refcount reaches 0, the state
168 gst_video_codec_state_unref (GstVideoCodecState * state)
170 g_return_if_fail (state != NULL);
171 g_return_if_fail (state->ref_count > 0);
173 if (g_atomic_int_dec_and_test (&state->ref_count)) {
174 _gst_video_codec_state_free (state);
178 G_DEFINE_BOXED_TYPE (GstVideoCodecState, gst_video_codec_state,
179 (GBoxedCopyFunc) gst_video_codec_state_ref,
180 (GBoxedFreeFunc) gst_video_codec_state_unref);