Skip to content

Commit

Permalink
add default property to sequence & closed captions
Browse files Browse the repository at this point in the history
  • Loading branch information
erankor committed Jan 27, 2024
1 parent 1750eb0 commit a8dfb8c
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 132 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,8 @@ Optional fields:
* `label` - a friendly string that identifies the sequence. If a language is specified,
a default label will be automatically derived by it - e.g. if language is `ita`,
by default `italiano` will be used as the label.
* `default` - a boolean that sets the value of the DEFAULT attribute of EXT-X-MEDIA tags using this sequence.
If not specified, the first EXT-X-MEDIA tag in each group returns DEFAULT=YES, while the others return DEFAULT=NO.
* `bitrate` - an object that can be used to set the bitrate for the different media types,
in bits per second. For example, `{"v": 900000, "a": 64000}`. If the bitrate is not supplied,
nginx-vod-module will estimate it based on the last clip in the sequence.
Expand Down
6 changes: 2 additions & 4 deletions ngx_http_vod_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -3577,7 +3577,7 @@ ngx_http_vod_run_generators(ngx_http_vod_ctx_t *ctx)
}

if (parse_params.langs_mask != NULL &&
!vod_is_bit_set(parse_params.langs_mask, cur_source->sequence->language))
!vod_is_bit_set(parse_params.langs_mask, cur_source->sequence->tags.language))
{
ngx_memzero(&cur_source->track_array, sizeof(cur_source->track_array));
continue;
Expand Down Expand Up @@ -5336,9 +5336,7 @@ ngx_http_vod_map_media_set_apply(ngx_http_vod_ctx_t *ctx, ngx_str_t* mapping, in
ctx->submodule_context.media_set.segmenter_conf = mapped_media_set.segmenter_conf;
sequence = cur_source->sequence;
sequence->mapped_uri = mapped_source->mapped_uri;
sequence->lang_str = mapped_media_set.sequences->lang_str;
sequence->language = mapped_media_set.sequences->language;
sequence->label = mapped_media_set.sequences->label;
sequence->tags = mapped_media_set.sequences->tags;
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
15 changes: 8 additions & 7 deletions ngx_http_vod_request_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,10 +734,10 @@ ngx_http_vod_parse_lang_param(ngx_str_t* value, void* output, int offset)
return NGX_HTTP_BAD_REQUEST;
}

sequence->lang_str.data = (u_char *)lang_get_rfc_5646_name(result);
sequence->lang_str.len = ngx_strlen(sequence->lang_str.data);
sequence->language = result;
lang_get_native_name(result, &sequence->label);
sequence->tags.lang_str.data = (u_char *)lang_get_rfc_5646_name(result);
sequence->tags.lang_str.len = ngx_strlen(sequence->tags.lang_str.data);
sequence->tags.language = result;
lang_get_native_name(result, &sequence->tags.label);

return VOD_OK;
}
Expand Down Expand Up @@ -1078,9 +1078,10 @@ ngx_http_vod_parse_uri_path(
}

cur_sequence->id.len = 0;
cur_sequence->lang_str.len = 0;
cur_sequence->language = 0;
cur_sequence->label.len = 0;
cur_sequence->tags.lang_str.len = 0;
cur_sequence->tags.language = 0;
cur_sequence->tags.label.len = 0;
cur_sequence->tags.is_default = -1;
cur_sequence->first_key_frame_offset = 0;
cur_sequence->key_frame_durations = NULL;
cur_sequence->drm_info = NULL;
Expand Down
24 changes: 12 additions & 12 deletions vod/dash/dash_packager.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,12 @@ dash_packager_compare_tracks(uintptr_t bitrate_threshold, const media_info_t* mi
(mi1->u.video.height == mi2->u.video.height);
}

if (mi1->label.len == 0 || mi2->label.len == 0)
if (mi1->tags.label.len == 0 || mi2->tags.label.len == 0)
{
return TRUE;
}

return vod_str_equals(mi1->label, mi2->label);
return vod_str_equals(mi1->tags.label, mi2->tags.label);
}

