omx: Refactor code flow a bit if output port settings have changed

This commit is contained in:
Sebastian Dröge 2013-02-27 16:55:16 +01:00
parent b12610efd7
commit e42faae652
3 changed files with 130 additions and 122 deletions

View file

@ -295,10 +295,19 @@ 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_RECONFIGURE) {
}
if (!gst_pad_has_current_caps (GST_AUDIO_ENCODER_SRC_PAD (self))
|| acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
GstAudioInfo *info =
gst_audio_encoder_get_audio_info (GST_AUDIO_ENCODER (self));
GstCaps *caps;
OMX_ERRORTYPE err;
GST_DEBUG_OBJECT (self, "Port settings have changed, updating caps");
/* Reallocate all buffers */
if (acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
err = gst_omx_port_set_enabled (port, FALSE);
if (err != OMX_ErrorNone)
goto reconfigure_error;
@ -315,33 +324,9 @@ gst_omx_audio_enc_loop (GstOMXAudioEnc * self)
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_set_enabled (port, TRUE);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_allocate_buffers (port);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_wait_enabled (port, 5 * GST_SECOND);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_mark_reconfigured (port);
if (err != OMX_ErrorNone)
goto reconfigure_error;
/* Update caps below */
}
GST_AUDIO_ENCODER_STREAM_LOCK (self);
if (!gst_pad_has_current_caps (GST_AUDIO_ENCODER_SRC_PAD (self))
|| acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
GstAudioInfo *info =
gst_audio_encoder_get_audio_info (GST_AUDIO_ENCODER (self));
GstCaps *caps;
GST_DEBUG_OBJECT (self, "Port settings have changed, updating caps");
caps = klass->get_caps (self, self->enc_out_port, info);
if (!caps) {
@ -362,13 +347,31 @@ gst_omx_audio_enc_loop (GstOMXAudioEnc * self)
}
gst_caps_unref (caps);
GST_AUDIO_ENCODER_STREAM_UNLOCK (self);
if (acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
err = gst_omx_port_set_enabled (port, TRUE);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_allocate_buffers (port);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_wait_enabled (port, 5 * GST_SECOND);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_mark_reconfigured (port);
if (err != OMX_ErrorNone)
goto reconfigure_error;
}
/* Now get a buffer */
if (acq_return != GST_OMX_ACQUIRE_BUFFER_OK) {
GST_AUDIO_ENCODER_STREAM_UNLOCK (self);
return;
}
}
GST_AUDIO_ENCODER_STREAM_UNLOCK (self);
g_assert (acq_return == GST_OMX_ACQUIRE_BUFFER_OK);

View file

@ -564,10 +564,19 @@ gst_omx_video_dec_loop (GstOMXVideoDec * self)
goto component_error;
} else if (acq_return == GST_OMX_ACQUIRE_BUFFER_FLUSHING) {
goto flushing;
} else if (acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
}
if (!gst_pad_has_current_caps (GST_VIDEO_DECODER_SRC_PAD (self)) ||
acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
OMX_ERRORTYPE err;
GstVideoCodecState *state;
OMX_PARAM_PORTDEFINITIONTYPE port_def;
GstVideoFormat format;
GST_DEBUG_OBJECT (self, "Port settings have changed, updating caps");
/* Reallocate all buffers */
if (acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
err = gst_omx_port_set_enabled (port, FALSE);
if (err != OMX_ErrorNone)
goto reconfigure_error;
@ -583,34 +592,10 @@ gst_omx_video_dec_loop (GstOMXVideoDec * self)
err = gst_omx_port_wait_enabled (port, 1 * GST_SECOND);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_set_enabled (port, TRUE);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_allocate_buffers (port);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_wait_enabled (port, 5 * GST_SECOND);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_mark_reconfigured (port);
if (err != OMX_ErrorNone)
goto reconfigure_error;
/* Update caps below */
}
GST_VIDEO_DECODER_STREAM_LOCK (self);
if (!gst_pad_has_current_caps (GST_VIDEO_DECODER_SRC_PAD (self))
|| acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
GstVideoCodecState *state;
OMX_PARAM_PORTDEFINITIONTYPE port_def;
GstVideoFormat format;
GST_DEBUG_OBJECT (self, "Port settings have changed, updating caps");
gst_omx_port_get_port_definition (port, &port_def);
g_assert (port_def.format.video.eCompressionFormat ==
@ -658,13 +643,31 @@ gst_omx_video_dec_loop (GstOMXVideoDec * self)
gst_video_codec_state_unref (state);
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
if (acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
err = gst_omx_port_set_enabled (port, TRUE);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_allocate_buffers (port);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_wait_enabled (port, 5 * GST_SECOND);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_mark_reconfigured (port);
if (err != OMX_ErrorNone)
goto reconfigure_error;
}
/* Now get a buffer */
if (acq_return != GST_OMX_ACQUIRE_BUFFER_OK) {
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
return;
}
}
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
g_assert (acq_return == GST_OMX_ACQUIRE_BUFFER_OK);

View file

@ -746,9 +746,17 @@ 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_RECONFIGURE) {
}
if (!gst_pad_has_current_caps (GST_VIDEO_ENCODER_SRC_PAD (self))
|| acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
GstCaps *caps;
GstVideoCodecState *state;
OMX_ERRORTYPE err;
GST_DEBUG_OBJECT (self, "Port settings have changed, updating caps");
if (acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
/* Reallocate all buffers */
err = gst_omx_port_set_enabled (port, FALSE);
if (err != OMX_ErrorNone)
@ -765,33 +773,9 @@ gst_omx_video_enc_loop (GstOMXVideoEnc * self)
err = gst_omx_port_wait_enabled (port, 1 * GST_SECOND);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_set_enabled (port, TRUE);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_allocate_buffers (port);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_wait_enabled (port, 5 * GST_SECOND);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_mark_reconfigured (port);
if (err != OMX_ErrorNone)
goto reconfigure_error;
/* Update caps below */
}
GST_VIDEO_ENCODER_STREAM_LOCK (self);
if (!gst_pad_has_current_caps (GST_VIDEO_ENCODER_SRC_PAD (self))
|| acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
GstCaps *caps;
GstVideoCodecState *state;
GST_DEBUG_OBJECT (self, "Port settings have changed, updating caps");
caps = klass->get_caps (self, self->enc_out_port, self->input_state);
if (!caps) {
@ -815,13 +799,31 @@ gst_omx_video_enc_loop (GstOMXVideoEnc * self)
goto caps_failed;
}
GST_VIDEO_ENCODER_STREAM_UNLOCK (self);
if (acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
err = gst_omx_port_set_enabled (port, TRUE);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_allocate_buffers (port);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_wait_enabled (port, 5 * GST_SECOND);
if (err != OMX_ErrorNone)
goto reconfigure_error;
err = gst_omx_port_mark_reconfigured (port);
if (err != OMX_ErrorNone)
goto reconfigure_error;
}
/* Now get a buffer */
if (acq_return != GST_OMX_ACQUIRE_BUFFER_OK) {
GST_VIDEO_ENCODER_STREAM_UNLOCK (self);
return;
}
}
GST_VIDEO_ENCODER_STREAM_UNLOCK (self);
g_assert (acq_return == GST_OMX_ACQUIRE_BUFFER_OK);