omxvideoenc: Don't fail if setting the bitrate or profile is not supported by the component

Also always set/get the profile, even if there are no peer caps.
This commit is contained in:
Sebastian Dröge 2011-08-02 15:14:37 +02:00
parent 624c2b4fdb
commit 714ba59b11
4 changed files with 338 additions and 305 deletions

View file

@ -105,14 +105,14 @@ gst_omx_h263_enc_set_format (GstOMXVideoEnc * enc, GstOMXPort * port,
GstCaps *peercaps;
OMX_VIDEO_H263PROFILETYPE profile = OMX_VIDEO_H263ProfileBaseline;
OMX_VIDEO_H263LEVELTYPE level = OMX_VIDEO_H263Level10;
OMX_VIDEO_PARAM_PROFILELEVELTYPE param;
OMX_ERRORTYPE err;
peercaps = gst_pad_peer_get_caps (GST_BASE_VIDEO_CODEC_SRC_PAD (enc));
if (peercaps) {
GstStructure *s;
GstCaps *intersection;
guint profile_id, level_id;
OMX_VIDEO_PARAM_PROFILELEVELTYPE param;
OMX_ERRORTYPE err;
intersection =
gst_caps_intersect (peercaps,
@ -187,6 +187,7 @@ gst_omx_h263_enc_set_format (GstOMXVideoEnc * enc, GstOMXPort * port,
return FALSE;
}
}
}
GST_OMX_INIT_STRUCT (&param);
param.nPortIndex = GST_OMX_VIDEO_ENC (self)->out_port->index;
@ -196,13 +197,15 @@ gst_omx_h263_enc_set_format (GstOMXVideoEnc * enc, GstOMXPort * port,
err =
gst_omx_component_set_parameter (GST_OMX_VIDEO_ENC (self)->component,
OMX_IndexParamVideoProfileLevelCurrent, &param);
if (err != OMX_ErrorNone) {
if (err == OMX_ErrorUnsupportedIndex) {
GST_WARNING_OBJECT (self,
"Setting profile/level not supported by component");
} else if (err != OMX_ErrorNone) {
GST_ERROR_OBJECT (self,
"Error setting profile %d and level %d: %s (0x%08x)", profile, level,
gst_omx_error_to_string (err), err);
return FALSE;
}
}
return TRUE;
}
@ -217,15 +220,29 @@ gst_omx_h263_enc_get_caps (GstOMXVideoEnc * enc, GstOMXPort * port,
OMX_VIDEO_PARAM_PROFILELEVELTYPE param;
guint profile, level;
caps =
gst_caps_new_simple ("video/x-h263", "width", G_TYPE_INT, state->width,
"height", G_TYPE_INT, state->height, NULL);
if (state->fps_n != 0)
gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION, state->fps_n,
state->fps_d, NULL);
if (state->par_n != 1 || state->par_d != 1)
gst_caps_set_simple (caps, "pixel-aspect-ratio", GST_TYPE_FRACTION,
state->par_n, state->par_d, NULL);
GST_OMX_INIT_STRUCT (&param);
param.nPortIndex = GST_OMX_VIDEO_ENC (self)->out_port->index;
err =
gst_omx_component_get_parameter (GST_OMX_VIDEO_ENC (self)->component,
OMX_IndexParamVideoProfileLevelCurrent, &param);
if (err != OMX_ErrorNone)
if (err != OMX_ErrorNone && err != OMX_ErrorUnsupportedIndex) {
gst_caps_unref (caps);
return NULL;
}
if (err == OMX_ErrorNone) {
switch (param.eProfile) {
case OMX_VIDEO_H263ProfileBaseline:
profile = 0;
@ -286,17 +303,9 @@ gst_omx_h263_enc_get_caps (GstOMXVideoEnc * enc, GstOMXPort * port,
break;
}
caps =
gst_caps_new_simple ("video/x-h263", "width", G_TYPE_INT, state->width,
"height", G_TYPE_INT, state->height,
gst_caps_set_simple (caps,
"profile", G_TYPE_UINT, profile, "level", G_TYPE_UINT, level, NULL);
if (state->fps_n != 0)
gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION, state->fps_n,
state->fps_d, NULL);
if (state->par_n != 1 || state->par_d != 1)
gst_caps_set_simple (caps, "pixel-aspect-ratio", GST_TYPE_FRACTION,
state->par_n, state->par_d, NULL);
}
return caps;
}

View file

@ -105,14 +105,14 @@ gst_omx_h264_enc_set_format (GstOMXVideoEnc * enc, GstOMXPort * port,
GstCaps *peercaps;
OMX_VIDEO_AVCPROFILETYPE profile = OMX_VIDEO_AVCProfileBaseline;
OMX_VIDEO_AVCLEVELTYPE level = OMX_VIDEO_AVCLevel11;
OMX_VIDEO_PARAM_PROFILELEVELTYPE param;
OMX_ERRORTYPE err;
peercaps = gst_pad_peer_get_caps (GST_BASE_VIDEO_CODEC_SRC_PAD (enc));
if (peercaps) {
GstStructure *s;
GstCaps *intersection;
const gchar *profile_string, *level_string;
OMX_VIDEO_PARAM_PROFILELEVELTYPE param;
OMX_ERRORTYPE err;
intersection =
gst_caps_intersect (peercaps,
@ -185,6 +185,7 @@ gst_omx_h264_enc_set_format (GstOMXVideoEnc * enc, GstOMXPort * port,
return FALSE;
}
}
}
GST_OMX_INIT_STRUCT (&param);
param.nPortIndex = GST_OMX_VIDEO_ENC (self)->out_port->index;
@ -194,13 +195,15 @@ gst_omx_h264_enc_set_format (GstOMXVideoEnc * enc, GstOMXPort * port,
err =
gst_omx_component_set_parameter (GST_OMX_VIDEO_ENC (self)->component,
OMX_IndexParamVideoProfileLevelCurrent, &param);
if (err != OMX_ErrorNone) {
if (err == OMX_ErrorUnsupportedIndex) {
GST_WARNING_OBJECT (self,
"Setting profile/level not supported by component");
} else if (err != OMX_ErrorNone) {
GST_ERROR_OBJECT (self,
"Error setting profile %d and level %d: %s (0x%08x)", profile, level,
gst_omx_error_to_string (err), err);
return FALSE;
}
}
return TRUE;
}
@ -215,15 +218,27 @@ gst_omx_h264_enc_get_caps (GstOMXVideoEnc * enc, GstOMXPort * port,
OMX_VIDEO_PARAM_PROFILELEVELTYPE param;
const gchar *profile, *level;
caps =
gst_caps_new_simple ("video/x-h264", "width", G_TYPE_INT, state->width,
"height", G_TYPE_INT, state->height, NULL);
if (state->fps_n != 0)
gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION, state->fps_n,
state->fps_d, NULL);
if (state->par_n != 1 || state->par_d != 1)
gst_caps_set_simple (caps, "pixel-aspect-ratio", GST_TYPE_FRACTION,
state->par_n, state->par_d, NULL);
GST_OMX_INIT_STRUCT (&param);
param.nPortIndex = GST_OMX_VIDEO_ENC (self)->out_port->index;
err =
gst_omx_component_get_parameter (GST_OMX_VIDEO_ENC (self)->component,
OMX_IndexParamVideoProfileLevelCurrent, &param);
if (err != OMX_ErrorNone)
if (err != OMX_ErrorNone && err != OMX_ErrorUnsupportedIndex)
return NULL;
if (err == OMX_ErrorNone) {
switch (param.eProfile) {
case OMX_VIDEO_AVCProfileBaseline:
profile = "baseline";
@ -304,18 +319,9 @@ gst_omx_h264_enc_get_caps (GstOMXVideoEnc * enc, GstOMXPort * port,
g_assert_not_reached ();
break;
}
caps =
gst_caps_new_simple ("video/x-h264", "width", G_TYPE_INT, state->width,
"height", G_TYPE_INT, state->height,
gst_caps_set_simple (caps,
"profile", G_TYPE_STRING, profile, "level", G_TYPE_STRING, level, NULL);
if (state->fps_n != 0)
gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION, state->fps_n,
state->fps_d, NULL);
if (state->par_n != 1 || state->par_d != 1)
gst_caps_set_simple (caps, "pixel-aspect-ratio", GST_TYPE_FRACTION,
state->par_n, state->par_d, NULL);
}
return caps;
}

View file

@ -110,14 +110,14 @@ gst_omx_mpeg4_video_enc_set_format (GstOMXVideoEnc * enc, GstOMXPort * port,
GstCaps *peercaps;
OMX_VIDEO_MPEG4PROFILETYPE profile = OMX_VIDEO_MPEG4ProfileSimple;
OMX_VIDEO_MPEG4LEVELTYPE level = OMX_VIDEO_MPEG4Level1;
OMX_VIDEO_PARAM_PROFILELEVELTYPE param;
OMX_ERRORTYPE err;
peercaps = gst_pad_peer_get_caps (GST_BASE_VIDEO_CODEC_SRC_PAD (enc));
if (peercaps) {
GstStructure *s;
GstCaps *intersection;
const gchar *profile_string, *level_string;
OMX_VIDEO_PARAM_PROFILELEVELTYPE param;
OMX_ERRORTYPE err;
intersection =
gst_caps_intersect (peercaps,
@ -192,6 +192,7 @@ gst_omx_mpeg4_video_enc_set_format (GstOMXVideoEnc * enc, GstOMXPort * port,
return FALSE;
}
}
}
GST_OMX_INIT_STRUCT (&param);
param.nPortIndex = GST_OMX_VIDEO_ENC (self)->out_port->index;
@ -201,13 +202,15 @@ gst_omx_mpeg4_video_enc_set_format (GstOMXVideoEnc * enc, GstOMXPort * port,
err =
gst_omx_component_set_parameter (GST_OMX_VIDEO_ENC (self)->component,
OMX_IndexParamVideoProfileLevelCurrent, &param);
if (err != OMX_ErrorNone) {
if (err == OMX_ErrorUnsupportedIndex) {
GST_WARNING_OBJECT (self,
"Setting profile/level not supported by component");
} else if (err != OMX_ErrorNone) {
GST_ERROR_OBJECT (self,
"Error setting profile %d and level %d: %s (0x%08x)", profile, level,
gst_omx_error_to_string (err), err);
return FALSE;
}
}
return TRUE;
}
@ -222,15 +225,30 @@ gst_omx_mpeg4_video_enc_get_caps (GstOMXVideoEnc * enc, GstOMXPort * port,
OMX_VIDEO_PARAM_PROFILELEVELTYPE param;
const gchar *profile, *level;
caps =
gst_caps_new_simple ("video/mpeg", "mpegversion", G_TYPE_INT, 4,
"systemstream", G_TYPE_BOOLEAN, FALSE, "width", G_TYPE_INT, state->width,
"height", G_TYPE_INT, state->height, NULL);
if (state->fps_n != 0)
gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION, state->fps_n,
state->fps_d, NULL);
if (state->par_n != 1 || state->par_d != 1)
gst_caps_set_simple (caps, "pixel-aspect-ratio", GST_TYPE_FRACTION,
state->par_n, state->par_d, NULL);
GST_OMX_INIT_STRUCT (&param);
param.nPortIndex = GST_OMX_VIDEO_ENC (self)->out_port->index;
err =
gst_omx_component_get_parameter (GST_OMX_VIDEO_ENC (self)->component,
OMX_IndexParamVideoProfileLevelCurrent, &param);
if (err != OMX_ErrorNone)
if (err != OMX_ErrorNone && err != OMX_ErrorUnsupportedIndex) {
gst_caps_unref (caps);
return NULL;
}
if (err == OMX_ErrorNone) {
switch (param.eProfile) {
case OMX_VIDEO_MPEG4ProfileSimple:
profile = "simple";
@ -315,18 +333,9 @@ gst_omx_mpeg4_video_enc_get_caps (GstOMXVideoEnc * enc, GstOMXPort * port,
break;
}
caps =
gst_caps_new_simple ("video/mpeg", "mpegversion", G_TYPE_INT, 4,
"systemstream", G_TYPE_BOOLEAN, FALSE, "width", G_TYPE_INT, state->width,
"height", G_TYPE_INT, state->height,
gst_caps_set_simple (caps,
"profile", G_TYPE_STRING, profile, "level", G_TYPE_STRING, level, NULL);
if (state->fps_n != 0)
gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION, state->fps_n,
state->fps_d, NULL);
if (state->par_n != 1 || state->par_d != 1)
gst_caps_set_simple (caps, "pixel-aspect-ratio", GST_TYPE_FRACTION,
state->par_n, state->par_d, NULL);
}
return caps;
}

View file

@ -358,7 +358,11 @@ gst_omx_video_enc_open (GstOMXVideoEnc * self)
err =
gst_omx_component_set_parameter (self->component,
OMX_IndexParamVideoBitrate, &bitrate_param);
if (err != OMX_ErrorNone) {
if (err == OMX_ErrorUnsupportedIndex) {
GST_WARNING_OBJECT (self,
"Setting a bitrate not supported by the component");
goto done;
} else if (err != OMX_ErrorNone) {
GST_ERROR_OBJECT (self, "Failed to set bitrate parameters: %s (0x%08x)",
gst_omx_error_to_string (err), err);
return FALSE;
@ -373,13 +377,18 @@ gst_omx_video_enc_open (GstOMXVideoEnc * self)
err =
gst_omx_component_set_parameter (self->component,
OMX_IndexParamVideoQuantization, &quant_param);
if (err != OMX_ErrorNone) {
if (err == OMX_ErrorUnsupportedIndex) {
GST_WARNING_OBJECT (self,
"Setting quantization parameters not supported by the component");
goto done;
} else if (err != OMX_ErrorNone) {
GST_ERROR_OBJECT (self,
"Failed to set quantization parameters: %s (0x%08x)",
gst_omx_error_to_string (err), err);
return FALSE;
}
}
done:
return TRUE;
}