2
* gstvaapiutils_tsb.c - Timestamp buffer store
4
* Copyright (C) 2011 Intel Corporation
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public License
8
* as published by the Free Software Foundation; either version 2.1
9
* 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
* Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the Free
18
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301 USA
22
#include "gstvaapiutils_tsb.h"
25
typedef struct _GstVaapiTSBEntry GstVaapiTSBEntry;
31
struct _GstVaapiTSBEntry {
37
static GstVaapiTSBEntry *
38
gst_vaapi_tsb_entry_new(GstBuffer *buffer)
42
e = g_slice_new(GstVaapiTSBEntry);
46
e->buffer = gst_buffer_ref(buffer);
47
e->buffer_size = GST_BUFFER_SIZE(buffer);
53
gst_vaapi_tsb_entry_destroy(GstVaapiTSBEntry *e)
59
gst_buffer_unref(e->buffer);
62
g_slice_free(GstVaapiTSBEntry, e);
68
* Creates a new #GstVaapiTSB.
70
* Return value: a new #GstVaapiTSB
77
tsb = g_new(GstVaapiTSB, 1);
86
* gst_vaapi_tsb_destroy:
87
* @tsb: a #GstVaapiTSB
89
* Destroys the #GstVaapiTSB. All buffers are unreferenced.
92
gst_vaapi_tsb_destroy(GstVaapiTSB *tsb)
98
g_list_foreach(tsb->list, (GFunc)gst_vaapi_tsb_entry_destroy, NULL);
99
g_list_free(tsb->list);
106
* gst_vaapi_tsb_push:
107
* @tsb: a #GstVaapiTSB
108
* @buffer: a #GstBuffer
110
* Pushes @buffer to the timestamp buffer store. The TSB owns and
111
* maintains an extra reference to the buffer.
113
* Return value: %TRUE if success, %FALSE otherwise
116
gst_vaapi_tsb_push(GstVaapiTSB *tsb, GstBuffer *buffer)
124
e = gst_vaapi_tsb_entry_new(buffer);
128
l = g_list_append(tsb->list, e);
138
* @tsb: a #GstVaapiTSB
139
* @size: number of bytes to remove from the TSB
141
* Removes @size bytes from the @tsb.
144
gst_vaapi_tsb_pop(GstVaapiTSB *tsb, gsize size)
150
if (!tsb || !tsb->list)
156
n = MIN(e->buffer_size - e->offset, size);
159
if (e->offset == e->buffer_size) {
160
gst_vaapi_tsb_entry_destroy(e);
162
g_list_free_1(tsb->list);
172
* gst_vaapi_tsb_peek:
173
* @tsb: a #GstVaapiTSB
175
* Returns the current #GstBuffer.
177
* Return value: current #GstBuffer, or %NULL if none was found
180
gst_vaapi_tsb_peek(GstVaapiTSB *tsb)
184
if (!tsb || !tsb->list)
195
* gst_vaapi_tsb_get_timestamp:
196
* @tsb: a #GstVaapiTSB
198
* Returns the timestamp for the current #GstBuffer.
200
* Return value: current #GstBuffer timestamp, or %GST_CLOCK_TIME_NONE if none was found
203
gst_vaapi_tsb_get_timestamp(GstVaapiTSB *tsb)
207
buffer = gst_vaapi_tsb_peek(tsb);
209
return GST_CLOCK_TIME_NONE;
211
return GST_BUFFER_TIMESTAMP(buffer);
215
* gst_vaapi_tsb_get_size:
216
* @tsb: a #GstVaapiTSB
218
* Returns the size of the #GstVaapiTSB.
220
* Return value: how many bytes left to consume from @tsb
223
gst_vaapi_tsb_get_size(GstVaapiTSB *tsb)
229
if (!tsb || !tsb->list)
232
for (l = tsb->list; l != NULL; l = l->next) {
234
size += e->buffer_size - e->offset;