Skip to content

Commit 7410910

Browse files
HeyJupiterwinshining
authored andcommitted
[dev] optimize GOP cache feature. (#66)
* [dev] make config file more compatible. * [dev] optimize GOP cache feature.
1 parent 1212756 commit 7410910

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

ngx_rtmp_gop_cache_module.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/*
33
* Copyright (C) Gnolizuh
44
* Copyright (C) Winshining
5+
* Copyright (C) HeyJupiter
56
*/
67

78

@@ -550,6 +551,7 @@ ngx_rtmp_gop_cache_send(ngx_rtmp_session_t *s)
550551
ngx_rtmp_live_chunk_stream_t *cs;
551552
ngx_rtmp_live_proc_handler_t *handler;
552553
ngx_http_request_t *r;
554+
ngx_flag_t error;
553555

554556
lacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_live_module);
555557
if (lacf == NULL) {
@@ -600,6 +602,7 @@ ngx_rtmp_gop_cache_send(ngx_rtmp_session_t *s)
600602
if (meta == NULL && meta_version != gctx->meta_version) {
601603
meta = handler->meta_message_pt(s, gctx->meta);
602604
if (meta == NULL) {
605+
ngx_rtmp_finalize_session(s);
603606
return;
604607
}
605608
}
@@ -638,6 +641,7 @@ ngx_rtmp_gop_cache_send(ngx_rtmp_session_t *s)
638641
}
639642

640643
delta = ch.timestamp - lh.timestamp;
644+
error = 0;
641645

642646
if (!cs->active) {
643647
switch (gf->h.type) {
@@ -651,12 +655,13 @@ ngx_rtmp_gop_cache_send(ngx_rtmp_session_t *s)
651655
if (header) {
652656
apkt = handler->append_message_pt(s, &lh, NULL, header);
653657
if (apkt == NULL) {
654-
return;
658+
error = 1;
659+
goto next;
655660
}
656661
}
657662

658663
if (apkt && handler->send_message_pt(s, apkt, 0) != NGX_OK) {
659-
continue;
664+
goto next;
660665
}
661666

662667
cs->timestamp = lh.timestamp;
@@ -666,16 +671,16 @@ ngx_rtmp_gop_cache_send(ngx_rtmp_session_t *s)
666671

667672
pkt = handler->append_message_pt(s, &ch, &lh, gf->frame);
668673
if (pkt == NULL) {
669-
return;
674+
error = 1;
675+
goto next;
670676
}
671677

672678
if (handler->send_message_pt(s, pkt, gf->prio) != NGX_OK) {
673679
++pub_ctx->ndropped;
674680

675681
cs->dropped += delta;
676682

677-
ngx_rtmp_finalize_session(s);
678-
return;
683+
goto next;
679684
}
680685

681686
ngx_log_debug4(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
@@ -687,6 +692,8 @@ ngx_rtmp_gop_cache_send(ngx_rtmp_session_t *s)
687692
cs->timestamp += delta;
688693
s->current_time = cs->timestamp;
689694

695+
next:
696+
690697
if (pkt) {
691698
handler->free_message_pt(s, pkt);
692699
pkt = NULL;
@@ -696,6 +703,11 @@ ngx_rtmp_gop_cache_send(ngx_rtmp_session_t *s)
696703
handler->free_message_pt(s, apkt);
697704
apkt = NULL;
698705
}
706+
707+
if (error) {
708+
ngx_rtmp_finalize_session(s);
709+
return;
710+
}
699711
}
700712
}
701713
}

0 commit comments

Comments
 (0)