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;
  }
}
예제 #2
0
파일: gsttwolame.c 프로젝트: jwzl/ossbuild
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;
    }
}
예제 #3
0
파일: util.c 프로젝트: ruthmagnus/audacity
// Print the library version and 
//  encoder parameter settings to STDERR
void twolame_print_config(twolame_options *glopts)
{
	FILE* fd = stderr;

    // Are we being silent ?
    if (glopts->verbosity<=0) return; 
    


	// Are we being brief ?
	if (glopts->verbosity==1) {
	
		fprintf(fd, "LibTwoLame version %s (%s)\n", get_twolame_version(), get_twolame_url());
		fprintf (fd, "Encoding as %dHz, ", twolame_get_out_samplerate(glopts));
		fprintf (fd, "%d kbps, ", twolame_get_bitrate(glopts) );
		if (twolame_get_VBR(glopts)) 	fprintf (fd, "VBR, " );
		else							fprintf (fd, "CBR, " );
		fprintf (fd, "%s Layer II\n", twolame_get_version_name(glopts));
		
	} else {
	
		fprintf (fd, "---------------------------------------------------------\n");
   		fprintf (fd, "LibTwoLame %s (%s)\n", get_twolame_version(), get_twolame_url());
		fprintf (fd, "Input : %d Hz, %d channels\n",
					twolame_get_in_samplerate(glopts),
					twolame_get_num_channels(glopts));
		fprintf (fd, "Output: %d Hz, %s\n",
					twolame_get_out_samplerate(glopts), 
					twolame_get_mode_name(glopts));
		fprintf (fd, "%d kbps ", twolame_get_bitrate(glopts) );
		if (twolame_get_VBR(glopts)) 	fprintf (fd, "VBR " );
		else							fprintf (fd, "CBR " );
		fprintf (fd, "%s Layer II ", twolame_get_version_name(glopts));
		fprintf (fd, "psycho model=%d \n", twolame_get_psymodel(glopts));
		
		fprintf (fd, "[De-emph:%s    Copyright:%s   Original:%s]\n",
		((twolame_get_emphasis(glopts)) ? "On " : "Off"),
		((twolame_get_copyright(glopts)) ? "Yes" : "No "),
		((twolame_get_original(glopts)) ? "Yes" : "No "));
		
		fprintf (fd, "[Padding:%s CRC:%s         DAB:%s     ]\n",
		((twolame_get_padding(glopts)) ? "Normal" : "Off   "),
		((twolame_get_error_protection(glopts)) ? "On " : "Off"),
		((twolame_get_DAB(glopts)) ? "On " : "Off")); 
		
		if (glopts->verbosity>=3) {
			if (twolame_get_VBR(glopts)) {
				fprintf (fd, " - VBR Enabled. Using MNR boost of %f\n", twolame_get_VBR_level(glopts));
				fprintf (fd, " - VBR bitrate index limits [%i -> %i]\n", glopts->lower_index, glopts->upper_index);
			}

			fprintf(fd," - ATH adjustment %f\n", twolame_get_ATH_level(glopts));
			fprintf(fd," - Reserving %i Ancillary bits\n", twolame_get_num_ancillary_bits(glopts));
			
			if (twolame_get_scale(glopts)!=1.0f)
				fprintf(fd," - Scaling audio by %f\n", twolame_get_scale(glopts));
			if (twolame_get_scale_left(glopts)!=1.0f)
				fprintf(fd," - Scaling left channel by %f\n", twolame_get_scale_left(glopts));
			if (twolame_get_scale_right(glopts)!=1.0f)
				fprintf(fd," - Scaling right channel by %f\n", twolame_get_scale_right(glopts));

			//if (glopts->num_channels_in == 2 && glopts->num_channels_out == 1 ) {
			//	fprintf(fd, " - Downmixing from stereo to mono.\n");
			//} else if (glopts->num_channels_in == 1 && glopts->num_channels_out == 2 ) {
			//	fprintf(fd, " - Upmixing from mono to stereo.\n");
			//}
		}
		
		fprintf (fd, "---------------------------------------------------------\n");
		
	}
}