Skip to content

Commit

Permalink
Merge pull request #3 from SRGSSR/feature/support_for_forced_subtitles
Browse files Browse the repository at this point in the history
forced subs support
  • Loading branch information
shugli authored Apr 5, 2022
2 parents 200ea0b + f6cdb28 commit 8943506
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions ngx_http_vod_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -5219,6 +5219,7 @@ ngx_http_vod_map_media_set_apply(ngx_http_vod_ctx_t *ctx, ngx_str_t* mapping, in
sequence->language = mapped_media_set.sequences->language;
sequence->label = mapped_media_set.sequences->label;
sequence->with_accessibility = mapped_media_set.sequences->with_accessibility;
sequence->forced = mapped_media_set.sequences->forced;
sequence->id = mapped_media_set.sequences->id;
ngx_memcpy(sequence->bitrate, mapped_media_set.sequences->bitrate, sizeof(sequence->bitrate));
ngx_memcpy(sequence->avg_bitrate, mapped_media_set.sequences->avg_bitrate, sizeof(sequence->avg_bitrate));
Expand Down
1 change: 1 addition & 0 deletions ngx_http_vod_request_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,7 @@ ngx_http_vod_parse_uri_path(
cur_sequence->language = 0;
cur_sequence->label.len = 0;
cur_sequence->with_accessibility = FALSE;
cur_sequence->forced = FALSE;
cur_sequence->first_key_frame_offset = 0;
cur_sequence->key_frame_durations = NULL;
cur_sequence->drm_info = NULL;
Expand Down
17 changes: 17 additions & 0 deletions vod/hls/m3u8_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define M3U8_EXT_MEDIA_DEFAULT "AUTOSELECT=YES,DEFAULT=YES,"
#define M3U8_EXT_MEDIA_AUTOSELECT "AUTOSELECT=YES,DEFAULT=NO,"
#define M3U8_EXT_MEDIA_NON_DEFAULT "AUTOSELECT=NO,DEFAULT=NO,"
#define M3U8_EXT_MEDIA_FORCED "FORCED=YES,"
#define M3U8_EXT_MEDIA_AD "CHARACTERISTICS=\"public.accessibility.describes-video\","
#define M3U8_EXT_MEDIA_SDH "CHARACTERISTICS=\"public.accessibility.describes-music-and-sound\","
#define M3U8_EXT_MEDIA_URI "URI=\""
Expand Down Expand Up @@ -933,6 +934,14 @@ m3u8_builder_ext_x_media_tags_get_size(
}
}

if (media_type == MEDIA_TYPE_SUBTITLE)
{
if (cur_track->media_info.forced)
{
result += sizeof(M3U8_EXT_MEDIA_FORCED) - 1;
}
}

if (base_url->len != 0)
{
result += vod_max(cur_track->file_info.uri.len, media_set->uri.len);
Expand Down Expand Up @@ -1044,6 +1053,14 @@ m3u8_builder_ext_x_media_tags_write(
p = vod_copy(p, M3U8_EXT_MEDIA_NON_DEFAULT, sizeof(M3U8_EXT_MEDIA_NON_DEFAULT) - 1);
}

if (media_type == MEDIA_TYPE_SUBTITLE)
{
if (tracks[media_type]->media_info.forced)
{
p = vod_copy(p, M3U8_EXT_MEDIA_FORCED, sizeof(M3U8_EXT_MEDIA_FORCED) - 1);
}
}

if (media_type == MEDIA_TYPE_AUDIO)
{
p = vod_sprintf(p, M3U8_EXT_MEDIA_CHANNELS,
Expand Down
1 change: 1 addition & 0 deletions vod/input/silence_generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ silence_generator_generate(
track->media_info.label = sequence->label;
track->media_info.language = sequence->language;
track->media_info.with_accessibility = sequence->with_accessibility;
track->media_info.forced = sequence->forced;

rc = media_format_finalize_track(
request_context,
Expand Down
1 change: 1 addition & 0 deletions vod/media_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ typedef struct media_info_s {
language_id_t language;
vod_str_t label;
bool_t with_accessibility;
bool_t forced;
union {
video_media_info_t video;
audio_media_info_t audio;
Expand Down
1 change: 1 addition & 0 deletions vod/media_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct media_sequence_s {
vod_str_t label;
language_id_t language;
bool_t with_accessibility; // Closed Captions for subtitle, Audio Description for audio
bool_t forced; // Forced for subtitle only
uint32_t bitrate[MEDIA_TYPE_COUNT];
uint32_t avg_bitrate[MEDIA_TYPE_COUNT];
int64_t first_key_frame_offset;
Expand Down
2 changes: 2 additions & 0 deletions vod/media_set_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ static json_object_value_def_t media_sequence_params[] = {
{ vod_string("language"), VOD_JSON_STRING, offsetof(media_sequence_t, language), media_set_parse_language },
{ vod_string("label"), VOD_JSON_STRING, offsetof(media_sequence_t, label), media_set_parse_null_term_string },
{ vod_string("withAccessibility"),VOD_JSON_BOOL, offsetof(media_sequence_t, with_accessibility), media_set_parse_bool },
{ vod_string("forced"), VOD_JSON_BOOL, offsetof(media_sequence_t, forced), media_set_parse_bool },
{ vod_string("bitrate"), VOD_JSON_OBJECT, offsetof(media_sequence_t, bitrate), media_set_parse_bitrate },
{ vod_string("avg_bitrate"), VOD_JSON_OBJECT, offsetof(media_sequence_t, avg_bitrate), media_set_parse_bitrate },
{ vod_null_string, 0, 0, NULL }
Expand Down Expand Up @@ -959,6 +960,7 @@ media_set_parse_sequences(
cur_output->language = 0;
cur_output->label.len = 0;
cur_output->with_accessibility = FALSE;
cur_output->forced = FALSE;
cur_output->first_key_frame_offset = 0;
cur_output->key_frame_durations = NULL;
cur_output->drm_info = NULL;
Expand Down
1 change: 1 addition & 0 deletions vod/mp4/mp4_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2791,6 +2791,7 @@ mp4_parser_process_moov_atom_callback(void* ctx, atom_info_t* atom_info)
// inherit the sequence language and label
sequence = context->parse_params.source->sequence;
metadata_parse_context.media_info.with_accessibility = sequence->with_accessibility;
metadata_parse_context.media_info.forced = sequence->forced;
if (sequence->label.len != 0)
{
metadata_parse_context.media_info.label = sequence->label;
Expand Down
3 changes: 3 additions & 0 deletions vod/subtitle/subtitle_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ subtitle_parse(
language_id_t lang_id;
vod_str_t label;
bool_t with_accessibility;
bool_t forced;
uint64_t duration;

metadata = vod_alloc(request_context->pool, sizeof(*metadata));
Expand All @@ -92,6 +93,7 @@ subtitle_parse(
// inherit the sequence language and label
sequence = parse_params->source->sequence;
with_accessibility = sequence->with_accessibility;
forced = sequence->forced;
if (sequence->label.len != 0)
{
label = sequence->label;
Expand Down Expand Up @@ -145,6 +147,7 @@ subtitle_parse(
track->media_info.label = label;
track->media_info.language = lang_id;
track->media_info.with_accessibility = with_accessibility;
track->media_info.forced = forced;
track->media_info.bitrate = (source->len * 1000 * 8) / full_duration;

metadata->source = *source;
Expand Down

0 comments on commit 8943506

Please sign in to comment.