summaryrefslogtreecommitdiff
path: root/gst-libs/gst/vaapi/gstvaapicodedbufferpool.c
blob: a46d5016de7d9d7c0eec445801dbb9f6fdf02e54 (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
/*
 *  gstvaapicodedbufferpool.c - VA coded buffer pool
 *
 *  Copyright (C) 2013-2014 Intel Corporation
 *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
 *
 *  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
 */

#include "sysdeps.h"
#include "gstvaapicodedbufferpool.h"
#include "gstvaapicodedbuffer_priv.h"
#include "gstvaapivideopool_priv.h"
#include "gstvaapiencoder_priv.h"

#define DEBUG 1
#include "gstvaapidebug.h"

/**
 * GstVaapiCodedBufferPool:
 *
 * A pool of lazily allocated #GstVaapiCodedBuffer objects.
 */
struct _GstVaapiCodedBufferPool
{
  /*< private > */
  GstVaapiVideoPool parent_instance;

  GstVaapiContext *context;
  gsize buf_size;
};

static void
coded_buffer_pool_init (GstVaapiCodedBufferPool * pool,
    GstVaapiContext * context, gsize buf_size)
{
  pool->context = gst_vaapi_object_ref (context);
  pool->buf_size = buf_size;
}

static void
coded_buffer_pool_finalize (GstVaapiCodedBufferPool * pool)
{
  gst_vaapi_video_pool_finalize (GST_VAAPI_VIDEO_POOL (pool));
  gst_vaapi_object_replace (&pool->context, NULL);
}

static gpointer
coded_buffer_pool_alloc_object (GstVaapiVideoPool * base_pool)
{
  GstVaapiCodedBufferPool *const pool = GST_VAAPI_CODED_BUFFER_POOL (base_pool);

  return gst_vaapi_coded_buffer_new (pool->context, pool->buf_size);
}

static inline const GstVaapiMiniObjectClass *
gst_vaapi_coded_buffer_pool_class (void)
{
  static const GstVaapiVideoPoolClass GstVaapiCodedBufferPoolClass = {
    {sizeof (GstVaapiCodedBufferPool),
        (GDestroyNotify) coded_buffer_pool_finalize}
    ,
    .alloc_object = coded_buffer_pool_alloc_object
  };
  return GST_VAAPI_MINI_OBJECT_CLASS (&GstVaapiCodedBufferPoolClass);
}

/**
 * gst_vaapi_coded_buffer_pool_new:
 * @encoder: a #GstVaapiEncoder
 * @buf_size: the max size of #GstVaapiCodedBuffer objects, in bytes
 *
 * Creates a new #GstVaapiVideoPool of #GstVaapiCodedBuffer objects
 * with the supplied maximum size in bytes, and bound to the specified
 * @encoder object.
 *
 * Return value: the newly allocated #GstVaapiVideoPool
 */
GstVaapiVideoPool *
gst_vaapi_coded_buffer_pool_new (GstVaapiEncoder * encoder, gsize buf_size)
{
  GstVaapiVideoPool *pool;
  GstVaapiContext *context;

  g_return_val_if_fail (encoder != NULL, NULL);
  g_return_val_if_fail (buf_size > 0, NULL);

  context = GST_VAAPI_ENCODER_CONTEXT (encoder);
  g_return_val_if_fail (context != NULL, NULL);

  pool = (GstVaapiVideoPool *)
      gst_vaapi_mini_object_new (gst_vaapi_coded_buffer_pool_class ());
  if (!pool)
    return NULL;

  gst_vaapi_video_pool_init (pool, GST_VAAPI_OBJECT_DISPLAY (context),
      GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_CODED_BUFFER);
  coded_buffer_pool_init (GST_VAAPI_CODED_BUFFER_POOL (pool),
      context, buf_size);
  return pool;
}

/**
 * gst_vaapi_coded_buffer_pool_get_buffer_size:
 * @pool: a #GstVaapiCodedBufferPool
 *
 * Determines the maximum size of each #GstVaapiCodedBuffer held in
 * the @pool.
 *
 * Return value: size of a #GstVaapiCodedBuffer in @pool
 */
gsize
gst_vaapi_coded_buffer_pool_get_buffer_size (GstVaapiCodedBufferPool * pool)
{
  g_return_val_if_fail (pool != NULL, 0);

  return pool->buf_size;
}