vdpau: add gst_vdp_decoder_render and gst_vdp_decoder_init_decoder

This commit is contained in:
Carl-Anton Ingmarsson 2010-07-23 00:28:49 +02:00
parent 6089bfd36a
commit 0b3c6e4b9e
4 changed files with 187 additions and 207 deletions

View file

@ -84,24 +84,121 @@ gst_vdp_decoder_post_error (GstVdpDecoder * decoder, GError * error)
g_error_free (error);
}
GstFlowReturn
static GstFlowReturn
gst_vdp_decoder_alloc_buffer (GstVdpDecoder * vdp_decoder,
GstVdpVideoBuffer ** video_buf, GError ** error)
GstVdpVideoBuffer ** video_buf)
{
GstVdpVideoSrcPad *vdp_pad;
GstFlowReturn ret;
GError *err = NULL;
vdp_pad = (GstVdpVideoSrcPad *) GST_BASE_VIDEO_DECODER_SRC_PAD (vdp_decoder);
return gst_vdp_video_src_pad_alloc_buffer (vdp_pad, video_buf, error);
ret = gst_vdp_video_src_pad_alloc_buffer (vdp_pad, video_buf, &err);
if (ret == GST_FLOW_ERROR)
gst_vdp_decoder_post_error (vdp_decoder, err);
return ret;
}
static GstFlowReturn
gst_vdp_decoder_get_device (GstVdpDecoder * vdp_decoder, GstVdpDevice ** device)
{
GstVdpVideoSrcPad *vdp_pad;
GstFlowReturn ret;
GError *err = NULL;
vdp_pad = (GstVdpVideoSrcPad *) GST_BASE_VIDEO_DECODER_SRC_PAD (vdp_decoder);
ret = gst_vdp_video_src_pad_get_device (vdp_pad, device, &err);
if (ret == GST_FLOW_ERROR)
gst_vdp_decoder_post_error (vdp_decoder, err);
return ret;
}
GstFlowReturn
gst_vdp_decoder_get_device (GstVdpDecoder * vdp_decoder, GstVdpDevice ** device,
GError ** error)
gst_vdp_decoder_render (GstVdpDecoder * vdp_decoder, VdpPictureInfo * info,
guint n_bufs, VdpBitstreamBuffer * bufs, GstVdpVideoBuffer ** video_buf)
{
GstVdpVideoSrcPad *vdp_pad;
GstFlowReturn ret;
vdp_pad = (GstVdpVideoSrcPad *) GST_BASE_VIDEO_DECODER_SRC_PAD (vdp_decoder);
return gst_vdp_video_src_pad_get_device (vdp_pad, device, error);
GstVdpDevice *device;
VdpVideoSurface surface;
VdpStatus status;
ret = gst_vdp_decoder_alloc_buffer (vdp_decoder, video_buf);
if (ret != GST_FLOW_OK)
return ret;
device = (*video_buf)->device;
surface = (*video_buf)->surface;
status = device->vdp_decoder_render (vdp_decoder->decoder, surface,
info, n_bufs, bufs);
if (status != VDP_STATUS_OK)
goto decode_error;
return GST_FLOW_OK;
decode_error:
GST_ELEMENT_ERROR (vdp_decoder, RESOURCE, READ,
("Could not decode"),
("Error returned from vdpau was: %s",
device->vdp_get_error_string (status)));
gst_buffer_unref (GST_BUFFER_CAST (video_buf));
return GST_FLOW_ERROR;
}
GstFlowReturn
gst_vdp_decoder_init_decoder (GstVdpDecoder * vdp_decoder,
VdpDecoderProfile profile, guint32 max_references)
{
GstFlowReturn ret;
GstVdpDevice *device;
VdpStatus status;
GstVideoState state;
ret = gst_vdp_decoder_get_device (vdp_decoder, &device);
if (ret != GST_FLOW_OK)
return ret;
if (vdp_decoder->decoder != VDP_INVALID_HANDLE) {
status = device->vdp_decoder_destroy (vdp_decoder->decoder);
if (status != VDP_STATUS_OK)
goto destroy_decoder_error;
}
state =
gst_base_video_decoder_get_state (GST_BASE_VIDEO_DECODER (vdp_decoder));
status = device->vdp_decoder_create (device->device, profile,
state.width, state.height, max_references, &vdp_decoder->decoder);
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;
}
static void
@ -158,6 +255,7 @@ gst_vdp_decoder_base_init (gpointer g_class)
static void
gst_vdp_decoder_init (GstVdpDecoder * decoder, GstVdpDecoderClass * klass)
{
decoder->decoder = VDP_INVALID_HANDLE;
}
static void

