Skip to content

Commit b15a2e1

Browse files
committed
misc bug fixes
1 parent 90eb203 commit b15a2e1

15 files changed

+184
-53
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ Where:
168168

169169
When configured to run in mapped mode, nginx-vod-module issues an HTTP request to a configured upstream server
170170
in order to receive the layout of media streams it should generate.
171-
The response has to be in JSON format, this section contains are a few simple examples followed by a reference
172-
of the supported objects and fields.
171+
The response has to be in JSON format.
173172

173+
This section contains a few simple examples followed by a reference of the supported objects and fields.
174174
But first, a couple of definitions:
175175

176176
1. `Source Clip` - a set of audio and/or video frames (tracks) extracted from a single media file

ngx_http_vod_conf.h

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct ngx_http_vod_loc_conf_s {
6565
// derived fields
6666
ngx_str_t proxy_header;
6767
ngx_hash_t uri_params_hash;
68+
ngx_hash_t pd_uri_params_hash;
6869

6970
// submodules
7071
ngx_http_vod_dash_loc_conf_t dash;

ngx_http_vod_hls.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ static const ngx_http_vod_request_t hls_index_request = {
296296

297297
static const ngx_http_vod_request_t hls_iframes_request = {
298298
REQUEST_FLAG_SINGLE_TRACK_PER_MEDIA_TYPE,
299-
PARSE_FLAG_FRAMES_ALL_EXCEPT_OFFSETS | PARSE_FLAG_PARSED_EXTRA_DATA_SIZE,
299+
PARSE_FLAG_FRAMES_ALL_EXCEPT_OFFSETS | PARSE_FLAG_PARSED_EXTRA_DATA_SIZE | PARSE_FLAG_ALL_CLIPS,
300300
REQUEST_CLASS_OTHER,
301301
ngx_http_vod_hls_handle_iframe_playlist,
302302
NULL,

ngx_http_vod_module.c

+48-18
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ struct ngx_http_vod_ctx_s {
107107
void* frame_processor_state;
108108
ngx_chain_t out;
109109
ngx_http_vod_write_segment_context_t write_segment_buffer_context;
110-
void* filter_state;
111110
};
112111

113112
// forward declarations
@@ -1799,15 +1798,14 @@ ngx_http_vod_run_state_machine(ngx_http_vod_ctx_t *ctx)
17991798
&ctx->submodule_context.request_context,
18001799
&ctx->read_cache_state,
18011800
&ctx->submodule_context.media_set,
1802-
&ctx->filter_state);
1801+
&ctx->frame_processor_state);
18031802
if (rc != VOD_OK)
18041803
{
18051804
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->submodule_context.request_context.log, 0,
18061805
"ngx_http_vod_run_state_machine: filter_init_state failed %i", rc);
18071806
return ngx_http_vod_status_to_ngx_error(rc);
18081807
}
18091808

1810-
ctx->frame_processor_state = &ctx->filter_state;
18111809
ctx->frame_processor = filter_run_state_machine;
18121810
}
18131811

@@ -2420,9 +2418,11 @@ ngx_http_vod_apply_mapping(ngx_http_vod_ctx_t *ctx, ngx_str_t* mapping)
24202418
{
24212419
ngx_http_vod_loc_conf_t* conf = ctx->submodule_context.conf;
24222420
media_clip_source_t *cur_source = *ctx->submodule_context.cur_source;
2421+
media_clip_source_t* mapped_source;
24232422
media_set_t mapped_media_set;
24242423
ngx_str_t path;
24252424
ngx_int_t rc;
2425+
bool_t parse_all_clips;
24262426

24272427
// optimization for the case of simple mapping response
24282428
if (mapping->len >= conf->path_response_prefix.len + conf->path_response_postfix.len &&
@@ -2469,12 +2469,15 @@ ngx_http_vod_apply_mapping(ngx_http_vod_ctx_t *ctx, ngx_str_t* mapping)
24692469

24702470
// TODO: in case the new media set may replace the existing one, propagate clip from, clip to, rate
24712471

2472+
parse_all_clips = ctx->submodule_context.request != NULL ? (ctx->submodule_context.request->parse_type & PARSE_FLAG_ALL_CLIPS) : 0;
2473+
24722474
rc = media_set_parse_json(
24732475
&ctx->submodule_context.request_context,
24742476
mapping->data,
24752477
&ctx->submodule_context.request_params,
24762478
&ctx->submodule_context.conf->segmenter,
24772479
&cur_source->uri,
2480+
parse_all_clips,
24782481
&mapped_media_set);
24792482

24802483
if (rc == VOD_NOT_FOUND)
@@ -2499,28 +2502,43 @@ ngx_http_vod_apply_mapping(ngx_http_vod_ctx_t *ctx, ngx_str_t* mapping)
24992502
mapped_media_set.durations == NULL &&
25002503
mapped_media_set.sequences[0].clips[0]->type == MEDIA_CLIP_SOURCE)
25012504
{
2502-
// mapping result is a simple file path, set the uri of the current source
2503-
cur_source->sequence->mapped_uri = mapped_media_set.sources[0]->mapped_uri;
2504-
cur_source->mapped_uri = mapped_media_set.sources[0]->mapped_uri;
2505+
mapped_source = (media_clip_source_t*)*mapped_media_set.sequences[0].clips;
2506+
2507+
if (mapped_source->clip_from == 0 &&
2508+
mapped_source->clip_to == UINT_MAX &&
2509+
mapped_source->tracks_mask[MEDIA_TYPE_AUDIO] == 0xffffffff &&
2510+
mapped_source->tracks_mask[MEDIA_TYPE_VIDEO] == 0xffffffff)
2511+
{
2512+
// mapping result is a simple file path, set the uri of the current source
2513+
cur_source->sequence->mapped_uri = mapped_source->mapped_uri;
2514+
cur_source->mapped_uri = mapped_source->mapped_uri;
2515+
return NGX_OK;
2516+
}
2517+
}
2518+
2519+
if (ctx->submodule_context.request == NULL)
2520+
{
2521+
ngx_log_error(NGX_LOG_ERR, ctx->submodule_context.request_context.log, 0,
2522+
"ngx_http_vod_apply_mapping: unsupported - non-trivial mapping in progressive download");
2523+
return NGX_HTTP_BAD_REQUEST;
25052524
}
2506-
else if (ctx->submodule_context.media_set.sequence_count == 1 &&
2525+
2526+
if (ctx->submodule_context.media_set.sequence_count == 1 &&
25072527
ctx->submodule_context.media_set.sequences[0].clips[0]->type == MEDIA_CLIP_SOURCE)
25082528
{
25092529
// media set was a single source, replace it with the mapping result
25102530
ctx->submodule_context.media_set = mapped_media_set;
25112531

25122532
// cur_source is pointing to the old media set, move it to the end of the new one
25132533
ctx->submodule_context.cur_source = mapped_media_set.sources_end;
2514-
}
2515-
else
2516-
{
2517-
ngx_log_error(NGX_LOG_ERR, ctx->submodule_context.request_context.log, 0,
2518-
"ngx_http_vod_apply_mapping: unsupported - multi uri request %V did not return a simple json",
2519-
&cur_source->stripped_uri);
2520-
return NGX_HTTP_BAD_REQUEST;
2534+
2535+
return NGX_OK;
25212536
}
25222537

2523-
return NGX_OK;
2538+
ngx_log_error(NGX_LOG_ERR, ctx->submodule_context.request_context.log, 0,
2539+
"ngx_http_vod_apply_mapping: unsupported - multi uri/filtered request %V did not return a simple json",
2540+
&cur_source->stripped_uri);
2541+
return NGX_HTTP_BAD_REQUEST;
25242542
}
25252543

25262544
static ngx_int_t
@@ -2930,7 +2948,13 @@ ngx_http_vod_parse_uri(
29302948
return rc;
29312949
}
29322950

2933-
rc = ngx_http_vod_parse_uri_path(r, conf, &uri_path, request_params, media_set);
2951+
rc = ngx_http_vod_parse_uri_path(
2952+
r,
2953+
&conf->multi_uri_suffix,
2954+
&conf->uri_params_hash,
2955+
&uri_path,
2956+
request_params,
2957+
media_set);
29342958
if (rc != NGX_OK)
29352959
{
29362960
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
@@ -3009,7 +3033,6 @@ ngx_http_vod_handler(ngx_http_request_t *r)
30093033
// parse the uri
30103034
ngx_memzero(&request_params, sizeof(request_params));
30113035
ngx_memzero(&media_set, sizeof(media_set));
3012-
request = NULL;
30133036
if (conf->submodule.parse_uri_file_name != NULL)
30143037
{
30153038
rc = ngx_http_vod_parse_uri(r, conf, &request_params, &media_set, &request);
@@ -3022,11 +3045,18 @@ ngx_http_vod_handler(ngx_http_request_t *r)
30223045
}
30233046
else
30243047
{
3048+
request = NULL;
30253049
request_params.sequences_mask = 1;
30263050
request_params.tracks_mask[MEDIA_TYPE_VIDEO] = 0xffffffff;
30273051
request_params.tracks_mask[MEDIA_TYPE_AUDIO] = 0xffffffff;
30283052

3029-
rc = ngx_http_vod_parse_uri_path(r, conf, &r->uri, &request_params, &media_set);
3053+
rc = ngx_http_vod_parse_uri_path(
3054+
r,
3055+
&conf->multi_uri_suffix,
3056+
&conf->pd_uri_params_hash,
3057+
&r->uri,
3058+
&request_params,
3059+
&media_set);
30303060
if (rc != NGX_OK)
30313061
{
30323062
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,

ngx_http_vod_request_parse.c

+86-27
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ typedef ngx_int_t(*ngx_http_vod_param_parser_t)(ngx_str_t* value, void* output,
1010

1111
typedef struct {
1212
int name_conf_offset;
13+
char* name;
1314
ngx_http_vod_param_parser_t parser;
1415
int target_offset;
1516
} ngx_http_vod_uri_param_def_t;
@@ -361,41 +362,99 @@ ngx_http_vod_parse_tracks_param(ngx_str_t* value, void* output, int offset)
361362
}
362363

363364
static ngx_http_vod_uri_param_def_t uri_param_defs[] = {
364-
{ offsetof(ngx_http_vod_loc_conf_t, clip_to_param_name), ngx_http_vod_parse_uint32_param, offsetof(media_clip_source_t, clip_to) },
365-
{ offsetof(ngx_http_vod_loc_conf_t, clip_from_param_name), ngx_http_vod_parse_uint32_param, offsetof(media_clip_source_t, clip_from) },
366-
{ offsetof(ngx_http_vod_loc_conf_t, tracks_param_name), ngx_http_vod_parse_tracks_param, offsetof(media_clip_source_t, tracks_mask) },
367-
{ offsetof(ngx_http_vod_loc_conf_t, speed_param_name), NULL, 0 },
365+
{ offsetof(ngx_http_vod_loc_conf_t, clip_to_param_name), "clip to", ngx_http_vod_parse_uint32_param, offsetof(media_clip_source_t, clip_to) },
366+
{ offsetof(ngx_http_vod_loc_conf_t, clip_from_param_name), "clip from", ngx_http_vod_parse_uint32_param, offsetof(media_clip_source_t, clip_from) },
367+
{ offsetof(ngx_http_vod_loc_conf_t, tracks_param_name), "tracks", ngx_http_vod_parse_tracks_param, offsetof(media_clip_source_t, tracks_mask) },
368+
{ offsetof(ngx_http_vod_loc_conf_t, speed_param_name), "speed", NULL, 0 },
369+
{ -1, NULL, NULL, 0}
368370
};
369371

370-
ngx_int_t
371-
ngx_http_vod_init_uri_params_hash(ngx_conf_t *cf, ngx_http_vod_loc_conf_t* conf)
372+
static ngx_http_vod_uri_param_def_t pd_uri_param_defs[] = {
373+
{ offsetof(ngx_http_vod_loc_conf_t, clip_to_param_name), "clip to", ngx_http_vod_parse_uint32_param, offsetof(media_clip_source_t, clip_to) },
374+
{ offsetof(ngx_http_vod_loc_conf_t, clip_from_param_name), "clip from", ngx_http_vod_parse_uint32_param, offsetof(media_clip_source_t, clip_from) },
375+
{ -1, NULL, NULL, 0 }
376+
};
377+
378+
static ngx_int_t
379+
ngx_http_vod_init_hash(
380+
ngx_conf_t *cf,
381+
ngx_http_vod_uri_param_def_t* elements,
382+
ngx_http_vod_loc_conf_t* conf,
383+
char* hash_name,
384+
ngx_hash_t* output)
372385
{
373-
ngx_hash_key_t hash_keys[sizeof(uri_param_defs) / sizeof(uri_param_defs[0])];
386+
ngx_http_vod_uri_param_def_t *element;
387+
ngx_array_t elements_arr;
388+
ngx_hash_key_t *hash_key;
374389
ngx_hash_init_t hash;
375-
ngx_str_t* param_name;
376-
ngx_int_t rc;
377-
unsigned i;
390+
ngx_str_t* cur_key;
378391

379-
for (i = 0; i < sizeof(hash_keys) / sizeof(hash_keys[0]); i++)
392+
if (ngx_array_init(&elements_arr, cf->temp_pool, 32, sizeof(ngx_hash_key_t)) != NGX_OK)
380393
{
381-
param_name = (ngx_str_t*)((u_char*)conf + uri_param_defs[i].name_conf_offset);
382-
hash_keys[i].key = *param_name;
383-
hash_keys[i].key_hash = ngx_hash_key_lc(param_name->data, param_name->len);
384-
hash_keys[i].value = &uri_param_defs[i];
394+
return NGX_ERROR;
385395
}
386396

387-
hash.hash = &conf->uri_params_hash;
388-
hash.key = ngx_hash_key;
397+
for (element = elements; element->name_conf_offset >= 0; element++)
398+
{
399+
cur_key = (ngx_str_t*)((u_char*)conf + element->name_conf_offset);
400+
if (cur_key->len == 0)
401+
{
402+
break;
403+
}
404+
405+
hash_key = ngx_array_push(&elements_arr);
406+
if (hash_key == NULL)
407+
{
408+
return NGX_ERROR;
409+
}
410+
411+
hash_key->key = *cur_key;
412+
hash_key->key_hash = ngx_hash_key_lc(cur_key->data, cur_key->len);
413+
hash_key->value = element;
414+
}
415+
416+
hash.hash = output;
417+
hash.key = ngx_hash_key_lc;
389418
hash.max_size = 512;
390419
hash.bucket_size = ngx_align(64, ngx_cacheline_size);
391-
hash.name = "uri_params_hash";
420+
hash.name = hash_name;
392421
hash.pool = cf->pool;
393422
hash.temp_pool = NULL;
394423

395-
rc = ngx_hash_init(&hash, hash_keys, sizeof(hash_keys) / sizeof(hash_keys[0]));
424+
if (ngx_hash_init(&hash, elements_arr.elts, elements_arr.nelts) != NGX_OK)
425+
{
426+
return NGX_ERROR;
427+
}
428+
429+
return NGX_OK;
430+
}
431+
432+
ngx_int_t
433+
ngx_http_vod_init_uri_params_hash(ngx_conf_t *cf, ngx_http_vod_loc_conf_t* conf)
434+
{
435+
ngx_int_t rc;
436+
437+
rc = ngx_http_vod_init_hash(
438+
cf,
439+
uri_param_defs,
440+
conf,
441+
"uri_params_hash",
442+
&conf->uri_params_hash);
443+
if (rc != NGX_OK)
444+
{
445+
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "failed to initialize uri params hash");
446+
return rc;
447+
}
448+
449+
rc = ngx_http_vod_init_hash(
450+
cf,
451+
pd_uri_param_defs,
452+
conf,
453+
"pd_uri_params_hash",
454+
&conf->pd_uri_params_hash);
396455
if (rc != NGX_OK)
397456
{
398-
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "ngx_hash_init failed %i", rc);
457+
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "failed to initialize progressive download uri params hash");
399458
return rc;
400459
}
401460

@@ -405,7 +464,7 @@ ngx_http_vod_init_uri_params_hash(ngx_conf_t *cf, ngx_http_vod_loc_conf_t* conf)
405464
static ngx_int_t
406465
ngx_http_vod_extract_uri_params(
407466
ngx_http_request_t* r,
408-
ngx_http_vod_loc_conf_t* conf,
467+
ngx_hash_t* params_hash,
409468
ngx_str_t* uri,
410469
media_sequence_t* sequence,
411470
uint32_t* clip_id,
@@ -476,7 +535,7 @@ ngx_http_vod_extract_uri_params(
476535

477536
if (param_def == NULL)
478537
{
479-
param_def = ngx_hash_find(&conf->uri_params_hash, cur_key_hash, param_name, param_name_pos - param_name);
538+
param_def = ngx_hash_find(params_hash, cur_key_hash, param_name, param_name_pos - param_name);
480539
if (param_def != NULL)
481540
{
482541
p = ngx_copy(p, copy_start, last_slash - copy_start);
@@ -516,8 +575,7 @@ ngx_http_vod_extract_uri_params(
516575
if (rc != NGX_OK)
517576
{
518577
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
519-
"ngx_http_vod_extract_uri_params: %V parser failed %i",
520-
(ngx_str_t*)((u_char*)conf + param_def->name_conf_offset), rc);
578+
"ngx_http_vod_extract_uri_params: %s parser failed %i", param_def->name, rc);
521579
return rc;
522580
}
523581
}
@@ -550,7 +608,8 @@ ngx_http_vod_extract_uri_params(
550608
ngx_int_t
551609
ngx_http_vod_parse_uri_path(
552610
ngx_http_request_t* r,
553-
ngx_http_vod_loc_conf_t* conf,
611+
ngx_str_t* multi_uri_suffix,
612+
ngx_hash_t* params_hash,
554613
ngx_str_t* uri,
555614
request_params_t* request_params,
556615
media_set_t* media_set)
@@ -570,7 +629,7 @@ ngx_http_vod_parse_uri_path(
570629
uint32_t i;
571630
int uri_count;
572631

573-
rc = ngx_http_vod_parse_multi_uri(r, uri, &conf->multi_uri_suffix, &multi_uri);
632+
rc = ngx_http_vod_parse_multi_uri(r, uri, multi_uri_suffix, &multi_uri);
574633
if (rc != NGX_OK)
575634
{
576635
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
@@ -634,7 +693,7 @@ ngx_http_vod_parse_uri_path(
634693
return rc;
635694
}
636695

637-
rc = ngx_http_vod_extract_uri_params(r, conf, &cur_uri, cur_sequence, &clip_id, cur_source, &cur_clip);
696+
rc = ngx_http_vod_extract_uri_params(r, params_hash, &cur_uri, cur_sequence, &clip_id, cur_source, &cur_clip);
638697
if (rc != NGX_OK)
639698
{
640699
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,

ngx_http_vod_request_parse.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ bool_t ngx_http_vod_split_uri_file_name(
5353

5454
ngx_int_t ngx_http_vod_parse_uri_path(
5555
ngx_http_request_t* r,
56-
struct ngx_http_vod_loc_conf_s* conf,
56+
ngx_str_t* multi_uri_suffix,
57+
ngx_hash_t* params_hash,
5758
ngx_str_t* uri,
5859
request_params_t* request_params,
5960
media_set_t* media_set);

vod/filters/audio_filter.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ audio_filter_alloc_state(
766766
rc = audio_filter_init_sink(
767767
request_context,
768768
state->filter_graph,
769-
state->output,
769+
output_track,
770770
filter_name,
771771
&state->sink,
772772
&inputs);

0 commit comments

Comments
 (0)