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

minor reformatting

parent 09b3926f
......@@ -34,7 +34,6 @@
#include <string.h> /* for memcpy() */
#include "FLAC/assert.h"
#include "protected/seekable_stream_encoder.h"
#include "protected/stream_encoder.h"
#ifdef max
#undef max
......@@ -716,13 +715,16 @@ void set_defaults_(FLAC__SeekableStreamEncoder *encoder)
encoder->private_->seek_table = 0;
}
FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__StreamEncoder *unused, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
{
FLAC__SeekableStreamEncoder *seekable_stream_encoder = (FLAC__SeekableStreamEncoder*)client_data;
FLAC__SeekableStreamEncoder *encoder = (FLAC__SeekableStreamEncoder*)client_data;
FLAC__StreamEncoderWriteStatus status;
FLAC__uint64 output_position;
if(seekable_stream_encoder->private_->tell_callback(seekable_stream_encoder, &output_position, seekable_stream_encoder->private_->client_data) != FLAC__SEEKABLE_STREAM_ENCODER_TELL_STATUS_OK)
(void)unused; /* silence compiler warning about unused parameter */
FLAC__ASSERT(encoder->private_->FLAC_stream_encoder == unused);
if(encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) != FLAC__SEEKABLE_STREAM_ENCODER_TELL_STATUS_OK)
return encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_TELL_ERROR;
/*
......@@ -731,9 +733,9 @@ FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__StreamEncoder *encode
if(samples == 0) {
FLAC__MetadataType type = (buffer[0] & 0x7f);
if(type == FLAC__METADATA_TYPE_STREAMINFO)
seekable_stream_encoder->protected_->streaminfo_offset = output_position;
else if(type == FLAC__METADATA_TYPE_SEEKTABLE && seekable_stream_encoder->protected_->seektable_offset == 0)
seekable_stream_encoder->protected_->seektable_offset = output_position;
encoder->protected_->streaminfo_offset = output_position;
else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
encoder->protected_->seektable_offset = output_position;
}
/*
......@@ -741,22 +743,22 @@ FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__StreamEncoder *encode
* means we're still writing metadata and haven't hit the first
* frame yet)
*/
if(0 != seekable_stream_encoder->private_->seek_table && seekable_stream_encoder->protected_->audio_offset > 0 && seekable_stream_encoder->private_->seek_table->num_points > 0) {
if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
const FLAC__uint64 frame_first_sample = seekable_stream_encoder->private_->samples_written;
const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
FLAC__uint64 test_sample;
unsigned i;
for(i = seekable_stream_encoder->private_->first_seekpoint_to_check; i < seekable_stream_encoder->private_->seek_table->num_points; i++) {
test_sample = seekable_stream_encoder->private_->seek_table->points[i].sample_number;
for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
test_sample = encoder->private_->seek_table->points[i].sample_number;
if(test_sample > frame_last_sample) {
break;
}
else if(test_sample >= frame_first_sample) {
seekable_stream_encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
seekable_stream_encoder->private_->seek_table->points[i].stream_offset = output_position - seekable_stream_encoder->protected_->audio_offset;
seekable_stream_encoder->private_->seek_table->points[i].frame_samples = blocksize;
seekable_stream_encoder->private_->first_seekpoint_to_check++;
encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
encoder->private_->seek_table->points[i].frame_samples = blocksize;
encoder->private_->first_seekpoint_to_check++;
/* DO NOT: "break;" and here's why:
* The seektable template may contain more than one target
* sample for any given frame; we will keep looping, generating
......@@ -765,25 +767,25 @@ FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__StreamEncoder *encode
*/
}
else {
seekable_stream_encoder->private_->first_seekpoint_to_check++;
encoder->private_->first_seekpoint_to_check++;
}
}
}
status = seekable_stream_encoder->private_->write_callback(seekable_stream_encoder, buffer, bytes, samples, current_frame, seekable_stream_encoder->private_->client_data);
status = encoder->private_->write_callback(encoder, buffer, bytes, samples, current_frame, encoder->private_->client_data);
if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
seekable_stream_encoder->private_->samples_written += samples;
encoder->private_->samples_written += samples;
}
else
seekable_stream_encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR;
encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR;
return status;
}
void metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data)
void metadata_callback_(const FLAC__StreamEncoder *unused, const FLAC__StreamMetadata *metadata, void *client_data)
{
FLAC__SeekableStreamEncoder *seekable_stream_encoder = (FLAC__SeekableStreamEncoder*)client_data;
FLAC__SeekableStreamEncoder *encoder = (FLAC__SeekableStreamEncoder*)client_data;
FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
const unsigned min_framesize = metadata->data.stream_info.min_framesize;
......@@ -797,7 +799,8 @@ void metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMe
* blocks.
*/
(void)encoder; /* silence compiler warning about unused parameter */
(void)unused; /* silence compiler warning about unused parameter */
FLAC__ASSERT(encoder->private_->FLAC_stream_encoder == unused);
/*@@@ reopen callback here? The docs currently require user to open files in update mode from the start */
......@@ -823,12 +826,12 @@ void metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMe
FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
) / 8;
if(seekable_stream_encoder->private_->seek_callback(seekable_stream_encoder, seekable_stream_encoder->protected_->streaminfo_offset + md5_offset, seekable_stream_encoder->private_->client_data) != FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK) {
seekable_stream_encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_SEEK_ERROR;
if(encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data) != FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK) {
encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_SEEK_ERROR;
return;
}
if(seekable_stream_encoder->private_->write_callback(seekable_stream_encoder, metadata->data.stream_info.md5sum, 16, 0, 0, seekable_stream_encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
seekable_stream_encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR;
if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR;
return;
}
}
......@@ -855,12 +858,12 @@ void metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMe
b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
b[4] = (FLAC__byte)(samples & 0xFF);
if(seekable_stream_encoder->private_->seek_callback(seekable_stream_encoder, seekable_stream_encoder->protected_->streaminfo_offset + total_samples_byte_offset, seekable_stream_encoder->private_->client_data) != FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK) {
seekable_stream_encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_SEEK_ERROR;
if(encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + total_samples_byte_offset, encoder->private_->client_data) != FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK) {
encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_SEEK_ERROR;
return;
}
if(seekable_stream_encoder->private_->write_callback(seekable_stream_encoder, b, 5, 0, 0, seekable_stream_encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
seekable_stream_encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR;
if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR;
return;
}
}
......@@ -882,12 +885,12 @@ void metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMe
b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
b[5] = (FLAC__byte)(max_framesize & 0xFF);
if(seekable_stream_encoder->private_->seek_callback(seekable_stream_encoder, seekable_stream_encoder->protected_->streaminfo_offset + min_framesize_offset, seekable_stream_encoder->private_->client_data) != FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK) {
seekable_stream_encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_SEEK_ERROR;
if(encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + min_framesize_offset, encoder->private_->client_data) != FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK) {
encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_SEEK_ERROR;
return;
}
if(seekable_stream_encoder->private_->write_callback(seekable_stream_encoder, b, 6, 0, 0, seekable_stream_encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
seekable_stream_encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR;
if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR;
return;
}
}
......@@ -895,22 +898,22 @@ void metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMe
/*
* Write seektable
*/
if(0 != seekable_stream_encoder->private_->seek_table && seekable_stream_encoder->private_->seek_table->num_points > 0 && seekable_stream_encoder->protected_->seektable_offset > 0) {
if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
unsigned i;
FLAC__format_seektable_sort(seekable_stream_encoder->private_->seek_table);
FLAC__format_seektable_sort(encoder->private_->seek_table);
FLAC__ASSERT(FLAC__format_seektable_is_legal(seekable_stream_encoder->private_->seek_table));
FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
if(seekable_stream_encoder->private_->seek_callback(seekable_stream_encoder, seekable_stream_encoder->protected_->seektable_offset + FLAC__STREAM_METADATA_HEADER_LENGTH, seekable_stream_encoder->private_->client_data) != FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK) {
seekable_stream_encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_SEEK_ERROR;
if(encoder->private_->seek_callback(encoder, encoder->protected_->seektable_offset + FLAC__STREAM_METADATA_HEADER_LENGTH, encoder->private_->client_data) != FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK) {
encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_SEEK_ERROR;
return;
}
for(i = 0; i < seekable_stream_encoder->private_->seek_table->num_points; i++) {
for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
FLAC__uint64 xx;
unsigned x;
xx = seekable_stream_encoder->private_->seek_table->points[i].sample_number;
xx = encoder->private_->seek_table->points[i].sample_number;
b[7] = (FLAC__byte)xx; xx >>= 8;
b[6] = (FLAC__byte)xx; xx >>= 8;
b[5] = (FLAC__byte)xx; xx >>= 8;
......@@ -919,7 +922,7 @@ void metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMe
b[2] = (FLAC__byte)xx; xx >>= 8;
b[1] = (FLAC__byte)xx; xx >>= 8;
b[0] = (FLAC__byte)xx; xx >>= 8;
xx = seekable_stream_encoder->private_->seek_table->points[i].stream_offset;
xx = encoder->private_->seek_table->points[i].stream_offset;
b[15] = (FLAC__byte)xx; xx >>= 8;
b[14] = (FLAC__byte)xx; xx >>= 8;
b[13] = (FLAC__byte)xx; xx >>= 8;
......@@ -928,11 +931,11 @@ void metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMe
b[10] = (FLAC__byte)xx; xx >>= 8;
b[9] = (FLAC__byte)xx; xx >>= 8;
b[8] = (FLAC__byte)xx; xx >>= 8;
x = seekable_stream_encoder->private_->seek_table->points[i].frame_samples;
x = encoder->private_->seek_table->points[i].frame_samples;
b[17] = (FLAC__byte)x; x >>= 8;
b[16] = (FLAC__byte)x; x >>= 8;
if(seekable_stream_encoder->private_->write_callback(seekable_stream_encoder, b, 18, 0, 0, seekable_stream_encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
seekable_stream_encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR;
if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
encoder->protected_->state = FLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR;
return;
}
}
......
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