2010-06-26 19:02:53 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2010-06-26 19:02:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstvdpdecoder.h"
|
2012-09-20 17:03:11 +00:00
|
|
|
#include "gstvdpvideomemory.h"
|
|
|
|
#include "gstvdpvideobufferpool.h"
|
2010-06-26 19:02:53 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_vdp_decoder_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_vdp_decoder_debug
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
#define DEBUG_INIT \
|
2010-06-26 19:02:53 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_vdp_decoder_debug, "vdpdecoder", 0, \
|
|
|
|
"VDPAU decoder base class");
|
2012-09-20 17:03:11 +00:00
|
|
|
#define gst_vdp_decoder_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstVdpDecoder, gst_vdp_decoder, GST_TYPE_VIDEO_DECODER,
|
|
|
|
DEBUG_INIT);
|
2010-06-26 19:02:53 +00:00
|
|
|
|
2010-06-27 07:55:22 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_DISPLAY
|
|
|
|
};
|
|
|
|
|
2010-06-26 22:35:11 +00:00
|
|
|
void
|
|
|
|
gst_vdp_decoder_post_error (GstVdpDecoder * decoder, GError * error)
|
|
|
|
{
|
|
|
|
GstMessage *message;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_VDP_DECODER (decoder));
|
|
|
|
g_return_if_fail (decoder != NULL);
|
|
|
|
|
|
|
|
message = gst_message_new_error (GST_OBJECT (decoder), error, NULL);
|
|
|
|
gst_element_post_message (GST_ELEMENT (decoder), message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
|
2010-06-26 19:02:53 +00:00
|
|
|
|
2010-07-22 22:28:49 +00:00
|
|
|
GstFlowReturn
|
|
|
|
gst_vdp_decoder_render (GstVdpDecoder * vdp_decoder, VdpPictureInfo * info,
|
2012-09-20 17:03:11 +00:00
|
|
|
guint n_bufs, VdpBitstreamBuffer * bufs, GstVideoCodecFrame * frame)
|
2010-07-22 22:28:49 +00:00
|
|
|
{
|
|
|
|
GstFlowReturn ret;
|
|
|
|
|
|
|
|
VdpStatus status;
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
GstVdpVideoMemory *vmem;
|
2013-07-29 07:35:08 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
2012-09-20 17:03:11 +00:00
|
|
|
GstClockTime before, after;
|
2013-07-29 07:35:08 +00:00
|
|
|
#endif
|
2010-07-22 22:28:49 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
GST_DEBUG_OBJECT (vdp_decoder, "n_bufs:%d, frame:%d", n_bufs,
|
|
|
|
frame->system_frame_number);
|
2010-07-22 22:28:49 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
ret =
|
|
|
|
gst_video_decoder_allocate_output_frame (GST_VIDEO_DECODER (vdp_decoder),
|
|
|
|
frame);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto fail_alloc;
|
|
|
|
|
|
|
|
vmem = (GstVdpVideoMemory *) gst_buffer_get_memory (frame->output_buffer, 0);
|
|
|
|
if (!vmem
|
|
|
|
|| !gst_memory_is_type ((GstMemory *) vmem,
|
|
|
|
GST_VDP_VIDEO_MEMORY_ALLOCATOR))
|
|
|
|
goto no_mem;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (vdp_decoder, "Calling VdpDecoderRender()");
|
2013-07-29 07:35:08 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
2012-09-20 17:03:11 +00:00
|
|
|
before = gst_util_get_timestamp ();
|
2013-07-29 07:35:08 +00:00
|
|
|
#endif
|
2012-09-20 17:03:11 +00:00
|
|
|
status =
|
|
|
|
vdp_decoder->device->vdp_decoder_render (vdp_decoder->decoder,
|
|
|
|
vmem->surface, info, n_bufs, bufs);
|
2013-07-29 07:35:08 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
2012-09-20 17:03:11 +00:00
|
|
|
after = gst_util_get_timestamp ();
|
2013-07-29 07:35:08 +00:00
|
|
|
#endif
|
2010-07-22 22:28:49 +00:00
|
|
|
if (status != VDP_STATUS_OK)
|
|
|
|
goto decode_error;
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
GST_DEBUG_OBJECT (vdp_decoder, "VdpDecoderRender() took %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (after - before));
|
|
|
|
|
2010-07-22 22:28:49 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
decode_error:
|
|
|
|
GST_ELEMENT_ERROR (vdp_decoder, RESOURCE, READ,
|
|
|
|
("Could not decode"),
|
|
|
|
("Error returned from vdpau was: %s",
|
2012-09-20 17:03:11 +00:00
|
|
|
vdp_decoder->device->vdp_get_error_string (status)));
|
2010-07-22 22:28:49 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
gst_video_decoder_drop_frame (GST_VIDEO_DECODER (vdp_decoder), frame);
|
2010-07-22 22:28:49 +00:00
|
|
|
|
|
|
|
return GST_FLOW_ERROR;
|
2012-09-20 17:03:11 +00:00
|
|
|
|
|
|
|
fail_alloc:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (vdp_decoder, "Failed to get an output frame");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
no_mem:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (vdp_decoder, "Didn't get VdpVideoSurface backed buffer");
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2010-07-22 22:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GstFlowReturn
|
|
|
|
gst_vdp_decoder_init_decoder (GstVdpDecoder * vdp_decoder,
|
2012-09-20 17:03:11 +00:00
|
|
|
VdpDecoderProfile profile, guint32 max_references,
|
|
|
|
GstVideoCodecState * output_state)
|
2010-07-22 22:28:49 +00:00
|
|
|
{
|
|
|
|
GstVdpDevice *device;
|
|
|
|
|
|
|
|
VdpStatus status;
|
|
|
|
|
2010-07-27 21:24:43 +00:00
|
|
|
device = vdp_decoder->device;
|
2010-07-22 22:28:49 +00:00
|
|
|
|
|
|
|
if (vdp_decoder->decoder != VDP_INVALID_HANDLE) {
|
|
|
|
status = device->vdp_decoder_destroy (vdp_decoder->decoder);
|
|
|
|
if (status != VDP_STATUS_OK)
|
|
|
|
goto destroy_decoder_error;
|
|
|
|
}
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
GST_DEBUG_OBJECT (vdp_decoder,
|
2013-04-08 16:34:41 +00:00
|
|
|
"device:%u, profile:%d, width:%d, height:%d, max_references:%d",
|
2012-09-20 17:03:11 +00:00
|
|
|
device->device, profile, output_state->info.width,
|
|
|
|
output_state->info.height, max_references);
|
2010-07-22 22:28:49 +00:00
|
|
|
|
|
|
|
status = device->vdp_decoder_create (device->device, profile,
|
2012-09-20 17:03:11 +00:00
|
|
|
output_state->info.width, output_state->info.height, max_references,
|
|
|
|
&vdp_decoder->decoder);
|
2010-07-22 22:28:49 +00:00
|
|
|
if (status != VDP_STATUS_OK)
|
|
|
|
goto create_decoder_error;
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
destroy_decoder_error:
|
|
|
|
GST_ELEMENT_ERROR (vdp_decoder, RESOURCE, READ,
|
|
|
|
("Could not destroy vdpau decoder"),
|
|
|
|
("Error returned from vdpau was: %s",
|
|
|
|
device->vdp_get_error_string (status)));
|
|
|
|
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
|
|
|
|
create_decoder_error:
|
|
|
|
GST_ELEMENT_ERROR (vdp_decoder, RESOURCE, READ,
|
|
|
|
("Could not create vdpau decoder"),
|
|
|
|
("Error returned from vdpau was: %s",
|
|
|
|
device->vdp_get_error_string (status)));
|
|
|
|
|
|
|
|
return GST_FLOW_ERROR;
|
2010-06-26 19:02:53 +00:00
|
|
|
}
|
|
|
|
|
2010-07-27 21:24:43 +00:00
|
|
|
static gboolean
|
2012-09-20 17:03:11 +00:00
|
|
|
gst_vdp_decoder_decide_allocation (GstVideoDecoder * video_decoder,
|
|
|
|
GstQuery * query)
|
|
|
|
{
|
|
|
|
GstVdpDecoder *vdp_decoder = GST_VDP_DECODER (video_decoder);
|
|
|
|
GstCaps *outcaps;
|
|
|
|
GstBufferPool *pool = NULL;
|
|
|
|
guint size, min = 0, max = 0;
|
|
|
|
GstStructure *config;
|
|
|
|
GstVideoInfo vinfo;
|
|
|
|
gboolean update_pool;
|
|
|
|
|
|
|
|
gst_query_parse_allocation (query, &outcaps, NULL);
|
|
|
|
gst_video_info_init (&vinfo);
|
|
|
|
gst_video_info_from_caps (&vinfo, outcaps);
|
|
|
|
|
|
|
|
if (gst_query_get_n_allocation_pools (query) > 0) {
|
|
|
|
gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
|
|
|
|
size = MAX (size, vinfo.size);
|
|
|
|
update_pool = TRUE;
|
|
|
|
} else {
|
|
|
|
pool = NULL;
|
|
|
|
size = vinfo.size;
|
|
|
|
min = max = 0;
|
|
|
|
|
|
|
|
update_pool = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pool == NULL
|
|
|
|
|| !gst_buffer_pool_has_option (pool,
|
|
|
|
GST_BUFFER_POOL_OPTION_VDP_VIDEO_META)) {
|
2014-09-16 09:43:02 +00:00
|
|
|
if (pool)
|
|
|
|
gst_object_unref (pool);
|
|
|
|
/* no pool or pool doesn't support GstVdpVideoMeta, we can make our own */
|
2012-09-20 17:03:11 +00:00
|
|
|
GST_DEBUG_OBJECT (video_decoder,
|
|
|
|
"no pool or doesn't support GstVdpVideoMeta, making new pool");
|
|
|
|
pool = gst_vdp_video_buffer_pool_new (vdp_decoder->device);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now configure */
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_set_params (config, outcaps, size, min, max);
|
|
|
|
gst_buffer_pool_config_add_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VDP_VIDEO_META);
|
|
|
|
gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
|
|
|
|
gst_buffer_pool_set_config (pool, config);
|
|
|
|
|
|
|
|
if (update_pool)
|
|
|
|
gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
|
|
|
|
else
|
|
|
|
gst_query_add_allocation_pool (query, pool, size, min, max);
|
|
|
|
|
|
|
|
if (pool)
|
|
|
|
gst_object_unref (pool);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vdp_decoder_start (GstVideoDecoder * video_decoder)
|
2010-07-27 21:24:43 +00:00
|
|
|
{
|
2012-09-20 17:03:11 +00:00
|
|
|
GstVdpDecoder *vdp_decoder = GST_VDP_DECODER (video_decoder);
|
|
|
|
GError *err = NULL;
|
2010-07-27 21:24:43 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
GST_DEBUG_OBJECT (video_decoder, "Starting");
|
2010-07-27 21:24:43 +00:00
|
|
|
|
2010-07-30 20:27:49 +00:00
|
|
|
vdp_decoder->device = gst_vdp_get_device (vdp_decoder->display, &err);
|
2010-07-27 21:24:43 +00:00
|
|
|
if (G_UNLIKELY (!vdp_decoder->device))
|
|
|
|
goto device_error;
|
|
|
|
|
|
|
|
vdp_decoder->decoder = VDP_INVALID_HANDLE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
device_error:
|
2010-07-30 20:27:49 +00:00
|
|
|
gst_vdp_decoder_post_error (vdp_decoder, err);
|
2010-07-27 21:24:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-09-20 17:03:11 +00:00
|
|
|
gst_vdp_decoder_stop (GstVideoDecoder * video_decoder)
|
2010-07-27 21:24:43 +00:00
|
|
|
{
|
2012-09-20 17:03:11 +00:00
|
|
|
GstVdpDecoder *vdp_decoder = GST_VDP_DECODER (video_decoder);
|
2010-07-27 21:24:43 +00:00
|
|
|
|
|
|
|
if (vdp_decoder->decoder != VDP_INVALID_HANDLE) {
|
|
|
|
GstVdpDevice *device = vdp_decoder->device;
|
|
|
|
VdpStatus status;
|
|
|
|
|
|
|
|
status = device->vdp_decoder_destroy (vdp_decoder->decoder);
|
|
|
|
if (status != VDP_STATUS_OK) {
|
|
|
|
GST_ELEMENT_ERROR (vdp_decoder, RESOURCE, READ,
|
|
|
|
("Could not destroy vdpau decoder"),
|
|
|
|
("Error returned from vdpau was: %s",
|
|
|
|
device->vdp_get_error_string (status)));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (vdp_decoder->device);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-06-27 07:55:22 +00:00
|
|
|
static void
|
|
|
|
gst_vdp_decoder_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstVdpDecoder *vdp_decoder = GST_VDP_DECODER (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_DISPLAY:
|
2010-07-27 21:24:43 +00:00
|
|
|
g_value_set_string (value, vdp_decoder->display);
|
2010-06-27 07:55:22 +00:00
|
|
|
break;
|
2010-07-27 21:24:43 +00:00
|
|
|
|
2010-06-27 07:55:22 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vdp_decoder_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstVdpDecoder *vdp_decoder = GST_VDP_DECODER (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_DISPLAY:
|
2010-07-27 21:24:43 +00:00
|
|
|
g_free (vdp_decoder->display);
|
|
|
|
vdp_decoder->display = g_value_dup_string (value);
|
2010-06-27 07:55:22 +00:00
|
|
|
break;
|
2010-07-27 21:24:43 +00:00
|
|
|
|
2010-06-27 07:55:22 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-27 21:24:43 +00:00
|
|
|
static void
|
|
|
|
gst_vdp_decoder_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstVdpDecoder *vdp_decoder = GST_VDP_DECODER (object);
|
|
|
|
|
|
|
|
g_free (vdp_decoder->display);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2010-06-26 19:02:53 +00:00
|
|
|
static void
|
2012-09-20 17:03:11 +00:00
|
|
|
gst_vdp_decoder_init (GstVdpDecoder * vdp_decoder)
|
2010-06-26 19:02:53 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vdp_decoder_class_init (GstVdpDecoderClass * klass)
|
|
|
|
{
|
2010-06-27 07:55:22 +00:00
|
|
|
GObjectClass *object_class;
|
2012-09-20 17:03:11 +00:00
|
|
|
GstVideoDecoderClass *video_decoder_class;
|
|
|
|
GstElementClass *element_class;
|
|
|
|
|
|
|
|
GstCaps *src_caps;
|
|
|
|
GstPadTemplate *src_template;
|
2010-06-27 07:55:22 +00:00
|
|
|
|
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
2012-09-20 17:03:11 +00:00
|
|
|
element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
video_decoder_class = GST_VIDEO_DECODER_CLASS (klass);
|
2010-06-27 07:55:22 +00:00
|
|
|
|
|
|
|
object_class->get_property = gst_vdp_decoder_get_property;
|
|
|
|
object_class->set_property = gst_vdp_decoder_set_property;
|
2010-07-27 21:24:43 +00:00
|
|
|
object_class->finalize = gst_vdp_decoder_finalize;
|
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
video_decoder_class->start = gst_vdp_decoder_start;
|
|
|
|
video_decoder_class->stop = gst_vdp_decoder_stop;
|
|
|
|
video_decoder_class->decide_allocation = gst_vdp_decoder_decide_allocation;
|
|
|
|
|
|
|
|
GST_FIXME ("Actually create srcpad template from hw capabilities");
|
2013-05-08 09:45:20 +00:00
|
|
|
src_caps =
|
|
|
|
gst_caps_from_string (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
|
|
|
(GST_CAPS_FEATURE_MEMORY_VDPAU,
|
|
|
|
"{ YV12 }") ";" GST_VIDEO_CAPS_MAKE ("{ YV12 }"));
|
|
|
|
src_template =
|
|
|
|
gst_pad_template_new (GST_VIDEO_DECODER_SRC_NAME, GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS, src_caps);
|
2010-06-26 19:02:53 +00:00
|
|
|
|
2012-09-20 17:03:11 +00:00
|
|
|
gst_element_class_add_pad_template (element_class, src_template);
|
2010-06-27 07:55:22 +00:00
|
|
|
|
2016-12-14 07:40:18 +00:00
|
|
|
if (src_caps)
|
|
|
|
gst_caps_unref (src_caps);
|
|
|
|
|
2010-06-27 07:55:22 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_DISPLAY, g_param_spec_string ("display", "Display", "X Display name",
|
|
|
|
NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
2010-06-26 19:02:53 +00:00
|
|
|
}
|