static void
Expand Down Expand Up @@ -858,12 +858,12 @@ dash_packager_write_mpd_period(

case MEDIA_TYPE_AUDIO:
reference_track = (*adaptation_set->first) + filtered_clip_offset;
if (reference_track->media_info.lang_str.len > 0 || reference_track->media_info.label.len > 0)
if (reference_track->media_info.tags.lang_str.len > 0 || reference_track->media_info.tags.label.len > 0)
{
p = vod_sprintf(p, VOD_DASH_MANIFEST_ADAPTATION_HEADER_AUDIO_LANG,
adapt_id++,
&reference_track->media_info.lang_str,
&reference_track->media_info.label);
&reference_track->media_info.tags.lang_str,
&reference_track->media_info.tags.label);
}
else
{
Expand All @@ -889,8 +889,8 @@ dash_packager_write_mpd_period(
{
reference_track = (*adaptation_set->first) + filtered_clip_offset;
p = vod_sprintf(p, VOD_DASH_MANIFEST_ADAPTATION_HEADER_SUBTITLE_SMPTE_TT,
&reference_track->media_info.lang_str,
&reference_track->media_info.label);
&reference_track->media_info.tags.lang_str,
&reference_track->media_info.tags.label);
break;
}

Expand Down Expand Up @@ -919,10 +919,10 @@ dash_packager_write_mpd_period(
representation_id.len--;
}

lang_code = lang_get_rfc_5646_name(cur_track->media_info.language);
lang_code = lang_get_rfc_5646_name(cur_track->media_info.tags.language);
p = vod_sprintf(p, VOD_DASH_MANIFEST_ADAPTATION_SUBTITLE_VTT,
&cur_track->media_info.lang_str,
&cur_track->media_info.label,
&cur_track->media_info.tags.lang_str,
&cur_track->media_info.tags.label,
lang_code,
subtitle_adapt_id++,
&cur_base_url,
Expand Down Expand Up @@ -1205,7 +1205,7 @@ dash_packager_remove_redundant_tracks(

// prefer to remove a track that doesn't have a label, so that we won't lose a language
// in case of multi language manifest
if (track1->media_info.label.len == 0 || track2->media_info.label.len != 0)
if (track1->media_info.tags.label.len == 0 || track2->media_info.tags.label.len != 0)
{
remove = track1;
}
Expand Down Expand Up @@ -1438,7 +1438,7 @@ dash_packager_build_mpd(
case MEDIA_TYPE_AUDIO:
case MEDIA_TYPE_SUBTITLE:
cur_track = (*adaptation_set->first) + filtered_clip_offset;
result_size += cur_track->media_info.label.len + cur_track->media_info.lang_str.len;
result_size += cur_track->media_info.tags.label.len + cur_track->media_info.tags.lang_str.len;
break;
}
}
Expand Down
16 changes: 8 additions & 8 deletions vod/hds/hds_manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,14 @@ hds_packager_build_manifest(
{
if (adaptation_set->first[MEDIA_TYPE_AUDIO] != NULL)
{
result_size += adaptation_set->first[MEDIA_TYPE_AUDIO]->media_info.label.len +
adaptation_set->first[MEDIA_TYPE_AUDIO]->media_info.lang_str.len;
result_size += adaptation_set->first[MEDIA_TYPE_AUDIO]->media_info.tags.label.len +
adaptation_set->first[MEDIA_TYPE_AUDIO]->media_info.tags.lang_str.len;
}
}
else
{
result_size += adaptation_set->first[0]->media_info.label.len +
adaptation_set->first[0]->media_info.lang_str.len;
result_size += adaptation_set->first[0]->media_info.tags.label.len +
adaptation_set->first[0]->media_info.tags.lang_str.len;
}

for (cur_track_ptr = adaptation_set->first; cur_track_ptr < adaptation_set->last; cur_track_ptr += muxed_tracks)
Expand Down Expand Up @@ -573,8 +573,8 @@ hds_packager_build_manifest(
}

p = vod_sprintf(p, HDS_MANIFEST_HEADER_LANG,
&track->media_info.label,
&track->media_info.lang_str);
&track->media_info.tags.label,
&track->media_info.tags.lang_str);
}

// bootstrap tags
Expand Down Expand Up @@ -704,8 +704,8 @@ hds_packager_build_manifest(
{
p = vod_sprintf(p, HDS_MEDIA_HEADER_PREFIX_AUDIO_LANG,
bitrate / 1000,
&tracks[MEDIA_TYPE_AUDIO]->media_info.label,
&tracks[MEDIA_TYPE_AUDIO]->media_info.lang_str);
&tracks[MEDIA_TYPE_AUDIO]->media_info.tags.label,
&tracks[MEDIA_TYPE_AUDIO]->media_info.tags.lang_str);
}
else
{
Expand Down
28 changes: 21 additions & 7 deletions vod/hls/m3u8_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ m3u8_builder_closed_captions_write(
{
media_closed_captions_t* closed_captions;
uint32_t index = 0;
bool_t is_default;

for (closed_captions = media_set->closed_captions; closed_captions < media_set->closed_captions_end; closed_captions++)
{
Expand All @@ -869,7 +870,13 @@ m3u8_builder_closed_captions_write(
p = vod_sprintf(p, M3U8_EXT_MEDIA_LANG, &closed_captions->language);
}

if (closed_captions == media_set->closed_captions)
is_default = closed_captions->is_default;
if (is_default < 0)
{
is_default = closed_captions == media_set->closed_captions;
}

if (is_default)
{
p = vod_copy(p, M3U8_EXT_MEDIA_DEFAULT, sizeof(M3U8_EXT_MEDIA_DEFAULT) - 1);
}
Expand Down Expand Up @@ -921,8 +928,8 @@ m3u8_builder_ext_x_media_tags_get_size(
{
cur_track = adaptation_set->first[0];

label_len = cur_track->media_info.label.len;
result += vod_max(label_len, default_label.len) + cur_track->media_info.lang_str.len;
label_len = cur_track->media_info.tags.label.len;
result += vod_max(label_len, default_label.len) + cur_track->media_info.tags.lang_str.len;

if (base_url->len != 0)
{
Expand All @@ -948,6 +955,7 @@ m3u8_builder_ext_x_media_tags_write(
media_track_t* tracks[MEDIA_TYPE_COUNT];
vod_str_t* label;
uint32_t group_index;
bool_t is_default;
char* group_id;
char* type;

Expand Down Expand Up @@ -988,7 +996,7 @@ m3u8_builder_ext_x_media_tags_write(
group_index = 0;
}

label = &tracks[media_type]->media_info.label;
label = &tracks[media_type]->media_info.tags.label;
if (label->len == 0)
{
label = &default_label;
Expand All @@ -1000,13 +1008,19 @@ m3u8_builder_ext_x_media_tags_write(
group_index,
label);

if (tracks[media_type]->media_info.lang_str.len > 0)
if (tracks[media_type]->media_info.tags.lang_str.len > 0)
{
p = vod_sprintf(p, M3U8_EXT_MEDIA_LANG,
&tracks[media_type]->media_info.lang_str);
&tracks[media_type]->media_info.tags.lang_str);
}

is_default = tracks[media_type]->media_info.tags.is_default;
if (is_default < 0)
{
is_default = adaptation_set == first_adaptation_set;
}

if (adaptation_set == first_adaptation_set)
if (is_default)
{
p = vod_copy(p, M3U8_EXT_MEDIA_DEFAULT, sizeof(M3U8_EXT_MEDIA_DEFAULT) - 1);
}
Expand Down
4 changes: 1 addition & 3 deletions vod/input/silence_generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ silence_generator_generate(
track->media_info.duration_millis = parse_params->clip_to - parse_params->clip_from;
track->media_info.full_duration = (uint64_t)track->media_info.duration_millis * track->media_info.timescale;
track->media_info.duration = track->media_info.full_duration;
track->media_info.lang_str = sequence->lang_str;
track->media_info.language = sequence->language;
track->media_info.label = sequence->label;
track->media_info.tags = sequence->tags;

rc = media_format_finalize_track(
request_context,
Expand Down
14 changes: 7 additions & 7 deletions vod/manifest_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,21 +441,21 @@ track_group_key_init(
break;
}

if (track->media_info.label.len == 0)
if (track->media_info.tags.label.len == 0)
{
return FALSE;
}
key->label = track->media_info.label;
key->label = track->media_info.tags.label;
break;

case MEDIA_TYPE_SUBTITLE:
key->codec_id = 0;

if (track->media_info.label.len == 0)
if (track->media_info.tags.label.len == 0)
{
return FALSE;
}
key->label = track->media_info.label;
key->label = track->media_info.tags.label;
break;

default: // MEDIA_TYPE_NONE
Expand Down Expand Up @@ -796,16 +796,16 @@ manifest_utils_is_multi_audio(media_set_t* media_set)
for (cur_track = media_set->filtered_tracks; cur_track < last_track; cur_track++)
{
if (cur_track->media_info.media_type != MEDIA_TYPE_AUDIO ||
cur_track->media_info.label.len == 0)
cur_track->media_info.tags.label.len == 0)
{
continue;
}

if (label == NULL)
{
label = &cur_track->media_info.label;
label = &cur_track->media_info.tags.label;
}
else if (!vod_str_equals(cur_track->media_info.label, *label))
else if (!vod_str_equals(cur_track->media_info.tags.label, *label))
{
return TRUE;
}
Expand Down
11 changes: 8 additions & 3 deletions vod/media_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ typedef struct {
mp4a_config_t codec_config;
} audio_media_info_t;

typedef struct {
language_id_t language;
vod_str_t lang_str;
vod_str_t label;
bool_t is_default;
} media_tags_t;

typedef struct media_info_s {
uint32_t media_type;
uint32_t format;
Expand All @@ -243,9 +250,7 @@ typedef struct media_info_s {
int64_t empty_duration; // temporary during parsing
int64_t start_time; // temporary during parsing
uint64_t codec_delay;
language_id_t language;
vod_str_t lang_str;
vod_str_t label;
media_tags_t tags;
union {
video_media_info_t video;
audio_media_info_t audio;
Expand Down
5 changes: 2 additions & 3 deletions vod/media_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ struct media_sequence_s {
media_clip_t** clips; // [clip_count]
vod_str_t stripped_uri;
vod_str_t id;
vod_str_t label;
vod_str_t lang_str;
language_id_t language;
media_tags_t tags;
uint32_t bitrate[MEDIA_TYPE_COUNT];
uint32_t avg_bitrate[MEDIA_TYPE_COUNT];
int64_t first_key_frame_offset;
Expand Down Expand Up @@ -109,6 +107,7 @@ typedef struct {
vod_str_t id;
vod_str_t language;
vod_str_t label;
bool_t is_default;
} media_closed_captions_t;

typedef struct {
Expand Down
Loading

0 comments on commit a8dfb8c

Please sign in to comment.