Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ID field for source clip #1478

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ Mandatory fields:
an empty captions file (useful in case only some videos in a playlist have captions)

Optional fields:
* `id` - a string that identifies the source clip (maximum 32 bytes)
* `sourceType` - sets the interface that should be used to read the MP4 file, allowed values are:
`file` and `http`. By default, the module uses `http` if `vod_remote_upstream_location` is set,
and `file` otherwise.
Expand Down
14 changes: 13 additions & 1 deletion vod/hls/hls_muxer.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

#define ID3_TEXT_JSON_FORMAT "{\"timestamp\":%uL}%Z"
#define ID3_TEXT_JSON_SEQUENCE_ID_PREFIX_FORMAT "{\"timestamp\":%uL,\"sequenceId\":\""
#define ID3_TEXT_JSON_CLIP_ID_FORMAT "\",\"clipId\":\""
#define ID3_TEXT_JSON_SEQUENCE_ID_SUFFIX "\"}"


// from ffmpeg mpegtsenc
#define DEFAULT_PES_HEADER_FREQ 16
#define DEFAULT_PES_PAYLOAD_SIZE ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170)
Expand Down Expand Up @@ -171,6 +173,7 @@ hls_muxer_init_id3_stream(
size_t data_size;
int64_t timestamp;
void* frames_source_context;
vod_str_t clip_id;

cur_stream = state->last_stream;

Expand All @@ -196,8 +199,9 @@ hls_muxer_init_id3_stream(
if (sequence_id->len != 0)
{
sequence_id_escape = vod_escape_json(NULL, sequence_id->data, sequence_id->len);
data_size = sizeof(ID3_TEXT_JSON_SEQUENCE_ID_PREFIX_FORMAT) + VOD_INT64_LEN +
data_size = sizeof(ID3_TEXT_JSON_SEQUENCE_ID_PREFIX_FORMAT) + VOD_INT64_LEN +
sequence_id->len + sequence_id_escape +
sizeof(ID3_TEXT_JSON_CLIP_ID_FORMAT) + CLIP_ID_MAX_SIZE +
sizeof(ID3_TEXT_JSON_SEQUENCE_ID_SUFFIX);
}
else
Expand Down Expand Up @@ -268,6 +272,14 @@ hls_muxer_init_id3_stream(
{
p = vod_copy(p, sequence_id->data, sequence_id->len);
}

clip_id = ref_track->file_info.source->id;
if (clip_id.len != 0)
{
p = vod_copy(p, ID3_TEXT_JSON_CLIP_ID_FORMAT, sizeof(ID3_TEXT_JSON_CLIP_ID_FORMAT) - 1);
p = vod_copy(p, clip_id.data, clip_id.len);
}

p = vod_copy(p, ID3_TEXT_JSON_SEQUENCE_ID_SUFFIX, sizeof(ID3_TEXT_JSON_SEQUENCE_ID_SUFFIX));

}
Expand Down
1 change: 1 addition & 0 deletions vod/media_clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ typedef struct ngx_http_vod_reader_s ngx_http_vod_reader_t;
struct media_clip_source_s {
// base
media_clip_t base;
vod_str_t id;
int64_t clip_time;
media_range_t* range;
media_track_array_t track_array;
Expand Down
1 change: 1 addition & 0 deletions vod/media_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define MAX_CLOSED_CAPTIONS (67)
#define MAX_CLIPS (128)
#define MAX_CLIPS_PER_REQUEST (16)
#define CLIP_ID_MAX_SIZE (32)
#define MAX_SEQUENCES (32)
#define MAX_SEQUENCE_IDS (4)
#define MAX_SEQUENCE_TRACKS_MASKS (2)
Expand Down
25 changes: 25 additions & 0 deletions vod/media_set_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ static vod_status_t media_set_parse_source(void* ctx, vod_json_object_t* element
static vod_status_t media_set_parse_clips_array(void* ctx, vod_json_value_t* value, void* dest);
static vod_status_t media_set_parse_bitrate(void* ctx, vod_json_value_t* value, void* dest);
static vod_status_t media_set_parse_source_type(void* ctx, vod_json_value_t* value, void* dest);
static vod_status_t media_set_parse_source_clip_id(void* ctx, vod_json_value_t* value, void* dest);

// constants
static json_parser_union_type_def_t media_clip_union_params[] = {
Expand All @@ -119,6 +120,7 @@ static json_parser_union_type_def_t media_clip_union_params[] = {
};

static json_object_value_def_t media_clip_source_params[] = {
{ vod_string("id"), VOD_JSON_STRING, offsetof(media_clip_source_t, id), media_set_parse_source_clip_id },
{ vod_string("path"), VOD_JSON_STRING, offsetof(media_clip_source_t, mapped_uri), media_set_parse_null_term_string },
{ vod_string("tracks"), VOD_JSON_STRING, offsetof(media_clip_source_t, tracks_mask), media_set_parse_tracks_spec },
{ vod_string("clipFrom"), VOD_JSON_INT, offsetof(media_clip_source_t, clip_from), media_set_parse_int64 },
Expand Down Expand Up @@ -320,6 +322,29 @@ media_set_parse_int64(
return VOD_OK;
}

static vod_status_t
media_set_parse_source_clip_id(
void* ctx,
vod_json_value_t* value,
void* dest)
{
media_filter_parse_context_t* context = ctx;
vod_status_t rc;
if (value->v.str.len > CLIP_ID_MAX_SIZE)
{
vod_log_error(VOD_LOG_ERR, context->request_context->log, 0,
"media_set_parse_source_clip_id: invalid size of id: %uz", value->v.str.len);
return VOD_BAD_MAPPING;
}

rc = media_set_parse_null_term_string(context, value, dest);
if (rc != VOD_OK)
{
return rc;
}
return VOD_OK;
}

static vod_status_t
media_set_parse_source_type(
void* ctx,
Expand Down
Loading