View file

@ -22,6 +22,7 @@
#define __GST_VDP_DECODER_H__
#include <gst/gst.h>
#include <vdpau/vdpau.h>
#include "../basevideodecoder/gstbasevideodecoder.h"
#include "../gstvdp/gstvdpvideobuffer.h"
@ -41,19 +42,24 @@ typedef struct _GstVdpDecoderClass GstVdpDecoderClass;
struct _GstVdpDecoder {
GstBaseVideoDecoder base_video_decoder;
VdpDecoder decoder;
};
struct _GstVdpDecoderClass {
GstBaseVideoDecoderClass base_video_decoder_class;
};
void gst_vdp_decoder_post_error (GstVdpDecoder * decoder, GError * error);
void
gst_vdp_decoder_post_error (GstVdpDecoder * decoder, GError * error);
GstFlowReturn gst_vdp_decoder_alloc_buffer (GstVdpDecoder * vdp_decoder,
GstVdpVideoBuffer **video_buf, GError ** error);
GstFlowReturn
gst_vdp_decoder_render (GstVdpDecoder * vdp_decoder, VdpPictureInfo *info,
guint n_bufs, VdpBitstreamBuffer *bufs, GstVdpVideoBuffer **video_buf);
GstFlowReturn gst_vdp_decoder_get_device (GstVdpDecoder * vdp_decoder,
GstVdpDevice ** device, GError ** error);
GstFlowReturn
gst_vdp_decoder_init_decoder (GstVdpDecoder * vdp_decoder,
VdpDecoderProfile profile, guint32 max_references);
GType gst_vdp_decoder_get_type (void);

View file

