From 6bed9ebe0fa3aeb5a97abc3d0f564ca3a5dc7613 Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Thu, 29 Nov 2012 15:06:00 +0100 Subject: [PATCH] decoder: expose new parse/decode API. Introduce new decoding process whereby a GstVideoCodecFrame is created first. Next, input stream buffers are accumulated into a GstAdapter, that is then passed to the _parse() function. The GstVaapiDecoder object accumulates all parsed units and when a complete frame or field is detected, that GstVideoCodecFrame is passed to the _decode() function. Ultimately, the caller receives a GstVaapiSurfaceProxy if decoding process was successful. --- gst-libs/gst/vaapi/gstvaapidecoder.c | 47 ++++++++++++++++++++ gst-libs/gst/vaapi/gstvaapidecoder.h | 11 +++++ gst-libs/gst/vaapi/gstvaapidecoder_objects.c | 4 ++ 3 files changed, 62 insertions(+) diff --git a/gst-libs/gst/vaapi/gstvaapidecoder.c b/gst-libs/gst/vaapi/gstvaapidecoder.c index e930f7e2d0..1e48d9fbc3 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder.c +++ b/gst-libs/gst/vaapi/gstvaapidecoder.c @@ -787,3 +787,50 @@ gst_vaapi_decoder_check_status(GstVaapiDecoder *decoder) return GST_VAAPI_DECODER_STATUS_ERROR_NO_SURFACE; return GST_VAAPI_DECODER_STATUS_SUCCESS; } + +GstVaapiDecoderStatus +gst_vaapi_decoder_parse(GstVaapiDecoder *decoder, + GstVideoCodecFrame *base_frame, GstAdapter *adapter, gboolean at_eos, + guint *got_unit_size_ptr, gboolean *got_frame_ptr) +{ + g_return_val_if_fail(GST_VAAPI_IS_DECODER(decoder), + GST_VAAPI_DECODER_STATUS_ERROR_INVALID_PARAMETER); + g_return_val_if_fail(base_frame != NULL, + GST_VAAPI_DECODER_STATUS_ERROR_INVALID_PARAMETER); + g_return_val_if_fail(adapter != NULL, + GST_VAAPI_DECODER_STATUS_ERROR_INVALID_PARAMETER); + g_return_val_if_fail(got_unit_size_ptr != NULL, + GST_VAAPI_DECODER_STATUS_ERROR_INVALID_PARAMETER); + g_return_val_if_fail(got_frame_ptr != NULL, + GST_VAAPI_DECODER_STATUS_ERROR_INVALID_PARAMETER); + + return do_parse(decoder, base_frame, adapter, at_eos, + got_unit_size_ptr, got_frame_ptr); +} + +GstVaapiDecoderStatus +gst_vaapi_decoder_decode(GstVaapiDecoder *decoder, + GstVideoCodecFrame *base_frame, GstVaapiSurfaceProxy **out_proxy_ptr) +{ + GstVaapiDecoderStatus status; + + g_return_val_if_fail(GST_VAAPI_IS_DECODER(decoder), + GST_VAAPI_DECODER_STATUS_ERROR_INVALID_PARAMETER); + g_return_val_if_fail(base_frame != NULL, + GST_VAAPI_DECODER_STATUS_ERROR_INVALID_PARAMETER); + g_return_val_if_fail(base_frame->user_data != NULL, + GST_VAAPI_DECODER_STATUS_ERROR_INVALID_PARAMETER); + g_return_val_if_fail(out_proxy_ptr != NULL, + GST_VAAPI_DECODER_STATUS_ERROR_INVALID_PARAMETER); + + status = gst_vaapi_decoder_check_status(decoder); + if (status != GST_VAAPI_DECODER_STATUS_SUCCESS) + return status; + + status = do_decode(decoder, base_frame); + if (status != GST_VAAPI_DECODER_STATUS_SUCCESS) + return status; + + *out_proxy_ptr = pop_surface(decoder); + return GST_VAAPI_DECODER_STATUS_SUCCESS; +} diff --git a/gst-libs/gst/vaapi/gstvaapidecoder.h b/gst-libs/gst/vaapi/gstvaapidecoder.h index 70188b6c5c..6632a26421 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder.h +++ b/gst-libs/gst/vaapi/gstvaapidecoder.h @@ -73,6 +73,7 @@ typedef struct _GstVaapiDecoderClass GstVaapiDecoderClass; * @GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER: Invalid or unsupported bitstream data. * @GST_VAAPI_DECODER_STATUS_ERROR_UNSUPPORTED_PROFILE: Unsupported codec profile. * @GST_VAAPI_DECODER_STATUS_ERROR_UNSUPPORTED_CHROMA_FORMAT: Unsupported chroma format. + * @GST_VAAPI_DECODER_STATUS_ERROR_INVALID_PARAMETER: Unsupported parameter. * @GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN: Unknown error. * * Decoder status for gst_vaapi_decoder_get_surface(). @@ -89,6 +90,7 @@ typedef enum { GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER, GST_VAAPI_DECODER_STATUS_ERROR_UNSUPPORTED_PROFILE, GST_VAAPI_DECODER_STATUS_ERROR_UNSUPPORTED_CHROMA_FORMAT, + GST_VAAPI_DECODER_STATUS_ERROR_INVALID_PARAMETER, GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN = -1 } GstVaapiDecoderStatus; @@ -141,6 +143,15 @@ gst_vaapi_decoder_get_surface( GstVaapiDecoderStatus *pstatus ); +GstVaapiDecoderStatus +gst_vaapi_decoder_parse(GstVaapiDecoder *decoder, + GstVideoCodecFrame *frame, GstAdapter *adapter, gboolean at_eos, + guint *got_unit_size_ptr, gboolean *got_frame_ptr); + +GstVaapiDecoderStatus +gst_vaapi_decoder_decode(GstVaapiDecoder *decoder, + GstVideoCodecFrame *frame, GstVaapiSurfaceProxy **out_proxy_ptr); + G_END_DECLS #endif /* GST_VAAPI_DECODER_H */ diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_objects.c b/gst-libs/gst/vaapi/gstvaapidecoder_objects.c index 165ac79128..aad758c8e8 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_objects.c +++ b/gst-libs/gst/vaapi/gstvaapidecoder_objects.c @@ -163,6 +163,10 @@ gst_vaapi_picture_create( picture->slices = g_ptr_array_new(); if (!picture->slices) return FALSE; + + gst_vaapi_mini_object_set_user_data( + GST_VAAPI_MINI_OBJECT(picture->proxy), + GST_VAAPI_DECODER_CODEC_FRAME(GET_DECODER(picture)), NULL); return TRUE; }