summaryrefslogtreecommitdiff
path: root/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c
blob: dc5d52ff1cb2fb2cac65f8f0d40bab5feba32b8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
/*
 *  gstvaapisurfaceproxy.c - VA surface proxy
 *
 *  Copyright (C) 2010-2011 Splitted-Desktop Systems
 *  Copyright (C) 2011-2012 Intel Corporation
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2.1
 *  of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301 USA
 */

/**
 * SECTION:gstvaapisurfaceproxy
 * @short_description: VA surface proxy
 */

#include "sysdeps.h"
#include "gstvaapisurfaceproxy.h"
#include "gstvaapiobject_priv.h"

#define DEBUG 1
#include "gstvaapidebug.h"

G_DEFINE_TYPE(GstVaapiSurfaceProxy, gst_vaapi_surface_proxy, G_TYPE_OBJECT)

#define GST_VAAPI_SURFACE_PROXY_GET_PRIVATE(obj)                \
    (G_TYPE_INSTANCE_GET_PRIVATE((obj),                         \
                                 GST_VAAPI_TYPE_SURFACE_PROXY,	\
                                 GstVaapiSurfaceProxyPrivate))

struct _GstVaapiSurfaceProxyPrivate {
    GstVaapiContext    *context;
    GstVaapiSurface    *surface;
    GstClockTime        timestamp;
    GstClockTime        duration;
    guint               is_interlaced   : 1;
    guint               tff             : 1;
};

enum {
    PROP_0,

    PROP_CONTEXT,
    PROP_SURFACE,
    PROP_TIMESTAMP,
    PROP_DURATION,
    PROP_INTERLACED,
    PROP_TFF
};

static void
gst_vaapi_surface_proxy_finalize(GObject *object)
{
    GstVaapiSurfaceProxy * const proxy = GST_VAAPI_SURFACE_PROXY(object);

    gst_vaapi_surface_proxy_set_surface(proxy, NULL);
    gst_vaapi_surface_proxy_set_context(proxy, NULL);

    G_OBJECT_CLASS(gst_vaapi_surface_proxy_parent_class)->finalize(object);
}

static void
gst_vaapi_surface_proxy_set_property(
    GObject      *object,
    guint         prop_id,
    const GValue *value,
    GParamSpec   *pspec
)
{
    GstVaapiSurfaceProxy * const proxy = GST_VAAPI_SURFACE_PROXY(object);

    switch (prop_id) {
    case PROP_CONTEXT:
        gst_vaapi_surface_proxy_set_context(proxy, g_value_get_pointer(value));
        break;
    case PROP_SURFACE:
        gst_vaapi_surface_proxy_set_surface(proxy, g_value_get_pointer(value));
        break;
    case PROP_TIMESTAMP:
        gst_vaapi_surface_proxy_set_timestamp(proxy, g_value_get_uint64(value));
        break;
    case PROP_DURATION:
        gst_vaapi_surface_proxy_set_duration(proxy, g_value_get_uint64(value));
        break;
    case PROP_INTERLACED:
        gst_vaapi_surface_proxy_set_interlaced(proxy, g_value_get_boolean(value));
        break;
    case PROP_TFF:
        gst_vaapi_surface_proxy_set_tff(proxy, g_value_get_boolean(value));
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
        break;
    }
}

static void
gst_vaapi_surface_proxy_get_property(
    GObject    *object,
    guint       prop_id,
    GValue     *value,
    GParamSpec *pspec
)
{
    GstVaapiSurfaceProxy * const proxy = GST_VAAPI_SURFACE_PROXY(object);

    switch (prop_id) {
    case PROP_CONTEXT:
        g_value_set_pointer(value, gst_vaapi_surface_proxy_get_context(proxy));
        break;
    case PROP_SURFACE:
        g_value_set_pointer(value, gst_vaapi_surface_proxy_get_surface(proxy));
        break;
    case PROP_TIMESTAMP:
        g_value_set_uint64(value, gst_vaapi_surface_proxy_get_timestamp(proxy));
        break;
    case PROP_DURATION:
        g_value_set_uint64(value, gst_vaapi_surface_proxy_get_duration(proxy));
        break;
    case PROP_INTERLACED:
        g_value_set_boolean(value, gst_vaapi_surface_proxy_get_interlaced(proxy));
        break;
    case PROP_TFF:
        g_value_set_boolean(value, gst_vaapi_surface_proxy_get_tff(proxy));
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
        break;
    }
}

