Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert unused seekpoints in template to placeholders #754

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/libFLAC/stream_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -3178,14 +3178,15 @@ void update_metadata_(const FLAC__StreamEncoder *encoder)
FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
- 4
) / 8;
FLAC__uint64 samples_uint36 = samples;
if(samples > (FLAC__U64L(1) << FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
samples = 0;
samples_uint36 = 0;

b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
b[4] = (FLAC__byte)(samples & 0xFF);
b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples_uint36 >> 32) & 0x0F);
b[1] = (FLAC__byte)((samples_uint36 >> 24) & 0xFF);
b[2] = (FLAC__byte)((samples_uint36 >> 16) & 0xFF);
b[3] = (FLAC__byte)((samples_uint36 >> 8) & 0xFF);
b[4] = (FLAC__byte)(samples_uint36 & 0xFF);
if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + total_samples_byte_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
Expand Down Expand Up @@ -3231,6 +3232,11 @@ void update_metadata_(const FLAC__StreamEncoder *encoder)
if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
uint32_t i;

/* Convert unused seekpoints to placeholders */
for(i = 0; i < encoder->private_->seek_table->num_points; i++)
if(encoder->private_->seek_table->points[i].sample_number > samples)
encoder->private_->seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;

FLAC__format_seektable_sort(encoder->private_->seek_table);

FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
Expand Down
Loading