@ -261,8 +261,9 @@ gst_vdp_h264_dec_idr (GstVdpH264Dec * h264_dec, GstH264Frame * h264_frame)
seq = slice->picture->sequence;
if (seq != h264_dec->sequence) {
GstVideoState state;
VdpDecoderProfile profile;
GstFlowReturn ret;
GstVdpDevice *device;
state =
gst_base_video_decoder_get_state (GST_BASE_VIDEO_DECODER (h264_dec));
@ -293,19 +294,6 @@ gst_vdp_h264_dec_idr (GstVdpH264Dec * h264_dec, GstH264Frame * h264_frame)
gst_base_video_decoder_set_state (GST_BASE_VIDEO_DECODER (h264_dec), state);
ret = gst_vdp_decoder_get_device (GST_VDP_DECODER (h264_dec), &device,
NULL);
if (ret == GST_FLOW_OK) {
VdpDecoderProfile profile;
VdpStatus status;
if (h264_dec->decoder != VDP_INVALID_HANDLE) {
device->vdp_decoder_destroy (h264_dec->decoder);
h264_dec->decoder = VDP_INVALID_HANDLE;
}
switch (seq->profile_idc) {
case 66:
profile = VDP_DECODER_PROFILE_H264_BASELINE;
@ -320,28 +308,23 @@ gst_vdp_h264_dec_idr (GstVdpH264Dec * h264_dec, GstH264Frame * h264_frame)
break;
default:
return FALSE;
GST_ELEMENT_ERROR (h264_dec, STREAM, WRONG_TYPE,
("vdpauh264dec doesn't support this streams profile"),
("profile_idc: %d", seq->profile_idc));
return GST_FLOW_ERROR;
}
status = device->vdp_decoder_create (device->device, profile,
state.width, state.height, seq->num_ref_frames, &h264_dec->decoder);
if (status != VDP_STATUS_OK) {
GST_ELEMENT_ERROR (h264_dec, RESOURCE, READ,
("Could not create vdpau decoder"),
("Error returned from vdpau was: %s",
device->vdp_get_error_string (status)));
return FALSE;
}
} else
return FALSE;
ret = gst_vdp_decoder_init_decoder (GST_VDP_DECODER (h264_dec), profile,
seq->num_ref_frames);
if (ret != GST_FLOW_OK)
return ret;
g_object_set (h264_dec->dpb, "num-ref-frames", seq->num_ref_frames, NULL);
h264_dec->sequence = seq;
}
return TRUE;
return GST_FLOW_OK;
}
static VdpPictureInfoH264
@ -464,14 +447,10 @@ gst_vdp_h264_dec_handle_frame (GstBaseVideoDecoder * base_video_decoder,
GstH264Sequence *seq;
GstFlowReturn ret;
GError *err = NULL;
GstVdpVideoBuffer *outbuf;
VdpPictureInfoH264 info;
GstVdpDevice *device;
VdpVideoSurface surface;
VdpBitstreamBuffer *bufs;
guint n_bufs;
VdpStatus status;
GST_DEBUG ("handle_frame");
@ -483,11 +462,13 @@ gst_vdp_h264_dec_handle_frame (GstBaseVideoDecoder * base_video_decoder,
if (slice->nal_unit.IdrPicFlag) {
if (gst_vdp_h264_dec_idr (h264_dec, h264_frame))
ret = gst_vdp_h264_dec_idr (h264_dec, h264_frame);
if (ret == GST_FLOW_OK)
h264_dec->got_idr = TRUE;
else {
gst_base_video_decoder_skip_frame (base_video_decoder, frame);
return GST_FLOW_OK;
return ret;
}
}
@ -498,29 +479,20 @@ gst_vdp_h264_dec_handle_frame (GstBaseVideoDecoder * base_video_decoder,
}
gst_vdp_h264_dec_init_frame_info (h264_dec, h264_frame);
/* decoding */
if ((ret = gst_vdp_decoder_alloc_buffer (GST_VDP_DECODER (h264_dec), &outbuf,
&err) != GST_FLOW_OK))
goto alloc_error;
device = GST_VDP_VIDEO_BUFFER (outbuf)->device;
surface = GST_VDP_VIDEO_BUFFER (outbuf)->surface;
info = gst_vdp_h264_dec_fill_info (h264_dec, h264_frame);
bufs = gst_vdp_h264_dec_create_bitstream_buffers (h264_dec, h264_frame,
&n_bufs);
status = device->vdp_decoder_render (h264_dec->decoder, surface,
(VdpPictureInfo *) & info, n_bufs, bufs);
ret = gst_vdp_decoder_render (GST_VDP_DECODER (h264_dec),
(VdpPictureInfo *) & info, n_bufs, bufs, &outbuf);
g_free (bufs);
if (status != VDP_STATUS_OK)
goto decode_error;
if (ret != GST_FLOW_OK) {
gst_base_video_decoder_skip_frame (base_video_decoder, frame);
return ret;
}
frame->src_buffer = GST_BUFFER_CAST (outbuf);
@ -588,24 +560,6 @@ gst_vdp_h264_dec_handle_frame (GstBaseVideoDecoder * base_video_decoder,
gst_h264_dpb_add (h264_dec->dpb, h264_frame);
return GST_FLOW_OK;
alloc_error:
gst_base_video_decoder_skip_frame (base_video_decoder, frame);
if (ret == GST_FLOW_ERROR)
gst_vdp_decoder_post_error (GST_VDP_DECODER (h264_dec), err);
return ret;
decode_error:
GST_ELEMENT_ERROR (h264_dec, RESOURCE, READ,
("Could not decode"),
("Error returned from vdpau was: %s",
device->vdp_get_error_string (status)));
gst_buffer_unref (GST_BUFFER_CAST (outbuf));
gst_base_video_decoder_skip_frame (base_video_decoder, frame);
return GST_FLOW_ERROR;
}
static gint
@ -875,19 +829,9 @@ gst_vdp_h264_dec_stop (GstBaseVideoDecoder * base_video_decoder)
{
GstVdpH264Dec *h264_dec = GST_VDP_H264_DEC (base_video_decoder);
GstFlowReturn ret;
GstVdpDevice *device;
g_object_unref (h264_dec->parser);
g_object_unref (h264_dec->dpb);
ret = gst_vdp_decoder_get_device (GST_VDP_DECODER (h264_dec), &device, NULL);
if (ret == GST_FLOW_OK) {
if (h264_dec->decoder != VDP_INVALID_HANDLE)
device->vdp_decoder_destroy (h264_dec->decoder);
}
return TRUE;
}

View file

@ -200,38 +200,7 @@ gst_vdp_mpeg_dec_handle_quant_matrix (GstVdpMpegDec * mpeg_dec,
return TRUE;
}
static gboolean
gst_vdp_mpeg_dec_create_decoder (GstVdpMpegDec * mpeg_dec)
{
GstFlowReturn ret;
GstVdpDevice *device;
ret = gst_vdp_decoder_get_device (GST_VDP_DECODER (mpeg_dec), &device, NULL);
if (ret == GST_FLOW_OK) {
VdpStatus status;
GstVdpMpegStreamInfo *stream_info;
stream_info = &mpeg_dec->stream_info;
if (mpeg_dec->decoder != VDP_INVALID_HANDLE)
device->vdp_decoder_destroy (mpeg_dec->decoder);
status = device->vdp_decoder_create (device->device, stream_info->profile,
stream_info->width, stream_info->height, 2, &mpeg_dec->decoder);
if (status != VDP_STATUS_OK) {
GST_ELEMENT_ERROR (mpeg_dec, RESOURCE, READ,
("Could not create vdpau decoder"),
("Error returned from vdpau was: %s",
device->vdp_get_error_string (status)));
return FALSE;
}
}
return TRUE;
}
static gboolean
static GstFlowReturn
gst_vdp_mpeg_dec_handle_sequence (GstVdpMpegDec * mpeg_dec,
GstBuffer * seq, GstBuffer * seq_ext)
{
@ -241,7 +210,7 @@ gst_vdp_mpeg_dec_handle_sequence (GstVdpMpegDec * mpeg_dec,
GstVdpMpegStreamInfo stream_info;
if (!mpeg_util_parse_sequence_hdr (&hdr, seq))
return FALSE;
return GST_FLOW_CUSTOM_ERROR;
memcpy (&mpeg_dec->vdp_info.intra_quantizer_matrix,
&hdr.intra_quantizer_matrix, 64);
@ -261,14 +230,11 @@ gst_vdp_mpeg_dec_handle_sequence (GstVdpMpegDec * mpeg_dec,
stream_info.version = 1;
stream_info.profile = VDP_DECODER_PROFILE_MPEG1;
if (mpeg_dec->state == GST_VDP_MPEG_DEC_STATE_NEED_SEQUENCE)
mpeg_dec->state = GST_VDP_MPEG_DEC_STATE_NEED_DATA;
if (seq_ext) {
MPEGSeqExtHdr ext;
if (!mpeg_util_parse_sequence_extension (&ext, seq_ext))
return FALSE;
return GST_FLOW_CUSTOM_ERROR;
stream_info.fps_n *= (ext.fps_n_ext + 1);
stream_info.fps_d *= (ext.fps_d_ext + 1);
@ -284,6 +250,7 @@ gst_vdp_mpeg_dec_handle_sequence (GstVdpMpegDec * mpeg_dec,
if (memcmp (&mpeg_dec->stream_info, &stream_info,
sizeof (GstVdpMpegStreamInfo)) != 0) {
GstVideoState state;
GstFlowReturn ret;
state = gst_base_video_decoder_get_state (base_video_decoder);
@ -300,11 +267,18 @@ gst_vdp_mpeg_dec_handle_sequence (GstVdpMpegDec * mpeg_dec,
gst_base_video_decoder_set_state (base_video_decoder, state);
ret = gst_vdp_decoder_init_decoder (GST_VDP_DECODER (mpeg_dec),
stream_info.profile, 2);
if (ret != GST_FLOW_OK)
return ret;
memcpy (&mpeg_dec->stream_info, &stream_info,
sizeof (GstVdpMpegStreamInfo));
}
return TRUE;
mpeg_dec->state = GST_VDP_MPEG_DEC_STATE_NEED_DATA;
return GST_FLOW_OK;
}
static GstFlowReturn
@ -317,18 +291,26 @@ gst_vdp_mpeg_dec_handle_frame (GstBaseVideoDecoder * base_video_decoder,
GstVdpMpegFrame *mpeg_frame;
GstFlowReturn ret;
GError *err = NULL;
GstVdpVideoBuffer *outbuf;
VdpVideoSurface surface;
GstVdpDevice *device;
VdpBitstreamBuffer vbit[1];
VdpStatus status;
GstVdpVideoBuffer *outbuf;
/* MPEG_PACKET_SEQUENCE */
mpeg_frame = GST_VDP_MPEG_FRAME (frame);
if (mpeg_frame->seq) {
gst_vdp_mpeg_dec_handle_sequence (mpeg_dec, mpeg_frame->seq,
ret = gst_vdp_mpeg_dec_handle_sequence (mpeg_dec, mpeg_frame->seq,
mpeg_frame->seq_ext);
if (ret != GST_FLOW_OK) {
gst_base_video_decoder_skip_frame (base_video_decoder, frame);
return ret;
}
}
if (mpeg_dec->state == GST_VDP_MPEG_DEC_STATE_NEED_SEQUENCE) {
GST_DEBUG_OBJECT (mpeg_dec, "Drop frame since we haven't found a "
"MPEG_PACKET_SEQUENCE yet");
gst_base_video_decoder_skip_frame (base_video_decoder, frame);
return GST_FLOW_OK;
}
/* MPEG_PACKET_PICTURE */
@ -389,16 +371,17 @@ gst_vdp_mpeg_dec_handle_frame (GstBaseVideoDecoder * base_video_decoder,
info->backward_reference = VDP_INVALID_HANDLE;
}
if ((ret = gst_vdp_decoder_alloc_buffer (GST_VDP_DECODER (mpeg_dec), &outbuf,
&err) != GST_FLOW_OK))
goto alloc_error;
/* decode */
vbit[0].struct_version = VDP_BITSTREAM_BUFFER_VERSION;
vbit[0].bitstream = GST_BUFFER_DATA (mpeg_frame->slices);
vbit[0].bitstream_bytes = GST_BUFFER_SIZE (mpeg_frame->slices);
/* create decoder */
if (mpeg_dec->decoder == VDP_INVALID_HANDLE)
gst_vdp_mpeg_dec_create_decoder (mpeg_dec);
device = GST_VDP_VIDEO_BUFFER (outbuf)->device;
ret = gst_vdp_decoder_render (GST_VDP_DECODER (mpeg_dec),
(VdpPictureInfo *) info, 1, vbit, &outbuf);
if (ret != GST_FLOW_OK)
return ret;
/* set buffer flags */
if (info->picture_coding_type == I_FRAME)
GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_DELTA_UNIT);
else
@ -409,46 +392,17 @@ gst_vdp_mpeg_dec_handle_frame (GstBaseVideoDecoder * base_video_decoder,
else
GST_BUFFER_FLAG_UNSET (outbuf, GST_VIDEO_BUFFER_TFF);
surface = GST_VDP_VIDEO_BUFFER (outbuf)->surface;
vbit[0].struct_version = VDP_BITSTREAM_BUFFER_VERSION;
vbit[0].bitstream = GST_BUFFER_DATA (mpeg_frame->slices);
vbit[0].bitstream_bytes = GST_BUFFER_SIZE (mpeg_frame->slices);
status = device->vdp_decoder_render (mpeg_dec->decoder, surface,
(VdpPictureInfo *) info, 1, vbit);
if (status != VDP_STATUS_OK)
goto decode_error;
frame->src_buffer = GST_BUFFER_CAST (outbuf);
if (info->picture_coding_type == B_FRAME) {
gst_base_video_decoder_finish_frame (base_video_decoder, frame);
} else {
info->backward_reference = surface;
info->backward_reference = GST_VDP_VIDEO_BUFFER (outbuf)->surface;
mpeg_dec->b_frame = gst_video_frame_ref (frame);
}
return GST_FLOW_OK;
alloc_error:
gst_base_video_decoder_skip_frame (base_video_decoder, frame);
if (ret == GST_FLOW_ERROR)
gst_vdp_decoder_post_error (GST_VDP_DECODER (mpeg_dec), err);
return ret;
decode_error:
GST_ELEMENT_ERROR (mpeg_dec, RESOURCE, READ,
("Could not decode"),
("Error returned from vdpau was: %s",
device->vdp_get_error_string (status)));
gst_buffer_unref (GST_BUFFER_CAST (outbuf));
gst_base_video_decoder_skip_frame (base_video_decoder, frame);
return GST_FLOW_ERROR;
}
static GstVideoFrame *
@ -475,17 +429,6 @@ gst_vdp_mpeg_dec_parse_data (GstBaseVideoDecoder * base_video_decoder,
/* start_code */
gst_bit_reader_get_bits_uint8 (&b_reader, &start_code, 8);
if (mpeg_dec->state == GST_VDP_MPEG_DEC_STATE_NEED_SEQUENCE) {
if (start_code != MPEG_PACKET_SEQUENCE) {
GST_DEBUG_OBJECT (mpeg_dec, "Drop data since we haven't found a "
"MPEG_PACKET_SEQUENCE yet");
gst_buffer_unref (buf);
return GST_FLOW_OK;
}
}
mpeg_frame = (GstVdpMpegFrame *)
gst_base_video_decoder_get_current_frame (base_video_decoder);
@ -508,7 +451,6 @@ gst_vdp_mpeg_dec_parse_data (GstBaseVideoDecoder * base_video_decoder,
}
mpeg_frame->seq = buf;
mpeg_dec->state = GST_VDP_MPEG_DEC_STATE_NEED_DATA;
break;
case MPEG_PACKET_PICTURE:
@ -667,16 +609,6 @@ gst_vdp_mpeg_dec_stop (GstBaseVideoDecoder * base_video_decoder)
{
GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (base_video_decoder);
GstFlowReturn ret;
GstVdpDevice *device;
ret = gst_vdp_decoder_get_device (GST_VDP_DECODER (mpeg_dec), &device, NULL);
if (ret == GST_FLOW_OK) {
if (mpeg_dec->decoder != VDP_INVALID_HANDLE)
device->vdp_decoder_destroy (mpeg_dec->decoder);
}
if (mpeg_dec->vdp_info.forward_reference != VDP_INVALID_HANDLE)
mpeg_dec->vdp_info.forward_reference = VDP_INVALID_HANDLE;
if (mpeg_dec->vdp_info.backward_reference != VDP_INVALID_HANDLE)