[-]
[+]
|
Changed |
nginx-1.2.changes
|
|
[-]
[+]
|
Changed |
nginx-1.2.spec
^
|
|
[-]
[+]
|
Changed |
nginx-rtmp-module-0.9.14.tar.bz2/hls/ngx_rtmp_hls_module.c
^
|
@@ -187,6 +187,27 @@
static ngx_int_t
+ngx_rtmp_hls_create_parent_dir(ngx_rtmp_session_t *s)
+{
+ ngx_rtmp_hls_app_conf_t *hacf;
+
+ hacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_hls_module);
+
+ ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
+ "hls: creating target folder: '%V'", &hacf->path);
+
+ if (ngx_create_dir(hacf->path.data, NGX_RTMP_HLS_DIR_ACCESS) == NGX_OK) {
+ return NGX_OK;
+ }
+
+ ngx_log_error(NGX_LOG_ERR, s->connection->log, ngx_errno,
+ "hls: error creating target folder: '%V'", &hacf->path);
+
+ return NGX_ERROR;
+}
+
+
+static ngx_int_t
ngx_rtmp_hls_update_playlist(ngx_rtmp_session_t *s)
{
static u_char buffer[1024];
@@ -209,21 +230,17 @@
NGX_FILE_TRUNCATE, NGX_FILE_DEFAULT_ACCESS);
if (fd == NGX_INVALID_FILE) {
- ngx_log_error(NGX_LOG_ERR, s->connection->log, ngx_errno,
- "hls: open failed: '%V'", &ctx->playlist_bak);
- /* try to create parent folder */
-
- if (nretry == 0 &&
- ngx_create_dir(hacf->path.data, NGX_RTMP_HLS_DIR_ACCESS) !=
- NGX_INVALID_FILE)
+ if (ngx_errno == NGX_ENOENT && nretry == 0 &&
+ ngx_rtmp_hls_create_parent_dir(s) == NGX_OK)
{
- ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
- "hls: creating target folder: '%V'", &hacf->path);
- ++nretry;
+ nretry++;
goto retry;
}
+ ngx_log_error(NGX_LOG_ERR, s->connection->log, ngx_errno,
+ "hls: open failed: '%V'", &ctx->playlist_bak);
+
return NGX_ERROR;
}
@@ -457,6 +474,7 @@
{
ngx_rtmp_hls_app_conf_t *hacf;
ngx_rtmp_hls_ctx_t *ctx;
+ ngx_int_t nretry;
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_hls_module);
@@ -500,10 +518,22 @@
ngx_str_set(&ctx->file.name, "hls");
+ nretry = 0;
+
+retry:
+
ctx->file.fd = ngx_open_file(ctx->stream.data, NGX_FILE_WRONLY,
NGX_FILE_TRUNCATE, NGX_FILE_DEFAULT_ACCESS);
if (ctx->file.fd == NGX_INVALID_FILE) {
+
+ if (ngx_errno == NGX_ENOENT && nretry == 0 &&
+ ngx_rtmp_hls_create_parent_dir(s) == NGX_OK)
+ {
+ nretry++;
+ goto retry;
+ }
+
ngx_log_error(NGX_LOG_ERR, s->connection->log, ngx_errno,
"hls: error creating fragment file");
return;
@@ -769,7 +799,7 @@
}
if (frag != ctx->frag + 1) {
- ctx->offset = (ctx->frag + 1) * (uint64_t) hacf->fraglen * 90 - ts;
+ ctx->offset += (ctx->frag + 1) * (uint64_t) hacf->fraglen * 90 - ts;
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"hls: time gap offset=%uL", ctx->offset);
}
|
[-]
[+]
|
Changed |
nginx-rtmp-module-0.9.14.tar.bz2/hls/ngx_rtmp_mpegts.c
^
|
@@ -123,7 +123,7 @@
ngx_buf_t *b)
{
ngx_uint_t pes_size, header_size, body_size, in_size, stuff_size, flags;
- u_char packet[188], *p;
+ u_char packet[188], *p, *base;
ngx_int_t first, rc;
ngx_log_debug6(NGX_LOG_DEBUG_HTTP, file->log, 0,
@@ -176,6 +176,9 @@
}
pes_size = (b->last - b->pos) + header_size + 3;
+ if (pes_size > 0xffff) {
+ pes_size = 0;
+ }
*p++ = (pes_size >> 8);
*p++ = pes_size;
@@ -205,19 +208,24 @@
stuff_size = (body_size - in_size);
if (packet[3] & 0x20) {
+
+ /* has adaptation */
+
+ base = &packet[5] + packet[4];
+ p = ngx_movemem(base + stuff_size, base, p - base);
+ ngx_memset(base, 0xff, stuff_size);
packet[4] += stuff_size;
- p = ngx_movemem(&packet[6] + stuff_size, &packet[6], p - &packet[4]);
- ngx_memset(&packet[6], 0xff, stuff_size);
} else {
+
+ /* no adaptation */
+
packet[3] |= 0x20;
- if (stuff_size == 1) {
- p = ngx_movemem(&packet[5], &packet[4], p - &packet[4]);
- packet[4] = 0;
- } else {
- p = ngx_movemem(&packet[4] + stuff_size, &packet[4],
- p - &packet[4]);
- packet[4] = stuff_size - 1;
+ p = ngx_movemem(&packet[4] + stuff_size, &packet[4],
+ p - &packet[4]);
+
+ packet[4] = stuff_size - 1;
+ if (stuff_size >= 2) {
packet[5] = 0;
ngx_memset(&packet[6], 0xff, stuff_size - 2);
}
|
[-]
[+]
|
Changed |
nginx-rtmp-module-0.9.14.tar.bz2/ngx_rtmp_notify_module.c
^
|
@@ -788,7 +788,14 @@
if (c >= (u_char)'0' && c <= (u_char)'9') {
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"notify: HTTP retcode: %dxx", (int)(c - '0'));
- return c == (u_char)'2' ? NGX_OK : NGX_ERROR;
+ switch (c) {
+ case (u_char) '2':
+ return NGX_OK;
+ case (u_char) '3':
+ return NGX_AGAIN;
+ default:
+ return NGX_ERROR;
+ }
}
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
@@ -814,14 +821,129 @@
static ngx_int_t
+ngx_rtmp_notify_parse_http_header(ngx_rtmp_session_t *s,
+ ngx_chain_t *in, ngx_str_t *name, u_char *data, size_t len)
+{
+ ngx_buf_t *b;
+ ngx_int_t matched;
+ u_char *p, c;
+ ngx_uint_t n;
+
+ enum {
+ parse_name,
+ parse_space,
+ parse_value,
+ parse_value_newline
+ } state = parse_name;
+
+ n = 0;
+ matched = 0;
+
+ while (in) {
+ b = in->buf;
+
+ for (p = b->pos; p != b->last; ++p) {
+ c = *p;
+
+ if (c == '\r') {
+ continue;
+ }
+
+ switch (state) {
+ case parse_value_newline:
+ if (c == ' ' || c == '\t') {
+ state = parse_space;
+ break;
+ }
+
+ if (matched) {
+ return n;
+ }
+
+ if (c == '\n') {
+ return NGX_OK;
+ }
+
+ n = 0;
+ state = parse_name;
+
+ case parse_name:
+ switch (c) {
+ case ':':
+ matched = (n == name->len);
+ n = 0;
+ state = parse_space;
+ break;
+ case '\n':
+ n = 0;
+ break;
+ default:
+ if (n < name->len &&
+ ngx_tolower(c) == ngx_tolower(name->data[n]))
+ {
+ ++n;
+ break;
+ }
+ n = name->len + 1;
+ }
+ break;
+
+ case parse_space:
+ if (c == ' ' || c == '\t') {
+ break;
+ }
+ state = parse_value;
+
+ case parse_value:
+ if (c == '\n') {
+ state = parse_value_newline;
+ break;
+ }
+
+ if (matched && n + 1 < len) {
+ data[n++] = c;
+ }
+
+ break;
+ }
+ }
+
+ in = in->next;
+ }
+
+ return NGX_OK;
+}
+
+
+static ngx_int_t
ngx_rtmp_notify_connect_handle(ngx_rtmp_session_t *s,
void *arg, ngx_chain_t *in)
{
- if (ngx_rtmp_notify_parse_http_retcode(s, in) != NGX_OK) {
+ ngx_rtmp_connect_t *v = arg;
+ ngx_int_t rc;
+ u_char app[NGX_RTMP_MAX_NAME];
+
+ static ngx_str_t location = ngx_string("location");
+
+ rc = ngx_rtmp_notify_parse_http_retcode(s, in);
+ if (rc == NGX_ERROR) {
return NGX_ERROR;
}
- return next_connect(s, (ngx_rtmp_connect_t *)arg);
+ if (rc == NGX_AGAIN) {
+ ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
+ "notify: connect redirect received");
+
+ rc = ngx_rtmp_notify_parse_http_header(s, in, &location, app,
+ sizeof(app) - 1);
+ if (rc > 0) {
+ *ngx_cpymem(v->app, app, rc) = 0;
+ ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
+ "notify: connect redirect to '%s'", v->app);
+ }
+ }
+
+ return next_connect(s, v);
}
@@ -829,11 +951,31 @@
ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s,
void *arg, ngx_chain_t *in)
{
- if (ngx_rtmp_notify_parse_http_retcode(s, in) != NGX_OK) {
+ ngx_rtmp_publish_t *v = arg;
+ ngx_int_t rc;
+ u_char name[NGX_RTMP_MAX_NAME];
+
+ static ngx_str_t location = ngx_string("location");
+
+ rc = ngx_rtmp_notify_parse_http_retcode(s, in);
+ if (rc == NGX_ERROR) {
return NGX_ERROR;
}
- return next_publish(s, (ngx_rtmp_publish_t *)arg);
+ if (rc == NGX_AGAIN) {
+ ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
+ "notify: publish redirect received");
+
+ rc = ngx_rtmp_notify_parse_http_header(s, in, &location, name,
+ sizeof(name) - 1);
+ if (rc > 0) {
+ *ngx_cpymem(v->name, name, rc) = 0;
+ ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
+ "notify: publish redirect to '%s'", v->name);
+ }
+ }
+
+ return next_publish(s, v);
}
@@ -841,11 +983,31 @@
ngx_rtmp_notify_play_handle(ngx_rtmp_session_t *s,
void *arg, ngx_chain_t *in)
{
- if (ngx_rtmp_notify_parse_http_retcode(s, in) != NGX_OK) {
+ ngx_rtmp_play_t *v = arg;
+ ngx_int_t rc;
+ u_char name[NGX_RTMP_MAX_NAME];
+
+ static ngx_str_t location = ngx_string("location");
+
+ rc = ngx_rtmp_notify_parse_http_retcode(s, in);
+ if (rc == NGX_ERROR) {
return NGX_ERROR;
}
- return next_play(s, (ngx_rtmp_play_t *)arg);
+ if (rc == NGX_AGAIN) {
+ ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
+ "notify: play redirect received");
+
+ rc = ngx_rtmp_notify_parse_http_header(s, in, &location, name,
+ sizeof(name) - 1);
+ if (rc > 0) {
+ *ngx_cpymem(v->name, name, rc) = 0;
+ ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
+ "notify: play redirect to '%s'", v->name);
+ }
+ }
+
+ return next_play(s, v);
}
|
[-]
[+]
|
Changed |
nginx-rtmp-module-0.9.14.tar.bz2/ngx_rtmp_stat_module.c
^
|
@@ -519,7 +519,6 @@
static u_char tbuf[NGX_TIME_T_LEN + 1];
static u_char nbuf[NGX_OFF_T_LEN + 1];
- r->keepalive = 0;
slcf = ngx_http_get_module_loc_conf(r, ngx_rtmp_stat_module);
if (slcf->stat == 0) {
return NGX_DECLINED;
|