diff options
author | Josh Coalson <jcoalson@users.sourceforce.net> | 2001-06-16 07:32:25 +0000 |
---|---|---|
committer | Josh Coalson <jcoalson@users.sourceforce.net> | 2001-06-16 07:32:25 +0000 |
commit | 00e53874cdc9193caff1e10504c19e4284103aab (patch) | |
tree | 65737dfa7634883d9c8f1c0500415b4e98142b57 /src | |
parent | c84e95b6a2c0ed8612e95e2c79f71ef0788d9497 (diff) | |
download | flac-00e53874cdc9193caff1e10504c19e4284103aab.tar.gz |
revamp encoder/decoder interface to use set methods instead on args to init
Diffstat (limited to 'src')
-rw-r--r-- | src/flac/decode.c | 55 | ||||
-rw-r--r-- | src/flac/encode.c | 57 | ||||
-rw-r--r-- | src/libFLAC/file_decoder.c | 120 | ||||
-rw-r--r-- | src/libFLAC/include/protected/file_decoder.h | 2 | ||||
-rw-r--r-- | src/libFLAC/include/protected/stream_decoder.h | 2 | ||||
-rw-r--r-- | src/libFLAC/include/protected/stream_encoder.h | 2 | ||||
-rw-r--r-- | src/libFLAC/stream_decoder.c | 80 | ||||
-rw-r--r-- | src/libFLAC/stream_encoder.c | 280 | ||||
-rw-r--r-- | src/plugin_winamp2/in_flac.c | 26 | ||||
-rw-r--r-- | src/plugin_winamp3/in_flac.cpp | 22 | ||||
-rw-r--r-- | src/plugin_xmms/plugin.c | 26 |
11 files changed, 487 insertions, 185 deletions
diff --git a/src/flac/decode.c b/src/flac/decode.c index e6be5526..f79aa958 100644 --- a/src/flac/decode.c +++ b/src/flac/decode.c @@ -54,7 +54,7 @@ static FLAC__FileDecoder *decoder; static bool is_big_endian_host; /* local routines */ -static bool init(const char *infile, stream_info_struct *stream_info); +static bool init(const char *infilename, stream_info_struct *stream_info); static bool write_little_endian_uint16(FILE *f, uint16 val); static bool write_little_endian_uint32(FILE *f, uint32 val); static FLAC__StreamDecoderWriteStatus write_callback(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const int32 *buffer[], void *client_data); @@ -103,7 +103,7 @@ int flac__decode_wav(const char *infile, const char *outfile, bool analysis_mode if(skip > 0) { if(!FLAC__file_decoder_process_metadata(decoder)) { - fprintf(stderr, "%s: ERROR while decoding metadata, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]); + fprintf(stderr, "%s: ERROR while decoding metadata, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]); goto wav_abort_; } if(stream_info.skip_count_too_high) { @@ -111,35 +111,35 @@ int flac__decode_wav(const char *infile, const char *outfile, bool analysis_mode goto wav_abort_; } if(!FLAC__file_decoder_seek_absolute(decoder, skip)) { - fprintf(stderr, "%s: ERROR seeking while skipping bytes, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]); + fprintf(stderr, "%s: ERROR seeking while skipping bytes, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]); goto wav_abort_; } if(!FLAC__file_decoder_process_remaining_frames(decoder)) { if(verbose) fprintf(stderr, "\n"); - fprintf(stderr, "%s: ERROR while decoding frames, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]); + fprintf(stderr, "%s: ERROR while decoding frames, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]); goto wav_abort_; } - if(FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_END_OF_FILE) { + if(FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_END_OF_FILE) { if(verbose) fprintf(stderr, "\n"); - fprintf(stderr, "%s: ERROR during decoding, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]); + fprintf(stderr, "%s: ERROR during decoding, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]); goto wav_abort_; } } else { if(!FLAC__file_decoder_process_whole_file(decoder)) { if(verbose) fprintf(stderr, "\n"); - fprintf(stderr, "%s: ERROR while decoding data, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]); + fprintf(stderr, "%s: ERROR while decoding data, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]); goto wav_abort_; } - if(FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_END_OF_FILE) { + if(FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_END_OF_FILE) { if(verbose) fprintf(stderr, "\n"); - fprintf(stderr, "%s: ERROR during decoding, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]); + fprintf(stderr, "%s: ERROR during decoding, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]); goto wav_abort_; } } if(decoder) { - if(FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED) + if(FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED) md5_failure = !FLAC__file_decoder_finish(decoder); print_stats(&stream_info); FLAC__file_decoder_delete(decoder); @@ -158,7 +158,7 @@ int flac__decode_wav(const char *infile, const char *outfile, bool analysis_mode return 0; wav_abort_: if(decoder) { - if(FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED) + if(FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED) FLAC__file_decoder_finish(decoder); FLAC__file_decoder_delete(decoder); } @@ -214,7 +214,7 @@ int flac__decode_raw(const char *infile, const char *outfile, bool analysis_mode if(skip > 0) { if(!FLAC__file_decoder_process_metadata(decoder)) { - fprintf(stderr, "%s: ERROR while decoding metadata, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]); + fprintf(stderr, "%s: ERROR while decoding metadata, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]); goto raw_abort_; } if(stream_info.skip_count_too_high) { @@ -222,35 +222,35 @@ int flac__decode_raw(const char *infile, const char *outfile, bool analysis_mode goto raw_abort_; } if(!FLAC__file_decoder_seek_absolute(decoder, skip)) { - fprintf(stderr, "%s: ERROR seeking while skipping bytes, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]); + fprintf(stderr, "%s: ERROR seeking while skipping bytes, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]); goto raw_abort_; } if(!FLAC__file_decoder_process_remaining_frames(decoder)) { if(verbose) fprintf(stderr, "\n"); - fprintf(stderr, "%s: ERROR while decoding frames, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]); + fprintf(stderr, "%s: ERROR while decoding frames, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]); goto raw_abort_; } - if(FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_END_OF_FILE) { + if(FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_END_OF_FILE) { if(verbose) fprintf(stderr, "\n"); - fprintf(stderr, "%s: ERROR during decoding, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]); + fprintf(stderr, "%s: ERROR during decoding, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]); goto raw_abort_; } } else { if(!FLAC__file_decoder_process_whole_file(decoder)) { if(verbose) fprintf(stderr, "\n"); - fprintf(stderr, "%s: ERROR while decoding data, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]); + fprintf(stderr, "%s: ERROR while decoding data, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]); goto raw_abort_; } - if(FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_END_OF_FILE) { + if(FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_END_OF_FILE) { if(verbose) fprintf(stderr, "\n"); - fprintf(stderr, "%s: ERROR during decoding, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]); + fprintf(stderr, "%s: ERROR during decoding, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]); goto raw_abort_; } } if(decoder) { - if(FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED) + if(FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED) md5_failure = !FLAC__file_decoder_finish(decoder); print_stats(&stream_info); FLAC__file_decoder_delete(decoder); @@ -269,7 +269,7 @@ int flac__decode_raw(const char *infile, const char *outfile, bool analysis_mode return 0; raw_abort_: if(decoder) { - if(FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED) + if(FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED) FLAC__file_decoder_finish(decoder); FLAC__file_decoder_delete(decoder); } @@ -282,7 +282,7 @@ raw_abort_: return 1; } -bool init(const char *infile, stream_info_struct *stream_info) +bool init(const char *infilename, stream_info_struct *stream_info) { uint32 test = 1; @@ -294,8 +294,15 @@ bool init(const char *infile, stream_info_struct *stream_info) return false; } - if(FLAC__file_decoder_init(decoder, true /*check_md5*/, infile, write_callback, metadata_callback, error_callback, stream_info) != FLAC__FILE_DECODER_OK) { - fprintf(stderr, "%s: ERROR initializing decoder, state=%d:%s\n", stream_info->inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]); + FLAC__file_decoder_set_md5_checking(decoder, true); + FLAC__file_decoder_set_filename(decoder, infilename); + FLAC__file_decoder_set_write_callback(decoder, write_callback); + FLAC__file_decoder_set_metadata_callback(decoder, metadata_callback); + FLAC__file_decoder_set_error_callback(decoder, error_callback); + FLAC__file_decoder_set_client_data(decoder, stream_info); + + if(FLAC__file_decoder_init(decoder) != FLAC__FILE_DECODER_OK) { + fprintf(stderr, "%s: ERROR initializing decoder, state=%d:%s\n", stream_info->inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]); return false; } diff --git a/src/flac/encode.c b/src/flac/encode.c index c53a01a2..0af5b4fe 100644 --- a/src/flac/encode.c +++ b/src/flac/encode.c @@ -276,7 +276,7 @@ int flac__encode_wav(FILE *infile, long infilesize, const char *infilename, cons /* NOTE: some versions of GCC can't figure out const-ness right and will give you an 'incompatible pointer type' warning on arg 2 here: */ if(!FLAC__stream_encoder_process(encoder_wrapper.encoder, input, wide_samples)) { - fprintf(stderr, "%s: ERROR during encoding, state = %d:%s\n", encoder_wrapper.inbasefilename, FLAC__stream_encoder_state(encoder_wrapper.encoder), FLAC__StreamEncoderStateString[FLAC__stream_encoder_state(encoder_wrapper.encoder)]); + fprintf(stderr, "%s: ERROR during encoding, state = %d:%s\n", encoder_wrapper.inbasefilename, FLAC__stream_encoder_get_state(encoder_wrapper.encoder), FLAC__StreamEncoderStateString[FLAC__stream_encoder_get_state(encoder_wrapper.encoder)]); goto wav_abort_; } data_bytes -= bytes_read; @@ -313,7 +313,7 @@ int flac__encode_wav(FILE *infile, long infilesize, const char *infilename, cons } if(encoder_wrapper.encoder) { - if(FLAC__stream_encoder_state(encoder_wrapper.encoder) == FLAC__STREAM_ENCODER_OK) + if(FLAC__stream_encoder_get_state(encoder_wrapper.encoder) == FLAC__STREAM_ENCODER_OK) FLAC__stream_encoder_finish(encoder_wrapper.encoder); FLAC__stream_encoder_delete(encoder_wrapper.encoder); } @@ -338,7 +338,7 @@ wav_abort_: if(encoder_wrapper.verbose && encoder_wrapper.total_samples_to_encode > 0) fprintf(stderr, "\n"); if(encoder_wrapper.encoder) { - if(FLAC__stream_encoder_state(encoder_wrapper.encoder) == FLAC__STREAM_ENCODER_OK) + if(FLAC__stream_encoder_get_state(encoder_wrapper.encoder) == FLAC__STREAM_ENCODER_OK) FLAC__stream_encoder_finish(encoder_wrapper.encoder); FLAC__stream_encoder_delete(encoder_wrapper.encoder); } @@ -469,14 +469,14 @@ int flac__encode_raw(FILE *infile, long infilesize, const char *infilename, cons /* NOTE: some versions of GCC can't figure out const-ness right and will give you an 'incompatible pointer type' warning on arg 2 here: */ if(!FLAC__stream_encoder_process(encoder_wrapper.encoder, input, wide_samples)) { - fprintf(stderr, "%s: ERROR during encoding, state = %d:%s\n", encoder_wrapper.inbasefilename, FLAC__stream_encoder_state(encoder_wrapper.encoder), FLAC__StreamEncoderStateString[FLAC__stream_encoder_state(encoder_wrapper.encoder)]); + fprintf(stderr, "%s: ERROR during encoding, state = %d:%s\n", encoder_wrapper.inbasefilename, FLAC__stream_encoder_get_state(encoder_wrapper.encoder), FLAC__StreamEncoderStateString[FLAC__stream_encoder_get_state(encoder_wrapper.encoder)]); goto raw_abort_; } } } if(encoder_wrapper.encoder) { - if(FLAC__stream_encoder_state(encoder_wrapper.encoder) == FLAC__STREAM_ENCODER_OK) + if(FLAC__stream_encoder_get_state(encoder_wrapper.encoder) == FLAC__STREAM_ENCODER_OK) FLAC__stream_encoder_finish(encoder_wrapper.encoder); FLAC__stream_encoder_delete(encoder_wrapper.encoder); } @@ -501,7 +501,7 @@ raw_abort_: if(encoder_wrapper.verbose && encoder_wrapper.total_samples_to_encode > 0) fprintf(stderr, "\n"); if(encoder_wrapper.encoder) { - if(FLAC__stream_encoder_state(encoder_wrapper.encoder) == FLAC__STREAM_ENCODER_OK) + if(FLAC__stream_encoder_get_state(encoder_wrapper.encoder) == FLAC__STREAM_ENCODER_OK) FLAC__stream_encoder_finish(encoder_wrapper.encoder); FLAC__stream_encoder_delete(encoder_wrapper.encoder); } @@ -566,8 +566,13 @@ bool init_encoder(bool lax, bool do_mid_side, bool loose_mid_side, bool do_exhau fprintf(stderr, "%s: ERROR creating the verify decoder instance\n", encoder_wrapper->inbasefilename); return false; } - if(FLAC__stream_decoder_init(encoder_wrapper->verify_fifo.decoder, verify_read_callback, verify_write_callback, verify_metadata_callback, verify_error_callback, encoder_wrapper) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA) { - fprintf(stderr, "%s: ERROR initializing decoder, state = %d:%s\n", encoder_wrapper->inbasefilename, FLAC__stream_decoder_state(encoder_wrapper->verify_fifo.decoder), FLAC__StreamDecoderStateString[FLAC__stream_decoder_state(encoder_wrapper->verify_fifo.decoder)]); + FLAC__stream_decoder_set_read_callback(encoder_wrapper->verify_fifo.decoder, verify_read_callback); + FLAC__stream_decoder_set_write_callback(encoder_wrapper->verify_fifo.decoder, verify_write_callback); + FLAC__stream_decoder_set_metadata_callback(encoder_wrapper->verify_fifo.decoder, verify_metadata_callback); + FLAC__stream_decoder_set_error_callback(encoder_wrapper->verify_fifo.decoder, verify_error_callback); + FLAC__stream_decoder_set_client_data(encoder_wrapper->verify_fifo.decoder, encoder_wrapper); + if(FLAC__stream_decoder_init(encoder_wrapper->verify_fifo.decoder) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA) { + fprintf(stderr, "%s: ERROR initializing decoder, state = %d:%s\n", encoder_wrapper->inbasefilename, FLAC__stream_decoder_get_state(encoder_wrapper->verify_fifo.decoder), FLAC__StreamDecoderStateString[FLAC__stream_decoder_get_state(encoder_wrapper->verify_fifo.decoder)]); return false; } } @@ -577,8 +582,30 @@ bool init_encoder(bool lax, bool do_mid_side, bool loose_mid_side, bool do_exhau return false; } - if(FLAC__stream_encoder_init(encoder_wrapper->encoder, !lax, do_mid_side, loose_mid_side, channels, bps, sample_rate, blocksize, max_lpc_order, qlp_coeff_precision, do_qlp_coeff_prec_search, do_exhaustive_model_search, min_residual_partition_order, max_residual_partition_order, rice_parameter_search_dist, encoder_wrapper->total_samples_to_encode, (encoder_wrapper->seek_table.num_points > 0)? &encoder_wrapper->seek_table : 0, padding, true /*last_metadata_is_last*/, write_callback, metadata_callback, encoder_wrapper) != FLAC__STREAM_ENCODER_OK) { - fprintf(stderr, "%s: ERROR initializing encoder, state = %d:%s\n", encoder_wrapper->inbasefilename, FLAC__stream_encoder_state(encoder_wrapper->encoder), FLAC__StreamEncoderStateString[FLAC__stream_encoder_state(encoder_wrapper->encoder)]); + FLAC__stream_encoder_set_streamable_subset(encoder_wrapper->encoder, !lax); + FLAC__stream_encoder_set_do_mid_side_stereo(encoder_wrapper->encoder, do_mid_side); + FLAC__stream_encoder_set_loose_mid_side_stereo(encoder_wrapper->encoder, loose_mid_side); + FLAC__stream_encoder_set_channels(encoder_wrapper->encoder, channels); + FLAC__stream_encoder_set_bits_per_sample(encoder_wrapper->encoder, bps); + FLAC__stream_encoder_set_sample_rate(encoder_wrapper->encoder, sample_rate); + FLAC__stream_encoder_set_blocksize(encoder_wrapper->encoder, blocksize); + FLAC__stream_encoder_set_max_lpc_order(encoder_wrapper->encoder, max_lpc_order); + FLAC__stream_encoder_set_qlp_coeff_precision(encoder_wrapper->encoder, qlp_coeff_precision); + FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder_wrapper->encoder, do_qlp_coeff_prec_search); + FLAC__stream_encoder_set_do_exhaustive_model_search(encoder_wrapper->encoder, do_exhaustive_model_search); + FLAC__stream_encoder_set_min_residual_partition_order(encoder_wrapper->encoder, min_residual_partition_order); + FLAC__stream_encoder_set_max_residual_partition_order(encoder_wrapper->encoder, max_residual_partition_order); + FLAC__stream_encoder_set_rice_parameter_search_dist(encoder_wrapper->encoder, rice_parameter_search_dist); + FLAC__stream_encoder_set_total_samples_estimate(encoder_wrapper->encoder, encoder_wrapper->total_samples_to_encode); + FLAC__stream_encoder_set_seek_table(encoder_wrapper->encoder, (encoder_wrapper->seek_table.num_points > 0)? &encoder_wrapper->seek_table : 0); + FLAC__stream_encoder_set_padding(encoder_wrapper->encoder, padding); + FLAC__stream_encoder_set_last_metadata_is_last(encoder_wrapper->encoder, true); + FLAC__stream_encoder_set_write_callback(encoder_wrapper->encoder, write_callback); + FLAC__stream_encoder_set_metadata_callback(encoder_wrapper->encoder, metadata_callback); + FLAC__stream_encoder_set_client_data(encoder_wrapper->encoder, encoder_wrapper); + + if(FLAC__stream_encoder_init(encoder_wrapper->encoder) != FLAC__STREAM_ENCODER_OK) { + fprintf(stderr, "%s: ERROR initializing encoder, state = %d:%s\n", encoder_wrapper->inbasefilename, FLAC__stream_encoder_get_state(encoder_wrapper->encoder), FLAC__StreamEncoderStateString[FLAC__stream_encoder_get_state(encoder_wrapper->encoder)]); return false; } @@ -783,11 +810,11 @@ void format_input(unsigned wide_samples, bool is_big_endian, bool is_unsigned_sa FLAC__StreamEncoderWriteStatus write_callback(const FLAC__StreamEncoder *encoder, const byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data) { encoder_wrapper_struct *encoder_wrapper = (encoder_wrapper_struct *)client_data; - const unsigned mask = (FLAC__stream_encoder_do_exhaustive_model_search(encoder) || FLAC__stream_encoder_do_qlp_coeff_prec_search(encoder))? 0x1f : 0x7f; + const unsigned mask = (FLAC__stream_encoder_get_do_exhaustive_model_search(encoder) || FLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder))? 0x1f : 0x7f; /* mark the current seek point if hit (if stream_offset == 0 that means we're still writing metadata and haven't hit the first frame yet) */ if(encoder_wrapper->stream_offset > 0 && encoder_wrapper->seek_table.num_points > 0) { - uint64 current_sample = (uint64)current_frame * (uint64)FLAC__stream_encoder_blocksize(encoder), test_sample; + uint64 current_sample = (uint64)current_frame * (uint64)FLAC__stream_encoder_get_blocksize(encoder), test_sample; unsigned i; for(i = encoder_wrapper->first_seek_point_to_check; i < encoder_wrapper->seek_table.num_points; i++) { test_sample = encoder_wrapper->seek_table.points[i].sample_number; @@ -796,7 +823,7 @@ FLAC__StreamEncoderWriteStatus write_callback(const FLAC__StreamEncoder *encoder } else if(test_sample == current_sample) { encoder_wrapper->seek_table.points[i].stream_offset = encoder_wrapper->bytes_written - encoder_wrapper->stream_offset; - encoder_wrapper->seek_table.points[i].frame_samples = FLAC__stream_encoder_blocksize(encoder); + encoder_wrapper->seek_table.points[i].frame_samples = FLAC__stream_encoder_get_blocksize(encoder); encoder_wrapper->first_seek_point_to_check++; break; } @@ -953,8 +980,8 @@ FLAC__StreamDecoderWriteStatus verify_write_callback(const FLAC__StreamDecoder * { encoder_wrapper_struct *encoder_wrapper = (encoder_wrapper_struct *)client_data; unsigned channel, l, r; - const unsigned channels = FLAC__stream_decoder_channels(decoder); - const unsigned bytes_per_block = sizeof(int32) * FLAC__stream_decoder_blocksize(decoder); + const unsigned channels = FLAC__stream_decoder_get_channels(decoder); + const unsigned bytes_per_block = sizeof(int32) * FLAC__stream_decoder_get_blocksize(decoder); for(channel = 0; channel < channels; channel++) { if(0 != memcmp(buffer[channel], encoder_wrapper->verify_fifo.original[channel], bytes_per_block)) { diff --git a/src/libFLAC/file_decoder.c b/src/libFLAC/file_decoder.c index 2c45c9e9..e9b9dd06 100644 --- a/src/libFLAC/file_decoder.c +++ b/src/libFLAC/file_decoder.c @@ -78,6 +78,7 @@ const char *FLAC__FileDecoderStateString[] = { "FLAC__FILE_DECODER_STREAM_ERROR", "FLAC__FILE_DECODER_STREAM_DECODER_ERROR", "FLAC__FILE_DECODER_ALREADY_INITIALIZED", + "FLAC__FILE_DECODER_INVALID_CALLBACK", "FLAC__FILE_DECODER_UNINITIALIZED" }; @@ -111,6 +112,12 @@ FLAC__FileDecoder *FLAC__file_decoder_new() decoder->protected->state = FLAC__FILE_DECODER_UNINITIALIZED; + decoder->private->filename = 0; + decoder->private->write_callback = 0; + decoder->private->metadata_callback = 0; + decoder->private->error_callback = 0; + decoder->private->client_data = 0; + return decoder; } @@ -131,52 +138,32 @@ void FLAC__file_decoder_delete(FLAC__FileDecoder *decoder) * ***********************************************************************/ -FLAC__FileDecoderState FLAC__file_decoder_init( - FLAC__FileDecoder *decoder, - bool check_md5, - const char *filename, - FLAC__StreamDecoderWriteStatus (*write_callback)(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const int32 *buffer[], void *client_data), - void (*metadata_callback)(const FLAC__FileDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data), - void (*error_callback)(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data), - void *client_data -) +FLAC__FileDecoderState FLAC__file_decoder_init(FLAC__FileDecoder *decoder) { FLAC__ASSERT(decoder != 0); - FLAC__ASSERT(write_callback != 0); - FLAC__ASSERT(metadata_callback != 0); - FLAC__ASSERT(error_callback != 0); if(decoder->protected->state != FLAC__FILE_DECODER_UNINITIALIZED) return decoder->protected->state = FLAC__FILE_DECODER_ALREADY_INITIALIZED; decoder->protected->state = FLAC__FILE_DECODER_OK; - decoder->protected->check_md5 = check_md5; + if(0 == decoder->private->write_callback || 0 == decoder->private->metadata_callback || 0 == decoder->private->error_callback) + return decoder->protected->state = FLAC__FILE_DECODER_INVALID_CALLBACK; - decoder->private->write_callback = write_callback; - decoder->private->metadata_callback = metadata_callback; - decoder->private->error_callback = error_callback; - decoder->private->client_data = client_data; decoder->private->file = 0; decoder->private->stream_decoder = 0; - decoder->private->filename = 0; decoder->private->seek_table = 0; - if(0 == strcmp(filename, "-")) { + if(0 == strcmp(decoder->private->filename, "-")) decoder->private->file = stdin; - } - else { - if(0 == (decoder->private->filename = (char*)malloc(strlen(filename)+1))) - return decoder->protected->state = FLAC__FILE_DECODER_MEMORY_ALLOCATION_ERROR; - strcpy(decoder->private->filename, filename); - decoder->private->file = fopen(filename, "rb"); - } + else + decoder->private->file = fopen(decoder->private->filename, "rb"); if(decoder->private->file == 0) return decoder->protected->state = FLAC__FILE_DECODER_ERROR_OPENING_FILE; /* We initialize the MD5Context even though we may never use it. This is - * because check_md5 may be turned on to start and then turned off if a + * because md5_checking may be turned on to start and then turned off if a * seek occurs. So we always init the context here and finalize it in * FLAC__file_decoder_finish() to make sure things are always cleaned up * properly. @@ -184,7 +171,14 @@ FLAC__FileDecoderState FLAC__file_decoder_init( MD5Init(&decoder->private->md5context); decoder->private->stream_decoder = FLAC__stream_decoder_new(); - if(FLAC__stream_decoder_init(decoder->private->stream_decoder, read_callback_, write_callback_, metadata_callback_, error_callback_, decoder) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA) + + FLAC__stream_decoder_set_read_callback(decoder->private->stream_decoder, read_callback_); + FLAC__stream_decoder_set_write_callback(decoder->private->stream_decoder, write_callback_); + FLAC__stream_decoder_set_metadata_callback(decoder->private->stream_decoder, metadata_callback_); + FLAC__stream_decoder_set_error_callback(decoder->private->stream_decoder, error_callback_); + FLAC__stream_decoder_set_client_data(decoder->private->stream_decoder, decoder); + + if(FLAC__stream_decoder_init(decoder->private->stream_decoder) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA) return decoder->protected->state = FLAC__FILE_DECODER_STREAM_DECODER_ERROR; return decoder->protected->state; @@ -209,7 +203,7 @@ bool FLAC__file_decoder_finish(FLAC__FileDecoder *decoder) FLAC__stream_decoder_finish(decoder->private->stream_decoder); FLAC__stream_decoder_delete(decoder->private->stream_decoder); } - if(decoder->protected->check_md5) { + if(decoder->protected->md5_checking) { if(memcmp(decoder->private->stored_md5sum, decoder->private->computed_md5sum, 16)) md5_failed = true; } @@ -217,14 +211,66 @@ bool FLAC__file_decoder_finish(FLAC__FileDecoder *decoder) return !md5_failed; } -FLAC__FileDecoderState FLAC__file_decoder_state(const FLAC__FileDecoder *decoder) +bool FLAC__file_decoder_set_md5_checking(const FLAC__FileDecoder *decoder, bool value) +{ + if(decoder->protected->state != FLAC__FILE_DECODER_UNINITIALIZED) + return false; + decoder->protected->md5_checking = value; + return true; +} + +bool FLAC__file_decoder_set_filename(const FLAC__FileDecoder *decoder, const char *value) +{ + if(decoder->protected->state != FLAC__FILE_DECODER_UNINITIALIZED) + return false; + if(0 == (decoder->private->filename = (char*)malloc(strlen(value)+1))) { + decoder->protected->state = FLAC__FILE_DECODER_MEMORY_ALLOCATION_ERROR; + return false; + } + strcpy(decoder->private->filename, value); + return true; +} + +bool FLAC__file_decoder_set_write_callback(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderWriteStatus (*value)(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const int32 *buffer[], void *client_data)) +{ + if(decoder->protected->state != FLAC__FILE_DECODER_UNINITIALIZED) + return false; + decoder->private->write_callback = value; + return true; +} + +bool FLAC__file_decoder_set_metadata_callback(const FLAC__FileDecoder *decoder, void (*value)(const FLAC__FileDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data)) +{ + if(decoder->protected->state != FLAC__FILE_DECODER_UNINITIALIZED) + return false; + decoder->private->metadata_callback = value; + return true; +} + +bool FLAC__file_decoder_set_error_callback(const FLAC__FileDecoder *decoder, void (*value)(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)) +{ + if(decoder->protected->state != FLAC__FILE_DECODER_UNINITIALIZED) + return false; + decoder->private->error_callback = value; + return true; +} + +bool FLAC__file_decoder_set_client_data(const FLAC__FileDecoder *decoder, void *value) +{ + if(decoder->protected->state != FLAC__FILE_DECODER_UNINITIALIZED) + return false; + decoder->private->client_data = value; + return true; +} + +FLAC__FileDecoderState FLAC__file_decoder_get_state(const FLAC__FileDecoder *decoder) { return decoder->protected->state; } -bool FLAC__file_decoder_check_md5(const FLAC__FileDecoder *decoder) +bool FLAC__file_decoder_get_md5_checking(const FLAC__FileDecoder *decoder) { - return decoder->protected->check_md5; + return decoder->protected->md5_checking; } bool FLAC__file_decoder_process_whole_file(FLAC__FileDecoder *decoder) @@ -329,7 +375,7 @@ bool FLAC__file_decoder_seek_absolute(FLAC__FileDecoder *decoder, uint64 sample) decoder->protected->state = FLAC__FILE_DECODER_SEEKING; /* turn off md5 checking if a seek is attempted */ - decoder->protected->check_md5 = false; + decoder->protected->md5_checking = false; if(!FLAC__stream_decoder_reset(decoder->private->stream_decoder)) { decoder->protected->state = FLAC__FILE_DECODER_STREAM_ERROR; @@ -421,7 +467,7 @@ FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decode } } else { - if(file_decoder->protected->check_md5) { + if(file_decoder->protected->md5_checking) { if(!FLAC__MD5Accumulate(&file_decoder->private->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8)) return FLAC__STREAM_DECODER_WRITE_ABORT; } @@ -439,7 +485,7 @@ void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMe /* save the MD5 signature for comparison later */ memcpy(file_decoder->private->stored_md5sum, metadata->data.stream_info.md5sum, 16); if(0 == memcmp(file_decoder->private->stored_md5sum, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16)) - file_decoder->protected->check_md5 = false; + file_decoder->protected->md5_checking = false; } else if(metadata->type == FLAC__METADATA_TYPE_SEEKTABLE) { file_decoder->private->seek_table = &metadata->data.seek_table; @@ -488,7 +534,7 @@ bool seek_to_absolute_sample_(FLAC__FileDecoder *decoder, long filesize, uint64 decoder->protected->state = FLAC__FILE_DECODER_SEEK_ERROR; return false; } - first_frame_offset -= FLAC__stream_decoder_input_bytes_unconsumed(decoder->private->stream_decoder); + first_frame_offset -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder->private->stream_decoder); FLAC__ASSERT(first_frame_offset >= 0); /* @@ -610,7 +656,7 @@ bool seek_to_absolute_sample_(FLAC__FileDecoder *decoder, long filesize, uint64 decoder->protected->state = FLAC__FILE_DECODER_SEEK_ERROR; return false; } - pos -= FLAC__stream_decoder_input_bytes_unconsumed(decoder->private->stream_decoder); + pos -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder->private->stream_decoder); needs_seek = false; } } diff --git a/src/libFLAC/include/protected/file_decoder.h b/src/libFLAC/include/protected/file_decoder.h index 7f34b2c8..3d0b6bdb 100644 --- a/src/libFLAC/include/protected/file_decoder.h +++ b/src/libFLAC/include/protected/file_decoder.h @@ -23,7 +23,7 @@ #include "FLAC/file_decoder.h" typedef struct FLAC__FileDecoderProtected { - bool check_md5; /* if true, generate MD5 signature of decoded data and compare against signature in the Encoding metadata block */ + bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the Encoding metadata block */ FLAC__FileDecoderState state; } FLAC__FileDecoderProtected; diff --git a/src/libFLAC/include/protected/stream_decoder.h b/src/libFLAC/include/protected/stream_decoder.h index df15db29..1314d3a5 100644 --- a/src/libFLAC/include/protected/stream_decoder.h +++ b/src/libFLAC/include/protected/stream_decoder.h @@ -34,6 +34,6 @@ typedef struct FLAC__StreamDecoderProtected { /* * return the number of input bytes consumed */ -unsigned FLAC__stream_decoder_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder); +unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder); #endif diff --git a/src/libFLAC/include/protected/stream_encoder.h b/src/libFLAC/include/protected/stream_encoder.h index 2951ce30..ea11e175 100644 --- a/src/libFLAC/include/protected/stream_encoder.h +++ b/src/libFLAC/include/protected/stream_encoder.h @@ -40,6 +40,8 @@ typedef struct FLAC__StreamEncoderProtected { unsigned rice_parameter_search_dist; uint64 total_samples_estimate; const FLAC__StreamMetaData_SeekTable *seek_table; + unsigned padding; + bool last_metadata_is_last; } FLAC__StreamEncoderProtected; #endif diff --git a/src/libFLAC/stream_decoder.c b/src/libFLAC/stream_decoder.c index dccd1d81..5933cb50 100644 --- a/src/libFLAC/stream_decoder.c +++ b/src/libFLAC/stream_decoder.c @@ -104,6 +104,7 @@ const char *FLAC__StreamDecoderStateString[] = { "FLAC__STREAM_DECODER_UNPARSEABLE_STREAM", "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR", "FLAC__STREAM_DECODER_ALREADY_INITIALIZED", + "FLAC__STREAM_DECODER_INVALID_CALLBACK", "FLAC__STREAM_DECODER_UNINITIALIZED" }; @@ -153,6 +154,12 @@ FLAC__StreamDecoder *FLAC__stream_decoder_new() decoder->protected->state = FLAC__STREAM_DECODER_UNINITIALIZED; + decoder->private->read_callback = 0; + decoder->private->write_callback = 0; + decoder->private->metadata_callback = 0; + decoder->private->error_callback = 0; + decoder->private->client_data = 0; + return decoder; } @@ -173,32 +180,19 @@ void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder) * ***********************************************************************/ -FLAC__StreamDecoderState FLAC__stream_decoder_init( - FLAC__StreamDecoder *decoder, - FLAC__StreamDecoderReadStatus (*read_callback)(const FLAC__StreamDecoder *decoder, byte buffer[], unsigned *bytes, void *client_data), - FLAC__StreamDecoderWriteStatus (*write_callback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const int32 *buffer[], void *client_data), - void (*metadata_callback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data), - void (*error_callback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data), - void *client_data) +FLAC__StreamDecoderState FLAC__stream_decoder_init(FLAC__StreamDecoder *decoder) { unsigned i; FLAC__ASSERT(decoder != 0); - FLAC__ASSERT(read_callback != 0); - FLAC__ASSERT(write_callback != 0); - FLAC__ASSERT(metadata_callback != 0); - FLAC__ASSERT(error_callback != 0); if(decoder->protected->state != FLAC__STREAM_DECODER_UNINITIALIZED) return decoder->protected->state = FLAC__STREAM_DECODER_ALREADY_INITIALIZED; decoder->protected->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA; - decoder->private->read_callback = read_callback; - decoder->private->write_callback = write_callback; - decoder->private->metadata_callback = metadata_callback; - decoder->private->error_callback = error_callback; - decoder->private->client_data = client_data; + if(0 == decoder->private->read_callback || 0 == decoder->private->write_callback || 0 == decoder->private->metadata_callback || 0 == decoder->private->error_callback) + return decoder->protected->state = FLAC__STREAM_DECODER_INVALID_CALLBACK; FLAC__bitbuffer_init(&decoder->private->input); @@ -267,32 +261,72 @@ void FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder) decoder->protected->state = FLAC__STREAM_DECODER_UNINITIALIZED; } -FLAC__StreamDecoderState FLAC__stream_decoder_state(const FLAC__StreamDecoder *decoder) +bool FLAC__stream_decoder_set_read_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderReadStatus (*value)(const FLAC__StreamDecoder *decoder, byte buffer[], unsigned *bytes, void *client_data)) +{ + if(decoder->protected->state != FLAC__STREAM_DECODER_UNINITIALIZED) + return false; + decoder->private->read_callback = value; + return true; +} + +bool FLAC__stream_decoder_set_write_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderWriteStatus (*value)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const int32 *buffer[], void *client_data)) +{ + if(decoder->protected->state != FLAC__STREAM_DECODER_UNINITIALIZED) + return false; + decoder->private->write_callback = value; + return true; +} + +bool FLAC__stream_decoder_set_metadata_callback(const FLAC__StreamDecoder *decoder, void (*value)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data)) +{ + if(decoder->protected->state != FLAC__STREAM_DECODER_UNINITIALIZED) + return false; + decoder->private->metadata_callback = value; + return true; +} + +bool FLAC__stream_decoder_set_error_callback(const FLAC__StreamDecoder *decoder, void (*value)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)) +{ + if(decoder->protected->state != FLAC__STREAM_DECODER_UNINITIALIZED) + return false; + decoder->private->error_callback = value; + return true; +} + +bool FLAC__stream_decoder_set_client_data(const FLAC__StreamDecoder *decoder, void *value) +{ + if(decoder->protected->state != FLAC__STREAM_DECODER_UNINITIALIZED) + return false; + decoder->private->client_data = value; + return true; +} + +FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder) { return decoder->protected->state; } -unsigned FLAC__stream_decoder_channels(const FLAC__StreamDecoder *decoder) +unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder) { return decoder->protected->channels; } -FLAC__ChannelAssignment FLAC__stream_decoder_channel_assignment(const FLAC__StreamDecoder *decoder) +FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder) { return decoder->protected->channel_assignment; } -unsigned FLAC__stream_decoder_bits_per_sample(const FLAC__StreamDecoder *decoder) +unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder) { return decoder->protected->bits_per_sample; } -unsigned FLAC__stream_decoder_sample_rate(const FLAC__StreamDecoder *decoder) +unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder) { return decoder->protected->sample_rate; } -unsigned FLAC__stream_decoder_blocksize(const FLAC__StreamDecoder *decoder) +unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder) { return decoder->protected->blocksize; } @@ -464,7 +498,7 @@ bool FLAC__stream_decoder_process_remaining_frames(FLAC__StreamDecoder *decoder) * ***********************************************************************/ -unsigned FLAC__stream_decoder_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder) +unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder) { FLAC__ASSERT(decoder != 0); return decoder->private->input.bytes - decoder->private->input.consumed_bytes; diff --git a/src/libFLAC/stream_encoder.c b/src/libFLAC/stream_encoder.c index eb186227..ba41d8f6 100644 --- a/src/libFLAC/stream_encoder.c +++ b/src/libFLAC/stream_encoder.c @@ -130,6 +130,7 @@ typedef struct FLAC__StreamEncoderPrivate { const char *FLAC__StreamEncoderStateString[] = { "FLAC__STREAM_ENCODER_OK", + "FLAC__STREAM_ENCODER_INVALID_CALLBACK", "FLAC__STREAM_ENCODER_INVALID_NUMBER_OF_CHANNELS", "FLAC__STREAM_ENCODER_INVALID_BITS_PER_SAMPLE", "FLAC__STREAM_ENCODER_INVALID_SAMPLE_RATE", @@ -182,6 +183,29 @@ FLAC__StreamEncoder *FLAC__stream_encoder_new() encoder->protected->state = FLAC__STREAM_ENCODER_UNINITIALIZED; + encoder->protected->streamable_subset = true; + encoder->protected->do_mid_side_stereo = false; + encoder->protected->loose_mid_side_stereo = false; + encoder->protected->channels = 2; + encoder->protected->bits_per_sample = 16; + encoder->protected->sample_rate = 44100; + encoder->protected->blocksize = 1152; + encoder->protected->max_lpc_order = 0; + encoder->protected->qlp_coeff_precision = 0; + encoder->protected->do_qlp_coeff_prec_search = false; + encoder->protected->do_exhaustive_model_search = false; + encoder->protected->min_residual_partition_order = 0; + encoder->protected->max_residual_partition_order = 0; + encoder->protected->rice_parameter_search_dist = 0; + encoder->protected->total_samples_estimate = 0; + encoder->protected->seek_table = 0; + encoder->protected->padding = 0; + encoder->protected->last_metadata_is_last = true; + + encoder->private->write_callback = 0; + encoder->private->metadata_callback = 0; + encoder->private->client_data = 0; + return encoder; } @@ -202,59 +226,21 @@ void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder) * ***********************************************************************/ -FLAC__StreamEncoderState FLAC__stream_encoder_init( - FLAC__StreamEncoder *encoder, - bool streamable_subset, - bool do_mid_side_stereo, - bool loose_mid_side_stereo, - unsigned channels, - unsigned bits_per_sample, - unsigned sample_rate, - unsigned blocksize, - unsigned max_lpc_order, - unsigned qlp_coeff_precision, - bool do_qlp_coeff_prec_search, - bool do_exhaustive_model_search, - unsigned min_residual_partition_order, - unsigned max_residual_partition_order, - unsigned rice_parameter_search_dist, - uint64 total_samples_estimate, - const FLAC__StreamMetaData_SeekTable *seek_table, - unsigned padding, - bool last_metadata_is_last, - FLAC__StreamEncoderWriteStatus (*write_callback)(const FLAC__StreamEncoder *encoder, const byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data), - void (*metadata_callback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetaData *metadata, void *client_data), - void *client_data) +FLAC__StreamEncoderState FLAC__stream_encoder_init(FLAC__StreamEncoder *encoder) { unsigned i; FLAC__StreamMetaData padding_block; FLAC__StreamMetaData seek_table_block; FLAC__ASSERT(encoder != 0); - FLAC__ASSERT(write_callback != 0); - FLAC__ASSERT(metadata_callback != 0); if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return encoder->protected->state = FLAC__STREAM_ENCODER_ALREADY_INITIALIZED; encoder->protected->state = FLAC__STREAM_ENCODER_OK; - encoder->protected->streamable_subset = streamable_subset; - encoder->protected->do_mid_side_stereo = do_mid_side_stereo; - encoder->protected->loose_mid_side_stereo = loose_mid_side_stereo; - encoder->protected->channels = channels; - encoder->protected->bits_per_sample = bits_per_sample; - encoder->protected->sample_rate = sample_rate; - encoder->protected->blocksize = blocksize; - encoder->protected->max_lpc_order = max_lpc_order; - encoder->protected->qlp_coeff_precision = qlp_coeff_precision; - encoder->protected->do_qlp_coeff_prec_search = do_qlp_coeff_prec_search; - encoder->protected->do_exhaustive_model_search = do_exhaustive_model_search; - encoder->protected->min_residual_partition_order = min_residual_partition_order; - encoder->protected->max_residual_partition_order = max_residual_partition_order; - encoder->protected->rice_parameter_search_dist = rice_parameter_search_dist; - encoder->protected->total_samples_estimate = total_samples_estimate; - encoder->protected->seek_table = seek_table; + if(0 == encoder->private->write_callback || 0 == encoder->private->metadata_callback) + return encoder->protected->state = FLAC__STREAM_ENCODER_INVALID_CALLBACK; if(encoder->protected->channels == 0 || encoder->protected->channels > FLAC__MAX_CHANNELS) return encoder->protected->state = FLAC__STREAM_ENCODER_INVALID_NUMBER_OF_CHANNELS; @@ -411,9 +397,6 @@ FLAC__StreamEncoderState FLAC__stream_encoder_init( return encoder->protected->state; } FLAC__bitbuffer_init(&encoder->private->frame); - encoder->private->write_callback = write_callback; - encoder->private->metadata_callback = metadata_callback; - encoder->private->client_data = client_data; /* * write the stream header @@ -425,7 +408,7 @@ FLAC__StreamEncoderState FLAC__stream_encoder_init( return encoder->protected->state = FLAC__STREAM_ENCODER_FRAMING_ERROR; encoder->private->metadata.type = FLAC__METADATA_TYPE_STREAMINFO; - encoder->private->metadata.is_last = (encoder->protected->seek_table == 0 && padding == 0 && last_metadata_is_last); + encoder->private->metadata.is_last = (encoder->protected->seek_table == 0 && encoder->protected->padding == 0 && encoder->protected->last_metadata_is_last); encoder->private->metadata.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH; encoder->private->metadata.data.stream_info.min_blocksize = encoder->protected->blocksize; /* this encoder uses the same blocksize for the whole stream */ encoder->private->metadata.data.stream_info.max_blocksize = encoder->protected->blocksize; @@ -444,7 +427,7 @@ FLAC__StreamEncoderState FLAC__stream_encoder_init( if(!FLAC__seek_table_is_valid(encoder->protected->seek_table)) return encoder->protected->state = FLAC__STREAM_ENCODER_INVALID_SEEK_TABLE; seek_table_block.type = FLAC__METADATA_TYPE_SEEKTABLE; - seek_table_block.is_last = (padding == 0 && last_metadata_is_last); + seek_table_block.is_last = (encoder->protected->padding == 0 && encoder->protected->last_metadata_is_last); seek_table_block.length = encoder->protected->seek_table->num_points * FLAC__STREAM_METADATA_SEEKPOINT_LEN; seek_table_block.data.seek_table = *encoder->protected->seek_table; if(!FLAC__add_metadata_block(&seek_table_block, &encoder->private->frame)) @@ -452,10 +435,10 @@ FLAC__StreamEncoderState FLAC__stream_encoder_init( } /* add a PADDING block if requested */ - if(padding > 0) { + if(encoder->protected->padding > 0) { padding_block.type = FLAC__METADATA_TYPE_PADDING; - padding_block.is_last = last_metadata_is_last; - padding_block.length = padding; + padding_block.is_last = encoder->protected->last_metadata_is_last; + padding_block.length = encoder->protected->padding; if(!FLAC__add_metadata_block(&padding_block, &encoder->private->frame)) return encoder->protected->state = FLAC__STREAM_ENCODER_FRAMING_ERROR; } @@ -539,77 +522,245 @@ void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder) encoder->protected->state = FLAC__STREAM_ENCODER_UNINITIALIZED; } -FLAC__StreamEncoderState FLAC__stream_encoder_state(const FLAC__StreamEncoder *encoder) +bool FLAC__stream_encoder_set_streamable_subset(const FLAC__StreamEncoder *encoder, bool value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->protected->streamable_subset = value; + return true; +} + +bool FLAC__stream_encoder_set_do_mid_side_stereo(const FLAC__StreamEncoder *encoder, bool value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->protected->do_mid_side_stereo = value; + return true; +} + +bool FLAC__stream_encoder_set_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder, bool value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->protected->loose_mid_side_stereo = value; + return true; +} + +bool FLAC__stream_encoder_set_channels(const FLAC__StreamEncoder *encoder, unsigned value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->protected->channels = value; + return true; +} + +bool FLAC__stream_encoder_set_bits_per_sample(const FLAC__StreamEncoder *encoder, unsigned value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->protected->bits_per_sample = value; + return true; +} + +bool FLAC__stream_encoder_set_sample_rate(const FLAC__StreamEncoder *encoder, unsigned value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->protected->sample_rate = value; + return true; +} + +bool FLAC__stream_encoder_set_blocksize(const FLAC__StreamEncoder *encoder, unsigned value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->protected->blocksize = value; + return true; +} + +bool FLAC__stream_encoder_set_max_lpc_order(const FLAC__StreamEncoder *encoder, unsigned value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->protected->max_lpc_order = value; + return true; +} + +bool FLAC__stream_encoder_set_qlp_coeff_precision(const FLAC__StreamEncoder *encoder, unsigned value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->protected->qlp_coeff_precision = value; + return true; +} + +bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder, bool value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->protected->do_qlp_coeff_prec_search = value; + return true; +} + +bool FLAC__stream_encoder_set_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder, bool value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->protected->do_exhaustive_model_search = value; + return true; +} + +bool FLAC__stream_encoder_set_min_residual_partition_order(const FLAC__StreamEncoder *encoder, unsigned value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->protected->min_residual_partition_order = value; + return true; +} + +bool FLAC__stream_encoder_set_max_residual_partition_order(const FLAC__StreamEncoder *encoder, unsigned value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->protected->max_residual_partition_order = value; + return true; +} + +bool FLAC__stream_encoder_set_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder, unsigned value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->protected->rice_parameter_search_dist = value; + return true; +} + +bool FLAC__stream_encoder_set_total_samples_estimate(const FLAC__StreamEncoder *encoder, uint64 value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->protected->total_samples_estimate = value; + return true; +} + +bool FLAC__stream_encoder_set_seek_table(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetaData_SeekTable *value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->protected->seek_table = value; + return true; +} + +bool FLAC__stream_encoder_set_padding(const FLAC__StreamEncoder *encoder, unsigned value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->protected->padding = value; + return true; +} + +bool FLAC__stream_encoder_set_last_metadata_is_last(const FLAC__StreamEncoder *encoder, bool value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->protected->last_metadata_is_last = value; + return true; +} + +bool FLAC__stream_encoder_set_write_callback(const FLAC__StreamEncoder *encoder, FLAC__StreamEncoderWriteStatus (*value)(const FLAC__StreamEncoder *encoder, const byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->private->write_callback = value; + return true; +} + +bool FLAC__stream_encoder_set_metadata_callback(const FLAC__StreamEncoder *encoder, void (*value)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetaData *metadata, void *client_data)) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->private->metadata_callback = value; + return true; +} + +bool FLAC__stream_encoder_set_client_data(const FLAC__StreamEncoder *encoder, void *value) +{ + if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; + encoder->private->client_data = value; + return true; +} + +FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder) { return encoder->protected->state; } -bool FLAC__stream_encoder_streamable_subset(const FLAC__StreamEncoder *encoder) +bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder) { return encoder->protected->streamable_subset; } -bool FLAC__stream_encoder_do_mid_side_stereo(const FLAC__StreamEncoder *encoder) +bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder) { return encoder->protected->do_mid_side_stereo; } -bool FLAC__stream_encoder_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder) +bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder) { return encoder->protected->loose_mid_side_stereo; } -unsigned FLAC__stream_encoder_channels(const FLAC__StreamEncoder *encoder) +unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder) { return encoder->protected->channels; } -unsigned FLAC__stream_encoder_bits_per_sample(const FLAC__StreamEncoder *encoder) +unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder) { return encoder->protected->bits_per_sample; } -unsigned FLAC__stream_encoder_sample_rate(const FLAC__StreamEncoder *encoder) +unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder) { return encoder->protected->sample_rate; } -unsigned FLAC__stream_encoder_blocksize(const FLAC__StreamEncoder *encoder) +unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder) { return encoder->protected->blocksize; } -unsigned FLAC__stream_encoder_max_lpc_order(const FLAC__StreamEncoder *encoder) +unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder) { return encoder->protected->max_lpc_order; } -unsigned FLAC__stream_encoder_qlp_coeff_precision(const FLAC__StreamEncoder *encoder) +unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder) { return encoder->protected->qlp_coeff_precision; } -bool FLAC__stream_encoder_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder) +bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder) { return encoder->protected->do_qlp_coeff_prec_search; } -bool FLAC__stream_encoder_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder) +bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder) { return encoder->protected->do_exhaustive_model_search; } -unsigned FLAC__stream_encoder_min_residual_partition_order(const FLAC__StreamEncoder *encoder) +unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder) { return encoder->protected->min_residual_partition_order; } -unsigned FLAC__stream_encoder_max_residual_partition_order(const FLAC__StreamEncoder *encoder) +unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder) { return encoder->protected->max_residual_partition_order; } -unsigned FLAC__stream_encoder_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder) +unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder) { return encoder->protected->rice_parameter_search_dist; } @@ -1637,4 +1788,3 @@ unsigned stream_encoder_get_wasted_bits_(int32 signal[], unsigned samples) return shift; } - diff --git a/src/plugin_winamp2/in_flac.c b/src/plugin_winamp2/in_flac.c index a8563cff..e4e8d92f 100644 --- a/src/plugin_winamp2/in_flac.c +++ b/src/plugin_winamp2/in_flac.c @@ -41,7 +41,7 @@ typedef struct { unsigned length_in_ms; } stream_info_struct; -static bool stream_init(const char *infile); +static bool stream_init(const char *infilename); static FLAC__StreamDecoderWriteStatus write_callback(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const int32 *buffer[], void *client_data); static void metadata_callback(const FLAC__FileDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data); static void error_callback(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); @@ -161,7 +161,7 @@ void stop() thread_handle = INVALID_HANDLE_VALUE; } if(decoder) { - if(FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED) + if(FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED) FLAC__file_decoder_finish(decoder); } @@ -210,14 +210,20 @@ void getfileinfo(char *filename, char *title, int *length_in_ms) FLAC__FileDecoder *tmp_decoder = FLAC__file_decoder_new(); stream_info_struct tmp_stream_info; tmp_stream_info.abort_flag = false; - if(FLAC__file_decoder_init(tmp_decoder, false /*md5_check*/, filename, write_callback, metadata_callback, error_callback, &tmp_stream_info) != FLAC__FILE_DECODER_OK) + FLAC__file_decoder_set_md5_checking(tmp_decoder, false); + FLAC__file_decoder_set_filename(tmp_decoder, filename); + FLAC__file_decoder_set_write_callback(tmp_decoder, write_callback); + FLAC__file_decoder_set_metadata_callback(tmp_decoder, metadata_callback); + FLAC__file_decoder_set_error_callback(tmp_decoder, error_callback); + FLAC__file_decoder_set_client_data(tmp_decoder, &tmp_stream_info); + if(FLAC__file_decoder_init(tmp_decoder) != FLAC__FILE_DECODER_OK) return; if(!FLAC__file_decoder_process_metadata(tmp_decoder)) return; *length_in_ms = (int)tmp_stream_info.length_in_ms; - if(FLAC__file_decoder_state(tmp_decoder) != FLAC__FILE_DECODER_UNINITIALIZED) + if(FLAC__file_decoder_get_state(tmp_decoder) != FLAC__FILE_DECODER_UNINITIALIZED) FLAC__file_decoder_finish(tmp_decoder); FLAC__file_decoder_delete(tmp_decoder); } @@ -261,7 +267,7 @@ DWORD WINAPI __stdcall DecodeThread(void *b) } else if (mod.outMod->CanWrite() >= ((int)(576*channels*bytes_per_sample) << (mod.dsp_isactive()?1:0))) { while(samples_in_reservoir < 576) { - if(FLAC__file_decoder_state(decoder) == FLAC__FILE_DECODER_END_OF_FILE) { + if(FLAC__file_decoder_get_state(decoder) == FLAC__FILE_DECODER_END_OF_FILE) { done = 1; break; } @@ -352,9 +358,15 @@ __declspec( dllexport ) In_Module * winampGetInModule2() /*********************************************************************** * local routines **********************************************************************/ -bool stream_init(const char *infile) +bool stream_init(const char *infilename) { - if(FLAC__file_decoder_init(decoder, false /*md5_check*/, infile, write_callback, metadata_callback, error_callback, &stream_info) != FLAC__FILE_DECODER_OK) { + FLAC__file_decoder_set_md5_checking(decoder, false); + FLAC__file_decoder_set_filename(decoder, infilename); + FLAC__file_decoder_set_write_callback(decoder, write_callback); + FLAC__file_decoder_set_metadata_callback(decoder, metadata_callback); + FLAC__file_decoder_set_error_callback(decoder, error_callback); + FLAC__file_decoder_set_client_data(decoder, &stream_info); + if(FLAC__file_decoder_init(decoder) != FLAC__FILE_DECODER_OK) { MessageBox(mod.hMainWindow,"ERROR initializing decoder, state = %d\n","ERROR initializing decoder",0); return false; } diff --git a/src/plugin_winamp3/in_flac.cpp b/src/plugin_winamp3/in_flac.cpp index 81c839ea..80ced211 100644 --- a/src/plugin_winamp3/in_flac.cpp +++ b/src/plugin_winamp3/in_flac.cpp @@ -89,7 +89,13 @@ int FLAC_Info::Open(char *url) return 1; } tmp_file_info.abort_flag = false; - if(FLAC__file_decoder_init(tmp_decoder, false /*md5_check*/, filename, write_callback_, metadata_callback_, error_callback_, &tmp_file_info) != FLAC__FILE_DECODER_OK) { + FLAC__file_decoder_set_md5_checking(tmp_decoder, false); + FLAC__file_decoder_set_filename(tmp_decoder, filename); + FLAC__file_decoder_set_write_callback(tmp_decoder, write_callback_); + FLAC__file_decoder_set_metadata_callback(tmp_decoder, metadata_callback_); + FLAC__file_decoder_set_error_callback(tmp_decoder, error_callback_); + FLAC__file_decoder_set_client_data(tmp_decoder, &tmp_file_info); + if(FLAC__file_decoder_init(tmp_decoder) != FLAC__FILE_DECODER_OK) { length_in_msec_ = -1; return 1; } @@ -100,7 +106,7 @@ int FLAC_Info::Open(char *url) length_in_msec_ = (int)tmp_file_info.length_in_msec; - if(FLAC__file_decoder_state(tmp_decoder) != FLAC__FILE_DECODER_UNINITIALIZED) + if(FLAC__file_decoder_get_state(tmp_decoder) != FLAC__FILE_DECODER_UNINITIALIZED) FLAC__file_decoder_finish(tmp_decoder); FLAC__file_decoder_delete(tmp_decoder); @@ -213,7 +219,7 @@ int FLAC_Source::GetSamples(char *sample_buffer, int bytes, int *bps, int *nch, const unsigned wide_samples = bytes / channels / bytes_per_sample; if(bytes&0x3)fprintf(stderr,"@@@ Got odd buffer size request\n"); while(reservoir_samples_ < wide_samples) { - if(FLAC__file_decoder_state(decoder) == FLAC__FILE_DECODER_END_OF_FILE) { + if(FLAC__file_decoder_get_state(decoder) == FLAC__FILE_DECODER_END_OF_FILE) { file_info_.eof = true; break; } @@ -256,7 +262,7 @@ int FLAC_Source::SetPosition(int position) void FLAC_Source::cleanup() { - if(decoder_ && FLAC__file_decoder_state(decoder_) != FLAC__FILE_DECODER_UNINITIALIZED) + if(decoder_ && FLAC__file_decoder_get_state(decoder_) != FLAC__FILE_DECODER_UNINITIALIZED) FLAC__file_decoder_finish(decoder_); reservoir_samples_ = 0; @@ -322,7 +328,13 @@ bool decoder_init_(const char *filename) if(decoder_ == 0) return false; - if(FLAC__file_decoder_init(decoder_, false /*md5_check*/, filename, write_callback_, metadata_callback_, error_callback_, &file_info_) != FLAC__FILE_DECODER_OK) + FLAC__file_decoder_set_md5_checking(decoder, false); + FLAC__file_decoder_set_filename(decoder, filename); + FLAC__file_decoder_set_write_callback(decoder, write_callback_); + FLAC__file_decoder_set_metadata_callback(decoder, metadata_callback_); + FLAC__file_decoder_set_error_callback(decoder, error_callback_); + FLAC__file_decoder_set_client_data(decoder, &file_info_); + if(FLAC__file_decoder_init(decoder_) != FLAC__FILE_DECODER_OK) return false; file_info_.abort_flag = false; diff --git a/src/plugin_xmms/plugin.c b/src/plugin_xmms/plugin.c index b854b05a..51e51b84 100644 --- a/src/plugin_xmms/plugin.c +++ b/src/plugin_xmms/plugin.c @@ -152,7 +152,7 @@ void FLAC_XMMS__play_file(char *filename) if (flac_ip.output->open_audio(file_info_.sample_format, file_info_.sample_rate, file_info_.channels) == 0) { audio_error_ = true; - if(decoder_ && FLAC__file_decoder_state(decoder_) != FLAC__FILE_DECODER_UNINITIALIZED) + if(decoder_ && FLAC__file_decoder_get_state(decoder_) != FLAC__FILE_DECODER_UNINITIALIZED) FLAC__file_decoder_finish(decoder_); return; } @@ -170,7 +170,7 @@ void FLAC_XMMS__stop() file_info_.is_playing = false; pthread_join(decode_thread_, NULL); flac_ip.output->close_audio(); - if(decoder_ && FLAC__file_decoder_state(decoder_) != FLAC__FILE_DECODER_UNINITIALIZED) + if(decoder_ && FLAC__file_decoder_get_state(decoder_) != FLAC__FILE_DECODER_UNINITIALIZED) FLAC__file_decoder_finish(decoder_); } } @@ -222,7 +222,13 @@ void FLAC_XMMS__get_song_info(char *filename, char **title, int *length_in_msec) return; } tmp_file_info.abort_flag = false; - if(FLAC__file_decoder_init(tmp_decoder, false /*md5_check*/, filename, write_callback_, metadata_callback_, error_callback_, &tmp_file_info) != FLAC__FILE_DECODER_OK) { + FLAC__file_decoder_set_md5_checking(tmp_decoder, false); + FLAC__file_decoder_set_filename(tmp_decoder, filename); + FLAC__file_decoder_set_write_callback(tmp_decoder, write_callback_); + FLAC__file_decoder_set_metadata_callback(tmp_decoder, metadata_callback_); + FLAC__file_decoder_set_error_callback(tmp_decoder, error_callback_); + FLAC__file_decoder_set_client_data(tmp_decoder, &tmp_file_info); + if(FLAC__file_decoder_init(tmp_decoder) != FLAC__FILE_DECODER_OK) { *length_in_msec = -1; return; } @@ -233,7 +239,7 @@ void FLAC_XMMS__get_song_info(char *filename, char **title, int *length_in_msec) *length_in_msec = (int)tmp_file_info.length_in_msec; - if(FLAC__file_decoder_state(tmp_decoder) != FLAC__FILE_DECODER_UNINITIALIZED) + if(FLAC__file_decoder_get_state(tmp_decoder) != FLAC__FILE_DECODER_UNINITIALIZED) FLAC__file_decoder_finish(tmp_decoder); FLAC__file_decoder_delete(tmp_decoder); } @@ -297,7 +303,7 @@ void *play_loop_(void *arg) while(file_info_.is_playing) { if(!file_info_.eof) { while(reservoir_samples_ < SAMPLES_PER_WRITE) { - if(FLAC__file_decoder_state(decoder_) == FLAC__FILE_DECODER_END_OF_FILE) { + if(FLAC__file_decoder_get_state(decoder_) == FLAC__FILE_DECODER_END_OF_FILE) { file_info_.eof = true; break; } @@ -342,7 +348,7 @@ void *play_loop_(void *arg) } } - if(decoder_ && FLAC__file_decoder_state(decoder_) != FLAC__FILE_DECODER_UNINITIALIZED) + if(decoder_ && FLAC__file_decoder_get_state(decoder_) != FLAC__FILE_DECODER_UNINITIALIZED) FLAC__file_decoder_finish(decoder_); /* are these two calls necessary? */ @@ -358,7 +364,13 @@ bool decoder_init_(const char *filename) if(decoder_ == 0) return false; - if(FLAC__file_decoder_init(decoder_, false /*md5_check*/, filename, write_callback_, metadata_callback_, error_callback_, &file_info_) != FLAC__FILE_DECODER_OK) + FLAC__file_decoder_set_md5_checking(decoder_, false); + FLAC__file_decoder_set_filename(decoder_, filename); + FLAC__file_decoder_set_write_callback(decoder_, write_callback_); + FLAC__file_decoder_set_metadata_callback(decoder_, metadata_callback_); + FLAC__file_decoder_set_error_callback(decoder_, error_callback_); + FLAC__file_decoder_set_client_data(decoder_, &file_info_); + if(FLAC__file_decoder_init(decoder_) != FLAC__FILE_DECODER_OK) return false; file_info_.abort_flag = false; |