gstreamer/gst-libs/gst/vaapi/gstvaapicodedbufferpool.c
Gwenole Beauchesne 0fb7c60508 encoder: rework GstVaapiCodedBuffer and related proxy.
Refactor the GstVaapiCodedBuffer APIs so that to more clearly separate
public and private interfaces. Besides, the map/unmap APIs should not
be exposed as is but appropriate accessors should be provided instead.

* GstVaapiCodedBuffer: VA coded buffer abstraction
- gst_vaapi_coded_buffer_get_size(): get coded buffer size.
- gst_vaapi_coded_buffer_copy_into(): copy coded buffer into GstBuffer

* GstVaapiCodedBufferPool: pool of VA coded buffer objects
- gst_vaapi_coded_buffer_pool_new(): create a pool of coded buffers of
  the specified max size, and bound to the supplied encoder

* GstVaapiCodedBufferProxy: pool-allocated VA coded buffer object proxy
- gst_vaapi_coded_buffer_proxy_new_from_pool(): create coded buf from pool
- gst_vaapi_coded_buffer_proxy_get_buffer(): get underlying coded buffer
- gst_vaapi_coded_buffer_proxy_get_buffer_size(): get coded buffer size

Rationale: more optimized transfer functions might be provided in the
future, thus rendering the map/unmap mechanism obsolete or sub-optimal.

https://bugzilla.gnome.org/show_bug.cgi?id=719775
2013-12-04 19:14:38 +01:00

113 lines
3.3 KiB
C

/*
* gstvaapicodedbufferpool.c - VA coded buffer pool
*
* Copyright (C) 2013 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_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;
}