mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-17 03:35:21 +00:00
omx: Handle the OMX_EventBufferFlag to detect EOS too
This commit is contained in:
parent
acf15e84a9
commit
22dce51dd4
5 changed files with 327 additions and 261 deletions
56
omx/gstomx.c
56
omx/gstomx.c
|
@ -321,6 +321,23 @@ gst_omx_component_handle_messages (GstOMXComponent * comp)
|
|||
|
||||
break;
|
||||
}
|
||||
case GST_OMX_MESSAGE_BUFFER_FLAG:{
|
||||
GstOMXPort *port = NULL;
|
||||
OMX_U32 index = msg->content.buffer_flag.port;
|
||||
OMX_U32 flags = msg->content.buffer_flag.flags;
|
||||
|
||||
port = gst_omx_component_get_port (comp, index);
|
||||
if (!port)
|
||||
break;
|
||||
|
||||
GST_DEBUG_OBJECT (comp->parent, "Port %u got buffer flags 0x%08x",
|
||||
port->index, flags);
|
||||
if ((flags & OMX_BUFFERFLAG_EOS)
|
||||
&& port->port_def.eDir == OMX_DirOutput)
|
||||
port->eos = TRUE;
|
||||
|
||||
break;
|
||||
}
|
||||
case GST_OMX_MESSAGE_BUFFER_DONE:{
|
||||
GstOMXBuffer *buf = msg->content.buffer_done.buffer->pAppPrivate;
|
||||
GstOMXPort *port;
|
||||
|
@ -356,6 +373,10 @@ gst_omx_component_handle_messages (GstOMXComponent * comp)
|
|||
* the port was flushed */
|
||||
GST_DEBUG_OBJECT (comp->parent, "Port %u filled buffer %p (%p)",
|
||||
port->index, buf, buf->omx_buf->pBuffer);
|
||||
|
||||
if ((buf->omx_buf->nFlags & OMX_BUFFERFLAG_EOS)
|
||||
&& port->port_def.eDir == OMX_DirOutput)
|
||||
port->eos = TRUE;
|
||||
}
|
||||
|
||||
buf->used = FALSE;
|
||||
|
@ -491,8 +512,21 @@ EventHandler (OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_EVENTTYPE eEvent,
|
|||
gst_omx_component_send_message (comp, msg);
|
||||
break;
|
||||
}
|
||||
case OMX_EventBufferFlag:{
|
||||
GstOMXMessage *msg;
|
||||
|
||||
msg = g_slice_new (GstOMXMessage);
|
||||
|
||||
msg->type = GST_OMX_MESSAGE_BUFFER_FLAG;
|
||||
msg->content.buffer_flag.port = nData1;
|
||||
msg->content.buffer_flag.flags = nData2;
|
||||
GST_DEBUG_OBJECT (comp->parent, "Port %u got buffer flags 0x%08x",
|
||||
msg->content.buffer_flag.port, msg->content.buffer_flag.flags);
|
||||
|
||||
gst_omx_component_send_message (comp, msg);
|
||||
break;
|
||||
}
|
||||
case OMX_EventPortFormatDetected:
|
||||
case OMX_EventBufferFlag:
|
||||
default:
|
||||
GST_DEBUG_OBJECT (comp->parent, "Unknown event 0x%08x", eEvent);
|
||||
break;
|
||||
|
@ -879,6 +913,7 @@ gst_omx_component_add_port (GstOMXComponent * comp, guint32 index)
|
|||
port->flushed = FALSE;
|
||||
port->enabled_pending = FALSE;
|
||||
port->disabled_pending = FALSE;
|
||||
port->eos = FALSE;
|
||||
|
||||
if (port->port_def.eDir == OMX_DirInput)
|
||||
comp->n_in_ports++;
|
||||
|
@ -1237,8 +1272,22 @@ retry:
|
|||
goto done;
|
||||
}
|
||||
|
||||
if (port->port_def.eDir == OMX_DirOutput && port->eos) {
|
||||
if (!g_queue_is_empty (&port->pending_buffers)) {
|
||||
GST_DEBUG_OBJECT (comp->parent,
|
||||
"Output port %u is EOS but has buffers pending", port->index);
|
||||
_buf = g_queue_pop_head (&port->pending_buffers);
|
||||
|
||||
ret = GST_OMX_ACQUIRE_BUFFER_OK;
|
||||
goto done;
|
||||
}
|
||||
|
||||
ret = GST_OMX_ACQUIRE_BUFFER_EOS;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/*
|
||||
* At this point we have no error or flushing port
|
||||
* At this point we have no error or flushing/eos port
|
||||
* and a properly configured port.
|
||||
*
|
||||
*/
|
||||
|
@ -1478,6 +1527,9 @@ gst_omx_port_set_flushing (GstOMXPort * port, GstClockTime timeout,
|
|||
err = OMX_ErrorTimeout;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Reset EOS flag */
|
||||
port->eos = FALSE;
|
||||
}
|
||||
|
||||
done:
|
||||
|
|
|
@ -118,6 +118,8 @@ typedef enum {
|
|||
GST_OMX_ACQUIRE_BUFFER_FLUSHING,
|
||||
/* The port must be reconfigured */
|
||||
GST_OMX_ACQUIRE_BUFFER_RECONFIGURE,
|
||||
/* The port is EOS */
|
||||
GST_OMX_ACQUIRE_BUFFER_EOS,
|
||||
/* A fatal error happened */
|
||||
GST_OMX_ACQUIRE_BUFFER_ERROR
|
||||
} GstOMXAcquireBufferReturn;
|
||||
|
@ -146,6 +148,7 @@ typedef enum {
|
|||
GST_OMX_MESSAGE_ERROR,
|
||||
GST_OMX_MESSAGE_PORT_ENABLE,
|
||||
GST_OMX_MESSAGE_PORT_SETTINGS_CHANGED,
|
||||
GST_OMX_MESSAGE_BUFFER_FLAG,
|
||||
GST_OMX_MESSAGE_BUFFER_DONE,
|
||||
} GstOMXMessageType;
|
||||
|
||||
|
@ -169,6 +172,10 @@ struct _GstOMXMessage {
|
|||
struct {
|
||||
OMX_U32 port;
|
||||
} port_settings_changed;
|
||||
struct {
|
||||
OMX_U32 port;
|
||||
OMX_U32 flags;
|
||||
} buffer_flag;
|
||||
struct {
|
||||
OMX_HANDLETYPE component;
|
||||
OMX_PTR app_data;
|
||||
|
@ -191,6 +198,7 @@ struct _GstOMXPort {
|
|||
gboolean flushed; /* TRUE after OMX_CommandFlush was done */
|
||||
gboolean enabled_pending; /* TRUE after OMX_Command{En,Dis}able */
|
||||
gboolean disabled_pending; /* was done until it took effect */
|
||||
gboolean eos; /* TRUE after a buffer with EOS flag was received */
|
||||
|
||||
/* Increased whenever the settings of these port change.
|
||||
* If settings_cookie != configured_settings_cookie
|
||||
|
|
|
@ -282,7 +282,6 @@ gst_omx_audio_enc_loop (GstOMXAudioEnc * self)
|
|||
GstOMXBuffer *buf = NULL;
|
||||
GstFlowReturn flow_ret = GST_FLOW_OK;
|
||||
GstOMXAcquireBufferReturn acq_return;
|
||||
gboolean is_eos;
|
||||
OMX_ERRORTYPE err;
|
||||
|
||||
klass = GST_OMX_AUDIO_ENC_GET_CLASS (self);
|
||||
|
@ -292,6 +291,8 @@ gst_omx_audio_enc_loop (GstOMXAudioEnc * self)
|
|||
goto component_error;
|
||||
} else if (acq_return == GST_OMX_ACQUIRE_BUFFER_FLUSHING) {
|
||||
goto flushing;
|
||||
} else if (acq_return == GST_OMX_ACQUIRE_BUFFER_EOS) {
|
||||
goto eos;
|
||||
}
|
||||
|
||||
if (!gst_pad_has_current_caps (GST_AUDIO_ENCODER_SRC_PAD (self))
|
||||
|
@ -374,8 +375,12 @@ gst_omx_audio_enc_loop (GstOMXAudioEnc * self)
|
|||
}
|
||||
|
||||
g_assert (acq_return == GST_OMX_ACQUIRE_BUFFER_OK);
|
||||
if (!buf) {
|
||||
g_assert ((klass->cdata.hacks & GST_OMX_HACK_NO_EMPTY_EOS_BUFFER));
|
||||
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
||||
goto eos;
|
||||
}
|
||||
|
||||
if (buf) {
|
||||
GST_DEBUG_OBJECT (self, "Handling buffer: 0x%08x %lu", buf->omx_buf->nFlags,
|
||||
buf->omx_buf->nTimeStamp);
|
||||
|
||||
|
@ -390,7 +395,6 @@ gst_omx_audio_enc_loop (GstOMXAudioEnc * self)
|
|||
}
|
||||
|
||||
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
||||
is_eos = ! !(buf->omx_buf->nFlags & OMX_BUFFERFLAG_EOS);
|
||||
|
||||
if ((buf->omx_buf->nFlags & OMX_BUFFERFLAG_CODECCONFIG)
|
||||
&& buf->omx_buf->nFilledLen > 0) {
|
||||
|
@ -410,8 +414,7 @@ gst_omx_audio_enc_loop (GstOMXAudioEnc * self)
|
|||
buf->omx_buf->nFilledLen);
|
||||
gst_buffer_unmap (codec_data, &map);
|
||||
|
||||
gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, codec_data,
|
||||
NULL);
|
||||
gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, codec_data, NULL);
|
||||
if (!gst_pad_set_caps (GST_AUDIO_ENCODER_SRC_PAD (self), caps)) {
|
||||
gst_caps_unref (caps);
|
||||
if (buf)
|
||||
|
@ -461,32 +464,13 @@ gst_omx_audio_enc_loop (GstOMXAudioEnc * self)
|
|||
|
||||
GST_DEBUG_OBJECT (self, "Handled output data");
|
||||
|
||||
if (is_eos || flow_ret == GST_FLOW_EOS) {
|
||||
g_mutex_lock (&self->drain_lock);
|
||||
if (self->draining) {
|
||||
GST_DEBUG_OBJECT (self, "Drained");
|
||||
self->draining = FALSE;
|
||||
g_cond_broadcast (&self->drain_cond);
|
||||
} else if (flow_ret == GST_FLOW_OK) {
|
||||
GST_DEBUG_OBJECT (self, "Component signalled EOS");
|
||||
flow_ret = GST_FLOW_EOS;
|
||||
}
|
||||
g_mutex_unlock (&self->drain_lock);
|
||||
} else {
|
||||
GST_DEBUG_OBJECT (self, "Finished frame: %s",
|
||||
gst_flow_get_name (flow_ret));
|
||||
}
|
||||
GST_DEBUG_OBJECT (self, "Finished frame: %s", gst_flow_get_name (flow_ret));
|
||||
|
||||
err = gst_omx_port_release_buffer (port, buf);
|
||||
if (err != OMX_ErrorNone)
|
||||
goto release_error;
|
||||
|
||||
self->downstream_flow_ret = flow_ret;
|
||||
} else {
|
||||
g_assert ((klass->cdata.hacks & GST_OMX_HACK_NO_EMPTY_EOS_BUFFER));
|
||||
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
||||
flow_ret = GST_FLOW_EOS;
|
||||
}
|
||||
|
||||
if (flow_ret != GST_FLOW_OK)
|
||||
goto flow_error;
|
||||
|
@ -513,6 +497,29 @@ flushing:
|
|||
gst_pad_pause_task (GST_AUDIO_ENCODER_SRC_PAD (self));
|
||||
self->downstream_flow_ret = GST_FLOW_FLUSHING;
|
||||
self->started = FALSE;
|
||||
return;
|
||||
}
|
||||
eos:
|
||||
{
|
||||
g_mutex_lock (&self->drain_lock);
|
||||
if (self->draining) {
|
||||
GST_DEBUG_OBJECT (self, "Drained");
|
||||
self->draining = FALSE;
|
||||
g_cond_broadcast (&self->drain_cond);
|
||||
flow_ret = GST_FLOW_OK;
|
||||
} else {
|
||||
GST_DEBUG_OBJECT (self, "Component signalled EOS");
|
||||
flow_ret = GST_FLOW_EOS;
|
||||
}
|
||||
g_mutex_unlock (&self->drain_lock);
|
||||
|
||||
self->downstream_flow_ret = flow_ret;
|
||||
|
||||
if (flow_ret != GST_FLOW_OK)
|
||||
goto flow_error;
|
||||
|
||||
GST_AUDIO_ENCODER_STREAM_UNLOCK (self);
|
||||
|
||||
return;
|
||||
}
|
||||
flow_error:
|
||||
|
|
|
@ -1361,23 +1361,21 @@ gst_omx_video_dec_deallocate_output_buffers (GstOMXVideoDec * self)
|
|||
static void
|
||||
gst_omx_video_dec_loop (GstOMXVideoDec * self)
|
||||
{
|
||||
GstOMXVideoDecClass *klass;
|
||||
GstOMXPort *port = self->dec_out_port;
|
||||
GstOMXBuffer *buf = NULL;
|
||||
GstVideoCodecFrame *frame;
|
||||
GstFlowReturn flow_ret = GST_FLOW_OK;
|
||||
GstOMXAcquireBufferReturn acq_return;
|
||||
GstClockTimeDiff deadline;
|
||||
gboolean is_eos;
|
||||
OMX_ERRORTYPE err;
|
||||
|
||||
klass = GST_OMX_VIDEO_DEC_GET_CLASS (self);
|
||||
|
||||
acq_return = gst_omx_port_acquire_buffer (port, &buf);
|
||||
if (acq_return == GST_OMX_ACQUIRE_BUFFER_ERROR) {
|
||||
goto component_error;
|
||||
} else if (acq_return == GST_OMX_ACQUIRE_BUFFER_FLUSHING) {
|
||||
goto flushing;
|
||||
} else if (acq_return == GST_OMX_ACQUIRE_BUFFER_EOS) {
|
||||
goto eos;
|
||||
}
|
||||
|
||||
if (!gst_pad_has_current_caps (GST_VIDEO_DECODER_SRC_PAD (self)) ||
|
||||
|
@ -1490,15 +1488,12 @@ gst_omx_video_dec_loop (GstOMXVideoDec * self)
|
|||
goto flushing;
|
||||
}
|
||||
|
||||
if (buf) {
|
||||
GST_DEBUG_OBJECT (self, "Handling buffer: 0x%08x %lu",
|
||||
buf->omx_buf->nFlags, buf->omx_buf->nTimeStamp);
|
||||
|
||||
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
||||
frame = _find_nearest_frame (self, buf);
|
||||
|
||||
is_eos = ! !(buf->omx_buf->nFlags & OMX_BUFFERFLAG_EOS);
|
||||
|
||||
if (frame
|
||||
&& (deadline = gst_video_decoder_get_max_decode_time
|
||||
(GST_VIDEO_DECODER (self), frame)) < 0) {
|
||||
|
@ -1607,21 +1602,7 @@ gst_omx_video_dec_loop (GstOMXVideoDec * self)
|
|||
|
||||
GST_DEBUG_OBJECT (self, "Read frame from component");
|
||||
|
||||
if (is_eos || flow_ret == GST_FLOW_EOS) {
|
||||
g_mutex_lock (&self->drain_lock);
|
||||
if (self->draining) {
|
||||
GST_DEBUG_OBJECT (self, "Drained");
|
||||
self->draining = FALSE;
|
||||
g_cond_broadcast (&self->drain_cond);
|
||||
} else if (flow_ret == GST_FLOW_OK) {
|
||||
GST_DEBUG_OBJECT (self, "Component signalled EOS");
|
||||
flow_ret = GST_FLOW_EOS;
|
||||
}
|
||||
g_mutex_unlock (&self->drain_lock);
|
||||
} else {
|
||||
GST_DEBUG_OBJECT (self, "Finished frame: %s",
|
||||
gst_flow_get_name (flow_ret));
|
||||
}
|
||||
GST_DEBUG_OBJECT (self, "Finished frame: %s", gst_flow_get_name (flow_ret));
|
||||
|
||||
if (buf) {
|
||||
err = gst_omx_port_release_buffer (port, buf);
|
||||
|
@ -1630,11 +1611,6 @@ gst_omx_video_dec_loop (GstOMXVideoDec * self)
|
|||
}
|
||||
|
||||
self->downstream_flow_ret = flow_ret;
|
||||
} else {
|
||||
g_assert ((klass->cdata.hacks & GST_OMX_HACK_NO_EMPTY_EOS_BUFFER));
|
||||
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
||||
flow_ret = GST_FLOW_EOS;
|
||||
}
|
||||
|
||||
if (flow_ret != GST_FLOW_OK)
|
||||
goto flow_error;
|
||||
|
@ -1665,6 +1641,29 @@ flushing:
|
|||
return;
|
||||
}
|
||||
|
||||
eos:
|
||||
{
|
||||
g_mutex_lock (&self->drain_lock);
|
||||
if (self->draining) {
|
||||
GST_DEBUG_OBJECT (self, "Drained");
|
||||
self->draining = FALSE;
|
||||
g_cond_broadcast (&self->drain_cond);
|
||||
flow_ret = GST_FLOW_OK;
|
||||
} else {
|
||||
GST_DEBUG_OBJECT (self, "Component signalled EOS");
|
||||
flow_ret = GST_FLOW_EOS;
|
||||
}
|
||||
g_mutex_unlock (&self->drain_lock);
|
||||
self->downstream_flow_ret = flow_ret;
|
||||
|
||||
if (flow_ret != GST_FLOW_OK)
|
||||
goto flow_error;
|
||||
|
||||
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
flow_error:
|
||||
{
|
||||
if (flow_ret == GST_FLOW_EOS) {
|
||||
|
|
|
@ -740,7 +740,6 @@ gst_omx_video_enc_loop (GstOMXVideoEnc * self)
|
|||
GstVideoCodecFrame *frame;
|
||||
GstFlowReturn flow_ret = GST_FLOW_OK;
|
||||
GstOMXAcquireBufferReturn acq_return;
|
||||
gboolean is_eos;
|
||||
OMX_ERRORTYPE err;
|
||||
|
||||
klass = GST_OMX_VIDEO_ENC_GET_CLASS (self);
|
||||
|
@ -750,6 +749,8 @@ gst_omx_video_enc_loop (GstOMXVideoEnc * self)
|
|||
goto component_error;
|
||||
} else if (acq_return == GST_OMX_ACQUIRE_BUFFER_FLUSHING) {
|
||||
goto flushing;
|
||||
} else if (acq_return == GST_OMX_ACQUIRE_BUFFER_EOS) {
|
||||
goto eos;
|
||||
}
|
||||
|
||||
if (!gst_pad_has_current_caps (GST_VIDEO_ENCODER_SRC_PAD (self))
|
||||
|
@ -845,45 +846,22 @@ gst_omx_video_enc_loop (GstOMXVideoEnc * self)
|
|||
goto flushing;
|
||||
}
|
||||
|
||||
if (buf) {
|
||||
GST_DEBUG_OBJECT (self, "Handling buffer: 0x%08x %lu", buf->omx_buf->nFlags,
|
||||
buf->omx_buf->nTimeStamp);
|
||||
|
||||
GST_VIDEO_ENCODER_STREAM_LOCK (self);
|
||||
frame = _find_nearest_frame (self, buf);
|
||||
|
||||
is_eos = ! !(buf->omx_buf->nFlags & OMX_BUFFERFLAG_EOS);
|
||||
|
||||
g_assert (klass->handle_output_frame);
|
||||
flow_ret =
|
||||
klass->handle_output_frame (self, self->enc_out_port, buf, frame);
|
||||
flow_ret = klass->handle_output_frame (self, self->enc_out_port, buf, frame);
|
||||
|
||||
if (is_eos || flow_ret == GST_FLOW_EOS) {
|
||||
g_mutex_lock (&self->drain_lock);
|
||||
if (self->draining) {
|
||||
GST_DEBUG_OBJECT (self, "Drained");
|
||||
self->draining = FALSE;
|
||||
g_cond_broadcast (&self->drain_cond);
|
||||
} else if (flow_ret == GST_FLOW_OK) {
|
||||
GST_DEBUG_OBJECT (self, "Component signalled EOS");
|
||||
flow_ret = GST_FLOW_EOS;
|
||||
}
|
||||
g_mutex_unlock (&self->drain_lock);
|
||||
} else {
|
||||
GST_DEBUG_OBJECT (self, "Finished frame: %s",
|
||||
gst_flow_get_name (flow_ret));
|
||||
}
|
||||
GST_DEBUG_OBJECT (self, "Finished frame: %s", gst_flow_get_name (flow_ret));
|
||||
|
||||
err = gst_omx_port_release_buffer (port, buf);
|
||||
if (err != OMX_ErrorNone)
|
||||
goto release_error;
|
||||
|
||||
self->downstream_flow_ret = flow_ret;
|
||||
} else {
|
||||
g_assert ((klass->cdata.hacks & GST_OMX_HACK_NO_EMPTY_EOS_BUFFER));
|
||||
GST_VIDEO_ENCODER_STREAM_LOCK (self);
|
||||
flow_ret = GST_FLOW_EOS;
|
||||
}
|
||||
|
||||
GST_DEBUG_OBJECT (self, "Read frame from component");
|
||||
|
||||
|
@ -914,6 +892,28 @@ flushing:
|
|||
self->started = FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
eos:
|
||||
{
|
||||
g_mutex_lock (&self->drain_lock);
|
||||
if (self->draining) {
|
||||
GST_DEBUG_OBJECT (self, "Drained");
|
||||
self->draining = FALSE;
|
||||
g_cond_broadcast (&self->drain_cond);
|
||||
flow_ret = GST_FLOW_OK;
|
||||
} else {
|
||||
GST_DEBUG_OBJECT (self, "Component signalled EOS");
|
||||
flow_ret = GST_FLOW_EOS;
|
||||
}
|
||||
g_mutex_unlock (&self->drain_lock);
|
||||
|
||||
if (flow_ret != GST_FLOW_OK)
|
||||
goto flow_error;
|
||||
|
||||
GST_VIDEO_ENCODER_STREAM_UNLOCK (self);
|
||||
|
||||
return;
|
||||
}
|
||||
flow_error:
|
||||
{
|
||||
if (flow_ret == GST_FLOW_EOS) {
|
||||
|
|
Loading…
Reference in a new issue