mfc: Request input buffers explicitely

This commit is contained in:
Sebastian Dröge 2013-01-02 14:32:32 +01:00
parent 644ef86728
commit 0fbfe0225c
4 changed files with 30 additions and 16 deletions

View file

@ -35,9 +35,10 @@ plugin_init (GstPlugin * plugin)
/* Just check here once if we can create a MFC context, i.e. /* Just check here once if we can create a MFC context, i.e.
* if the hardware is available */ * if the hardware is available */
mfc_dec_init_debug (); mfc_dec_init_debug ();
context = mfc_dec_create (CODEC_TYPE_H264, 1); context = mfc_dec_create (CODEC_TYPE_H264);
if (!context) { if (!context) {
GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, "Failed to initialize MFC decoder context"); GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING,
"Failed to initialize MFC decoder context");
return FALSE; return FALSE;
} }
mfc_dec_destroy (context); mfc_dec_destroy (context);

View file

@ -144,7 +144,7 @@ gst_mfc_dec_open (GstVideoDecoder * decoder)
/* Just check here once if we can create a MFC context, i.e. /* Just check here once if we can create a MFC context, i.e.
* if the hardware is available * if the hardware is available
*/ */
self->context = mfc_dec_create (CODEC_TYPE_H264, 1); self->context = mfc_dec_create (CODEC_TYPE_H264);
if (!self->context) { if (!self->context) {
GST_ELEMENT_ERROR (self, LIBRARY, INIT, GST_ELEMENT_ERROR (self, LIBRARY, INIT,
("Failed to initialize MFC decoder context"), (NULL)); ("Failed to initialize MFC decoder context"), (NULL));
@ -237,7 +237,7 @@ gst_mfc_dec_set_format (GstVideoDecoder * decoder, GstVideoCodecState * state)
self->initialized = FALSE; self->initialized = FALSE;
if (gst_structure_has_name (s, "video/x-h264")) { if (gst_structure_has_name (s, "video/x-h264")) {
self->context = mfc_dec_create (CODEC_TYPE_H264, 1); self->context = mfc_dec_create (CODEC_TYPE_H264);
if (!self->context) { if (!self->context) {
GST_ELEMENT_ERROR (self, LIBRARY, INIT, GST_ELEMENT_ERROR (self, LIBRARY, INIT,
("Failed to initialize MFC decoder context"), (NULL)); ("Failed to initialize MFC decoder context"), (NULL));
@ -252,9 +252,9 @@ gst_mfc_dec_set_format (GstVideoDecoder * decoder, GstVideoCodecState * state)
return FALSE; return FALSE;
if (mpegversion == 1 || mpegversion == 2) { if (mpegversion == 1 || mpegversion == 2) {
self->context = mfc_dec_create (CODEC_TYPE_MPEG2, 1); self->context = mfc_dec_create (CODEC_TYPE_MPEG2);
} else { } else {
self->context = mfc_dec_create (CODEC_TYPE_MPEG4, 1); self->context = mfc_dec_create (CODEC_TYPE_MPEG4);
} }
if (!self->context) { if (!self->context) {
@ -263,7 +263,7 @@ gst_mfc_dec_set_format (GstVideoDecoder * decoder, GstVideoCodecState * state)
return FALSE; return FALSE;
} }
} else if (gst_structure_has_name (s, "video/x-h263")) { } else if (gst_structure_has_name (s, "video/x-h263")) {
self->context = mfc_dec_create (CODEC_TYPE_H263, 1); self->context = mfc_dec_create (CODEC_TYPE_H263);
if (!self->context) { if (!self->context) {
GST_ELEMENT_ERROR (self, LIBRARY, INIT, GST_ELEMENT_ERROR (self, LIBRARY, INIT,
("Failed to initialize MFC decoder context"), (NULL)); ("Failed to initialize MFC decoder context"), (NULL));
@ -273,6 +273,12 @@ gst_mfc_dec_set_format (GstVideoDecoder * decoder, GstVideoCodecState * state)
g_return_val_if_reached (FALSE); g_return_val_if_reached (FALSE);
} }
if (mfc_dec_init_input (self->context, 1) < 0) {
GST_ELEMENT_ERROR (self, LIBRARY, INIT,
("Failed to initialize MFC decoder context input"), (NULL));
return FALSE;
}
gst_buffer_replace (&self->codec_data, state->codec_data); gst_buffer_replace (&self->codec_data, state->codec_data);
done: done:
@ -721,7 +727,7 @@ gst_mfc_dec_dequeue_output (GstMFCDec * self)
if (!self->initialized) { if (!self->initialized) {
GST_DEBUG_OBJECT (self, "Initializing decoder"); GST_DEBUG_OBJECT (self, "Initializing decoder");
if ((mfc_ret = mfc_dec_init (self->context, 1)) < 0) if ((mfc_ret = mfc_dec_init_output (self->context, 1)) < 0)
goto initialize_error; goto initialize_error;
self->initialized = TRUE; self->initialized = TRUE;
} }

View file

@ -220,7 +220,6 @@ static int request_input_buffers(struct mfc_dec_context *ctx, int num)
return 0; return 0;
} }
static int request_output_buffers(struct mfc_dec_context *ctx, int num) static int request_output_buffers(struct mfc_dec_context *ctx, int num)
{ {
struct v4l2_requestbuffers reqbuf = { struct v4l2_requestbuffers reqbuf = {
@ -276,7 +275,7 @@ static int request_output_buffers(struct mfc_dec_context *ctx, int num)
return 0; return 0;
} }
struct mfc_dec_context* mfc_dec_create(unsigned int codec, int num_input_buffers) struct mfc_dec_context* mfc_dec_create(unsigned int codec)
{ {
struct mfc_dec_context *ctx; struct mfc_dec_context *ctx;
struct v4l2_capability caps; struct v4l2_capability caps;
@ -320,8 +319,7 @@ struct mfc_dec_context* mfc_dec_create(unsigned int codec, int num_input_buffers
return NULL; return NULL;
} }
if (mfc_dec_set_codec(ctx, codec) || if (mfc_dec_set_codec(ctx, codec) < 0) {
request_input_buffers(ctx, num_input_buffers)) {
mfc_dec_destroy(ctx); mfc_dec_destroy(ctx);
return NULL; return NULL;
} }
@ -400,7 +398,15 @@ static int start_output_stream(struct mfc_dec_context *ctx)
return 0; return 0;
} }
int mfc_dec_init(struct mfc_dec_context *ctx, int extra_buffers) int mfc_dec_init_input(struct mfc_dec_context *ctx, int num_input_buffers)
{
if (request_input_buffers(ctx, num_input_buffers) < 0)
return -1;
return 0;
}
int mfc_dec_init_output(struct mfc_dec_context *ctx, int extra_buffers)
{ {
if (start_input_stream(ctx) < 0) if (start_input_stream(ctx) < 0)
return -1; return -1;

View file

@ -84,8 +84,9 @@ void mfc_dec_init_debug (void);
* context is needed for most other calls below, and should be * context is needed for most other calls below, and should be
* deallocated with mfc_dec_destroy(). * deallocated with mfc_dec_destroy().
*/ */
struct mfc_dec_context* mfc_dec_create(enum mfc_codec_type codec, struct mfc_dec_context* mfc_dec_create(enum mfc_codec_type codec);
int num_input_buffers);
int mfc_dec_init_input(struct mfc_dec_context*, int num_input_buffers);
/* /*
* Destroy context created with mfc_dec_create(). * Destroy context created with mfc_dec_create().
@ -105,7 +106,7 @@ void mfc_dec_destroy(struct mfc_dec_context*);
* *
* Returns: Zero for success, negative value on failure. * Returns: Zero for success, negative value on failure.
*/ */
int mfc_dec_init(struct mfc_dec_context*, int extra_buffers); int mfc_dec_init_output(struct mfc_dec_context*, int extra_buffers);
/* /*