Skip to content

Commit b564a09

Browse files
committed
Merge branch 'peer-timestamp'
2 parents 8856d11 + 940ff26 commit b564a09

7 files changed

+28
-0
lines changed

ngx_rtmp.h

+1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ typedef struct {
221221
ngx_msec_t epoch;
222222
ngx_msec_t peer_epoch;
223223
ngx_msec_t base_time;
224+
uint32_t current_time;
224225

225226
/* ping */
226227
ngx_event_t ping_evt;

ngx_rtmp_flv_module.c

+2
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,8 @@ ngx_rtmp_flv_send(ngx_rtmp_session_t *s, ngx_file_t *f, ngx_uint_t *ts)
542542
h.timestamp > end_timestamp ? h.timestamp - end_timestamp : 0,
543543
h.timestamp, end_timestamp, (ngx_int_t) buflen);
544544

545+
s->current_time = h.timestamp;
546+
545547
/* too much data sent; schedule timeout */
546548
if (h.timestamp > end_timestamp) {
547549
return h.timestamp - end_timestamp;

ngx_rtmp_live_module.c

+5
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
718718
"live: %s packet timestamp=%uD",
719719
type_s, h->timestamp);
720720

721+
s->current_time = h->timestamp;
722+
721723
peers = 0;
722724
apkt = NULL;
723725
aapkt = NULL;
@@ -917,6 +919,7 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
917919

918920
cs->timestamp = lh.timestamp;
919921
cs->active = 1;
922+
ss->current_time = cs->timestamp;
920923

921924
} else {
922925

@@ -938,6 +941,7 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
938941

939942
cs->timestamp = ch.timestamp;
940943
cs->active = 1;
944+
ss->current_time = cs->timestamp;
941945

942946
++peers;
943947

@@ -971,6 +975,7 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
971975

972976
cs->timestamp += delta;
973977
++peers;
978+
ss->current_time = cs->timestamp;
974979
}
975980

976981
if (rpkt) {

ngx_rtmp_mp4_module.c

+2
Original file line numberDiff line numberDiff line change
@@ -2271,6 +2271,8 @@ ngx_rtmp_mp4_send(ngx_rtmp_session_t *s, ngx_file_t *f, ngx_uint_t *ts)
22712271
return NGX_AGAIN;
22722272
}
22732273

2274+
s->current_time = timestamp;
2275+
22742276
if (ngx_rtmp_mp4_next(s, t) != NGX_OK) {
22752277
continue;
22762278
}

ngx_rtmp_notify_module.c

+5
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ ngx_rtmp_notify_update_create(ngx_rtmp_session_t *s, void *arg,
695695
b = ngx_create_temp_buf(pool,
696696
sizeof("&call=update") + sfx.len +
697697
sizeof("&time=") + NGX_TIME_T_LEN +
698+
sizeof("&timestamp=") + NGX_INT32_LEN +
698699
sizeof("&name=") + name_len * 3 +
699700
1 + args_len);
700701
if (b == NULL) {
@@ -712,6 +713,10 @@ ngx_rtmp_notify_update_create(ngx_rtmp_session_t *s, void *arg,
712713
sizeof("&time=") - 1);
713714
b->last = ngx_sprintf(b->last, "%T", ngx_cached_time->sec - ctx->start);
714715

716+
b->last = ngx_cpymem(b->last, (u_char *) "&timestamp=",
717+
sizeof("&timestamp=") - 1);
718+
b->last = ngx_sprintf(b->last, "%D", s->current_time);
719+
715720
if (name_len) {
716721
b->last = ngx_cpymem(b->last, (u_char*) "&name=", sizeof("&name=") - 1);
717722
b->last = (u_char*) ngx_escape_uri(b->last, ctx->name, name_len,

ngx_rtmp_stat_module.c

+11
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,11 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
424424
}
425425
NGX_RTMP_STAT_L("</avsync>");
426426

427+
NGX_RTMP_STAT_L("<timestamp>");
428+
NGX_RTMP_STAT(bbuf, ngx_snprintf(bbuf, sizeof(bbuf),
429+
"%D", s->current_time) - bbuf);
430+
NGX_RTMP_STAT_L("</timestamp>");
431+
427432
if (ctx->publishing) {
428433
NGX_RTMP_STAT_L("<publishing/>");
429434
}
@@ -510,6 +515,7 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
510515
ngx_rtmp_session_t *s;
511516
ngx_uint_t n, nclients, total_nclients;
512517
u_char buf[NGX_INT_T_LEN];
518+
u_char bbuf[NGX_INT32_LEN];
513519
ngx_rtmp_stat_loc_conf_t *slcf;
514520

515521
if (pacf->entries.nelts == 0) {
@@ -544,6 +550,11 @@ ngx_rtmp_stat_play(ngx_http_request_t *r, ngx_chain_t ***lll,
544550

545551
ngx_rtmp_stat_client(r, lll, s);
546552

553+
NGX_RTMP_STAT_L("<timestamp>");
554+
NGX_RTMP_STAT(bbuf, ngx_snprintf(bbuf, sizeof(bbuf),
555+
"%D", s->current_time) - bbuf);
556+
NGX_RTMP_STAT_L("</timestamp>");
557+
547558
NGX_RTMP_STAT_L("</client>\r\n");
548559
}
549560
}

stat.xsl

+2
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
<th>Page URL</th>
197197
<th>SWF URL</th>
198198
<th>Dropped</th>
199+
<th>Timestamp</th>
199200
<th>A-V</th>
200201
<th>Time</th>
201202
</tr>
@@ -295,6 +296,7 @@
295296
</td>
296297
<td><xsl:value-of select="swfurl"/></td>
297298
<td><xsl:value-of select="dropped"/></td>
299+
<td><xsl:value-of select="timestamp"/></td>
298300
<td><xsl:value-of select="avsync"/></td>
299301
<td>
300302
<xsl:call-template name="showtime">

0 commit comments

Comments
 (0)