static void
gst_vaapi_surface_proxy_class_init(GstVaapiSurfaceProxyClass *klass)
{
    GObjectClass * const object_class = G_OBJECT_CLASS(klass);

    g_type_class_add_private(klass, sizeof(GstVaapiSurfaceProxyPrivate));

    object_class->finalize     = gst_vaapi_surface_proxy_finalize;
    object_class->set_property = gst_vaapi_surface_proxy_set_property;
    object_class->get_property = gst_vaapi_surface_proxy_get_property;

    g_object_class_install_property
        (object_class,
         PROP_CONTEXT,
         g_param_spec_pointer("context",
                              "Context",
                              "The context stored in the proxy",
                              G_PARAM_READWRITE));

    g_object_class_install_property
        (object_class,
         PROP_SURFACE,
         g_param_spec_pointer("surface",
                              "Surface",
                              "The surface stored in the proxy",
                              G_PARAM_READWRITE));

    g_object_class_install_property
        (object_class,
         PROP_TIMESTAMP,
         g_param_spec_uint64("timestamp",
                             "Timestamp",
                             "The presentation time of the surface",
                             0, G_MAXUINT64, GST_CLOCK_TIME_NONE,
                             G_PARAM_READWRITE));

    g_object_class_install_property
        (object_class,
         PROP_DURATION,
         g_param_spec_uint64("duration",
                             "Duration",
                             "The amount of time the surface is to be presented",
                             0, G_MAXUINT64, GST_CLOCK_TIME_NONE,
                             G_PARAM_READWRITE));

    g_object_class_install_property
        (object_class,
         PROP_INTERLACED,
         g_param_spec_boolean("interlaced",
                              "Interlaced",
                              "Flag indicating whether surface is interlaced",
                              FALSE,
                              G_PARAM_READWRITE));

    g_object_class_install_property
        (object_class,
         PROP_TFF,
         g_param_spec_boolean("tff",
                              "Top-Field-First",
                              "Flag indicating for interlaced surfaces whether Top Field is First",
                              FALSE,
                              G_PARAM_READWRITE));
}

static void
gst_vaapi_surface_proxy_init(GstVaapiSurfaceProxy *proxy)
{ 
    GstVaapiSurfaceProxyPrivate *priv;

    priv                = GST_VAAPI_SURFACE_PROXY_GET_PRIVATE(proxy);
    proxy->priv         = priv;
    priv->context       = NULL;
    priv->surface       = NULL;
    priv->timestamp     = GST_CLOCK_TIME_NONE;
    priv->duration      = GST_CLOCK_TIME_NONE;
    priv->is_interlaced = FALSE;
    priv->tff           = FALSE;
}

/**
 * gst_vaapi_surface_proxy_new:
 * @context: a #GstVaapiContext
 * @surface: a #GstVaapiSurface
 *
 * Creates a new #GstVaapiSurfaceProxy with the specified context and
 * surface.
 *
 * Return value: the newly allocated #GstVaapiSurfaceProxy object
 */
GstVaapiSurfaceProxy *
gst_vaapi_surface_proxy_new(GstVaapiContext *context, GstVaapiSurface *surface)
{
    g_return_val_if_fail(GST_VAAPI_IS_CONTEXT(context), NULL);
    g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), NULL);

    return g_object_new(GST_VAAPI_TYPE_SURFACE_PROXY,
                        "context",  context,
                        "surface",  surface,
                        NULL);
}

/**
 * gst_vaapi_surface_proxy_get_context:
 * @proxy: a #GstVaapiSurfaceProxy
 *
 * Returns the #GstVaapiContext stored in the @proxy.
 *
 * Return value: the #GstVaapiContext
 */
GstVaapiContext *
gst_vaapi_surface_proxy_get_context(GstVaapiSurfaceProxy *proxy)
{
    g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);

    return proxy->priv->context;
}

/**
 * gst_vaapi_surface_proxy_set_context:
 * @proxy: a #GstVaapiSurfaceProxy
 * @context: the new #GstVaapiContext to be stored in @proxy
 *
 * Stores a new @context into the @proxy. The proxy releases the
 * previous reference, if any, and then holds a reference to the new
 * @context.
 */
void
gst_vaapi_surface_proxy_set_context(
    GstVaapiSurfaceProxy *proxy,
    GstVaapiContext      *context
)
{
    GstVaapiSurfaceProxyPrivate *priv;

    g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));

    priv = proxy->priv;

    g_clear_object(&priv->context);

    if (context)
        priv->context = g_object_ref(context);
}

/**
 * gst_vaapi_surface_proxy_get_surface:
 * @proxy: a #GstVaapiSurfaceProxy
 *
 * Returns the #GstVaapiSurface stored in the @proxy.
 *
 * Return value: the #GstVaapiSurface
 */
GstVaapiSurface *
gst_vaapi_surface_proxy_get_surface(GstVaapiSurfaceProxy *proxy)
{
    g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);

    return proxy->priv->surface;
}

/**
 * gst_vaapi_surface_proxy_get_surface_id:
 * @proxy: a #GstVaapiSurfaceProxy
 *
 * Returns the VA surface ID stored in the @proxy.
 *
 * Return value: the #GstVaapiID
 */
GstVaapiID
gst_vaapi_surface_proxy_get_surface_id(GstVaapiSurfaceProxy *proxy)
{
    g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), GST_VAAPI_ID_NONE);
    g_return_val_if_fail(proxy->priv->surface != NULL, GST_VAAPI_ID_NONE);

    return GST_VAAPI_OBJECT_ID(proxy->priv->surface);
}

/**
 * gst_vaapi_surface_proxy_set_surface:
 * @proxy: a #GstVaapiSurfaceProxy
 * @surface: the new #GstVaapiSurface to be stored in @proxy
 *
 * Stores a new @surface into the @proxy. The proxy releases the
 * previous reference, if any, and then holds a reference to the new
 * @surface.
 */
void
gst_vaapi_surface_proxy_set_surface(
    GstVaapiSurfaceProxy *proxy,
    GstVaapiSurface      *surface
)
{
    GstVaapiSurfaceProxyPrivate *priv;

    g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));

    priv = proxy->priv;

    if (priv->surface) {
        if (priv->context)
            gst_vaapi_context_put_surface(priv->context, priv->surface);
        g_object_unref(priv->surface);
        priv->surface = NULL;
    }

    if (surface)
        priv->surface = g_object_ref(surface);
}

/**
 * gst_vaapi_surface_proxy_get_timestamp:
 * @proxy: a #GstVaapiSurfaceProxy
 *
 * Returns the presentation timestamp of the #GstVaapiSurface held by @proxy.
 *
 * Return value: the presentation timestamp of the surface, or
 *   %GST_CLOCK_TIME_NONE is none was set
 */
GstClockTime
gst_vaapi_surface_proxy_get_timestamp(GstVaapiSurfaceProxy *proxy)
{
    g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), GST_CLOCK_TIME_NONE);

    return proxy->priv->timestamp;
}

/**
 * gst_vaapi_surface_proxy_set_timestamp:
 * @proxy: a #GstVaapiSurfaceProxy
 * @timestamp: the new presentation timestamp as a #GstClockTime
 *
 * Sets the presentation timestamp of the @proxy surface to @timestamp.
 */
void
gst_vaapi_surface_proxy_set_timestamp(
    GstVaapiSurfaceProxy *proxy,
    GstClockTime          timestamp
)
{
    g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));

    proxy->priv->timestamp = timestamp;
}

/**
 * gst_vaapi_surface_proxy_get_duration:
 * @proxy: a #GstVaapiSurfaceProxy
 *
 * Returns the presentation duration of the #GstVaapiSurface held by @proxy.
 *
 * Return value: the presentation duration of the surface, or
 *   %GST_CLOCK_TIME_NONE is none was set
 */
GstClockTime
gst_vaapi_surface_proxy_get_duration(GstVaapiSurfaceProxy *proxy)
{
    g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy),
                         GST_CLOCK_TIME_NONE);

    return proxy->priv->duration;
}

/**
 * gst_vaapi_surface_proxy_set_duration:
 * @proxy: a #GstVaapiSurfaceProxy
 * @duration: the presentation duration of this surface as a #GstClockTime
 *
 * Sets the presentation duration of the @proxy surface to @duration.
 */
void
gst_vaapi_surface_proxy_set_duration(
    GstVaapiSurfaceProxy *proxy,
    GstClockTime          duration
)
{
    g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));

    proxy->priv->duration = duration;
}

/**
 * gst_vaapi_surface_proxy_get_interlaced:
 * @proxy: a #GstVaapiSurfaceProxy
 *
 * Returns whether the @proxy holds an interlaced #GstVaapiSurface or not.
 *
 * Return value: %TRUE if the underlying surface is interlaced, %FALSE
 *     otherwise.
 */
gboolean
gst_vaapi_surface_proxy_get_interlaced(GstVaapiSurfaceProxy *proxy)
{
    g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), FALSE);

    return proxy->priv->is_interlaced;
}

/**
 * gst_vaapi_surface_proxy_set_interlaced:
 * @proxy: a #GstVaapiSurfaceProxy
 * @b: a boolean value
 *
 * Sets whether the underlying #GstVaapiSurface for @proxy is interlaced
 * or not.
 */
void
gst_vaapi_surface_proxy_set_interlaced(GstVaapiSurfaceProxy *proxy, gboolean b)
{
    g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));

    proxy->priv->is_interlaced = b;
}

/**
 * gst_vaapi_surface_proxy_get_tff:
 * @proxy: a #GstVaapiSurfaceProxy
 *
 * Returns the TFF flag of the #GstVaapiSurface held by @proxy.
 *
 * Return value: the TFF flag of the surface
 */
gboolean
gst_vaapi_surface_proxy_get_tff(GstVaapiSurfaceProxy *proxy)
{
    g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), FALSE);

    return proxy->priv->is_interlaced && proxy->priv->tff;
}

/**
 * gst_vaapi_surface_proxy_set_tff:
 * @proxy: a #GstVaapiSurfaceProxy
 * @tff: the new value of the TFF flag
 *
 * Sets the TFF flag of the @proxy surface to @tff.
 */
void
gst_vaapi_surface_proxy_set_tff(GstVaapiSurfaceProxy *proxy, gboolean tff)
{
    g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));

    proxy->priv->tff = tff;
}