fixed stat & live module

This commit is contained in:
Roman Arutyunyan
2012-10-28 15:10:12 +04:00
parent 7fbfb36440
commit b5461f61c6
3 changed files with 38 additions and 29 deletions

View File

@ -377,10 +377,10 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
sync = 0; sync = 0;
peers = 0; peers = 0;
header = NULL;
aheader = NULL; aheader = NULL;
rheader = NULL; rheader = NULL;
apkt = NULL; apkt = NULL;
header = NULL;
header_version = 0; header_version = 0;
meta = NULL; meta = NULL;
meta_version = 0; meta_version = 0;
@ -460,13 +460,6 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
ss = pctx->session; ss = pctx->session;
cs = &pctx->cs[csidx]; cs = &pctx->cs[csidx];
ch.timestamp = timestamp;
if (lacf->atc == 0) {
ch.timestamp -= (uint32_t) ss->epoch;
}
lh.timestamp = ch.timestamp - delta;
/* send metadata */ /* send metadata */
if (meta && meta_version != pctx->meta_version) { if (meta && meta_version != pctx->meta_version) {
@ -480,28 +473,42 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
/* sync stream */ /* sync stream */
if (cs->active && if (cs->active && (sync || (lacf->sync && cs->dropped > lacf->sync))) {
(sync || (lacf->sync &&
(int32_t) (cs->timestamp + lacf->sync - lh.timestamp) < 0)))
{
ngx_log_debug2(NGX_LOG_DEBUG_RTMP, ss->connection->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_RTMP, ss->connection->log, 0,
"live: sync %s: %i", "live: sync %s dropped=%uD", type_s, cs->dropped);
type_s, (ngx_int_t) (lh.timestamp - cs->timestamp));
cs->active = 0; cs->active = 0;
cs->dropped = 0;
} }
/* absolute packet */ /* absolute packet */
if (!cs->active) { if (!cs->active) {
if (lacf->wait_key && h->type == NGX_RTMP_MSG_VIDEO && if (lacf->wait_key && prio != NGX_RTMP_VIDEO_KEY_FRAME &&
prio != NGX_RTMP_VIDEO_KEY_FRAME) (lacf->interleave || h->type == NGX_RTMP_MSG_VIDEO))
{ {
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, ss->connection->log, 0, ngx_log_debug0(NGX_LOG_DEBUG_RTMP, ss->connection->log, 0,
"live: skip non-key"); "live: skip non-key");
continue; continue;
} }
ch.timestamp = timestamp;
if (lacf->atc == 0) {
ch.timestamp -= (uint32_t) ss->epoch;
}
lh.timestamp = ch.timestamp - delta;
/*
if (ngx_rtmp_send_user_stream_eof(ss, NGX_RTMP_MSID) != NGX_OK) {
continue;
}
if (ngx_rtmp_send_user_stream_begin(ss, NGX_RTMP_MSID) != NGX_OK) {
continue;
}*/
if (header) { if (header) {
/* send absolute codec header */ /* send absolute codec header */
@ -598,10 +605,14 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
"live: rel %s packet delta=%uD", "live: rel %s packet delta=%uD",
type_s, delta); type_s, delta);
if (ngx_rtmp_send_message(ss, rpkt, prio) == NGX_OK) { if (ngx_rtmp_send_message(ss, rpkt, prio) != NGX_OK) {
cs->timestamp += delta; ++pctx->ndropped;
++peers; cs->dropped += delta;
continue;
} }
cs->timestamp += delta;
++peers;
} }
if (rpkt) { if (rpkt) {

View File

@ -25,6 +25,7 @@ typedef struct {
unsigned active:1; unsigned active:1;
uint32_t timestamp; uint32_t timestamp;
uint32_t csid; uint32_t csid;
uint32_t dropped;
} ngx_rtmp_live_chunk_stream_t; } ngx_rtmp_live_chunk_stream_t;
@ -33,7 +34,7 @@ struct ngx_rtmp_live_ctx_s {
ngx_rtmp_live_stream_t *stream; ngx_rtmp_live_stream_t *stream;
ngx_rtmp_live_ctx_t *next; ngx_rtmp_live_ctx_t *next;
ngx_uint_t flags; ngx_uint_t flags;
ngx_uint_t dropped; ngx_uint_t ndropped;
ngx_rtmp_live_chunk_stream_t cs[2]; ngx_rtmp_live_chunk_stream_t cs[2];
ngx_uint_t header_versions[2]; ngx_uint_t header_versions[2];
ngx_uint_t meta_version; ngx_uint_t meta_version;

View File

@ -306,19 +306,16 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
NGX_RTMP_STAT_L("<dropped>"); NGX_RTMP_STAT_L("<dropped>");
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf), NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
"%uz", ctx->dropped) - buf); "%uz", ctx->ndropped) - buf);
NGX_RTMP_STAT_L("</dropped>"); NGX_RTMP_STAT_L("</dropped>");
if (ctx->cs[0].active && ctx->cs[1].active) { NGX_RTMP_STAT_L("<avsync>");
NGX_RTMP_STAT_L("<avsync>"); NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf),
"%uD/%uD", ctx->cs[0].dropped,
ctx->cs[1].dropped) - buf);
NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf), NGX_RTMP_STAT_L("</avsync>");
"%L", (int64_t) ctx->cs[0].timestamp -
(int64_t) ctx->cs[1].timestamp) - buf);
NGX_RTMP_STAT_L("</avsync>");
}
if (s->flashver.len) { if (s->flashver.len) {
NGX_RTMP_STAT_L("<flashver>"); NGX_RTMP_STAT_L("<flashver>");