omx: Catch errors when releasing buffers to a port and handle them

This commit is contained in:
Sebastian Dröge 2013-03-11 10:04:10 +01:00
parent eac2078056
commit 65174bbd7f
3 changed files with 125 additions and 26 deletions

View file

@ -283,6 +283,7 @@ gst_omx_audio_enc_loop (GstOMXAudioEnc * self)
GstFlowReturn flow_ret = GST_FLOW_OK; GstFlowReturn flow_ret = GST_FLOW_OK;
GstOMXAcquireBufferReturn acq_return; GstOMXAcquireBufferReturn acq_return;
gboolean is_eos; gboolean is_eos;
OMX_ERRORTYPE err;
klass = GST_OMX_AUDIO_ENC_GET_CLASS (self); klass = GST_OMX_AUDIO_ENC_GET_CLASS (self);
@ -298,7 +299,6 @@ gst_omx_audio_enc_loop (GstOMXAudioEnc * self)
GstAudioInfo *info = GstAudioInfo *info =
gst_audio_encoder_get_audio_info (GST_AUDIO_ENCODER (self)); gst_audio_encoder_get_audio_info (GST_AUDIO_ENCODER (self));
GstCaps *caps; GstCaps *caps;
OMX_ERRORTYPE err;
GST_DEBUG_OBJECT (self, "Port settings have changed, updating caps"); GST_DEBUG_OBJECT (self, "Port settings have changed, updating caps");
@ -477,7 +477,9 @@ gst_omx_audio_enc_loop (GstOMXAudioEnc * self)
gst_flow_get_name (flow_ret)); gst_flow_get_name (flow_ret));
} }
gst_omx_port_release_buffer (port, buf); err = gst_omx_port_release_buffer (port, buf);
if (err != OMX_ErrorNone)
goto release_error;
self->downstream_flow_ret = flow_ret; self->downstream_flow_ret = flow_ret;
} else { } else {
@ -552,6 +554,18 @@ caps_failed:
self->started = FALSE; self->started = FALSE;
return; return;
} }
release_error:
{
GST_ELEMENT_ERROR (self, LIBRARY, SETTINGS, (NULL),
("Failed to relase output buffer to component: %s (0x%08x)",
gst_omx_error_to_string (err), err));
gst_pad_push_event (GST_AUDIO_ENCODER_SRC_PAD (self), gst_event_new_eos ());
gst_pad_pause_task (GST_AUDIO_ENCODER_SRC_PAD (self));
self->downstream_flow_ret = GST_FLOW_ERROR;
self->started = FALSE;
GST_AUDIO_ENCODER_STREAM_UNLOCK (self);
return;
}
} }
static gboolean static gboolean
@ -844,6 +858,7 @@ gst_omx_audio_enc_handle_frame (GstAudioEncoder * encoder, GstBuffer * inbuf)
gsize size; gsize size;
guint offset = 0; guint offset = 0;
GstClockTime timestamp, duration, timestamp_offset = 0; GstClockTime timestamp, duration, timestamp_offset = 0;
OMX_ERRORTYPE err;
self = GST_OMX_AUDIO_ENC (encoder); self = GST_OMX_AUDIO_ENC (encoder);
@ -881,8 +896,6 @@ gst_omx_audio_enc_handle_frame (GstAudioEncoder * encoder, GstBuffer * inbuf)
GST_AUDIO_ENCODER_STREAM_LOCK (self); GST_AUDIO_ENCODER_STREAM_LOCK (self);
goto flushing; goto flushing;
} else if (acq_ret == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) { } else if (acq_ret == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
OMX_ERRORTYPE err;
/* Reallocate all buffers */ /* Reallocate all buffers */
err = gst_omx_port_set_enabled (port, FALSE); err = gst_omx_port_set_enabled (port, FALSE);
if (err != OMX_ErrorNone) { if (err != OMX_ErrorNone) {
@ -980,7 +993,9 @@ gst_omx_audio_enc_handle_frame (GstAudioEncoder * encoder, GstBuffer * inbuf)
offset += buf->omx_buf->nFilledLen; offset += buf->omx_buf->nFilledLen;
self->started = TRUE; self->started = TRUE;
gst_omx_port_release_buffer (port, buf); err = gst_omx_port_release_buffer (port, buf);
if (err != OMX_ErrorNone)
goto release_error;
} }
GST_DEBUG_OBJECT (self, "Passed frame to component"); GST_DEBUG_OBJECT (self, "Passed frame to component");
@ -1014,6 +1029,13 @@ reconfigure_error:
("Unable to reconfigure input port")); ("Unable to reconfigure input port"));
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
release_error:
{
GST_ELEMENT_ERROR (self, LIBRARY, SETTINGS, (NULL),
("Failed to relase input buffer to component: %s (0x%08x)",
gst_omx_error_to_string (err), err));
return GST_FLOW_ERROR;
}
} }
static gboolean static gboolean
@ -1021,6 +1043,7 @@ gst_omx_audio_enc_sink_event (GstAudioEncoder * encoder, GstEvent * event)
{ {
GstOMXAudioEnc *self; GstOMXAudioEnc *self;
GstOMXAudioEncClass *klass; GstOMXAudioEncClass *klass;
OMX_ERRORTYPE err;
self = GST_OMX_AUDIO_ENC (encoder); self = GST_OMX_AUDIO_ENC (encoder);
klass = GST_OMX_AUDIO_ENC_GET_CLASS (self); klass = GST_OMX_AUDIO_ENC_GET_CLASS (self);
@ -1067,8 +1090,13 @@ gst_omx_audio_enc_sink_event (GstAudioEncoder * encoder, GstEvent * event)
GST_SECOND); GST_SECOND);
buf->omx_buf->nTickCount = 0; buf->omx_buf->nTickCount = 0;
buf->omx_buf->nFlags |= OMX_BUFFERFLAG_EOS; buf->omx_buf->nFlags |= OMX_BUFFERFLAG_EOS;
gst_omx_port_release_buffer (self->enc_in_port, buf); err = gst_omx_port_release_buffer (self->enc_in_port, buf);
GST_DEBUG_OBJECT (self, "Sent EOS to the component"); if (err != OMX_ErrorNone) {
GST_ERROR_OBJECT (self, "Failed to send EOS to component: %s (0x%08x)",
gst_omx_error_to_string (err), err);
} else {
GST_DEBUG_OBJECT (self, "Sent EOS to the component");
}
} else { } else {
GST_ERROR_OBJECT (self, "Failed to acquire buffer for EOS: %d", acq_ret); GST_ERROR_OBJECT (self, "Failed to acquire buffer for EOS: %d", acq_ret);
} }
@ -1087,6 +1115,7 @@ gst_omx_audio_enc_drain (GstOMXAudioEnc * self)
GstOMXAudioEncClass *klass; GstOMXAudioEncClass *klass;
GstOMXBuffer *buf; GstOMXBuffer *buf;
GstOMXAcquireBufferReturn acq_ret; GstOMXAcquireBufferReturn acq_ret;
OMX_ERRORTYPE err;
GST_DEBUG_OBJECT (self, "Draining component"); GST_DEBUG_OBJECT (self, "Draining component");
@ -1133,7 +1162,13 @@ gst_omx_audio_enc_drain (GstOMXAudioEnc * self)
GST_SECOND); GST_SECOND);
buf->omx_buf->nTickCount = 0; buf->omx_buf->nTickCount = 0;
buf->omx_buf->nFlags |= OMX_BUFFERFLAG_EOS; buf->omx_buf->nFlags |= OMX_BUFFERFLAG_EOS;
gst_omx_port_release_buffer (self->enc_in_port, buf); err = gst_omx_port_release_buffer (self->enc_in_port, buf);
if (err != OMX_ErrorNone) {
GST_ERROR_OBJECT (self, "Failed to drain component: %s (0x%08x)",
gst_omx_error_to_string (err), err);
GST_AUDIO_ENCODER_STREAM_LOCK (self);
return GST_FLOW_ERROR;
}
GST_DEBUG_OBJECT (self, "Waiting until component is drained"); GST_DEBUG_OBJECT (self, "Waiting until component is drained");
g_cond_wait (&self->drain_cond, &self->drain_lock); g_cond_wait (&self->drain_cond, &self->drain_lock);
GST_DEBUG_OBJECT (self, "Drained component"); GST_DEBUG_OBJECT (self, "Drained component");

