Skip to content

Commit

Permalink
Merge pull request #8 from SRGSSR/feature/subtitles_chromecast
Browse files Browse the repository at this point in the history
fix: hls subtitle frame never duplicated
  • Loading branch information
SebastienChauvin authored Jan 30, 2023
2 parents 142b5b4 + 1cabf66 commit a0dfbd2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 15 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/nginx-vod-module.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions vod/hds/hds_amf0_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ hds_amf0_write_metadata(u_char* p, media_set_t* media_set, media_track_t** track
uint64_t duration;
uint32_t timescale;
uint32_t count;
uint32_t bitrate = 0;
uint8_t sound_format;

count = AMF0_COMMON_FIELDS_COUNT;
Expand Down Expand Up @@ -155,7 +154,6 @@ hds_amf0_write_metadata(u_char* p, media_set_t* media_set, media_track_t** track
if (tracks[MEDIA_TYPE_VIDEO] != NULL)
{
media_info = &tracks[MEDIA_TYPE_VIDEO]->media_info;
bitrate += media_info->bitrate;
p = hds_amf0_append_array_number_value(p, &amf0_width, media_info->u.video.width);
p = hds_amf0_append_array_number_value(p, &amf0_height, media_info->u.video.height);
p = hds_amf0_append_array_number_value(p, &amf0_videodatarate, (double)media_info->bitrate / 1000.0);
Expand All @@ -166,7 +164,6 @@ hds_amf0_write_metadata(u_char* p, media_set_t* media_set, media_track_t** track
if (tracks[MEDIA_TYPE_AUDIO] != NULL)
{
media_info = &tracks[MEDIA_TYPE_AUDIO]->media_info;
bitrate += media_info->bitrate;
p = hds_amf0_append_array_number_value(p, &amf0_audiodatarate, (double)media_info->bitrate / 1000.0);
p = hds_amf0_append_array_number_value(p, &amf0_audiosamplerate, media_info->u.audio.sample_rate);
p = hds_amf0_append_array_number_value(p, &amf0_audiosamplesize, media_info->u.audio.bits_per_sample);
Expand Down
30 changes: 18 additions & 12 deletions vod/subtitle/webvtt_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ webvtt_builder_build(
input_frame_t* cur_frame;
input_frame_t* last_frame;
uint64_t start_time;
uint64_t segment_start_time = media_set->segment_start_time;
//uint64_t segment_end_time = media_set->segment_start_time + media_set->segment_duration;
uint32_t id_size;
size_t result_size;
u_char* end;
Expand Down Expand Up @@ -85,21 +87,25 @@ webvtt_builder_build(
last_frame = part->last_frame;
}

src = (u_char*)(uintptr_t)cur_frame->offset;
if (start_time >= segment_start_time) {
src = (u_char * )(uintptr_t)
cur_frame->offset;

// cue identifier
id_size = cur_frame->key_frame;
p = vod_copy(p, src, id_size);
src += id_size;
// cue identifier
id_size = cur_frame->key_frame;
p = vod_copy(p, src, id_size);
src += id_size;

// cue timings
p = webvtt_builder_write_timestamp(p, start_time);
p = vod_copy(p, WEBVTT_TIMESTAMP_DELIM, sizeof(WEBVTT_TIMESTAMP_DELIM) - 1);
p = webvtt_builder_write_timestamp(p, start_time + cur_frame->pts_delay);
start_time += cur_frame->duration;
// cue timings
p = webvtt_builder_write_timestamp(p, start_time);
p = vod_copy(p, WEBVTT_TIMESTAMP_DELIM, sizeof(WEBVTT_TIMESTAMP_DELIM) - 1);
p = webvtt_builder_write_timestamp(p, start_time + cur_frame->pts_delay);

// cue settings list + cue payload
p = vod_copy(p, src, cur_frame->size - id_size);
}

// cue settings list + cue payload
p = vod_copy(p, src, cur_frame->size - id_size);
start_time += cur_frame->duration;
}
}

Expand Down

0 comments on commit a0dfbd2

Please sign in to comment.