Esempio n. 1
0
static GstVaapiEncoder *
encoder_new (GstVaapiDisplay * display)
{
  GstVaapiEncoder *encoder = NULL;

  if (!g_strcmp0 (g_codec_str, "mpeg2"))
    encoder = gst_vaapi_encoder_mpeg2_new (display);
  else if (!g_strcmp0 (g_codec_str, "h264"))
    encoder = gst_vaapi_encoder_h264_new (display);
  else
    return NULL;

  gst_vaapi_encoder_set_bitrate (encoder, g_bitrate);

  return encoder;
}
/**
 * gst_vaapi_encoder_set_property:
 * @encoder: a #GstVaapiEncoder
 * @prop_id: the id of the property to change
 * @value: the new value to set
 *
 * Update the requested property, designed by @prop_id, with the
 * supplied @value. A @NULL value argument resets the property to its
 * default value.
 *
 * Return value: a #GstVaapiEncoderStatus
 */
static GstVaapiEncoderStatus
set_property (GstVaapiEncoder * encoder, gint prop_id, const GValue * value)
{
  GstVaapiEncoderStatus status =
      GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_PARAMETER;

  g_assert (value != NULL);

  /* Handle codec-specific properties */
  if (prop_id < 0) {
    GstVaapiEncoderClass *const klass = GST_VAAPI_ENCODER_GET_CLASS (encoder);

    if (klass->set_property) {
      if (encoder->num_codedbuf_queued > 0)
        goto error_operation_failed;
      status = klass->set_property (encoder, prop_id, value);
    }
    return status;
  }

  /* Handle common properties */
  switch (prop_id) {
    case GST_VAAPI_ENCODER_PROP_RATECONTROL:
      status = gst_vaapi_encoder_set_rate_control (encoder,
          g_value_get_enum (value));
      break;
    case GST_VAAPI_ENCODER_PROP_BITRATE:
      status = gst_vaapi_encoder_set_bitrate (encoder,
          g_value_get_uint (value));
      break;
    case GST_VAAPI_ENCODER_PROP_KEYFRAME_PERIOD:
      status = gst_vaapi_encoder_set_keyframe_period (encoder,
          g_value_get_uint (value));
      break;
    case GST_VAAPI_ENCODER_PROP_TUNE:
      status = gst_vaapi_encoder_set_tuning (encoder, g_value_get_enum (value));
      break;
  }
  return status;

  /* ERRORS */
error_operation_failed:
  {
    GST_ERROR ("could not change codec state after encoding started");
    return GST_VAAPI_ENCODER_STATUS_ERROR_OPERATION_FAILED;
  }
}