View file

@ -546,8 +546,9 @@ gst_omx_buffer_pool_release_buffer (GstBufferPool * bpool, GstBuffer * buffer)
/* Release back to the port, can be filled again */ /* Release back to the port, can be filled again */
err = gst_omx_port_release_buffer (pool->port, omx_buf); err = gst_omx_port_release_buffer (pool->port, omx_buf);
if (err != OMX_ErrorNone) { if (err != OMX_ErrorNone) {
/* TODO: Do something about this */ GST_ELEMENT_ERROR (pool->element, LIBRARY, SETTINGS, (NULL),
g_assert_not_reached (); ("Failed to relase output buffer to component: %s (0x%08x)",
gst_omx_error_to_string (err), err));
} }
} else { } else {
/* TODO: Implement. /* TODO: Implement.
@ -1360,6 +1361,7 @@ gst_omx_video_dec_loop (GstOMXVideoDec * self)
GstOMXAcquireBufferReturn acq_return; GstOMXAcquireBufferReturn acq_return;
GstClockTimeDiff deadline; GstClockTimeDiff deadline;
gboolean is_eos; gboolean is_eos;
OMX_ERRORTYPE err;
klass = GST_OMX_VIDEO_DEC_GET_CLASS (self); klass = GST_OMX_VIDEO_DEC_GET_CLASS (self);
@ -1372,7 +1374,6 @@ gst_omx_video_dec_loop (GstOMXVideoDec * self)
if (!gst_pad_has_current_caps (GST_VIDEO_DECODER_SRC_PAD (self)) || if (!gst_pad_has_current_caps (GST_VIDEO_DECODER_SRC_PAD (self)) ||
acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) { acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
OMX_ERRORTYPE err;
GstVideoCodecState *state; GstVideoCodecState *state;
OMX_PARAM_PORTDEFINITIONTYPE port_def; OMX_PARAM_PORTDEFINITIONTYPE port_def;
GstVideoFormat format; GstVideoFormat format;
@ -1614,8 +1615,11 @@ gst_omx_video_dec_loop (GstOMXVideoDec * self)
gst_flow_get_name (flow_ret)); gst_flow_get_name (flow_ret));
} }
if (buf) if (buf) {
gst_omx_port_release_buffer (port, buf); err = gst_omx_port_release_buffer (port, buf);
if (err != OMX_ErrorNone)
goto release_error;
}
self->downstream_flow_ret = flow_ret; self->downstream_flow_ret = flow_ret;
} else { } else {
@ -1708,6 +1712,18 @@ caps_failed:
self->started = FALSE; self->started = FALSE;
return; return;
} }
release_error:
{
GST_ELEMENT_ERROR (self, LIBRARY, SETTINGS, (NULL),
("Failed to relase output buffer to component: %s (0x%08x)",
gst_omx_error_to_string (err), err));
gst_pad_push_event (GST_VIDEO_DECODER_SRC_PAD (self), gst_event_new_eos ());
gst_pad_pause_task (GST_VIDEO_DECODER_SRC_PAD (self));
self->downstream_flow_ret = GST_FLOW_ERROR;
self->started = FALSE;
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
return;
}
} }
static gboolean static gboolean
@ -2172,6 +2188,7 @@ gst_omx_video_dec_handle_frame (GstVideoDecoder * decoder,
GstBuffer *codec_data = NULL; GstBuffer *codec_data = NULL;
guint offset = 0, size; guint offset = 0, size;
GstClockTime timestamp, duration, timestamp_offset = 0; GstClockTime timestamp, duration, timestamp_offset = 0;
OMX_ERRORTYPE err;
self = GST_OMX_VIDEO_DEC (decoder); self = GST_OMX_VIDEO_DEC (decoder);
klass = GST_OMX_VIDEO_DEC_GET_CLASS (self); klass = GST_OMX_VIDEO_DEC_GET_CLASS (self);
@ -2221,8 +2238,6 @@ gst_omx_video_dec_handle_frame (GstVideoDecoder * decoder,
GST_VIDEO_DECODER_STREAM_LOCK (self); GST_VIDEO_DECODER_STREAM_LOCK (self);
goto flushing; goto flushing;
} else if (acq_ret == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) { } else if (acq_ret == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
OMX_ERRORTYPE err;
/* Reallocate all buffers */ /* Reallocate all buffers */
err = gst_omx_port_set_enabled (port, FALSE); err = gst_omx_port_set_enabled (port, FALSE);
if (err != OMX_ErrorNone) { if (err != OMX_ErrorNone) {
@ -2308,8 +2323,10 @@ gst_omx_video_dec_handle_frame (GstVideoDecoder * decoder,
buf->omx_buf->nFilledLen); buf->omx_buf->nFilledLen);
self->started = TRUE; self->started = TRUE;
gst_omx_port_release_buffer (port, buf); err = gst_omx_port_release_buffer (port, buf);
gst_buffer_replace (&self->codec_data, NULL); gst_buffer_replace (&self->codec_data, NULL);
if (err != OMX_ErrorNone)
goto release_error;
/* Acquire new buffer for the actual frame */ /* Acquire new buffer for the actual frame */
continue; continue;
} }
@ -2362,7 +2379,9 @@ gst_omx_video_dec_handle_frame (GstVideoDecoder * decoder,
offset += buf->omx_buf->nFilledLen; offset += buf->omx_buf->nFilledLen;
self->started = TRUE; self->started = TRUE;
gst_omx_port_release_buffer (port, buf); err = gst_omx_port_release_buffer (port, buf);
if (err != OMX_ErrorNone)
goto release_error;
} }
gst_video_codec_frame_unref (frame); gst_video_codec_frame_unref (frame);
@ -2420,6 +2439,14 @@ reconfigure_error:
("Unable to reconfigure input port")); ("Unable to reconfigure input port"));
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
release_error:
{
gst_video_codec_frame_unref (frame);
GST_ELEMENT_ERROR (self, LIBRARY, SETTINGS, (NULL),
("Failed to relase input buffer to component: %s (0x%08x)",
gst_omx_error_to_string (err), err));
return GST_FLOW_ERROR;
}
} }
static GstFlowReturn static GstFlowReturn
@ -2438,6 +2465,7 @@ gst_omx_video_dec_drain (GstOMXVideoDec * self, gboolean is_eos)
GstOMXVideoDecClass *klass; GstOMXVideoDecClass *klass;
GstOMXBuffer *buf; GstOMXBuffer *buf;
GstOMXAcquireBufferReturn acq_ret; GstOMXAcquireBufferReturn acq_ret;
OMX_ERRORTYPE err;
GST_DEBUG_OBJECT (self, "Draining component"); GST_DEBUG_OBJECT (self, "Draining component");
@ -2486,7 +2514,14 @@ gst_omx_video_dec_drain (GstOMXVideoDec * self, gboolean is_eos)
GST_SECOND); GST_SECOND);
buf->omx_buf->nTickCount = 0; buf->omx_buf->nTickCount = 0;
buf->omx_buf->nFlags |= OMX_BUFFERFLAG_EOS; buf->omx_buf->nFlags |= OMX_BUFFERFLAG_EOS;
gst_omx_port_release_buffer (self->dec_in_port, buf); err = gst_omx_port_release_buffer (self->dec_in_port, buf);
if (err != OMX_ErrorNone) {
GST_ERROR_OBJECT (self, "Failed to drain component: %s (0x%08x)",
gst_omx_error_to_string (err), err);
GST_VIDEO_DECODER_STREAM_LOCK (self);
return GST_FLOW_ERROR;
}
GST_DEBUG_OBJECT (self, "Waiting until component is drained"); GST_DEBUG_OBJECT (self, "Waiting until component is drained");
if (G_UNLIKELY (self->dec->hacks & GST_OMX_HACK_DRAIN_MAY_NOT_RETURN)) { if (G_UNLIKELY (self->dec->hacks & GST_OMX_HACK_DRAIN_MAY_NOT_RETURN)) {

View file

@ -734,6 +734,7 @@ gst_omx_video_enc_loop (GstOMXVideoEnc * self)
GstFlowReturn flow_ret = GST_FLOW_OK; GstFlowReturn flow_ret = GST_FLOW_OK;
GstOMXAcquireBufferReturn acq_return; GstOMXAcquireBufferReturn acq_return;
gboolean is_eos; gboolean is_eos;
OMX_ERRORTYPE err;
klass = GST_OMX_VIDEO_ENC_GET_CLASS (self); klass = GST_OMX_VIDEO_ENC_GET_CLASS (self);
@ -748,7 +749,6 @@ gst_omx_video_enc_loop (GstOMXVideoEnc * self)
|| acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) { || acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
GstCaps *caps; GstCaps *caps;
GstVideoCodecState *state; GstVideoCodecState *state;
OMX_ERRORTYPE err;
GST_DEBUG_OBJECT (self, "Port settings have changed, updating caps"); GST_DEBUG_OBJECT (self, "Port settings have changed, updating caps");
@ -867,7 +867,9 @@ gst_omx_video_enc_loop (GstOMXVideoEnc * self)
gst_flow_get_name (flow_ret)); gst_flow_get_name (flow_ret));
} }
gst_omx_port_release_buffer (port, buf); err = gst_omx_port_release_buffer (port, buf);
if (err != OMX_ErrorNone)
goto release_error;
self->downstream_flow_ret = flow_ret; self->downstream_flow_ret = flow_ret;
} else { } else {
@ -944,6 +946,18 @@ caps_failed:
self->started = FALSE; self->started = FALSE;
return; return;
} }
release_error:
{
GST_ELEMENT_ERROR (self, LIBRARY, SETTINGS, (NULL),
("Failed to relase output buffer to component: %s (0x%08x)",
gst_omx_error_to_string (err), err));
gst_pad_push_event (GST_VIDEO_ENCODER_SRC_PAD (self), gst_event_new_eos ());
gst_pad_pause_task (GST_VIDEO_ENCODER_SRC_PAD (self));
self->downstream_flow_ret = GST_FLOW_ERROR;
self->started = FALSE;
GST_VIDEO_ENCODER_STREAM_UNLOCK (self);
return;
}
} }
static gboolean static gboolean
@ -1494,6 +1508,7 @@ gst_omx_video_enc_handle_frame (GstVideoEncoder * encoder,
GstOMXVideoEnc *self; GstOMXVideoEnc *self;
GstOMXPort *port; GstOMXPort *port;
GstOMXBuffer *buf; GstOMXBuffer *buf;
OMX_ERRORTYPE err;
self = GST_OMX_VIDEO_ENC (encoder); self = GST_OMX_VIDEO_ENC (encoder);
@ -1529,8 +1544,6 @@ gst_omx_video_enc_handle_frame (GstVideoEncoder * encoder,
GST_VIDEO_ENCODER_STREAM_LOCK (self); GST_VIDEO_ENCODER_STREAM_LOCK (self);
goto flushing; goto flushing;
} else if (acq_ret == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) { } else if (acq_ret == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
OMX_ERRORTYPE err;
/* Reallocate all buffers */ /* Reallocate all buffers */
err = gst_omx_port_set_enabled (port, FALSE); err = gst_omx_port_set_enabled (port, FALSE);
if (err != OMX_ErrorNone) { if (err != OMX_ErrorNone) {
@ -1602,7 +1615,6 @@ gst_omx_video_enc_handle_frame (GstVideoEncoder * encoder,
GST_DEBUG_OBJECT (self, "Handling frame"); GST_DEBUG_OBJECT (self, "Handling frame");
if (GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME (frame)) { if (GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME (frame)) {
OMX_ERRORTYPE err;
OMX_CONFIG_INTRAREFRESHVOPTYPE config; OMX_CONFIG_INTRAREFRESHVOPTYPE config;
GST_OMX_INIT_STRUCT (&config); GST_OMX_INIT_STRUCT (&config);
@ -1646,14 +1658,16 @@ gst_omx_video_enc_handle_frame (GstVideoEncoder * encoder,
(GDestroyNotify) buffer_identification_free); (GDestroyNotify) buffer_identification_free);
self->started = TRUE; self->started = TRUE;
gst_omx_port_release_buffer (port, buf); err = gst_omx_port_release_buffer (port, buf);
if (err != OMX_ErrorNone)
goto release_error;
GST_DEBUG_OBJECT (self, "Passed frame to component"); GST_DEBUG_OBJECT (self, "Passed frame to component");
} }
gst_video_codec_frame_unref (frame); gst_video_codec_frame_unref (frame);
return self->downstream_flow_ret;; return self->downstream_flow_ret;
full_buffer: full_buffer:
{ {
@ -1700,6 +1714,14 @@ buffer_fill_error:
gst_video_codec_frame_unref (frame); gst_video_codec_frame_unref (frame);
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
release_error:
{
gst_video_codec_frame_unref (frame);
GST_ELEMENT_ERROR (self, LIBRARY, SETTINGS, (NULL),
("Failed to relase input buffer to component: %s (0x%08x)",
gst_omx_error_to_string (err), err));
return GST_FLOW_ERROR;
}
} }
static GstFlowReturn static GstFlowReturn
@ -1718,6 +1740,7 @@ gst_omx_video_enc_drain (GstOMXVideoEnc * self, gboolean at_eos)
GstOMXVideoEncClass *klass; GstOMXVideoEncClass *klass;
GstOMXBuffer *buf; GstOMXBuffer *buf;
GstOMXAcquireBufferReturn acq_ret; GstOMXAcquireBufferReturn acq_ret;
OMX_ERRORTYPE err;
GST_DEBUG_OBJECT (self, "Draining component"); GST_DEBUG_OBJECT (self, "Draining component");
@ -1766,7 +1789,13 @@ gst_omx_video_enc_drain (GstOMXVideoEnc * self, gboolean at_eos)
GST_SECOND); GST_SECOND);
buf->omx_buf->nTickCount = 0; buf->omx_buf->nTickCount = 0;
buf->omx_buf->nFlags |= OMX_BUFFERFLAG_EOS; buf->omx_buf->nFlags |= OMX_BUFFERFLAG_EOS;
gst_omx_port_release_buffer (self->enc_in_port, buf); err = gst_omx_port_release_buffer (self->enc_in_port, buf);
if (err != OMX_ErrorNone) {
GST_ERROR_OBJECT (self, "Failed to drain component: %s (0x%08x)",
gst_omx_error_to_string (err), err);
GST_VIDEO_ENCODER_STREAM_LOCK (self);
return GST_FLOW_ERROR;
}
GST_DEBUG_OBJECT (self, "Waiting until component is drained"); GST_DEBUG_OBJECT (self, "Waiting until component is drained");
g_cond_wait (&self->drain_cond, &self->drain_lock); g_cond_wait (&self->drain_cond, &self->drain_lock);
GST_DEBUG_OBJECT (self, "Drained component"); GST_DEBUG_OBJECT (self, "Drained component");