2010-04-23 16:05:58 +00:00
|
|
|
/*
|
|
|
|
* gstvaapidecoder.c - VA decoder abstraction
|
|
|
|
*
|
2012-01-16 09:41:10 +00:00
|
|
|
* Copyright (C) 2010-2011 Splitted-Desktop Systems
|
2012-01-16 10:03:51 +00:00
|
|
|
* Copyright (C) 2011-2012 Intel Corporation
|
2010-04-23 16:05:58 +00:00
|
|
|
*
|
2010-05-03 07:07:27 +00:00
|
|
|
* 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.
|
2010-04-23 16:05:58 +00:00
|
|
|
*
|
2010-05-03 07:07:27 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2010-04-23 16:05:58 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2010-05-03 07:07:27 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2010-04-23 16:05:58 +00:00
|
|
|
*
|
2010-05-03 07:07:27 +00:00
|
|
|
* 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
|
2010-04-23 16:05:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gstvaapidecoder
|
|
|
|
* @short_description: VA decoder abstraction
|
|
|
|
*/
|
|
|
|
|
2012-01-30 17:12:59 +00:00
|
|
|
#include "sysdeps.h"
|
2010-04-23 16:05:58 +00:00
|
|
|
#include "gstvaapicompat.h"
|
|
|
|
#include "gstvaapidecoder.h"
|
|
|
|
#include "gstvaapidecoder_priv.h"
|
|
|
|
#include "gstvaapiutils.h"
|
|
|
|
#include "gstvaapi_priv.h"
|
|
|
|
|
|
|
|
#define DEBUG 1
|
|
|
|
#include "gstvaapidebug.h"
|
|
|
|
|
2012-09-07 14:14:11 +00:00
|
|
|
G_DEFINE_TYPE(GstVaapiDecoder, gst_vaapi_decoder, G_TYPE_OBJECT)
|
2010-04-23 16:05:58 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_DISPLAY,
|
2010-05-03 21:49:35 +00:00
|
|
|
PROP_CAPS,
|
2012-08-08 03:50:41 +00:00
|
|
|
|
|
|
|
N_PROPERTIES
|
2010-04-23 16:05:58 +00:00
|
|
|
};
|
|
|
|
|
2012-08-08 03:50:41 +00:00
|
|
|
static GParamSpec *g_properties[N_PROPERTIES] = { NULL, };
|
|
|
|
|
2010-05-03 08:51:28 +00:00
|
|
|
static void
|
|
|
|
destroy_buffer(GstBuffer *buffer)
|
|
|
|
{
|
|
|
|
gst_buffer_unref(buffer);
|
|
|
|
}
|
|
|
|
|
2010-04-23 16:05:58 +00:00
|
|
|
static gboolean
|
|
|
|
push_buffer(GstVaapiDecoder *decoder, GstBuffer *buffer)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderPrivate * const priv = decoder->priv;
|
|
|
|
|
2010-04-26 11:44:32 +00:00
|
|
|
if (!buffer) {
|
2010-05-03 21:25:46 +00:00
|
|
|
buffer = gst_buffer_new();
|
2010-04-27 15:26:19 +00:00
|
|
|
if (!buffer)
|
|
|
|
return FALSE;
|
2010-05-03 21:25:46 +00:00
|
|
|
GST_BUFFER_FLAG_SET(buffer, GST_BUFFER_FLAG_EOS);
|
2010-04-26 11:44:32 +00:00
|
|
|
}
|
2010-04-23 16:05:58 +00:00
|
|
|
|
|
|
|
GST_DEBUG("queue encoded data buffer %p (%d bytes)",
|
|
|
|
buffer, GST_BUFFER_SIZE(buffer));
|
|
|
|
|
2010-04-30 15:37:28 +00:00
|
|
|
g_queue_push_tail(priv->buffers, buffer);
|
2010-04-23 16:05:58 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-05-15 09:43:28 +00:00
|
|
|
static void
|
|
|
|
push_back_buffer(GstVaapiDecoder *decoder, GstBuffer *buffer)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderPrivate * const priv = decoder->priv;
|
|
|
|
|
|
|
|
GST_DEBUG("requeue encoded data buffer %p (%d bytes)",
|
|
|
|
buffer, GST_BUFFER_SIZE(buffer));
|
|
|
|
|
|
|
|
g_queue_push_head(priv->buffers, buffer);
|
|
|
|
}
|
|
|
|
|
2010-04-27 15:26:19 +00:00
|
|
|
static GstBuffer *
|
|
|
|
pop_buffer(GstVaapiDecoder *decoder)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderPrivate * const priv = decoder->priv;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
|
2010-04-30 15:37:28 +00:00
|
|
|
buffer = g_queue_pop_head(priv->buffers);
|
2010-04-29 17:11:32 +00:00
|
|
|
if (!buffer)
|
|
|
|
return NULL;
|
2010-04-27 15:26:19 +00:00
|
|
|
|
2010-04-29 14:28:43 +00:00
|
|
|
GST_DEBUG("dequeue buffer %p for decoding (%d bytes)",
|
|
|
|
buffer, GST_BUFFER_SIZE(buffer));
|
|
|
|
|
2010-04-27 15:26:19 +00:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2010-04-30 15:37:28 +00:00
|
|
|
static GstVaapiDecoderStatus
|
|
|
|
decode_step(GstVaapiDecoder *decoder)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderStatus status;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
|
2010-05-15 05:36:15 +00:00
|
|
|
/* Decoding will fail if there is no surface left */
|
2012-02-06 14:54:09 +00:00
|
|
|
status = gst_vaapi_decoder_check_status(decoder);
|
|
|
|
if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
|
|
|
|
return status;
|
2010-05-15 05:36:15 +00:00
|
|
|
|
2010-04-30 15:37:28 +00:00
|
|
|
do {
|
|
|
|
buffer = pop_buffer(decoder);
|
|
|
|
if (!buffer)
|
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
|
|
|
|
|
|
|
|
status = GST_VAAPI_DECODER_GET_CLASS(decoder)->decode(decoder, buffer);
|
|
|
|
GST_DEBUG("decode frame (status = %d)", status);
|
2011-10-12 12:00:50 +00:00
|
|
|
if (status != GST_VAAPI_DECODER_STATUS_SUCCESS && GST_BUFFER_IS_EOS(buffer))
|
|
|
|
status = GST_VAAPI_DECODER_STATUS_END_OF_STREAM;
|
2010-05-15 06:59:54 +00:00
|
|
|
gst_buffer_unref(buffer);
|
2010-04-30 15:37:28 +00:00
|
|
|
} while (status == GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2012-01-26 13:54:31 +00:00
|
|
|
static inline void
|
|
|
|
push_surface(GstVaapiDecoder *decoder, GstVaapiSurfaceProxy *proxy)
|
2010-04-28 23:09:52 +00:00
|
|
|
{
|
|
|
|
GstVaapiDecoderPrivate * const priv = decoder->priv;
|
2012-09-11 08:59:33 +00:00
|
|
|
GstClockTime duration;
|
2010-04-28 23:09:52 +00:00
|
|
|
|
2010-04-30 15:37:28 +00:00
|
|
|
GST_DEBUG("queue decoded surface %" GST_VAAPI_ID_FORMAT,
|
2012-01-05 16:09:35 +00:00
|
|
|
GST_VAAPI_ID_ARGS(gst_vaapi_surface_proxy_get_surface_id(proxy)));
|
2010-05-03 21:14:01 +00:00
|
|
|
|
2012-09-11 08:59:33 +00:00
|
|
|
if (priv->fps_n && priv->fps_d) {
|
|
|
|
/* Actual field duration is computed in vaapipostproc */
|
|
|
|
duration = gst_util_uint64_scale(GST_SECOND, priv->fps_d, priv->fps_n);
|
|
|
|
gst_vaapi_surface_proxy_set_duration(proxy, duration);
|
|
|
|
}
|
2010-05-03 21:14:01 +00:00
|
|
|
g_queue_push_tail(priv->surfaces, proxy);
|
2010-04-28 23:09:52 +00:00
|
|
|
}
|
|
|
|
|
2010-05-03 21:14:01 +00:00
|
|
|
static inline GstVaapiSurfaceProxy *
|
2010-04-30 15:37:28 +00:00
|
|
|
pop_surface(GstVaapiDecoder *decoder)
|
2010-04-28 23:09:52 +00:00
|
|
|
{
|
|
|
|
GstVaapiDecoderPrivate * const priv = decoder->priv;
|
|
|
|
|
2010-04-30 15:37:28 +00:00
|
|
|
return g_queue_pop_head(priv->surfaces);
|
2010-04-28 23:09:52 +00:00
|
|
|
}
|
|
|
|
|
2010-04-28 21:50:44 +00:00
|
|
|
static inline void
|
|
|
|
set_codec_data(GstVaapiDecoder *decoder, GstBuffer *codec_data)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderPrivate * const priv = decoder->priv;
|
|
|
|
|
|
|
|
if (priv->codec_data) {
|
|
|
|
gst_buffer_unref(priv->codec_data);
|
|
|
|
priv->codec_data = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (codec_data)
|
|
|
|
priv->codec_data = gst_buffer_ref(codec_data);
|
|
|
|
}
|
|
|
|
|
2010-05-03 21:49:35 +00:00
|
|
|
static void
|
|
|
|
set_caps(GstVaapiDecoder *decoder, GstCaps *caps)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderPrivate * const priv = decoder->priv;
|
2010-05-03 22:02:41 +00:00
|
|
|
GstStructure * const structure = gst_caps_get_structure(caps, 0);
|
2010-05-03 21:49:35 +00:00
|
|
|
GstVaapiProfile profile;
|
|
|
|
const GValue *v_codec_data;
|
2010-05-03 22:02:41 +00:00
|
|
|
gint v1, v2;
|
2012-02-07 14:54:15 +00:00
|
|
|
gboolean b;
|
2010-05-03 21:49:35 +00:00
|
|
|
|
2010-05-03 22:02:41 +00:00
|
|
|
profile = gst_vaapi_profile_from_caps(caps);
|
|
|
|
if (!profile)
|
|
|
|
return;
|
|
|
|
|
2010-05-15 15:33:20 +00:00
|
|
|
priv->caps = gst_caps_copy(caps);
|
|
|
|
|
2010-05-03 22:02:41 +00:00
|
|
|
priv->codec = gst_vaapi_profile_get_codec(profile);
|
|
|
|
if (!priv->codec)
|
|
|
|
return;
|
2010-05-03 21:49:35 +00:00
|
|
|
|
2010-05-03 22:02:41 +00:00
|
|
|
if (gst_structure_get_int(structure, "width", &v1))
|
|
|
|
priv->width = v1;
|
|
|
|
if (gst_structure_get_int(structure, "height", &v2))
|
|
|
|
priv->height = v2;
|
|
|
|
|
|
|
|
if (gst_structure_get_fraction(structure, "framerate", &v1, &v2)) {
|
|
|
|
priv->fps_n = v1;
|
|
|
|
priv->fps_d = v2;
|
2010-05-03 21:49:35 +00:00
|
|
|
}
|
2010-05-03 22:02:41 +00:00
|
|
|
|
2010-05-15 15:33:20 +00:00
|
|
|
if (gst_structure_get_fraction(structure, "pixel-aspect-ratio", &v1, &v2)) {
|
|
|
|
priv->par_n = v1;
|
|
|
|
priv->par_d = v2;
|
|
|
|
}
|
|
|
|
|
2012-02-07 14:54:15 +00:00
|
|
|
if (gst_structure_get_boolean(structure, "interlaced", &b))
|
|
|
|
priv->is_interlaced = b;
|
|
|
|
|
2010-05-03 22:02:41 +00:00
|
|
|
v_codec_data = gst_structure_get_value(structure, "codec_data");
|
|
|
|
if (v_codec_data)
|
|
|
|
set_codec_data(decoder, gst_value_get_buffer(v_codec_data));
|
2010-05-03 21:49:35 +00:00
|
|
|
}
|
|
|
|
|
2010-04-23 16:05:58 +00:00
|
|
|
static void
|
2010-04-30 15:37:28 +00:00
|
|
|
clear_queue(GQueue *q, GDestroyNotify destroy)
|
2010-04-23 16:05:58 +00:00
|
|
|
{
|
2010-04-30 15:37:28 +00:00
|
|
|
while (!g_queue_is_empty(q))
|
|
|
|
destroy(g_queue_pop_head(q));
|
2010-04-23 16:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_decoder_finalize(GObject *object)
|
|
|
|
{
|
2010-04-26 11:44:32 +00:00
|
|
|
GstVaapiDecoder * const decoder = GST_VAAPI_DECODER(object);
|
|
|
|
GstVaapiDecoderPrivate * const priv = decoder->priv;
|
2010-04-23 16:05:58 +00:00
|
|
|
|
2010-04-28 21:50:44 +00:00
|
|
|
set_codec_data(decoder, NULL);
|
|
|
|
|
2010-05-15 15:33:20 +00:00
|
|
|
if (priv->caps) {
|
|
|
|
gst_caps_unref(priv->caps);
|
|
|
|
priv->caps = NULL;
|
|
|
|
}
|
|
|
|
|
2010-04-23 16:05:58 +00:00
|
|
|
if (priv->context) {
|
|
|
|
g_object_unref(priv->context);
|
|
|
|
priv->context = NULL;
|
2011-08-05 09:53:50 +00:00
|
|
|
priv->va_context = VA_INVALID_ID;
|
2010-04-23 16:05:58 +00:00
|
|
|
}
|
2010-05-03 21:49:35 +00:00
|
|
|
|
2010-04-27 15:26:19 +00:00
|
|
|
if (priv->buffers) {
|
2010-05-03 08:51:28 +00:00
|
|
|
clear_queue(priv->buffers, (GDestroyNotify)destroy_buffer);
|
2010-04-30 15:37:28 +00:00
|
|
|
g_queue_free(priv->buffers);
|
2010-04-27 15:26:19 +00:00
|
|
|
priv->buffers = NULL;
|
2010-04-23 16:05:58 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 15:26:19 +00:00
|
|
|
if (priv->surfaces) {
|
2010-05-03 21:14:01 +00:00
|
|
|
clear_queue(priv->surfaces, (GDestroyNotify)g_object_unref);
|
2010-04-30 15:37:28 +00:00
|
|
|
g_queue_free(priv->surfaces);
|
2010-04-27 15:26:19 +00:00
|
|
|
priv->surfaces = NULL;
|
2010-04-23 16:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->display) {
|
|
|
|
g_object_unref(priv->display);
|
|
|
|
priv->display = NULL;
|
2011-08-05 09:53:50 +00:00
|
|
|
priv->va_display = NULL;
|
2010-04-23 16:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS(gst_vaapi_decoder_parent_class)->finalize(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_decoder_set_property(
|
|
|
|
GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec
|
|
|
|
)
|
|
|
|
{
|
2010-05-03 21:49:35 +00:00
|
|
|
GstVaapiDecoder * const decoder = GST_VAAPI_DECODER(object);
|
|
|
|
GstVaapiDecoderPrivate * const priv = decoder->priv;
|
2010-04-23 16:05:58 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_DISPLAY:
|
|
|
|
priv->display = g_object_ref(g_value_get_object(value));
|
2011-08-05 09:53:50 +00:00
|
|
|
if (priv->display)
|
|
|
|
priv->va_display = gst_vaapi_display_get_display(priv->display);
|
|
|
|
else
|
|
|
|
priv->va_display = NULL;
|
2010-04-23 16:05:58 +00:00
|
|
|
break;
|
2010-05-03 21:49:35 +00:00
|
|
|
case PROP_CAPS:
|
|
|
|
set_caps(decoder, g_value_get_pointer(value));
|
2010-05-03 15:11:32 +00:00
|
|
|
break;
|
2010-04-23 16:05:58 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_decoder_get_property(
|
|
|
|
GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderPrivate * const priv = GST_VAAPI_DECODER(object)->priv;
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_DISPLAY:
|
|
|
|
g_value_set_object(value, priv->display);
|
|
|
|
break;
|
2010-05-15 15:33:20 +00:00
|
|
|
case PROP_CAPS:
|
|
|
|
gst_value_set_caps(value, priv->caps);
|
|
|
|
break;
|
2010-04-23 16:05:58 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_decoder_class_init(GstVaapiDecoderClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass * const object_class = G_OBJECT_CLASS(klass);
|
|
|
|
|
|
|
|
g_type_class_add_private(klass, sizeof(GstVaapiDecoderPrivate));
|
|
|
|
|
|
|
|
object_class->finalize = gst_vaapi_decoder_finalize;
|
|
|
|
object_class->set_property = gst_vaapi_decoder_set_property;
|
|
|
|
object_class->get_property = gst_vaapi_decoder_get_property;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstVaapiDecoder:display:
|
|
|
|
*
|
|
|
|
* The #GstVaapiDisplay this decoder is bound to.
|
|
|
|
*/
|
2012-08-08 03:50:41 +00:00
|
|
|
g_properties[PROP_DISPLAY] =
|
2010-04-23 16:05:58 +00:00
|
|
|
g_param_spec_object("display",
|
|
|
|
"Display",
|
|
|
|
"The GstVaapiDisplay this decoder is bound to",
|
|
|
|
GST_VAAPI_TYPE_DISPLAY,
|
2012-08-08 03:50:41 +00:00
|
|
|
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY);
|
2010-04-23 16:05:58 +00:00
|
|
|
|
2012-08-08 03:50:41 +00:00
|
|
|
g_properties[PROP_CAPS] =
|
2010-05-03 21:49:35 +00:00
|
|
|
g_param_spec_pointer("caps",
|
|
|
|
"Decoder caps",
|
|
|
|
"The decoder caps",
|
2012-08-08 03:50:41 +00:00
|
|
|
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY);
|
|
|
|
|
|
|
|
g_object_class_install_properties(object_class, N_PROPERTIES, g_properties);
|
2010-04-23 16:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_decoder_init(GstVaapiDecoder *decoder)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderPrivate *priv = GST_VAAPI_DECODER_GET_PRIVATE(decoder);
|
|
|
|
|
|
|
|
decoder->priv = priv;
|
2011-08-05 09:53:50 +00:00
|
|
|
priv->display = NULL;
|
|
|
|
priv->va_display = NULL;
|
2010-04-23 16:05:58 +00:00
|
|
|
priv->context = NULL;
|
2011-08-05 09:53:50 +00:00
|
|
|
priv->va_context = VA_INVALID_ID;
|
2010-05-15 15:33:20 +00:00
|
|
|
priv->caps = NULL;
|
2010-04-23 16:05:58 +00:00
|
|
|
priv->codec = 0;
|
2010-04-28 21:50:44 +00:00
|
|
|
priv->codec_data = NULL;
|
2010-05-03 15:11:32 +00:00
|
|
|
priv->width = 0;
|
|
|
|
priv->height = 0;
|
2010-05-15 15:33:20 +00:00
|
|
|
priv->fps_n = 0;
|
|
|
|
priv->fps_d = 0;
|
|
|
|
priv->par_n = 0;
|
|
|
|
priv->par_d = 0;
|
2010-04-30 15:37:28 +00:00
|
|
|
priv->buffers = g_queue_new();
|
|
|
|
priv->surfaces = g_queue_new();
|
2012-02-07 14:54:15 +00:00
|
|
|
priv->is_interlaced = FALSE;
|
2010-04-26 11:44:32 +00:00
|
|
|
}
|
|
|
|
|
2010-05-15 15:33:20 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_decoder_get_caps:
|
|
|
|
* @decoder: a #GstVaapiDecoder
|
|
|
|
*
|
|
|
|
* Retrieves the @decoder caps. The deocder owns the returned caps, so
|
|
|
|
* use gst_caps_ref() whenever necessary.
|
|
|
|
*
|
|
|
|
* Return value: the @decoder caps
|
|
|
|
*/
|
|
|
|
GstCaps *
|
|
|
|
gst_vaapi_decoder_get_caps(GstVaapiDecoder *decoder)
|
|
|
|
{
|
|
|
|
return decoder->priv->caps;
|
|
|
|
}
|
|
|
|
|
2010-04-23 16:05:58 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_decoder_put_buffer:
|
|
|
|
* @decoder: a #GstVaapiDecoder
|
|
|
|
* @buf: a #GstBuffer
|
|
|
|
*
|
|
|
|
* Queues a #GstBuffer to the HW decoder. The decoder holds a
|
|
|
|
* reference to @buf.
|
|
|
|
*
|
|
|
|
* Caller can notify an End-Of-Stream with @buf set to %NULL.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_vaapi_decoder_put_buffer(GstVaapiDecoder *decoder, GstBuffer *buf)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_DECODER(decoder), FALSE);
|
|
|
|
|
2010-04-26 11:44:32 +00:00
|
|
|
return push_buffer(decoder, buf ? gst_buffer_ref(buf) : NULL);
|
2010-04-23 16:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_decoder_get_surface:
|
|
|
|
* @decoder: a #GstVaapiDecoder
|
|
|
|
* @pstatus: return location for the decoder status, or %NULL
|
|
|
|
*
|
2010-04-30 15:37:28 +00:00
|
|
|
* Flushes encoded buffers to the decoder and returns a decoded
|
|
|
|
* surface, if any.
|
2010-04-23 16:05:58 +00:00
|
|
|
*
|
|
|
|
* Return value: a #GstVaapiSurfaceProxy holding the decoded surface,
|
|
|
|
* or %NULL if none is available (e.g. an error). Caller owns the
|
|
|
|
* returned object. g_object_unref() after usage.
|
|
|
|
*/
|
2010-04-30 15:37:28 +00:00
|
|
|
GstVaapiSurfaceProxy *
|
|
|
|
gst_vaapi_decoder_get_surface(
|
2010-04-23 16:05:58 +00:00
|
|
|
GstVaapiDecoder *decoder,
|
|
|
|
GstVaapiDecoderStatus *pstatus
|
|
|
|
)
|
|
|
|
{
|
2010-05-03 21:14:01 +00:00
|
|
|
GstVaapiSurfaceProxy *proxy;
|
|
|
|
GstVaapiDecoderStatus status;
|
|
|
|
|
|
|
|
if (pstatus)
|
|
|
|
*pstatus = GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
|
2010-04-28 23:09:52 +00:00
|
|
|
|
2010-04-30 15:37:28 +00:00
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_DECODER(decoder), NULL);
|
|
|
|
|
2010-05-03 21:14:01 +00:00
|
|
|
proxy = pop_surface(decoder);
|
|
|
|
if (!proxy) {
|
2010-04-30 15:37:28 +00:00
|
|
|
do {
|
|
|
|
status = decode_step(decoder);
|
|
|
|
} while (status == GST_VAAPI_DECODER_STATUS_SUCCESS);
|
2010-05-03 21:14:01 +00:00
|
|
|
proxy = pop_surface(decoder);
|
2010-04-30 15:37:28 +00:00
|
|
|
}
|
|
|
|
|
2010-05-03 21:14:01 +00:00
|
|
|
if (proxy)
|
|
|
|
status = GST_VAAPI_DECODER_STATUS_SUCCESS;
|
2010-04-27 15:26:19 +00:00
|
|
|
|
|
|
|
if (pstatus)
|
|
|
|
*pstatus = status;
|
|
|
|
return proxy;
|
2010-04-23 16:05:58 +00:00
|
|
|
}
|
|
|
|
|
2010-05-15 15:33:20 +00:00
|
|
|
void
|
|
|
|
gst_vaapi_decoder_set_picture_size(
|
|
|
|
GstVaapiDecoder *decoder,
|
|
|
|
guint width,
|
|
|
|
guint height
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderPrivate * const priv = decoder->priv;
|
2011-07-22 13:34:48 +00:00
|
|
|
gboolean size_changed = FALSE;
|
2010-05-15 15:33:20 +00:00
|
|
|
|
|
|
|
if (priv->width != width) {
|
|
|
|
GST_DEBUG("picture width changed to %d", width);
|
|
|
|
priv->width = width;
|
|
|
|
gst_caps_set_simple(priv->caps, "width", G_TYPE_INT, width, NULL);
|
2011-07-22 13:34:48 +00:00
|
|
|
size_changed = TRUE;
|
2010-05-15 15:33:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->height != height) {
|
|
|
|
GST_DEBUG("picture height changed to %d", height);
|
|
|
|
priv->height = height;
|
|
|
|
gst_caps_set_simple(priv->caps, "height", G_TYPE_INT, height, NULL);
|
2011-07-22 13:34:48 +00:00
|
|
|
size_changed = TRUE;
|
2010-05-15 15:33:20 +00:00
|
|
|
}
|
|
|
|
|
2011-07-22 13:34:48 +00:00
|
|
|
if (size_changed)
|
2012-08-08 03:50:41 +00:00
|
|
|
g_object_notify_by_pspec(G_OBJECT(decoder), g_properties[PROP_CAPS]);
|
2010-05-15 15:33:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_vaapi_decoder_set_framerate(
|
|
|
|
GstVaapiDecoder *decoder,
|
|
|
|
guint fps_n,
|
|
|
|
guint fps_d
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderPrivate * const priv = decoder->priv;
|
|
|
|
|
|
|
|
if (!fps_n || !fps_d)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (priv->fps_n != fps_n || priv->fps_d != fps_d) {
|
|
|
|
GST_DEBUG("framerate changed to %u/%u", fps_n, fps_d);
|
|
|
|
priv->fps_n = fps_n;
|
|
|
|
priv->fps_d = fps_d;
|
|
|
|
gst_caps_set_simple(
|
|
|
|
priv->caps,
|
|
|
|
"framerate", GST_TYPE_FRACTION, fps_n, fps_d,
|
|
|
|
NULL
|
|
|
|
);
|
2012-08-08 03:50:41 +00:00
|
|
|
g_object_notify_by_pspec(G_OBJECT(decoder), g_properties[PROP_CAPS]);
|
2010-05-15 15:33:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_vaapi_decoder_set_pixel_aspect_ratio(
|
|
|
|
GstVaapiDecoder *decoder,
|
|
|
|
guint par_n,
|
|
|
|
guint par_d
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderPrivate * const priv = decoder->priv;
|
|
|
|
|
|
|
|
if (!par_n || !par_d)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (priv->par_n != par_n || priv->par_d != par_d) {
|
|
|
|
GST_DEBUG("pixel-aspect-ratio changed to %u/%u", par_n, par_d);
|
|
|
|
priv->par_n = par_n;
|
|
|
|
priv->par_d = par_d;
|
|
|
|
gst_caps_set_simple(
|
|
|
|
priv->caps,
|
|
|
|
"pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d,
|
|
|
|
NULL
|
|
|
|
);
|
2012-08-08 03:50:41 +00:00
|
|
|
g_object_notify_by_pspec(G_OBJECT(decoder), g_properties[PROP_CAPS]);
|
2010-05-15 15:33:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-07 14:54:15 +00:00
|
|
|
void
|
|
|
|
gst_vaapi_decoder_set_interlaced(GstVaapiDecoder *decoder, gboolean interlaced)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderPrivate * const priv = decoder->priv;
|
|
|
|
|
|
|
|
if (priv->is_interlaced != interlaced) {
|
|
|
|
GST_DEBUG("interlaced changed to %s", interlaced ? "true" : "false");
|
|
|
|
priv->is_interlaced = interlaced;
|
|
|
|
gst_caps_set_simple(
|
|
|
|
priv->caps,
|
|
|
|
"interlaced", G_TYPE_BOOLEAN, interlaced,
|
|
|
|
NULL
|
|
|
|
);
|
2012-08-08 03:50:41 +00:00
|
|
|
g_object_notify_by_pspec(G_OBJECT(decoder), g_properties[PROP_CAPS]);
|
2012-02-07 14:54:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-23 16:05:58 +00:00
|
|
|
gboolean
|
|
|
|
gst_vaapi_decoder_ensure_context(
|
2012-09-10 16:26:51 +00:00
|
|
|
GstVaapiDecoder *decoder,
|
|
|
|
GstVaapiContextInfo *cip
|
2010-04-23 16:05:58 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderPrivate * const priv = decoder->priv;
|
|
|
|
|
2012-09-10 16:26:51 +00:00
|
|
|
gst_vaapi_decoder_set_picture_size(decoder, cip->width, cip->height);
|
2011-08-05 09:53:50 +00:00
|
|
|
|
2012-09-10 16:26:51 +00:00
|
|
|
if (priv->context) {
|
|
|
|
if (!gst_vaapi_context_reset_full(priv->context, cip))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
priv->context = gst_vaapi_context_new_full(priv->display, cip);
|
|
|
|
if (!priv->context)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-08-05 09:53:50 +00:00
|
|
|
priv->va_context = gst_vaapi_context_get_id(priv->context);
|
|
|
|
return TRUE;
|
2010-04-23 16:05:58 +00:00
|
|
|
}
|
|
|
|
|
2010-05-15 09:43:28 +00:00
|
|
|
gboolean
|
|
|
|
gst_vaapi_decoder_push_buffer_sub(
|
|
|
|
GstVaapiDecoder *decoder,
|
|
|
|
GstBuffer *buffer,
|
|
|
|
guint offset,
|
|
|
|
guint size
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstBuffer *subbuffer;
|
|
|
|
|
|
|
|
subbuffer = gst_buffer_create_sub(buffer, offset, size);
|
|
|
|
if (!subbuffer)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
push_back_buffer(decoder, subbuffer);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-01-26 13:54:31 +00:00
|
|
|
void
|
2012-01-05 16:09:35 +00:00
|
|
|
gst_vaapi_decoder_push_surface_proxy(
|
|
|
|
GstVaapiDecoder *decoder,
|
2012-01-26 13:54:31 +00:00
|
|
|
GstVaapiSurfaceProxy *proxy
|
2012-01-05 16:09:35 +00:00
|
|
|
)
|
|
|
|
{
|
2012-09-07 09:58:53 +00:00
|
|
|
push_surface(decoder, proxy);
|
2010-04-23 16:05:58 +00:00
|
|
|
}
|
2012-02-06 14:54:09 +00:00
|
|
|
|
|
|
|
GstVaapiDecoderStatus
|
|
|
|
gst_vaapi_decoder_check_status(GstVaapiDecoder *decoder)
|
|
|
|
{
|
|
|
|
GstVaapiDecoderPrivate * const priv = decoder->priv;
|
|
|
|
|
|
|
|
if (priv->context && gst_vaapi_context_get_surface_count(priv->context) < 1)
|
|
|
|
return GST_VAAPI_DECODER_STATUS_ERROR_NO_SURFACE;
|
|
|
|
return GST_VAAPI_DECODER_STATUS_SUCCESS;
|
|
|
|
}
|