/src/gstreamer/subprojects/gst-plugins-base/gst-libs/gst/video/gstvideoutils.c
Line | Count | Source |
1 | | /* GStreamer |
2 | | * Copyright (C) 2008 David Schleef <ds@schleef.org> |
3 | | * Copyright (C) 2012 Collabora Ltd. |
4 | | * Author : Edward Hervey <edward@collabora.com> |
5 | | * |
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. |
10 | | * |
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. |
15 | | * |
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., 51 Franklin St, Fifth Floor, |
19 | | * Boston, MA 02110-1301, USA. |
20 | | */ |
21 | | #ifdef HAVE_CONFIG_H |
22 | | #include "config.h" |
23 | | #endif |
24 | | |
25 | | #include <gst/video/video.h> |
26 | | #include "gstvideoutils.h" |
27 | | |
28 | | /** |
29 | | * SECTION:gstvideoutils |
30 | | * @title: GstVideo Codec utility function |
31 | | * @short_description: Extra utility functions for video codecs |
32 | | */ |
33 | | |
34 | | #include <string.h> |
35 | | |
36 | 0 | G_DEFINE_BOXED_TYPE (GstVideoCodecFrame, gst_video_codec_frame, |
37 | 0 | (GBoxedCopyFunc) gst_video_codec_frame_ref, |
38 | 0 | (GBoxedFreeFunc) gst_video_codec_frame_unref); |
39 | 0 |
|
40 | 0 | static void |
41 | 0 | _gst_video_codec_frame_free (GstVideoCodecFrame * frame) |
42 | 4 | { |
43 | 4 | g_return_if_fail (frame != NULL); |
44 | | |
45 | 4 | GST_DEBUG ("free frame %p", frame); |
46 | | |
47 | 4 | if (frame->input_buffer) { |
48 | 4 | gst_buffer_unref (frame->input_buffer); |
49 | 4 | } |
50 | | |
51 | 4 | if (frame->output_buffer) { |
52 | 0 | gst_buffer_unref (frame->output_buffer); |
53 | 0 | } |
54 | | |
55 | 4 | g_list_free_full (frame->events, (GDestroyNotify) gst_event_unref); |
56 | 4 | frame->events = NULL; |
57 | | |
58 | 4 | if (frame->user_data_destroy_notify) |
59 | 0 | frame->user_data_destroy_notify (frame->user_data); |
60 | | |
61 | 4 | g_free (frame); |
62 | 4 | } |
63 | | |
64 | | /** |
65 | | * gst_video_codec_frame_set_user_data: |
66 | | * @frame: a #GstVideoCodecFrame |
67 | | * @user_data: private data |
68 | | * @notify: (closure user_data): a #GDestroyNotify |
69 | | * |
70 | | * Sets @user_data on the frame and the #GDestroyNotify that will be called when |
71 | | * the frame is freed. Allows to attach private data by the subclass to frames. |
72 | | * |
73 | | * If a @user_data was previously set, then the previous set @notify will be called |
74 | | * before the @user_data is replaced. |
75 | | */ |
76 | | void |
77 | | gst_video_codec_frame_set_user_data (GstVideoCodecFrame * frame, |
78 | | gpointer user_data, GDestroyNotify notify) |
79 | 0 | { |
80 | 0 | if (frame->user_data_destroy_notify) |
81 | 0 | frame->user_data_destroy_notify (frame->user_data); |
82 | |
|
83 | 0 | frame->user_data = user_data; |
84 | 0 | frame->user_data_destroy_notify = notify; |
85 | 0 | } |
86 | | |
87 | | /** |
88 | | * gst_video_codec_frame_get_user_data: |
89 | | * @frame: a #GstVideoCodecFrame |
90 | | * |
91 | | * Gets private data set on the frame by the subclass via |
92 | | * gst_video_codec_frame_set_user_data() previously. |
93 | | * |
94 | | * Returns: (transfer none): The previously set user_data |
95 | | */ |
96 | | gpointer |
97 | | gst_video_codec_frame_get_user_data (GstVideoCodecFrame * frame) |
98 | 0 | { |
99 | 0 | return frame->user_data; |
100 | 0 | } |
101 | | |
102 | | /** |
103 | | * gst_video_codec_frame_ref: |
104 | | * @frame: a #GstVideoCodecFrame |
105 | | * |
106 | | * Increases the refcount of the given frame by one. |
107 | | * |
108 | | * Returns: @buf |
109 | | */ |
110 | | GstVideoCodecFrame * |
111 | | gst_video_codec_frame_ref (GstVideoCodecFrame * frame) |
112 | 4 | { |
113 | 4 | g_return_val_if_fail (frame != NULL, NULL); |
114 | | |
115 | 4 | GST_TRACE ("%p ref %d->%d", frame, frame->ref_count, frame->ref_count + 1); |
116 | | |
117 | 4 | g_atomic_int_inc (&frame->ref_count); |
118 | | |
119 | 4 | return frame; |
120 | 4 | } |
121 | | |
122 | | /** |
123 | | * gst_video_codec_frame_unref: |
124 | | * @frame: a #GstVideoCodecFrame |
125 | | * |
126 | | * Decreases the refcount of the frame. If the refcount reaches 0, the frame |
127 | | * will be freed. |
128 | | */ |
129 | | void |
130 | | gst_video_codec_frame_unref (GstVideoCodecFrame * frame) |
131 | 8 | { |
132 | 8 | g_return_if_fail (frame != NULL); |
133 | 8 | g_return_if_fail (frame->ref_count > 0); |
134 | | |
135 | 8 | GST_TRACE ("%p unref %d->%d", frame, frame->ref_count, frame->ref_count - 1); |
136 | | |
137 | 8 | if (g_atomic_int_dec_and_test (&frame->ref_count)) { |
138 | 4 | _gst_video_codec_frame_free (frame); |
139 | 4 | } |
140 | 8 | } |
141 | | |
142 | | |
143 | | /** |
144 | | * gst_video_codec_state_ref: |
145 | | * @state: a #GstVideoCodecState |
146 | | * |
147 | | * Increases the refcount of the given state by one. |
148 | | * |
149 | | * Returns: @buf |
150 | | */ |
151 | | GstVideoCodecState * |
152 | | gst_video_codec_state_ref (GstVideoCodecState * state) |
153 | 2 | { |
154 | 2 | g_return_val_if_fail (state != NULL, NULL); |
155 | | |
156 | 2 | GST_TRACE ("%p ref %d->%d", state, state->ref_count, state->ref_count + 1); |
157 | | |
158 | 2 | g_atomic_int_inc (&state->ref_count); |
159 | | |
160 | 2 | return state; |
161 | 2 | } |
162 | | |
163 | | static void |
164 | | _gst_video_codec_state_free (GstVideoCodecState * state) |
165 | 2 | { |
166 | 2 | GST_DEBUG ("free state %p", state); |
167 | | |
168 | 2 | if (state->caps) |
169 | 2 | gst_caps_unref (state->caps); |
170 | 2 | if (state->allocation_caps) |
171 | 0 | gst_caps_unref (state->allocation_caps); |
172 | 2 | if (state->codec_data) |
173 | 0 | gst_buffer_unref (state->codec_data); |
174 | 2 | if (state->mastering_display_info) |
175 | 0 | g_free (state->mastering_display_info); |
176 | 2 | if (state->content_light_level) |
177 | 0 | g_free (state->content_light_level); |
178 | 2 | g_free (state); |
179 | 2 | } |
180 | | |
181 | | /** |
182 | | * gst_video_codec_state_unref: |
183 | | * @state: a #GstVideoCodecState |
184 | | * |
185 | | * Decreases the refcount of the state. If the refcount reaches 0, the state |
186 | | * will be freed. |
187 | | */ |
188 | | void |
189 | | gst_video_codec_state_unref (GstVideoCodecState * state) |
190 | 4 | { |
191 | 4 | g_return_if_fail (state != NULL); |
192 | 4 | g_return_if_fail (state->ref_count > 0); |
193 | | |
194 | 4 | GST_TRACE ("%p unref %d->%d", state, state->ref_count, state->ref_count - 1); |
195 | | |
196 | 4 | if (g_atomic_int_dec_and_test (&state->ref_count)) { |
197 | 2 | _gst_video_codec_state_free (state); |
198 | 2 | } |
199 | 4 | } |
200 | | |
201 | | G_DEFINE_BOXED_TYPE (GstVideoCodecState, gst_video_codec_state, |
202 | | (GBoxedCopyFunc) gst_video_codec_state_ref, |
203 | | (GBoxedFreeFunc) gst_video_codec_state_unref); |