omx: Auto-detect the port indizes if possible

This commit is contained in:
Sebastian Dröge 2013-02-25 12:38:27 +01:00
parent 3e090dd83b
commit 5b45cb0810
4 changed files with 103 additions and 27 deletions

View file

@ -2587,9 +2587,9 @@ _class_init (gpointer g_class, gpointer data)
in_port_index = in_port_index =
g_key_file_get_integer (config, element_name, "in-port-index", &err); g_key_file_get_integer (config, element_name, "in-port-index", &err);
if (err != NULL) { if (err != NULL) {
GST_DEBUG ("No 'in-port-index' set for element '%s', assuming 0: %s", GST_DEBUG ("No 'in-port-index' set for element '%s', auto-detecting: %s",
element_name, err->message); element_name, err->message);
in_port_index = 0; in_port_index = -1;
g_error_free (err); g_error_free (err);
} }
class_data->in_port_index = in_port_index; class_data->in_port_index = in_port_index;
@ -2598,9 +2598,9 @@ _class_init (gpointer g_class, gpointer data)
out_port_index = out_port_index =
g_key_file_get_integer (config, element_name, "out-port-index", &err); g_key_file_get_integer (config, element_name, "out-port-index", &err);
if (err != NULL) { if (err != NULL) {
GST_DEBUG ("No 'out-port-index' set for element '%s', assuming 1: %s", GST_DEBUG ("No 'out-port-index' set for element '%s', auto-detecting: %s",
element_name, err->message); element_name, err->message);
out_port_index = 1; out_port_index = -1;
g_error_free (err); g_error_free (err);
} }
class_data->out_port_index = out_port_index; class_data->out_port_index = out_port_index;

View file

@ -103,6 +103,7 @@ static gboolean
gst_omx_audio_enc_open (GstOMXAudioEnc * self) gst_omx_audio_enc_open (GstOMXAudioEnc * self)
{ {
GstOMXAudioEncClass *klass = GST_OMX_AUDIO_ENC_GET_CLASS (self); GstOMXAudioEncClass *klass = GST_OMX_AUDIO_ENC_GET_CLASS (self);
gint in_port_index, out_port_index;
self->enc = self->enc =
gst_omx_component_new (GST_OBJECT_CAST (self), klass->cdata.core_name, gst_omx_component_new (GST_OBJECT_CAST (self), klass->cdata.core_name,
@ -117,10 +118,34 @@ gst_omx_audio_enc_open (GstOMXAudioEnc * self)
GST_CLOCK_TIME_NONE) != OMX_StateLoaded) GST_CLOCK_TIME_NONE) != OMX_StateLoaded)
return FALSE; return FALSE;
self->enc_in_port = in_port_index = klass->cdata.in_port_index;
gst_omx_component_add_port (self->enc, klass->cdata.in_port_index); out_port_index = klass->cdata.out_port_index;
self->enc_out_port =
gst_omx_component_add_port (self->enc, klass->cdata.out_port_index); if (in_port_index == -1 || out_port_index == -1) {
OMX_PORT_PARAM_TYPE param;
OMX_ERRORTYPE err;
GST_OMX_INIT_STRUCT (&param);
err =
gst_omx_component_get_parameter (self->enc, OMX_IndexParamAudioInit,
&param);
if (err != OMX_ErrorNone) {
GST_WARNING_OBJECT (self, "Couldn't get port information: %s (0x%08x)",
gst_omx_error_to_string (err), err);
/* Fallback */
in_port_index = 0;
out_port_index = 1;
} else {
GST_DEBUG_OBJECT (self, "Detected %u ports, starting at %u", param.nPorts,
param.nStartPortNumber);
in_port_index = param.nStartPortNumber + 0;
out_port_index = param.nStartPortNumber + 1;
}
}
self->enc_in_port = gst_omx_component_add_port (self->enc, in_port_index);
self->enc_out_port = gst_omx_component_add_port (self->enc, out_port_index);
if (!self->enc_in_port || !self->enc_out_port) if (!self->enc_in_port || !self->enc_out_port)
return FALSE; return FALSE;

View file

