further implementation of new CUESHEET metadata block
This commit is contained in:
parent
16cf47e351
commit
e48693818d
@ -146,7 +146,8 @@ FLAC_API const char * const FLAC__MetadataTypeString[] = {
|
||||
"PADDING",
|
||||
"APPLICATION",
|
||||
"SEEKTABLE",
|
||||
"VORBIS_COMMENT"
|
||||
"VORBIS_COMMENT",
|
||||
"CUESHEET"
|
||||
};
|
||||
|
||||
FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
|
||||
|
@ -71,6 +71,8 @@ static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_application_
|
||||
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_seektable_(FILE *file, FLAC__StreamMetadata_SeekTable *block, unsigned block_length);
|
||||
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_entry_(FILE *file, FLAC__StreamMetadata_VorbisComment_Entry *entry);
|
||||
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_(FILE *file, FLAC__StreamMetadata_VorbisComment *block);
|
||||
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_track_(FILE *file, FLAC__StreamMetadata_CueSheet_Track *track);
|
||||
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_(FILE *file, FLAC__StreamMetadata_CueSheet *block);
|
||||
|
||||
static FLAC__bool write_metadata_block_header_(FILE *file, FLAC__Metadata_SimpleIteratorStatus *status, const FLAC__StreamMetadata *block);
|
||||
static FLAC__bool write_metadata_block_data_(FILE *file, FLAC__Metadata_SimpleIteratorStatus *status, const FLAC__StreamMetadata *block);
|
||||
@ -79,6 +81,7 @@ static FLAC__Metadata_SimpleIteratorStatus write_metadata_block_data_padding_(FI
|
||||
static FLAC__Metadata_SimpleIteratorStatus write_metadata_block_data_application_(FILE *file, const FLAC__StreamMetadata_Application *block, unsigned block_length);
|
||||
static FLAC__Metadata_SimpleIteratorStatus write_metadata_block_data_seektable_(FILE *file, const FLAC__StreamMetadata_SeekTable *block);
|
||||
static FLAC__Metadata_SimpleIteratorStatus write_metadata_block_data_vorbis_comment_(FILE *file, const FLAC__StreamMetadata_VorbisComment *block);
|
||||
static FLAC__Metadata_SimpleIteratorStatus write_metadata_block_data_cuesheet_(FILE *file, const FLAC__StreamMetadata_CueSheet *block);
|
||||
static FLAC__bool write_metadata_block_stationary_(FLAC__Metadata_SimpleIterator *iterator, const FLAC__StreamMetadata *block);
|
||||
static FLAC__bool write_metadata_block_stationary_with_padding_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, unsigned padding_length, FLAC__bool padding_is_last);
|
||||
static FLAC__bool rewrite_whole_file_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool append);
|
||||
@ -1336,7 +1339,7 @@ FLAC__bool read_metadata_block_header_(FLAC__Metadata_SimpleIterator *iterator)
|
||||
iterator->length = unpack_uint32_(raw_header + 1, 3);
|
||||
|
||||
/* do some checking */
|
||||
if(iterator->type > FLAC__METADATA_TYPE_VORBIS_COMMENT) {
|
||||
if(iterator->type >= FLAC__METADATA_TYPE_UNDEFINED) {
|
||||
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA;
|
||||
return false;
|
||||
}
|
||||
@ -1365,6 +1368,9 @@ FLAC__bool read_metadata_block_data_(FLAC__Metadata_SimpleIterator *iterator, FL
|
||||
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
|
||||
iterator->status = read_metadata_block_data_vorbis_comment_(iterator->file, &block->data.vorbis_comment);
|
||||
break;
|
||||
case FLAC__METADATA_TYPE_CUESHEET:
|
||||
iterator->status = read_metadata_block_data_cuesheet_(iterator->file, &block->data.cue_sheet);
|
||||
break;
|
||||
default:
|
||||
FLAC__ASSERT(0);
|
||||
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR;
|
||||
@ -1526,6 +1532,116 @@ FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_(FIL
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
|
||||
}
|
||||
|
||||
FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_track_(FILE *file, FLAC__StreamMetadata_CueSheet_Track *track)
|
||||
{
|
||||
unsigned i, len;
|
||||
FLAC__byte buffer[32]; /* asserted below that this is big enough */
|
||||
|
||||
FLAC__ASSERT(sizeof(buffer) >= sizeof(FLAC__uint64));
|
||||
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN/8);
|
||||
FLAC__ASSERT(sizeof(buffer) >= (FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) / 8);
|
||||
|
||||
FLAC__ASSERT(0 != file);
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN / 8;
|
||||
if(fread(buffer, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
|
||||
track->offset = unpack_uint64_(buffer, len);
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN / 8;
|
||||
if(fread(buffer, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
|
||||
track->number = (FLAC__byte)unpack_uint32_(buffer, len);
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN / 8;
|
||||
if(fread(track->isrc, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
|
||||
|
||||
FLAC__ASSERT((FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) % 8 == 0);
|
||||
len = (FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) / 8;
|
||||
if(fread(buffer, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN == 1);
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN == 1);
|
||||
track->type = buffer[0] >> 7;
|
||||
track->pre_emphasis = (buffer[0] >> 6) & 1;
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN / 8;
|
||||
if(fread(buffer, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
|
||||
track->num_indices = (FLAC__byte)unpack_uint32_(buffer, len);
|
||||
|
||||
if(track->num_indices == 0) {
|
||||
track->indices = 0;
|
||||
}
|
||||
else if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)calloc(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index))))
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
|
||||
|
||||
for(i = 0; i < track->num_indices; i++) {
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN / 8;
|
||||
if(fread(buffer, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
|
||||
track->indices[i].offset = unpack_uint64_(buffer, len);
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN / 8;
|
||||
if(fread(buffer, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
|
||||
track->indices[i].number = (FLAC__byte)unpack_uint32_(buffer, len);
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN / 8;
|
||||
if(fread(buffer, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
|
||||
}
|
||||
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
|
||||
}
|
||||
|
||||
FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_(FILE *file, FLAC__StreamMetadata_CueSheet *block)
|
||||
{
|
||||
unsigned i, len;
|
||||
FLAC__Metadata_SimpleIteratorStatus status;
|
||||
FLAC__byte buffer[sizeof(FLAC__uint64)]; /* the largest object we'll read in one shot */
|
||||
|
||||
FLAC__ASSERT(0 != file);
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN / 8;
|
||||
if(fread(block->media_catalog_number, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN / 8;
|
||||
if(fread(buffer, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
|
||||
block->lead_in = unpack_uint64_(buffer, len);
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN / 8;
|
||||
if(fread(buffer, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
|
||||
block->num_tracks = unpack_uint32_(buffer, len);
|
||||
|
||||
if(block->num_tracks == 0) {
|
||||
block->tracks = 0;
|
||||
}
|
||||
else if(0 == (block->tracks = (FLAC__StreamMetadata_CueSheet_Track*)calloc(block->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track))))
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
|
||||
|
||||
for(i = 0; i < block->num_tracks; i++) {
|
||||
if(FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK != (status = read_metadata_block_data_cuesheet_track_(file, block->tracks + i)))
|
||||
return status;
|
||||
}
|
||||
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
|
||||
}
|
||||
|
||||
FLAC__bool write_metadata_block_header_(FILE *file, FLAC__Metadata_SimpleIteratorStatus *status, const FLAC__StreamMetadata *block)
|
||||
{
|
||||
FLAC__byte buffer[FLAC__STREAM_METADATA_HEADER_LENGTH];
|
||||
@ -1566,6 +1682,9 @@ FLAC__bool write_metadata_block_data_(FILE *file, FLAC__Metadata_SimpleIteratorS
|
||||
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
|
||||
*status = write_metadata_block_data_vorbis_comment_(file, &block->data.vorbis_comment);
|
||||
break;
|
||||
case FLAC__METADATA_TYPE_CUESHEET:
|
||||
*status = write_metadata_block_data_cuesheet_(file, &block->data.cue_sheet);
|
||||
break;
|
||||
default:
|
||||
FLAC__ASSERT(0);
|
||||
*status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR;
|
||||
@ -1692,6 +1811,93 @@ FLAC__Metadata_SimpleIteratorStatus write_metadata_block_data_vorbis_comment_(FI
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
|
||||
}
|
||||
|
||||
FLAC__Metadata_SimpleIteratorStatus write_metadata_block_data_cuesheet_(FILE *file, const FLAC__StreamMetadata_CueSheet *block)
|
||||
{
|
||||
unsigned i, j, len;
|
||||
FLAC__byte buffer[32]; /* asserted below that this is big enough */
|
||||
|
||||
FLAC__ASSERT(sizeof(buffer) >= sizeof(FLAC__uint64));
|
||||
FLAC__ASSERT(sizeof(buffer) >= (FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN)/8);
|
||||
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN/8);
|
||||
|
||||
FLAC__ASSERT(0 != file);
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN / 8;
|
||||
if(fwrite(block->media_catalog_number, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR;
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN / 8;
|
||||
pack_uint64_(block->lead_in, buffer, len);
|
||||
if(fwrite(buffer, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR;
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN / 8;
|
||||
pack_uint32_(block->num_tracks, buffer, len);
|
||||
if(fwrite(buffer, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR;
|
||||
|
||||
for(i = 0; i < block->num_tracks; i++) {
|
||||
FLAC__StreamMetadata_CueSheet_Track *track = block->tracks + i;
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN / 8;
|
||||
pack_uint64_(track->offset, buffer, len);
|
||||
if(fwrite(buffer, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR;
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN / 8;
|
||||
pack_uint32_(track->number, buffer, len);
|
||||
if(fwrite(buffer, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR;
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN / 8;
|
||||
if(fwrite(track->isrc, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR;
|
||||
|
||||
FLAC__ASSERT((FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) % 8 == 0);
|
||||
len = (FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) / 8;
|
||||
memset(buffer, 0, len);
|
||||
buffer[0] = (track->type << 7) | (track->pre_emphasis << 6);
|
||||
if(fwrite(buffer, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR;
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN / 8;
|
||||
pack_uint32_(track->num_indices, buffer, len);
|
||||
if(fwrite(buffer, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR;
|
||||
|
||||
for(j = 0; j < track->num_indices; j++) {
|
||||
FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN / 8;
|
||||
pack_uint64_(index->offset, buffer, len);
|
||||
if(fwrite(buffer, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR;
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN / 8;
|
||||
pack_uint32_(index->number, buffer, len);
|
||||
if(fwrite(buffer, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR;
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN % 8 == 0);
|
||||
len = FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN / 8;
|
||||
memset(buffer, 0, len);
|
||||
if(fwrite(buffer, 1, len, file) != len)
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
|
||||
}
|
||||
|
||||
FLAC__bool write_metadata_block_stationary_(FLAC__Metadata_SimpleIterator *iterator, const FLAC__StreamMetadata *block)
|
||||
{
|
||||
if(0 != fseek(iterator->file, iterator->offset[iterator->depth], SEEK_SET)) {
|
||||
|
@ -57,6 +57,7 @@ static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
|
||||
static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
|
||||
static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
|
||||
static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
|
||||
static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
|
||||
static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
|
||||
static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
|
||||
static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame);
|
||||
@ -95,7 +96,7 @@ typedef struct FLAC__StreamDecoderPrivate {
|
||||
FLAC__bool has_stream_info, has_seek_table;
|
||||
FLAC__StreamMetadata stream_info;
|
||||
FLAC__StreamMetadata seek_table;
|
||||
FLAC__bool metadata_filter[FLAC__METADATA_TYPE_VORBIS_COMMENT+1];
|
||||
FLAC__bool metadata_filter[FLAC__METADATA_TYPE_UNDEFINED];
|
||||
FLAC__byte *metadata_filter_ids;
|
||||
unsigned metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
|
||||
FLAC__Frame frame;
|
||||
@ -386,7 +387,7 @@ FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecode
|
||||
FLAC__ASSERT(0 != decoder);
|
||||
FLAC__ASSERT(0 != decoder->private_);
|
||||
FLAC__ASSERT(0 != decoder->protected_);
|
||||
FLAC__ASSERT(type <= FLAC__METADATA_TYPE_VORBIS_COMMENT);
|
||||
FLAC__ASSERT(type < FLAC__METADATA_TYPE_UNDEFINED);
|
||||
if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
|
||||
return false;
|
||||
decoder->private_->metadata_filter[type] = true;
|
||||
@ -440,7 +441,7 @@ FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder
|
||||
FLAC__ASSERT(0 != decoder);
|
||||
FLAC__ASSERT(0 != decoder->private_);
|
||||
FLAC__ASSERT(0 != decoder->protected_);
|
||||
FLAC__ASSERT(type <= FLAC__METADATA_TYPE_VORBIS_COMMENT);
|
||||
FLAC__ASSERT(type < FLAC__METADATA_TYPE_UNDEFINED);
|
||||
if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
|
||||
return false;
|
||||
decoder->private_->metadata_filter[type] = false;
|
||||
@ -857,7 +858,7 @@ FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
|
||||
block.length = length;
|
||||
|
||||
if(type == FLAC__METADATA_TYPE_APPLICATION) {
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8, read_callback_, decoder))
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
|
||||
real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
|
||||
@ -867,14 +868,14 @@ FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
|
||||
}
|
||||
|
||||
if(skip_it) {
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned(decoder->private_->input, 0, real_length, read_callback_, decoder))
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned_no_crc(decoder->private_->input, 0, real_length, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
}
|
||||
else {
|
||||
switch(type) {
|
||||
case FLAC__METADATA_TYPE_PADDING:
|
||||
/* skip the padding bytes */
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned(decoder->private_->input, 0, real_length, read_callback_, decoder))
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned_no_crc(decoder->private_->input, 0, real_length, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
break;
|
||||
case FLAC__METADATA_TYPE_APPLICATION:
|
||||
@ -884,7 +885,7 @@ FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
|
||||
decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
|
||||
return false;
|
||||
}
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned(decoder->private_->input, block.data.application.data, real_length, read_callback_, decoder))
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
}
|
||||
else
|
||||
@ -894,6 +895,10 @@ FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
|
||||
if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
|
||||
return false;
|
||||
break;
|
||||
case FLAC__METADATA_TYPE_CUESHEET:
|
||||
if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
|
||||
return false;
|
||||
break;
|
||||
case FLAC__METADATA_TYPE_STREAMINFO:
|
||||
case FLAC__METADATA_TYPE_SEEKTABLE:
|
||||
default:
|
||||
@ -919,6 +924,14 @@ FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
|
||||
if(0 != block.data.vorbis_comment.comments)
|
||||
free(block.data.vorbis_comment.comments);
|
||||
break;
|
||||
case FLAC__METADATA_TYPE_CUESHEET:
|
||||
if(block.data.cue_sheet.num_tracks > 0)
|
||||
for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
|
||||
if(0 != block.data.cue_sheet.tracks[i].indices)
|
||||
free(block.data.cue_sheet.tracks[i].indices);
|
||||
if(0 != block.data.cue_sheet.tracks)
|
||||
free(block.data.cue_sheet.tracks);
|
||||
break;
|
||||
case FLAC__METADATA_TYPE_STREAMINFO:
|
||||
case FLAC__METADATA_TYPE_SEEKTABLE:
|
||||
default:
|
||||
@ -991,14 +1004,14 @@ FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
used_bits += bits;
|
||||
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16, read_callback_, decoder))
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
used_bits += 16*8;
|
||||
|
||||
/* skip the rest of the block */
|
||||
FLAC__ASSERT(used_bits % 8 == 0);
|
||||
length -= (used_bits / 8);
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned(decoder->private_->input, 0, length, read_callback_, decoder))
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned_no_crc(decoder->private_->input, 0, length, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
|
||||
return true;
|
||||
@ -1038,7 +1051,7 @@ FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_
|
||||
/* if there is a partial point left, skip over it */
|
||||
if(length > 0) {
|
||||
/*@@@ do an error_callback() here? there's an argument for either way */
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned(decoder->private_->input, 0, length, read_callback_, decoder))
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned_no_crc(decoder->private_->input, 0, length, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
}
|
||||
|
||||
@ -1060,7 +1073,7 @@ FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__Stre
|
||||
decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
|
||||
return false;
|
||||
}
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length, read_callback_, decoder))
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
}
|
||||
else
|
||||
@ -1086,7 +1099,7 @@ FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__Stre
|
||||
decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
|
||||
return false;
|
||||
}
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length, read_callback_, decoder))
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
}
|
||||
else
|
||||
@ -1100,6 +1113,82 @@ FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__Stre
|
||||
return true;
|
||||
}
|
||||
|
||||
FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
|
||||
{
|
||||
FLAC__uint32 i, j, x;
|
||||
|
||||
FLAC__ASSERT(FLAC__bitbuffer_is_consumed_byte_aligned(decoder->private_->input));
|
||||
|
||||
memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned_no_crc(decoder->private_->input, obj->media_catalog_number, FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN/8, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
|
||||
if(!FLAC__bitbuffer_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
|
||||
if(!FLAC__bitbuffer_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
obj->num_tracks = x;
|
||||
|
||||
if(obj->num_tracks > 0) {
|
||||
if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)calloc(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
|
||||
decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
|
||||
return false;
|
||||
}
|
||||
for(i = 0; i < obj->num_tracks; i++) {
|
||||
FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
|
||||
if(!FLAC__bitbuffer_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
|
||||
if(!FLAC__bitbuffer_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
track->number = x;
|
||||
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned_no_crc(decoder->private_->input, track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
|
||||
if(!FLAC__bitbuffer_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
track->type = x;
|
||||
|
||||
if(!FLAC__bitbuffer_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
track->pre_emphasis = x;
|
||||
|
||||
if(!FLAC__bitbuffer_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
|
||||
if(!FLAC__bitbuffer_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
track->num_indices = x;
|
||||
|
||||
if(track->num_indices > 0) {
|
||||
if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)calloc(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
|
||||
decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
|
||||
return false;
|
||||
}
|
||||
for(j = 0; j < track->num_indices; j++) {
|
||||
FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
|
||||
if(!FLAC__bitbuffer_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
|
||||
if(!FLAC__bitbuffer_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
index->number = x;
|
||||
|
||||
if(!FLAC__bitbuffer_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
|
||||
{
|
||||
FLAC__uint32 x;
|
||||
@ -1117,7 +1206,7 @@ FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
|
||||
skip |= (x & 0x7f);
|
||||
}
|
||||
/* skip the rest of the tag */
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned(decoder->private_->input, 0, skip, read_callback_, decoder))
|
||||
if(!FLAC__bitbuffer_read_byte_block_aligned_no_crc(decoder->private_->input, 0, skip, read_callback_, decoder))
|
||||
return false; /* the read_callback_ sets the state for us */
|
||||
return true;
|
||||
}
|
||||
|
@ -659,7 +659,9 @@ FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_init(FLAC__StreamEncoder
|
||||
metadata_has_seektable = false;
|
||||
metadata_has_vorbis_comment = false;
|
||||
for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
|
||||
if(encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_STREAMINFO)
|
||||
if(encoder->protected_->metadata[i]->type >= FLAC__METADATA_TYPE_UNDEFINED)
|
||||
return encoder->protected_->state = FLAC__STREAM_ENCODER_INVALID_METADATA;
|
||||
else if(encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_STREAMINFO)
|
||||
return encoder->protected_->state = FLAC__STREAM_ENCODER_INVALID_METADATA;
|
||||
else if(encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
|
||||
if(metadata_has_seektable) /* only one is allowed */
|
||||
@ -673,6 +675,10 @@ FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_init(FLAC__StreamEncoder
|
||||
return encoder->protected_->state = FLAC__STREAM_ENCODER_INVALID_METADATA;
|
||||
metadata_has_vorbis_comment = true;
|
||||
}
|
||||
else if(encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_CUESHEET) {
|
||||
if(!FLAC__format_cuesheet_is_legal(&encoder->protected_->metadata[i]->data.cue_sheet, /*check_cd_da_subset=*/false, /*violation=*/0))
|
||||
return encoder->protected_->state = FLAC__STREAM_ENCODER_INVALID_METADATA;
|
||||
}
|
||||
}
|
||||
|
||||
encoder->private_->input_capacity = 0;
|
||||
|
@ -33,7 +33,7 @@ static FLAC__bool add_residual_partitioned_rice_(FLAC__BitBuffer *bb, const FLAC
|
||||
|
||||
FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitBuffer *bb)
|
||||
{
|
||||
unsigned i;
|
||||
unsigned i, j;
|
||||
const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
|
||||
|
||||
if(!FLAC__bitbuffer_write_raw_uint32(bb, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
|
||||
@ -119,6 +119,44 @@ FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case FLAC__METADATA_TYPE_CUESHEET:
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
|
||||
if(!FLAC__bitbuffer_write_byte_block(bb, (const FLAC__byte*)metadata->data.cue_sheet.media_catalog_number, FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN/8))
|
||||
return false;
|
||||
if(!FLAC__bitbuffer_write_raw_uint64(bb, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
|
||||
return false;
|
||||
if(!FLAC__bitbuffer_write_raw_uint32(bb, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
|
||||
return false;
|
||||
for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
|
||||
const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
|
||||
|
||||
if(!FLAC__bitbuffer_write_raw_uint64(bb, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
|
||||
return false;
|
||||
if(!FLAC__bitbuffer_write_raw_uint32(bb, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
|
||||
return false;
|
||||
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
|
||||
if(!FLAC__bitbuffer_write_byte_block(bb, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
|
||||
return false;
|
||||
if(!FLAC__bitbuffer_write_raw_uint32(bb, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
|
||||
return false;
|
||||
if(!FLAC__bitbuffer_write_raw_uint32(bb, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
|
||||
return false;
|
||||
if(!FLAC__bitbuffer_write_zeroes(bb, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
|
||||
return false;
|
||||
if(!FLAC__bitbuffer_write_raw_uint32(bb, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
|
||||
return false;
|
||||
for(j = 0; j < track->num_indices; j++) {
|
||||
const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
|
||||
|
||||
if(!FLAC__bitbuffer_write_raw_uint64(bb, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
|
||||
return false;
|
||||
if(!FLAC__bitbuffer_write_raw_uint32(bb, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
|
||||
return false;
|
||||
if(!FLAC__bitbuffer_write_zeroes(bb, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
FLAC__ASSERT(0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user