Exemple #1
0
static gboolean
gst_two_lame_sink_setcaps (GstPad * pad, GstCaps * caps)
{
    GstTwoLame *twolame;
    gint out_samplerate;
    gint version;
    GstStructure *structure;
    GstCaps *othercaps;

    twolame = GST_TWO_LAME (GST_PAD_PARENT (pad));
    structure = gst_caps_get_structure (caps, 0);

    if (strcmp (gst_structure_get_name (structure), "audio/x-raw-int") == 0)
        twolame->float_input = FALSE;
    else
        twolame->float_input = TRUE;

    if (!gst_structure_get_int (structure, "rate", &twolame->samplerate))
        goto no_rate;
    if (!gst_structure_get_int (structure, "channels", &twolame->num_channels))
        goto no_channels;

    GST_DEBUG_OBJECT (twolame, "setting up twolame");
    if (!gst_two_lame_setup (twolame))
        goto setup_failed;

    out_samplerate = twolame_get_out_samplerate (twolame->glopts);
    if (out_samplerate == 0)
        goto zero_output_rate;

    if (out_samplerate != twolame->samplerate) {
        GST_WARNING_OBJECT (twolame,
                            "output samplerate %d is different from incoming samplerate %d",
                            out_samplerate, twolame->samplerate);
    }

    version = twolame_get_version (twolame->glopts);
    if (version == TWOLAME_MPEG2)
        version = 2;
    else
        version = 1;

    othercaps =
        gst_caps_new_simple ("audio/mpeg",
                             "mpegversion", G_TYPE_INT, 1,
                             "mpegaudioversion", G_TYPE_INT, version,
                             "layer", G_TYPE_INT, 2,
                             "channels", G_TYPE_INT,
                             twolame->mode == TWOLAME_MONO ? 1 : twolame->num_channels, "rate",
                             G_TYPE_INT, out_samplerate, NULL);

    /* and use these caps */
    gst_pad_set_caps (twolame->srcpad, othercaps);
    gst_caps_unref (othercaps);

    return TRUE;

no_rate:
    {
        GST_ERROR_OBJECT (twolame, "input caps have no sample rate field");
        return FALSE;
    }
no_channels:
    {
        GST_ERROR_OBJECT (twolame, "input caps have no channels field");
        return FALSE;
    }
zero_output_rate:
    {
        GST_ELEMENT_ERROR (twolame, LIBRARY, SETTINGS, (NULL),
                           ("TwoLAME decided on a zero sample rate"));
        return FALSE;
    }
setup_failed:
    {
        GST_ELEMENT_ERROR (twolame, LIBRARY, SETTINGS,
                           (_("Failed to configure TwoLAME encoder. Check your encoding parameters.")), (NULL));
        return FALSE;
    }
}
static gboolean
gst_two_lame_set_format (GstAudioEncoder * enc, GstAudioInfo * info)
{
  GstTwoLame *twolame;
  gint out_samplerate;
  gint version;
  GstCaps *othercaps;

  twolame = GST_TWO_LAME (enc);

  /* parameters already parsed for us */
  twolame->samplerate = GST_AUDIO_INFO_RATE (info);
  twolame->num_channels = GST_AUDIO_INFO_CHANNELS (info);
  twolame->float_input = !GST_AUDIO_INFO_IS_INTEGER (info);

  /* but we might be asked to reconfigure, so reset */
  gst_two_lame_release_memory (twolame);

  GST_DEBUG_OBJECT (twolame, "setting up twolame");
  if (!gst_two_lame_setup (twolame))
    goto setup_failed;

  out_samplerate = twolame_get_out_samplerate (twolame->glopts);
  if (out_samplerate == 0)
    goto zero_output_rate;

  if (out_samplerate != twolame->samplerate) {
    GST_WARNING_OBJECT (twolame,
        "output samplerate %d is different from incoming samplerate %d",
        out_samplerate, twolame->samplerate);
  }

  version = twolame_get_version (twolame->glopts);
  if (version == TWOLAME_MPEG2)
    version = 2;
  else
    version = 1;

  othercaps =
      gst_caps_new_simple ("audio/mpeg",
      "mpegversion", G_TYPE_INT, 1,
      "mpegaudioversion", G_TYPE_INT, version,
      "layer", G_TYPE_INT, 2,
      "channels", G_TYPE_INT,
      twolame->mode == TWOLAME_MONO ? 1 : twolame->num_channels, "rate",
      G_TYPE_INT, out_samplerate, NULL);

  /* and use these caps */
  gst_audio_encoder_set_output_format (GST_AUDIO_ENCODER (twolame), othercaps);
  gst_caps_unref (othercaps);

  /* report needs to base class:
   * hand one frame at a time, if we are pretty sure what a frame is */
  if (out_samplerate == twolame->samplerate) {
    gst_audio_encoder_set_frame_samples_min (enc, 1152);
    gst_audio_encoder_set_frame_samples_max (enc, 1152);
    gst_audio_encoder_set_frame_max (enc, 1);
  }

  return TRUE;

zero_output_rate:
  {
    GST_ELEMENT_ERROR (twolame, LIBRARY, SETTINGS, (NULL),
        ("TwoLAME decided on a zero sample rate"));
    return FALSE;
  }
setup_failed:
  {
    GST_ELEMENT_ERROR (twolame, LIBRARY, SETTINGS,
        (_("Failed to configure TwoLAME encoder. Check your encoding parameters.")), (NULL));
    return FALSE;
  }
}