Esempio n. 1
0
static void
flac_decode_internal(struct decoder * decoder,
		     struct input_stream *input_stream,
		     bool is_ogg)
{
	FLAC__StreamDecoder *flac_dec;
	struct flac_data data;

	flac_dec = flac_decoder_new();
	if (flac_dec == NULL)
		return;

	flac_data_init(&data, decoder, input_stream);
	data.tag = tag_new();

	FLAC__StreamDecoderInitStatus status =
		stream_init(flac_dec, &data, is_ogg);
	if (status != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
		flac_data_deinit(&data);
		FLAC__stream_decoder_delete(flac_dec);
#if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7
		g_warning("%s", FLAC__StreamDecoderInitStatusString[status]);
#endif
		return;
	}

	if (!flac_decoder_initialize(&data, flac_dec, 0)) {
		flac_data_deinit(&data);
		FLAC__stream_decoder_finish(flac_dec);
		FLAC__stream_decoder_delete(flac_dec);
		return;
	}

	flac_decoder_loop(&data, flac_dec, 0, 0);

	flac_data_deinit(&data);

	FLAC__stream_decoder_finish(flac_dec);
	FLAC__stream_decoder_delete(flac_dec);
}
Esempio n. 2
0
static void
flac_decode_internal(struct decoder * decoder,
		     struct input_stream *input_stream,
		     bool is_ogg)
{
	FLAC__StreamDecoder *flac_dec;
	struct flac_data data;
	const char *err = NULL;

	flac_dec = flac_decoder_new();
	if (flac_dec == NULL)
		return;

	flac_data_init(&data, decoder, input_stream);
	data.tag = tag_new();

	if (is_ogg) {
#if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7
		FLAC__StreamDecoderInitStatus status =
			FLAC__stream_decoder_init_ogg_stream(flac_dec,
							     flac_read_cb,
							     flac_seek_cb,
							     flac_tell_cb,
							     flac_length_cb,
							     flac_eof_cb,
							     flac_write_cb,
							     flacMetadata,
							     flac_error_cb,
							     (void *)&data);
		if (status != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
			err = "doing Ogg init()";
			goto fail;
		}
#else
		goto fail;
#endif
	} else {
		FLAC__StreamDecoderInitStatus status =
			FLAC__stream_decoder_init_stream(flac_dec,
							 flac_read_cb,
							 flac_seek_cb,
							 flac_tell_cb,
							 flac_length_cb,
							 flac_eof_cb,
							 flac_write_cb,
							 flacMetadata,
							 flac_error_cb,
							 (void *)&data);
		if (status != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
			err = "doing init()";
			goto fail;
		}
	}

	if (!flac_decoder_initialize(&data, flac_dec, 0)) {
		flac_data_deinit(&data);
		FLAC__stream_decoder_delete(flac_dec);
		return;
	}

	flac_decoder_loop(&data, flac_dec, 0, 0);

fail:
	flac_data_deinit(&data);
	FLAC__stream_decoder_delete(flac_dec);

	if (err)
		g_warning("%s\n", err);
}