mirror of
https://github.com/zotanmew/nginx-rtmp-module.git
synced 2024-05-14 08:01:07 +02:00
implemented mp4 track selector
This commit is contained in:
parent
9c88e12cf8
commit
af5703b357
|
@ -12,7 +12,8 @@ static ngx_int_t ngx_rtmp_flv_postconfiguration(ngx_conf_t *cf);
|
|||
static void ngx_rtmp_flv_read_meta(ngx_rtmp_session_t *s, ngx_file_t *f);
|
||||
static ngx_int_t ngx_rtmp_flv_timestamp_to_offset(ngx_rtmp_session_t *s,
|
||||
ngx_file_t *f, ngx_int_t timestamp);
|
||||
static ngx_int_t ngx_rtmp_flv_init(ngx_rtmp_session_t *s, ngx_file_t *f);
|
||||
static ngx_int_t ngx_rtmp_flv_init(ngx_rtmp_session_t *s, ngx_file_t *f,
|
||||
ngx_int_t aindex, ngx_int_t vindex);
|
||||
static ngx_int_t ngx_rtmp_flv_start(ngx_rtmp_session_t *s, ngx_file_t *f);
|
||||
static ngx_int_t ngx_rtmp_flv_seek(ngx_rtmp_session_t *s, ngx_file_t *f,
|
||||
ngx_uint_t offset);
|
||||
|
@ -548,7 +549,8 @@ next:
|
|||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_flv_init(ngx_rtmp_session_t *s, ngx_file_t *f)
|
||||
ngx_rtmp_flv_init(ngx_rtmp_session_t *s, ngx_file_t *f, ngx_int_t aindex,
|
||||
ngx_int_t vindex)
|
||||
{
|
||||
ngx_rtmp_flv_ctx_t *ctx;
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
|
||||
|
||||
static ngx_int_t ngx_rtmp_mp4_postconfiguration(ngx_conf_t *cf);
|
||||
static ngx_int_t ngx_rtmp_mp4_init(ngx_rtmp_session_t *s, ngx_file_t *f);
|
||||
static ngx_int_t ngx_rtmp_mp4_init(ngx_rtmp_session_t *s, ngx_file_t *f,
|
||||
ngx_int_t aindex, ngx_int_t vindex);
|
||||
static ngx_int_t ngx_rtmp_mp4_done(ngx_rtmp_session_t *s, ngx_file_t *f);
|
||||
static ngx_int_t ngx_rtmp_mp4_start(ngx_rtmp_session_t *s, ngx_file_t *f);
|
||||
static ngx_int_t ngx_rtmp_mp4_seek(ngx_rtmp_session_t *s, ngx_file_t *f,
|
||||
|
@ -173,6 +174,9 @@ typedef struct {
|
|||
ngx_uint_t sample_size;
|
||||
ngx_uint_t sample_rate;
|
||||
|
||||
ngx_int_t atracks, vtracks;
|
||||
ngx_int_t aindex, vindex;
|
||||
|
||||
uint32_t start_timestamp, epoch;
|
||||
} ngx_rtmp_mp4_ctx_t;
|
||||
|
||||
|
@ -368,6 +372,26 @@ ngx_rtmp_mp4_parse_trak(ngx_rtmp_session_t *s, u_char *pos, u_char *last)
|
|||
{
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||
"mp4: adding track %ui", ctx->ntracks);
|
||||
|
||||
if (ctx->track->type == NGX_RTMP_MSG_AUDIO) {
|
||||
if (ctx->atracks++ != ctx->aindex) {
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||
"mp4: skipping audio track %ui!=%ui",
|
||||
ctx->atracks - 1, ctx->aindex);
|
||||
ctx->track = NULL;
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (ctx->vtracks++ != ctx->vindex) {
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||
"mp4: skipping video track %i!=%i",
|
||||
ctx->vtracks - 1, ctx->vindex);
|
||||
ctx->track = NULL;
|
||||
return NGX_OK;
|
||||
}
|
||||
}
|
||||
|
||||
++ctx->ntracks;
|
||||
|
||||
} else {
|
||||
|
@ -2168,7 +2192,8 @@ next:
|
|||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_mp4_init(ngx_rtmp_session_t *s, ngx_file_t *f)
|
||||
ngx_rtmp_mp4_init(ngx_rtmp_session_t *s, ngx_file_t *f, ngx_int_t aindex,
|
||||
ngx_int_t vindex)
|
||||
{
|
||||
ngx_rtmp_mp4_ctx_t *ctx;
|
||||
uint32_t hdr[2];
|
||||
|
@ -2189,6 +2214,9 @@ ngx_rtmp_mp4_init(ngx_rtmp_session_t *s, ngx_file_t *f)
|
|||
|
||||
ngx_memzero(ctx, sizeof(*ctx));
|
||||
|
||||
ctx->aindex = aindex;
|
||||
ctx->vindex = vindex;
|
||||
|
||||
offset = 0;
|
||||
size = 0;
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@ ngx_rtmp_play_do_init(ngx_rtmp_session_t *s)
|
|||
}
|
||||
|
||||
if (ctx->fmt && ctx->fmt->init &&
|
||||
ctx->fmt->init(s, &ctx->file) != NGX_OK)
|
||||
ctx->fmt->init(s, &ctx->file, ctx->aindex, ctx->vindex) != NGX_OK)
|
||||
{
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
@ -433,6 +433,33 @@ next:
|
|||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_play_parse_index(char type, u_char *args)
|
||||
{
|
||||
u_char *p, c;
|
||||
static u_char name[] = "xindex=";
|
||||
|
||||
name[0] = (u_char) type;
|
||||
|
||||
for ( ;; ) {
|
||||
p = (u_char *) ngx_strstr(args, name);
|
||||
if (p == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (p != args) {
|
||||
c = *(p - 1);
|
||||
if (c != '?' && c != '&') {
|
||||
args = p + 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return atoi((char *) p + (sizeof(name) - 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_play_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v)
|
||||
{
|
||||
|
@ -487,6 +514,9 @@ ngx_rtmp_play_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v)
|
|||
|
||||
ngx_memzero(ctx, sizeof(*ctx));
|
||||
|
||||
ctx->aindex = ngx_rtmp_play_parse_index('a', v->args);
|
||||
ctx->vindex = ngx_rtmp_play_parse_index('v', v->args);
|
||||
|
||||
ctx->file.log = s->connection->log;
|
||||
|
||||
name.len = ngx_strlen(v->name);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
|
||||
typedef ngx_int_t (*ngx_rtmp_play_init_pt) (ngx_rtmp_session_t *s,
|
||||
ngx_file_t *f);
|
||||
ngx_file_t *f, ngx_int_t aindex, ngx_int_t vindex);
|
||||
typedef ngx_int_t (*ngx_rtmp_play_done_pt) (ngx_rtmp_session_t *s,
|
||||
ngx_file_t *f);
|
||||
typedef ngx_int_t (*ngx_rtmp_play_start_pt) (ngx_rtmp_session_t *s,
|
||||
|
@ -45,6 +45,7 @@ typedef struct {
|
|||
unsigned playing:1;
|
||||
ngx_uint_t ncrs;
|
||||
ngx_str_t name;
|
||||
ngx_int_t aindex, vindex;
|
||||
} ngx_rtmp_play_ctx_t;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue