omxvideoenc: Better handling of encoder parameters

Only set them if necessary and allow to use the component
defaults.
This commit is contained in:
Sebastian Dröge 2011-11-02 13:50:14 +01:00
parent 08fabd6a07
commit ef67a43702
2 changed files with 86 additions and 50 deletions

View file

@ -45,6 +45,7 @@ gst_omx_video_enc_control_rate_get_type (void)
"variable-skip-frames"}, "variable-skip-frames"},
{OMX_Video_ControlRateConstantSkipFrames, "Constant Skip Frames", {OMX_Video_ControlRateConstantSkipFrames, "Constant Skip Frames",
"constant-skip-frames"}, "constant-skip-frames"},
{0xffffffff, "Component Default", "default"},
{0, NULL, NULL} {0, NULL, NULL}
}; };
@ -99,11 +100,11 @@ enum
}; };
/* FIXME: Better defaults */ /* FIXME: Better defaults */
#define GST_OMX_VIDEO_ENC_CONTROL_RATE_DEFAULT (OMX_Video_ControlRateConstant) #define GST_OMX_VIDEO_ENC_CONTROL_RATE_DEFAULT (0xffffffff)
#define GST_OMX_VIDEO_ENC_TARGET_BITRATE_DEFAULT (64000) #define GST_OMX_VIDEO_ENC_TARGET_BITRATE_DEFAULT (0xffffffff)
#define GST_OMX_VIDEO_ENC_QUANT_I_FRAMES_DEFAULT (9) #define GST_OMX_VIDEO_ENC_QUANT_I_FRAMES_DEFAULT (0xffffffff)
#define GST_OMX_VIDEO_ENC_QUANT_P_FRAMES_DEFAULT (6) #define GST_OMX_VIDEO_ENC_QUANT_P_FRAMES_DEFAULT (0xffffffff)
#define GST_OMX_VIDEO_ENC_QUANT_B_FRAMES_DEFAULT (2) #define GST_OMX_VIDEO_ENC_QUANT_B_FRAMES_DEFAULT (0xffffffff)
/* class initialization */ /* class initialization */
@ -271,28 +272,28 @@ gst_omx_video_enc_class_init (GstOMXVideoEncClass * klass)
g_object_class_install_property (gobject_class, PROP_TARGET_BITRATE, g_object_class_install_property (gobject_class, PROP_TARGET_BITRATE,
g_param_spec_uint ("target-bitrate", "Target Bitrate", g_param_spec_uint ("target-bitrate", "Target Bitrate",
"Target bitrate", "Target bitrate (0xffffffff=component default)",
0, G_MAXUINT, GST_OMX_VIDEO_ENC_TARGET_BITRATE_DEFAULT, 0, G_MAXUINT, GST_OMX_VIDEO_ENC_TARGET_BITRATE_DEFAULT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
GST_PARAM_MUTABLE_PLAYING)); GST_PARAM_MUTABLE_PLAYING));
g_object_class_install_property (gobject_class, PROP_QUANT_I_FRAMES, g_object_class_install_property (gobject_class, PROP_QUANT_I_FRAMES,
g_param_spec_uint ("quant-i-frames", "I-Frame Quantization", g_param_spec_uint ("quant-i-frames", "I-Frame Quantization",
"Quantization parameter for I-frames", "Quantization parameter for I-frames (0xffffffff=component default)",
0, G_MAXUINT, GST_OMX_VIDEO_ENC_QUANT_I_FRAMES_DEFAULT, 0, G_MAXUINT, GST_OMX_VIDEO_ENC_QUANT_I_FRAMES_DEFAULT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
GST_PARAM_MUTABLE_READY)); GST_PARAM_MUTABLE_READY));
g_object_class_install_property (gobject_class, PROP_QUANT_P_FRAMES, g_object_class_install_property (gobject_class, PROP_QUANT_P_FRAMES,
g_param_spec_uint ("quant-p-frames", "P-Frame Quantization", g_param_spec_uint ("quant-p-frames", "P-Frame Quantization",
"Quantization parameter for P-frames", "Quantization parameter for P-frames (0xffffffff=component default)",
0, G_MAXUINT, GST_OMX_VIDEO_ENC_QUANT_P_FRAMES_DEFAULT, 0, G_MAXUINT, GST_OMX_VIDEO_ENC_QUANT_P_FRAMES_DEFAULT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
GST_PARAM_MUTABLE_READY)); GST_PARAM_MUTABLE_READY));
g_object_class_install_property (gobject_class, PROP_QUANT_B_FRAMES, g_object_class_install_property (gobject_class, PROP_QUANT_B_FRAMES,
g_param_spec_uint ("quant-b-frames", "B-Frame Quantization", g_param_spec_uint ("quant-b-frames", "B-Frame Quantization",
"Quantization parameter for B-frames", "Quantization parameter for B-frames (0xffffffff=component default)",
0, G_MAXUINT, GST_OMX_VIDEO_ENC_QUANT_B_FRAMES_DEFAULT, 0, G_MAXUINT, GST_OMX_VIDEO_ENC_QUANT_B_FRAMES_DEFAULT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
GST_PARAM_MUTABLE_READY)); GST_PARAM_MUTABLE_READY));
@ -355,52 +356,87 @@ gst_omx_video_enc_open (GstOMXVideoEnc * self)
/* Set properties */ /* Set properties */
{ {
OMX_VIDEO_PARAM_BITRATETYPE bitrate_param;
OMX_VIDEO_PARAM_QUANTIZATIONTYPE quant_param;
OMX_ERRORTYPE err; OMX_ERRORTYPE err;
GST_OMX_INIT_STRUCT (&bitrate_param); if (self->control_rate != 0xffffffff || self->target_bitrate != 0xffffffff) {
bitrate_param.nPortIndex = self->out_port->index; OMX_VIDEO_PARAM_BITRATETYPE bitrate_param;
bitrate_param.eControlRate = self->control_rate;
bitrate_param.nTargetBitrate = self->target_bitrate;
err = GST_OMX_INIT_STRUCT (&bitrate_param);
gst_omx_component_set_parameter (self->component, bitrate_param.nPortIndex = self->out_port->index;
OMX_IndexParamVideoBitrate, &bitrate_param);
if (err == OMX_ErrorUnsupportedIndex) { err = gst_omx_component_get_parameter (self->component,
GST_WARNING_OBJECT (self, OMX_IndexParamVideoBitrate, &bitrate_param);
"Setting a bitrate not supported by the component");
} else if (err == OMX_ErrorUnsupportedSetting) { if (err == OMX_ErrorNone) {
GST_WARNING_OBJECT (self, if (self->control_rate != 0xffffffff)
"Setting bitrate settings %u %u not supported by the component", bitrate_param.eControlRate = self->control_rate;
self->control_rate, self->target_bitrate); if (self->target_bitrate != 0xffffffff)
} else if (err != OMX_ErrorNone) { bitrate_param.nTargetBitrate = self->target_bitrate;
GST_ERROR_OBJECT (self, "Failed to set bitrate parameters: %s (0x%08x)",
gst_omx_error_to_string (err), err); err =
return FALSE; gst_omx_component_set_parameter (self->component,
OMX_IndexParamVideoBitrate, &bitrate_param);
if (err == OMX_ErrorUnsupportedIndex) {
GST_WARNING_OBJECT (self,
"Setting a bitrate not supported by the component");
} else if (err == OMX_ErrorUnsupportedSetting) {
GST_WARNING_OBJECT (self,
"Setting bitrate settings %u %u not supported by the component",
self->control_rate, self->target_bitrate);
} 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;
}
} else {
GST_ERROR_OBJECT (self, "Failed to get bitrate parameters: %s (0x%08x)",
gst_omx_error_to_string (err), err);
}
} }
GST_OMX_INIT_STRUCT (&quant_param); if (self->quant_i_frames != 0xffffffff ||
quant_param.nPortIndex = self->out_port->index; self->quant_p_frames != 0xffffffff ||
quant_param.nQpI = self->quant_i_frames; self->quant_b_frames != 0xffffffff) {
quant_param.nQpP = self->quant_p_frames; OMX_VIDEO_PARAM_QUANTIZATIONTYPE quant_param;
quant_param.nQpB = self->quant_b_frames;
err = GST_OMX_INIT_STRUCT (&quant_param);
gst_omx_component_set_parameter (self->component, quant_param.nPortIndex = self->out_port->index;
OMX_IndexParamVideoQuantization, &quant_param);
if (err == OMX_ErrorUnsupportedIndex) { err = gst_omx_component_get_parameter (self->component,
GST_WARNING_OBJECT (self, OMX_IndexParamVideoQuantization, &quant_param);
"Setting quantization parameters not supported by the component");
} else if (err == OMX_ErrorUnsupportedSetting) { if (err == OMX_ErrorNone) {
GST_WARNING_OBJECT (self,
"Setting quantization parameters %u %u %u not supported by the component", if (self->quant_i_frames != 0xffffffff)
self->quant_i_frames, self->quant_p_frames, self->quant_b_frames); quant_param.nQpI = self->quant_i_frames;
} else if (err != OMX_ErrorNone) { if (self->quant_p_frames != 0xffffffff)
GST_ERROR_OBJECT (self, quant_param.nQpP = self->quant_p_frames;
"Failed to set quantization parameters: %s (0x%08x)", if (self->quant_b_frames != 0xffffffff)
gst_omx_error_to_string (err), err); quant_param.nQpB = self->quant_b_frames;
return FALSE;
err =
gst_omx_component_set_parameter (self->component,
OMX_IndexParamVideoQuantization, &quant_param);
if (err == OMX_ErrorUnsupportedIndex) {
GST_WARNING_OBJECT (self,
"Setting quantization parameters not supported by the component");
} else if (err == OMX_ErrorUnsupportedSetting) {
GST_WARNING_OBJECT (self,
"Setting quantization parameters %u %u %u not supported by the component",
self->quant_i_frames, self->quant_p_frames, self->quant_b_frames);
} 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;
}
} else {
GST_ERROR_OBJECT (self,
"Failed to get quantization parameters: %s (0x%08x)",
gst_omx_error_to_string (err), err);
}
} }
} }

View file

@ -65,7 +65,7 @@ struct _GstOMXVideoEnc
gboolean draining; gboolean draining;
/* properties */ /* properties */
OMX_VIDEO_CONTROLRATETYPE control_rate; guint32 control_rate;
guint32 target_bitrate; guint32 target_bitrate;
guint32 quant_i_frames; guint32 quant_i_frames;
guint32 quant_p_frames; guint32 quant_p_frames;