@ -127,6 +127,7 @@ gst_omx_video_dec_open (GstVideoDecoder * decoder)
{ {
GstOMXVideoDec *self = GST_OMX_VIDEO_DEC (decoder); GstOMXVideoDec *self = GST_OMX_VIDEO_DEC (decoder);
GstOMXVideoDecClass *klass = GST_OMX_VIDEO_DEC_GET_CLASS (self); GstOMXVideoDecClass *klass = GST_OMX_VIDEO_DEC_GET_CLASS (self);
gint in_port_index, out_port_index;
GST_DEBUG_OBJECT (self, "Opening decoder"); GST_DEBUG_OBJECT (self, "Opening decoder");
@ -143,10 +144,33 @@ gst_omx_video_dec_open (GstVideoDecoder * decoder)
GST_CLOCK_TIME_NONE) != OMX_StateLoaded) GST_CLOCK_TIME_NONE) != OMX_StateLoaded)
return FALSE; return FALSE;
self->dec_in_port = in_port_index = klass->cdata.in_port_index;
gst_omx_component_add_port (self->dec, klass->cdata.in_port_index); out_port_index = klass->cdata.out_port_index;
self->dec_out_port =
gst_omx_component_add_port (self->dec, klass->cdata.out_port_index); if (in_port_index == -1 || out_port_index == -1) {
OMX_PORT_PARAM_TYPE param;
OMX_ERRORTYPE err;
GST_OMX_INIT_STRUCT (&param);
err =
gst_omx_component_get_parameter (self->dec, OMX_IndexParamVideoInit,
&param);
if (err != OMX_ErrorNone) {
GST_WARNING_OBJECT (self, "Couldn't get port information: %s (0x%08x)",
gst_omx_error_to_string (err), err);
/* Fallback */
in_port_index = 0;
out_port_index = 1;
} else {
GST_DEBUG_OBJECT (self, "Detected %u ports, starting at %u", param.nPorts,
param.nStartPortNumber);
in_port_index = param.nStartPortNumber + 0;
out_port_index = param.nStartPortNumber + 1;
}
}
self->dec_in_port = gst_omx_component_add_port (self->dec, in_port_index);
self->dec_out_port = gst_omx_component_add_port (self->dec, out_port_index);
if (!self->dec_in_port || !self->dec_out_port) if (!self->dec_in_port || !self->dec_out_port)
return FALSE; return FALSE;
@ -256,8 +280,8 @@ gst_omx_video_dec_change_state (GstElement * element, GstStateChange transition)
return ret; return ret;
ret = ret =
GST_ELEMENT_CLASS (gst_omx_video_dec_parent_class)->change_state (element, GST_ELEMENT_CLASS (gst_omx_video_dec_parent_class)->change_state
transition); (element, transition);
if (ret == GST_STATE_CHANGE_FAILURE) if (ret == GST_STATE_CHANGE_FAILURE)
return ret; return ret;
@ -369,8 +393,8 @@ _find_nearest_frame (GstOMXVideoDec * self, GstOMXBuffer * buf)
} }
static gboolean static gboolean
gst_omx_video_dec_fill_buffer (GstOMXVideoDec * self, GstOMXBuffer * inbuf, gst_omx_video_dec_fill_buffer (GstOMXVideoDec * self,
GstBuffer * outbuf) GstOMXBuffer * inbuf, GstBuffer * outbuf)
{ {
GstVideoCodecState *state = GstVideoCodecState *state =
gst_video_decoder_get_output_state (GST_VIDEO_DECODER (self)); gst_video_decoder_get_output_state (GST_VIDEO_DECODER (self));
@ -577,8 +601,8 @@ gst_omx_video_dec_loop (GstOMXVideoDec * self)
GST_DEBUG_OBJECT (self, GST_DEBUG_OBJECT (self,
"Setting output state: format %s, width %d, height %d", "Setting output state: format %s, width %d, height %d",
gst_video_format_to_string (format), port_def.format.video.nFrameWidth, gst_video_format_to_string (format),
port_def.format.video.nFrameHeight); port_def.format.video.nFrameWidth, port_def.format.video.nFrameHeight);
state = gst_video_decoder_set_output_state (GST_VIDEO_DECODER (self), state = gst_video_decoder_set_output_state (GST_VIDEO_DECODER (self),
format, port_def.format.video.nFrameWidth, format, port_def.format.video.nFrameWidth,
@ -616,8 +640,8 @@ gst_omx_video_dec_loop (GstOMXVideoDec * self)
} }
if (buf) { if (buf) {
GST_DEBUG_OBJECT (self, "Handling buffer: 0x%08x %lu", buf->omx_buf->nFlags, GST_DEBUG_OBJECT (self, "Handling buffer: 0x%08x %lu",
buf->omx_buf->nTimeStamp); buf->omx_buf->nFlags, buf->omx_buf->nTimeStamp);
GST_VIDEO_DECODER_STREAM_LOCK (self); GST_VIDEO_DECODER_STREAM_LOCK (self);
frame = _find_nearest_frame (self, buf); frame = _find_nearest_frame (self, buf);
@ -653,7 +677,8 @@ gst_omx_video_dec_loop (GstOMXVideoDec * self)
flow_ret = gst_pad_push (GST_VIDEO_DECODER_SRC_PAD (self), outbuf); flow_ret = gst_pad_push (GST_VIDEO_DECODER_SRC_PAD (self), outbuf);
} else if (buf->omx_buf->nFilledLen > 0) { } else if (buf->omx_buf->nFilledLen > 0) {
if ((flow_ret = gst_video_decoder_allocate_output_frame (GST_VIDEO_DECODER if ((flow_ret =
gst_video_decoder_allocate_output_frame (GST_VIDEO_DECODER
(self), frame)) == GST_FLOW_OK) { (self), frame)) == GST_FLOW_OK) {
/* FIXME: This currently happens because of a race condition too. /* FIXME: This currently happens because of a race condition too.
* We first need to reconfigure the output port and then the input * We first need to reconfigure the output port and then the input
@ -741,8 +766,9 @@ flow_error:
gst_event_new_eos ()); gst_event_new_eos ());
gst_pad_pause_task (GST_VIDEO_DECODER_SRC_PAD (self)); gst_pad_pause_task (GST_VIDEO_DECODER_SRC_PAD (self));
} else if (flow_ret == GST_FLOW_NOT_LINKED || flow_ret < GST_FLOW_EOS) { } else if (flow_ret == GST_FLOW_NOT_LINKED || flow_ret < GST_FLOW_EOS) {
GST_ELEMENT_ERROR (self, STREAM, FAILED, ("Internal data stream error."), GST_ELEMENT_ERROR (self, STREAM, FAILED,
("stream stopped, reason %s", gst_flow_get_name (flow_ret))); ("Internal data stream error."), ("stream stopped, reason %s",
gst_flow_get_name (flow_ret)));
gst_pad_push_event (GST_VIDEO_DECODER_SRC_PAD (self), gst_pad_push_event (GST_VIDEO_DECODER_SRC_PAD (self),
gst_event_new_eos ()); gst_event_new_eos ());

View file

@ -218,6 +218,7 @@ gst_omx_video_enc_open (GstVideoEncoder * encoder)
{ {
GstOMXVideoEnc *self = GST_OMX_VIDEO_ENC (encoder); GstOMXVideoEnc *self = GST_OMX_VIDEO_ENC (encoder);
GstOMXVideoEncClass *klass = GST_OMX_VIDEO_ENC_GET_CLASS (self); GstOMXVideoEncClass *klass = GST_OMX_VIDEO_ENC_GET_CLASS (self);
gint in_port_index, out_port_index;
self->enc = self->enc =
gst_omx_component_new (GST_OBJECT_CAST (self), klass->cdata.core_name, gst_omx_component_new (GST_OBJECT_CAST (self), klass->cdata.core_name,
@ -232,10 +233,34 @@ gst_omx_video_enc_open (GstVideoEncoder * encoder)
GST_CLOCK_TIME_NONE) != OMX_StateLoaded) GST_CLOCK_TIME_NONE) != OMX_StateLoaded)
return FALSE; return FALSE;
self->enc_in_port = in_port_index = klass->cdata.in_port_index;
gst_omx_component_add_port (self->enc, klass->cdata.in_port_index); out_port_index = klass->cdata.out_port_index;
self->enc_out_port =
gst_omx_component_add_port (self->enc, klass->cdata.out_port_index); if (in_port_index == -1 || out_port_index == -1) {
OMX_PORT_PARAM_TYPE param;
OMX_ERRORTYPE err;
GST_OMX_INIT_STRUCT (&param);
err =
gst_omx_component_get_parameter (self->enc, OMX_IndexParamVideoInit,
&param);
if (err != OMX_ErrorNone) {
GST_WARNING_OBJECT (self, "Couldn't get port information: %s (0x%08x)",
gst_omx_error_to_string (err), err);
/* Fallback */
in_port_index = 0;
out_port_index = 1;
} else {
GST_DEBUG_OBJECT (self, "Detected %u ports, starting at %u", param.nPorts,
param.nStartPortNumber);
in_port_index = param.nStartPortNumber + 0;
out_port_index = param.nStartPortNumber + 1;
}
}
self->enc_in_port = gst_omx_component_add_port (self->enc, in_port_index);
self->enc_out_port = gst_omx_component_add_port (self->enc, out_port_index);
if (!self->enc_in_port || !self->enc_out_port) if (!self->enc_in_port || !self->enc_out_port)
return FALSE; return FALSE;