Commit 72983924 authored by Josh Coalson's avatar Josh Coalson
Browse files

rename ENCODING to STREAMINFO

parent 353c250e
......@@ -393,11 +393,11 @@ void metadata_callback(const FLAC__FileDecoder *decoder, const FLAC__StreamMetaD
{
stream_info_struct *stream_info = (stream_info_struct *)client_data;
(void)decoder;
if(metadata->type == FLAC__METADATA_TYPE_ENCODING) {
stream_info->total_samples = metadata->data.encoding.total_samples - stream_info->skip;
stream_info->bps = metadata->data.encoding.bits_per_sample;
stream_info->channels = metadata->data.encoding.channels;
stream_info->sample_rate = metadata->data.encoding.sample_rate;
if(metadata->type == FLAC__METADATA_TYPE_STREAMINFO) {
stream_info->total_samples = metadata->data.stream_info.total_samples - stream_info->skip;
stream_info->bps = metadata->data.stream_info.bits_per_sample;
stream_info->channels = metadata->data.stream_info.channels;
stream_info->sample_rate = metadata->data.stream_info.sample_rate;
if(stream_info->bps != 8 && stream_info->bps != 16) {
fprintf(stderr, "ERROR: bits per sample is not 8 or 16\n");
......
......@@ -36,7 +36,7 @@ typedef struct FLAC__FileDecoderPrivate {
byte stored_md5sum[16]; /* this is what is stored in the metadata */
byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
/* the rest of these are only used for seeking: */
FLAC__StreamMetaData_Encoding metadata; /* we keep this around so we can figure out how to seek quickly */
FLAC__StreamMetaData_StreamInfo stream_info; /* we keep this around so we can figure out how to seek quickly */
FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
uint64 target_sample;
} FLAC__FileDecoderPrivate;
......@@ -256,7 +256,7 @@ bool FLAC__file_decoder_seek_absolute(FLAC__FileDecoder *decoder, uint64 sample)
decoder->state = FLAC__FILE_DECODER_STREAM_ERROR;
return false;
}
if(sample > decoder->guts->metadata.total_samples) {
if(sample > decoder->guts->stream_info.total_samples) {
decoder->state = FLAC__FILE_DECODER_SEEK_ERROR;
return false;
}
......@@ -340,10 +340,10 @@ void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMe
FLAC__FileDecoder *file_decoder = (FLAC__FileDecoder *)client_data;
(void)decoder;
if(metadata->type == FLAC__METADATA_TYPE_ENCODING) {
file_decoder->guts->metadata = metadata->data.encoding;
if(metadata->type == FLAC__METADATA_TYPE_STREAMINFO) {
file_decoder->guts->stream_info = metadata->data.stream_info;
/* save the MD5 signature for comparison later */
memcpy(file_decoder->guts->stored_md5sum, metadata->data.encoding.md5sum, 16);
memcpy(file_decoder->guts->stored_md5sum, metadata->data.stream_info.md5sum, 16);
if(0 == memcmp(file_decoder->guts->stored_md5sum, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16))
file_decoder->check_md5 = false;
}
......@@ -366,15 +366,15 @@ bool seek_to_absolute_sample_(FLAC__FileDecoder *decoder, long filesize, uint64
unsigned approx_bytes_per_frame;
uint64 last_frame_sample = 0xffffffffffffffff;
bool needs_seek;
const bool is_variable_blocksize_stream = (decoder->guts->metadata.min_blocksize != decoder->guts->metadata.max_blocksize);
const bool is_variable_blocksize_stream = (decoder->guts->stream_info.min_blocksize != decoder->guts->stream_info.max_blocksize);
if(!is_variable_blocksize_stream) {
/* we are just guessing here, but we want to guess high, not low */
/* note there are no () around 'decoder->guts->metadata.bits_per_sample/8' to keep precision up since it's an integer calulation */
approx_bytes_per_frame = decoder->guts->metadata.min_blocksize * decoder->guts->metadata.channels * decoder->guts->metadata.bits_per_sample/8 + 64;
/* note there are no () around 'decoder->guts->stream_info.bits_per_sample/8' to keep precision up since it's an integer calulation */
approx_bytes_per_frame = decoder->guts->stream_info.min_blocksize * decoder->guts->stream_info.channels * decoder->guts->stream_info.bits_per_sample/8 + 64;
}
else
approx_bytes_per_frame = 1152 * decoder->guts->metadata.channels * decoder->guts->metadata.bits_per_sample/8 + 64;
approx_bytes_per_frame = 1152 * decoder->guts->stream_info.channels * decoder->guts->stream_info.bits_per_sample/8 + 64;
/* Now we need to use the metadata and the filelength to search to the frame with the correct sample */
if(-1 == (l = ftell(decoder->guts->file))) {
......@@ -384,11 +384,11 @@ bool seek_to_absolute_sample_(FLAC__FileDecoder *decoder, long filesize, uint64
l -= FLAC__stream_decoder_input_bytes_unconsumed(decoder->guts->stream);
#ifdef _MSC_VER
/* with VC++ you have to spoon feed it the casting */
pos = l + (long)((double)(int64)target_sample / (double)(int64)decoder->guts->metadata.total_samples * (double)(filesize-l+1)) - approx_bytes_per_frame;
pos = l + (long)((double)(int64)target_sample / (double)(int64)decoder->guts->stream_info.total_samples * (double)(filesize-l+1)) - approx_bytes_per_frame;
#else
pos = l + (long)((double)target_sample / (double)decoder->guts->metadata.total_samples * (double)(filesize-l+1)) - approx_bytes_per_frame;
pos = l + (long)((double)target_sample / (double)decoder->guts->stream_info.total_samples * (double)(filesize-l+1)) - approx_bytes_per_frame;
#endif
r = filesize - ((decoder->guts->metadata.channels * decoder->guts->metadata.bits_per_sample * FLAC__MAX_BLOCK_SIZE) / 8 + 64);
r = filesize - ((decoder->guts->stream_info.channels * decoder->guts->stream_info.bits_per_sample * FLAC__MAX_BLOCK_SIZE) / 8 + 64);
if(pos >= r)
pos = r-1;
if(pos < l)
......
......@@ -440,55 +440,55 @@ bool stream_decoder_read_metadata_(FLAC__StreamDecoder *decoder)
return false; /* the read_callback_ sets the state for us */
if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN, read_callback_, decoder))
return false; /* the read_callback_ sets the state for us */
if(type == FLAC__METADATA_TYPE_ENCODING) {
if(type == FLAC__METADATA_TYPE_STREAMINFO) {
unsigned used_bits = 0;
decoder->guts->stream_header.type = type;
decoder->guts->stream_header.is_last = last_block;
decoder->guts->stream_header.length = length;
if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_ENCODING_MIN_BLOCK_SIZE_LEN, read_callback_, decoder))
if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN, read_callback_, decoder))
return false; /* the read_callback_ sets the state for us */
decoder->guts->stream_header.data.encoding.min_blocksize = x;
used_bits += FLAC__STREAM_METADATA_ENCODING_MIN_BLOCK_SIZE_LEN;
decoder->guts->stream_header.data.stream_info.min_blocksize = x;
used_bits += FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_ENCODING_MAX_BLOCK_SIZE_LEN, read_callback_, decoder))
if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN, read_callback_, decoder))
return false; /* the read_callback_ sets the state for us */
decoder->guts->stream_header.data.encoding.max_blocksize = x;
used_bits += FLAC__STREAM_METADATA_ENCODING_MAX_BLOCK_SIZE_LEN;
decoder->guts->stream_header.data.stream_info.max_blocksize = x;
used_bits += FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_ENCODING_MIN_FRAME_SIZE_LEN, read_callback_, decoder))
if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN, read_callback_, decoder))
return false; /* the read_callback_ sets the state for us */
decoder->guts->stream_header.data.encoding.min_framesize = x;
used_bits += FLAC__STREAM_METADATA_ENCODING_MIN_FRAME_SIZE_LEN;
decoder->guts->stream_header.data.stream_info.min_framesize = x;
used_bits += FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_ENCODING_MAX_FRAME_SIZE_LEN, read_callback_, decoder))
if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN, read_callback_, decoder))
return false; /* the read_callback_ sets the state for us */
decoder->guts->stream_header.data.encoding.max_framesize = x;
used_bits += FLAC__STREAM_METADATA_ENCODING_MAX_FRAME_SIZE_LEN;
decoder->guts->stream_header.data.stream_info.max_framesize = x;
used_bits += FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_ENCODING_SAMPLE_RATE_LEN, read_callback_, decoder))
if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN, read_callback_, decoder))
return false; /* the read_callback_ sets the state for us */
decoder->guts->stream_header.data.encoding.sample_rate = x;
used_bits += FLAC__STREAM_METADATA_ENCODING_SAMPLE_RATE_LEN;
decoder->guts->stream_header.data.stream_info.sample_rate = x;
used_bits += FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_ENCODING_CHANNELS_LEN, read_callback_, decoder))
if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN, read_callback_, decoder))
return false; /* the read_callback_ sets the state for us */
decoder->guts->stream_header.data.encoding.channels = x+1;
used_bits += FLAC__STREAM_METADATA_ENCODING_CHANNELS_LEN;
decoder->guts->stream_header.data.stream_info.channels = x+1;
used_bits += FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_ENCODING_BITS_PER_SAMPLE_LEN, read_callback_, decoder))
if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN, read_callback_, decoder))
return false; /* the read_callback_ sets the state for us */
decoder->guts->stream_header.data.encoding.bits_per_sample = x+1;
used_bits += FLAC__STREAM_METADATA_ENCODING_BITS_PER_SAMPLE_LEN;
decoder->guts->stream_header.data.stream_info.bits_per_sample = x+1;
used_bits += FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
if(!FLAC__bitbuffer_read_raw_uint64(&decoder->guts->input, &decoder->guts->stream_header.data.encoding.total_samples, FLAC__STREAM_METADATA_ENCODING_TOTAL_SAMPLES_LEN, read_callback_, decoder))
if(!FLAC__bitbuffer_read_raw_uint64(&decoder->guts->input, &decoder->guts->stream_header.data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN, read_callback_, decoder))
return false; /* the read_callback_ sets the state for us */
used_bits += FLAC__STREAM_METADATA_ENCODING_TOTAL_SAMPLES_LEN;
used_bits += FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
for(i = 0; i < 16; i++) {
if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, 8, read_callback_, decoder))
return false; /* the read_callback_ sets the state for us */
decoder->guts->stream_header.data.encoding.md5sum[i] = (byte)x;
decoder->guts->stream_header.data.stream_info.md5sum[i] = (byte)x;
}
used_bits += 128;
......@@ -548,8 +548,8 @@ bool stream_decoder_frame_sync_(FLAC__StreamDecoder *decoder)
/* If we know the total number of samples in the stream, stop if we've read that many. */
/* This will stop us, for example, from wasting time trying to sync on an ID3V1 tag. */
if(decoder->guts->has_stream_header && decoder->guts->stream_header.data.encoding.total_samples) {
if(decoder->guts->samples_decoded >= decoder->guts->stream_header.data.encoding.total_samples) {
if(decoder->guts->has_stream_header && decoder->guts->stream_header.data.stream_info.total_samples) {
if(decoder->guts->samples_decoded >= decoder->guts->stream_header.data.stream_info.total_samples) {
decoder->state = FLAC__STREAM_DECODER_END_OF_STREAM;
return true;
}
......@@ -733,8 +733,8 @@ bool stream_decoder_read_frame_header_(FLAC__StreamDecoder *decoder)
switch(x = raw_header[1] >> 4) {
case 0:
if(decoder->guts->has_stream_header && decoder->guts->stream_header.data.encoding.min_blocksize == decoder->guts->stream_header.data.encoding.max_blocksize) /* i.e. it's a fixed-blocksize stream */
decoder->guts->frame.header.blocksize = decoder->guts->stream_header.data.encoding.min_blocksize;
if(decoder->guts->has_stream_header && decoder->guts->stream_header.data.stream_info.min_blocksize == decoder->guts->stream_header.data.stream_info.max_blocksize) /* i.e. it's a fixed-blocksize stream */
decoder->guts->frame.header.blocksize = decoder->guts->stream_header.data.stream_info.min_blocksize;
else
is_unparseable = true;
break;
......@@ -759,7 +759,7 @@ bool stream_decoder_read_frame_header_(FLAC__StreamDecoder *decoder)
switch(x = raw_header[1] & 0x0f) {
case 0:
if(decoder->guts->has_stream_header)
decoder->guts->frame.header.sample_rate = decoder->guts->stream_header.data.encoding.sample_rate;
decoder->guts->frame.header.sample_rate = decoder->guts->stream_header.data.stream_info.sample_rate;
else
is_unparseable = true;
break;
......@@ -831,7 +831,7 @@ bool stream_decoder_read_frame_header_(FLAC__StreamDecoder *decoder)
switch(x = (unsigned)(raw_header[2] & 0x0e) >> 1) {
case 0:
if(decoder->guts->has_stream_header)
decoder->guts->frame.header.bits_per_sample = decoder->guts->stream_header.data.encoding.bits_per_sample;
decoder->guts->frame.header.bits_per_sample = decoder->guts->stream_header.data.stream_info.bits_per_sample;
else
is_unparseable = true;
break;
......@@ -889,8 +889,8 @@ bool stream_decoder_read_frame_header_(FLAC__StreamDecoder *decoder)
return true;
}
}
if(decoder->guts->has_stream_header && decoder->guts->stream_header.data.encoding.min_blocksize == decoder->guts->stream_header.data.encoding.max_blocksize) /* i.e. it's a fixed-blocksize stream */
decoder->guts->frame.header.number.sample_number = (uint64)decoder->guts->last_frame_number * (int64)decoder->guts->stream_header.data.encoding.min_blocksize + xx;
if(decoder->guts->has_stream_header && decoder->guts->stream_header.data.stream_info.min_blocksize == decoder->guts->stream_header.data.stream_info.max_blocksize) /* i.e. it's a fixed-blocksize stream */
decoder->guts->frame.header.number.sample_number = (uint64)decoder->guts->last_frame_number * (int64)decoder->guts->stream_header.data.stream_info.min_blocksize + xx;
else
decoder->guts->frame.header.number.sample_number = xx;
}
......@@ -920,7 +920,7 @@ bool stream_decoder_read_frame_header_(FLAC__StreamDecoder *decoder)
}
decoder->guts->last_frame_number = x;
if(decoder->guts->has_stream_header) {
decoder->guts->frame.header.number.sample_number = (int64)decoder->guts->stream_header.data.encoding.min_blocksize * (int64)x;
decoder->guts->frame.header.number.sample_number = (int64)decoder->guts->stream_header.data.stream_info.min_blocksize * (int64)x;
}
else {
is_unparseable = true;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment