Пример #1
0
static void
mp3_decode(struct decoder *decoder, struct input_stream *input_stream)
{
	struct mp3_data data;
	GError *error = NULL;
	struct tag *tag = NULL;
	struct audio_format audio_format;

	if (!mp3_open(input_stream, &data, decoder, &tag)) {
		if (decoder_get_command(decoder) == DECODE_COMMAND_NONE)
			g_warning
			    ("Input does not appear to be a mp3 bit stream.\n");
		return;
	}

	if (!audio_format_init_checked(&audio_format,
				       data.frame.header.samplerate,
				       SAMPLE_FORMAT_S24_P32,
				       MAD_NCHANNELS(&data.frame.header),
				       &error)) {
		g_warning("%s", error->message);
		g_error_free(error);

		if (tag != NULL)
			tag_free(tag);
		mp3_data_finish(&data);
		return;
	}

	decoder_initialized(decoder, &audio_format,
			    data.input_stream->seekable, data.total_time);

	if (tag != NULL) {
		decoder_tag(decoder, input_stream, tag);
		tag_free(tag);
	}

	while (mp3_read(&data)) ;

	mp3_data_finish(&data);
}
Пример #2
0
static bool
mp3_open(struct input_stream *is, struct mp3_data *data,
	 struct decoder *decoder, struct tag **tag)
{
	mp3_data_init(data, decoder, is);
	*tag = NULL;
	if (!mp3_decode_first_frame(data, tag)) {
		mp3_data_finish(data);
		if (tag && *tag)
			tag_free(*tag);
		return false;
	}

	return true;
}
Пример #3
0
/* this is primarily used for getting total time for tags */
static int
mad_decoder_total_file_time(struct input_stream *is)
{
	struct mp3_data data;
	int ret;

	mp3_data_init(&data, NULL, is);
	if (!mp3_decode_first_frame(&data, NULL))
		ret = -1;
	else
		ret = data.total_time + 0.5;
	mp3_data_finish(&data);

	return ret;
}
Пример #4
0
/* this is primarily used for getting total time for tags */
static int mp3_total_file_time(const char *file)
{
	struct input_stream input_stream;
	struct mp3_data data;
	int ret;

	if (!input_stream_open(&input_stream, file))
		return -1;
	mp3_data_init(&data, NULL, &input_stream);
	if (!mp3_decode_first_frame(&data, NULL, NULL))
		ret = -1;
	else
		ret = data.total_time + 0.5;
	mp3_data_finish(&data);
	input_stream_close(&input_stream);

	return ret;
}
Пример #5
0
static void
mp3_decode(struct decoder *decoder, struct input_stream *input_stream)
{
	struct mp3_data data;
	struct tag *tag = NULL;
	struct replay_gain_info *replay_gain_info = NULL;
	struct audio_format audio_format;

	if (!mp3_open(input_stream, &data, decoder, &tag, &replay_gain_info)) {
		if (decoder_get_command(decoder) == DECODE_COMMAND_NONE)
			g_warning
			    ("Input does not appear to be a mp3 bit stream.\n");
		return;
	}

	mp3_audio_format(&data, &audio_format);

	decoder_initialized(decoder, &audio_format,
			    data.input_stream->seekable, data.total_time);

	if (tag != NULL) {
		decoder_tag(decoder, input_stream, tag);
		tag_free(tag);
	}

	while (mp3_read(&data, &replay_gain_info)) ;

	if (replay_gain_info)
		replay_gain_info_free(replay_gain_info);

	if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK &&
	    data.mute_frame == MUTEFRAME_SEEK)
		decoder_command_finished(decoder);

	mp3_data_finish(&data);
}