decoder/flac: add ctor/dtor to struct flac_data
This commit is contained in:
@@ -34,31 +34,22 @@ extern "C" {
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
void
|
flac_data::flac_data(struct decoder *_decoder,
|
||||||
flac_data_init(struct flac_data *data, struct decoder * decoder,
|
struct input_stream *_input_stream)
|
||||||
struct input_stream *input_stream)
|
:initialized(false), unsupported(false),
|
||||||
|
total_frames(0), first_frame(0), next_frame(0), position(0),
|
||||||
|
decoder(_decoder), input_stream(_input_stream),
|
||||||
|
tag(nullptr)
|
||||||
{
|
{
|
||||||
pcm_buffer_init(&data->buffer);
|
pcm_buffer_init(&buffer);
|
||||||
|
|
||||||
data->unsupported = false;
|
|
||||||
data->initialized = false;
|
|
||||||
data->total_frames = 0;
|
|
||||||
data->first_frame = 0;
|
|
||||||
data->next_frame = 0;
|
|
||||||
|
|
||||||
data->position = 0;
|
|
||||||
data->decoder = decoder;
|
|
||||||
data->input_stream = input_stream;
|
|
||||||
data->tag = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
flac_data::~flac_data()
|
||||||
flac_data_deinit(struct flac_data *data)
|
|
||||||
{
|
{
|
||||||
pcm_buffer_deinit(&data->buffer);
|
pcm_buffer_deinit(&buffer);
|
||||||
|
|
||||||
if (data->tag != nullptr)
|
if (tag != nullptr)
|
||||||
tag_free(data->tag);
|
tag_free(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum sample_format
|
static enum sample_format
|
||||||
|
@@ -78,19 +78,16 @@ struct flac_data {
|
|||||||
FLAC__uint64 next_frame;
|
FLAC__uint64 next_frame;
|
||||||
|
|
||||||
FLAC__uint64 position;
|
FLAC__uint64 position;
|
||||||
|
|
||||||
struct decoder *decoder;
|
struct decoder *decoder;
|
||||||
struct input_stream *input_stream;
|
struct input_stream *input_stream;
|
||||||
|
|
||||||
struct tag *tag;
|
struct tag *tag;
|
||||||
|
|
||||||
|
flac_data(struct decoder *decoder, struct input_stream *input_stream);
|
||||||
|
~flac_data();
|
||||||
};
|
};
|
||||||
|
|
||||||
/* initializes a given FlacData struct */
|
|
||||||
void
|
|
||||||
flac_data_init(struct flac_data *data, struct decoder * decoder,
|
|
||||||
struct input_stream *input_stream);
|
|
||||||
|
|
||||||
void
|
|
||||||
flac_data_deinit(struct flac_data *data);
|
|
||||||
|
|
||||||
void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
|
void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
|
||||||
struct flac_data *data);
|
struct flac_data *data);
|
||||||
|
|
||||||
|
@@ -317,26 +317,23 @@ flac_decode_internal(struct decoder * decoder,
|
|||||||
bool is_ogg)
|
bool is_ogg)
|
||||||
{
|
{
|
||||||
FLAC__StreamDecoder *flac_dec;
|
FLAC__StreamDecoder *flac_dec;
|
||||||
struct flac_data data;
|
|
||||||
|
|
||||||
flac_dec = flac_decoder_new();
|
flac_dec = flac_decoder_new();
|
||||||
if (flac_dec == nullptr)
|
if (flac_dec == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
flac_data_init(&data, decoder, input_stream);
|
struct flac_data data(decoder, input_stream);
|
||||||
data.tag = tag_new();
|
data.tag = tag_new();
|
||||||
|
|
||||||
FLAC__StreamDecoderInitStatus status =
|
FLAC__StreamDecoderInitStatus status =
|
||||||
stream_init(flac_dec, &data, is_ogg);
|
stream_init(flac_dec, &data, is_ogg);
|
||||||
if (status != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
|
if (status != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
|
||||||
flac_data_deinit(&data);
|
|
||||||
FLAC__stream_decoder_delete(flac_dec);
|
FLAC__stream_decoder_delete(flac_dec);
|
||||||
g_warning("%s", FLAC__StreamDecoderInitStatusString[status]);
|
g_warning("%s", FLAC__StreamDecoderInitStatusString[status]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!flac_decoder_initialize(&data, flac_dec, 0)) {
|
if (!flac_decoder_initialize(&data, flac_dec, 0)) {
|
||||||
flac_data_deinit(&data);
|
|
||||||
FLAC__stream_decoder_finish(flac_dec);
|
FLAC__stream_decoder_finish(flac_dec);
|
||||||
FLAC__stream_decoder_delete(flac_dec);
|
FLAC__stream_decoder_delete(flac_dec);
|
||||||
return;
|
return;
|
||||||
@@ -344,8 +341,6 @@ flac_decode_internal(struct decoder * decoder,
|
|||||||
|
|
||||||
flac_decoder_loop(&data, flac_dec, 0, 0);
|
flac_decoder_loop(&data, flac_dec, 0, 0);
|
||||||
|
|
||||||
flac_data_deinit(&data);
|
|
||||||
|
|
||||||
FLAC__stream_decoder_finish(flac_dec);
|
FLAC__stream_decoder_finish(flac_dec);
|
||||||
FLAC__stream_decoder_delete(flac_dec);
|
FLAC__stream_decoder_delete(flac_dec);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user