Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion h3.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ static int h3_valid_params(h3_ctx *ctx, const h3_params *params) {
return 0;
}
}
if (params->frames < 5 || h3_align_frame_count(params->frames) > 362) {
int aligned_frames = h3_align_frame_count(params->frames);
if (params->frames < 5 || !aligned_frames || aligned_frames > 362) {
h3_set_error(ctx, "frames must align within the released 5..362 range");
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions h3_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ static const int h3_frame_per_token[5] = {1, 4, 4, 4, 4};
static const double h3_frame_rescale = 5.0 / 3.0;

int h3_align_frame_count(int requested) {
int value = requested < 5 ? 5 : requested;
int remainder = (value - 5) % 17;
int64_t value = requested < 5 ? 5 : requested;
int64_t remainder = (value - 5) % 17;
if (remainder < 0) remainder += 17;
if (remainder != 0) value += 17 - remainder;
return value;
return value > INT_MAX ? 0 : (int)value;
}

int h3_video_latent_t(int frame_count) {
Expand Down
1 change: 1 addition & 0 deletions h3_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ typedef struct {
int has_spare;
} h3_rng;

/* Return the next legal frame count, or zero if it cannot fit in an int. */
int h3_align_frame_count(int requested);
int h3_video_latent_t(int frame_count);
int h3_video_encoder_latent_t(int frame_count);
Expand Down
1 change: 1 addition & 0 deletions tests/test_h3.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static void test_temporal_and_canvas(void) {
CHECK(got.video_t == cases[index].video_t);
CHECK(got.audio_t == cases[index].audio_t);
}
CHECK(h3_align_frame_count(INT32_MAX) == 0);
CHECK(h3_video_encoder_latent_t(1) == 1);
CHECK(h3_video_encoder_latent_t(5) == 2);
CHECK(h3_video_encoder_latent_t(22) == 6);
Expand Down