Skip to content

Commit 76a1a65

Browse files
committed
1.fix extend timestamp when using librtmp; 2.add rpm packet script;
1 parent 4386a19 commit 76a1a65

17 files changed

+793
-16
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
docker/*.tar*
22
openresty/
3-
nginx/
43
.git/
54
*.code-workspace
65
.DS_Store
76
h5player/
7+
.vscode/
8+
nginx/
9+
source/
10+
rpmbuild/

config.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
df_path=$1
2+
service=$2
3+
4+
install_path=$df_path"/usr/local/"$service
5+
6+
cp -rf ./deps/* $install_path"/sbin"
7+
8+
cp ./resource/conf-template/nginx.conf $install_path"/conf/nginx.conf"
9+
10+
cp ./resource/stat.xsl $install_path"/html/stat.xsl"
11+
12+
cp ./resource/crossdomain.xml $install_path"/html/crossdomain.xml"
13+
14+
cp -r ./h5player $install_path"/html/"

deps/ffmpeg

71.8 MB
Binary file not shown.

modules/nginx-rtmp-module/ngx_rtmp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ typedef struct {
176176
uint32_t dtime;
177177
uint32_t len; /* current fragment length */
178178
uint8_t ext;
179+
uint32_t last_extimestamp;
179180
ngx_chain_t *in;
180181
} ngx_rtmp_stream_t;
181182

modules/nginx-rtmp-module/ngx_rtmp_core_module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ ngx_rtmp_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
388388
ngx_conf_merge_msec_value(conf->ping_timeout, prev->ping_timeout, 30000);
389389

390390
ngx_conf_merge_value(conf->so_keepalive, prev->so_keepalive, 0);
391-
ngx_conf_merge_value(conf->max_streams, prev->max_streams, 32);
391+
ngx_conf_merge_value(conf->max_streams, prev->max_streams, 64);
392392
ngx_conf_merge_value(conf->chunk_size, prev->chunk_size, 4096);
393393
ngx_conf_merge_uint_value(conf->ack_window, prev->ack_window, 5000000);
394394
ngx_conf_merge_size_value(conf->max_message, prev->max_message,

modules/nginx-rtmp-module/ngx_rtmp_handler.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ ngx_rtmp_recv(ngx_event_t *rev)
204204
u_char *p, *pp, *old_pos;
205205
size_t size, fsize, old_size;
206206
uint8_t fmt, ext;
207-
uint32_t csid, timestamp;
207+
uint32_t csid, timestamp, extimestamp = 0;
208208

209209
c = rev->data;
210210
s = c->data;
@@ -243,7 +243,7 @@ ngx_rtmp_recv(ngx_event_t *rev)
243243

244244
if (old_size) {
245245

246-
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->log, 0,
246+
ngx_log_error(NGX_LOG_DEBUG, s->log, 0,
247247
"reusing formerly read data: %d", old_size);
248248

249249
b->pos = b->start;
@@ -284,7 +284,7 @@ ngx_rtmp_recv(ngx_event_t *rev)
284284
s->in_bytes += n;
285285

286286
if (s->in_bytes >= 0xf0000000) {
287-
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->log, 0,
287+
ngx_log_error(NGX_LOG_DEBUG, s->log, 0,
288288
"resetting byte counter");
289289
s->in_bytes = 0;
290290
s->in_last_ack = 0;
@@ -294,7 +294,7 @@ ngx_rtmp_recv(ngx_event_t *rev)
294294

295295
s->in_last_ack = s->in_bytes;
296296

297-
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->log, 0,
297+
ngx_log_error(NGX_LOG_DEBUG, s->log, 0,
298298
"sending RTMP ACK(%uD)", s->in_bytes);
299299

300300
if (ngx_rtmp_send_ack(s, s->in_bytes)) {
@@ -329,7 +329,7 @@ ngx_rtmp_recv(ngx_event_t *rev)
329329
csid += (uint32_t)256 * (*(uint8_t*)p++);
330330
}
331331

332-
ngx_log_debug2(NGX_LOG_DEBUG_RTMP, s->log, 0,
332+
ngx_log_error(NGX_LOG_DEBUG, s->log, 0,
333333
"RTMP bheader fmt=%d csid=%D",
334334
(int)fmt, csid);
335335

@@ -405,14 +405,22 @@ ngx_rtmp_recv(ngx_event_t *rev)
405405
}
406406

407407
/* extended header */
408+
extimestamp = 0;
408409
if (ext) {
409410
if (b->last - p < 4)
410411
continue;
411-
pp = (u_char*)&timestamp;
412+
pp = (u_char*)&extimestamp;
412413
pp[3] = *p++;
413414
pp[2] = *p++;
414415
pp[1] = *p++;
415416
pp[0] = *p++;
417+
if (extimestamp != st->last_extimestamp && fmt == 3) {
418+
p -= 4;
419+
ext = 0;
420+
} else {
421+
st->last_extimestamp = extimestamp;
422+
timestamp = extimestamp;
423+
}
416424
}
417425

418426
if (st->len == 0) {
@@ -430,11 +438,14 @@ ngx_rtmp_recv(ngx_event_t *rev)
430438
}
431439
}
432440

433-
ngx_log_debug8(NGX_LOG_DEBUG_RTMP, s->log, 0,
441+
#ifdef NGX_DEBUG
442+
ngx_log_debug(NGX_LOG_DEBUG_RTMP, s->log, 0,
434443
"RTMP mheader fmt=%d %s (%d) "
435-
"time=%uD+%uD mlen=%D len=%D msid=%D",
444+
"time=%uD+%uD mlen=%D len=%D msid=%D bsize=%D extime=%uD",
436445
(int)fmt, ngx_rtmp_message_type(h->type), (int)h->type,
437-
h->timestamp, st->dtime, h->mlen, st->len, h->msid);
446+
h->timestamp, st->dtime, h->mlen, st->len, h->msid,
447+
b->last - b->pos, extimestamp);
448+
#endif
438449

439450
/* header done */
440451
b->pos = p;
@@ -551,10 +562,12 @@ ngx_rtmp_prepare_out_chain(ngx_rtmp_session_t *s)
551562

552563
hsize = hdrsize[fmt];
553564

565+
#ifdef NGX_DEBUG
554566
ngx_log_debug7(NGX_LOG_DEBUG_RTMP, s->log, 0,
555567
"RTMP prep %s (%d) fmt=%d csid=%uD timestamp=%uD mlen=%uD msid=%uD",
556568
ngx_rtmp_message_type(frame->hdr.type), (int)frame->hdr.type,
557569
(int)fmt, frame->hdr.csid, timestamp, mlen, frame->hdr.msid);
570+
#endif
558571

559572
ext_timestamp = 0;
560573
if (timestamp >= 0x00ffffff) {
@@ -951,4 +964,3 @@ ngx_rtmp_finalize_set_chunk_size(ngx_rtmp_session_t *s)
951964
return NGX_OK;
952965
}
953966

954-

modules/nginx-rtmp-module/ngx_rtmp_notify_module.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -907,16 +907,20 @@ ngx_rtmp_notify_init_master_netcall(ngx_cycle_t *cycle)
907907
{
908908
ngx_rtmp_notify_main_conf_t *omcf;
909909
ngx_rtmp_notify_event_t *event;
910-
ngx_rtmp_conf_ctx_t *ctx;
911-
ngx_netcall_ctx_t *nctx;
912-
ngx_event_t *ev;
910+
ngx_rtmp_conf_ctx_t *ctx;
911+
ngx_netcall_ctx_t *nctx;
912+
ngx_event_t *ev;
913913

914914
if (ngx_process != NGX_PROCESS_WORKER &&
915915
ngx_process != NGX_PROCESS_SINGLE)
916916
{
917917
return NGX_OK;
918918
}
919919

920+
if (ngx_worker != 0) {
921+
return NGX_OK;
922+
}
923+
920924
if (ngx_rtmp_core_main_conf == NULL) {
921925
return NGX_OK;
922926
}

release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ then
258258
if [ ! -d $WWW_ROOT"/h5player" ]
259259
then
260260
cd $WWW_ROOT
261-
git clone https://github.com/im-pingo/h5player.git
261+
git clone https://github.com/pingostack/h5player.git
262262
cd $OPWD
263263
fi
264264
fi
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
user root;
2+
daemon on;
3+
master_process on;
4+
worker_processes 1;
5+
#worker_rlimit 4g;
6+
7+
#error_log logs/error.log;
8+
#error_log logs/error.log notice;
9+
error_log logs/error.log info;
10+
11+
worker_rlimit_nofile 102400;
12+
worker_rlimit_core 2G;
13+
working_directory /tmp;
14+
15+
#pid logs/nginx.pid;
16+
17+
events {
18+
# use epoll;
19+
worker_connections 1024;
20+
multi_listen unix:/tmp/http 6080;
21+
multi_listen unix:/tmp/rtmp 6035;
22+
dynamic_refresh_interval 5s;
23+
dynamic_domain_buckets 1001;
24+
resolver 114.114.114.114 valid=10s;
25+
resolver_timeout 30s;
26+
}
27+
28+
stream_zone buckets=1024 streams=4096;
29+
30+
rtmp {
31+
on_master http://{control_addr}/control/server stage=start,update update=5 args=serverId=pms-mmm&announceIp={announceIp}&httpPort=6080&httpsPort=443&rtmpPort=6035&protocol=rtmp;
32+
log_format log_bandwidth '{"app":"$app","name":"$name","bitrate":$bitrate,"args":"$args","timestamp":$ntp,"ts":"$time_local","type":"$command","remote_addr":"$remote_addr","domain":"$domain"}';
33+
access_log logs/bandwidth.log log_bandwidth trunc=10s;
34+
35+
server {
36+
listen 6035;
37+
serverid pms-mmm;
38+
out_queue 2048;
39+
server_name localhost;
40+
41+
application * {
42+
idle_streams on;
43+
on_publish http://{control_addr}/control/publish stage=start,update,done update=2 args=serverId=$serverid&announceIp=live.pingos.io&scheme=$scheme&token=$parg_token;
44+
on_meta http://{control_addr}/control/meta stage=start,update,done update=2 args=serverId=$serverid&scheme=$scheme&announceIp=live.pingos.io&$metadata;
45+
46+
rtmp_auto_pull off;
47+
rtmp_auto_pull_port unix:/tmp/rtmp;
48+
49+
# live_record on;
50+
# live_record_path /tmp/record;
51+
52+
# recorder r1{
53+
# record all;
54+
# record_path /tmp/record;
55+
# }
56+
57+
# exec_publish bash -c "ffmepg -i rtmp://127.0.0.1/live/$name -c copy /tmp/mp4/$name-$starttime.mp4";
58+
59+
live on;
60+
hls on;
61+
hls_path /tmp/hls;
62+
hls_fragment 4000ms;
63+
# hls_max_fragment 6000ms;
64+
hls_playlist_length 12000ms;
65+
66+
hls2memory on;
67+
mpegts_cache_time 20s;
68+
69+
hls2_fragment 1300ms;
70+
hls2_max_fragment 1600ms;
71+
hls2_playlist_length 3900ms;
72+
73+
wait_key on;
74+
wait_video on;
75+
cache_time 1s;
76+
low_latency off;
77+
fix_timestamp 0s;
78+
# h265 codecid, default 12
79+
hevc_codecid 12;
80+
}
81+
}
82+
}
83+
84+
http {
85+
include mime.types;
86+
default_type application/octet-stream;
87+
88+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
89+
'$status $body_bytes_sent "$http_referer" '
90+
'"$http_user_agent" "$http_X-Forwarded-For" "$http_X-Real-IP" "$host"';
91+
92+
93+
access_log logs/access.log main;
94+
95+
sendfile on;
96+
#tcp_nopush on;
97+
98+
#keepalive_timeout 0;
99+
keepalive_timeout 65;
100+
101+
#reset_server_name www.test1.com www.test2.com;
102+
#gzip on;
103+
server {
104+
listen 6080;
105+
location /rtmp_stat {
106+
rtmp_stat all;
107+
rtmp_stat_stylesheet /stat.xsl;
108+
}
109+
110+
location /xstat {
111+
rtmp_stat all;
112+
}
113+
114+
location /sys_stat {
115+
sys_stat;
116+
}
117+
118+
location /proxy/ {
119+
rewrite ^/proxy/(.*) /sys_stat break;
120+
proxy_pass http://$1:;
121+
}
122+
123+
location /bs {
124+
broadcast unix:/tmp/http /proxy;
125+
broadcast_rewrite_prefix " " [;
126+
broadcast_suffix ];
127+
}
128+
129+
location /control {
130+
rtmp_control all;
131+
}
132+
133+
location /flv {
134+
flv_live 6035;
135+
chunked_transfer_encoding off;
136+
add_header 'Access-Control-Allow-Origin' '*';
137+
add_header Cache-Control no-cache;
138+
}
139+
140+
location /ts {
141+
ts_live 6035 app=live;
142+
}
143+
144+
location /hls {
145+
# Serve HLS fragments
146+
types {
147+
application/vnd.apple.mpegurl m3u8;
148+
video/mp2t ts;
149+
}
150+
root /tmp;
151+
add_header Cache-Control no-cache;
152+
add_header 'Access-Control-Allow-Origin' '*';
153+
}
154+
155+
location /hls2 {
156+
hls2_live 6035 app=live;
157+
add_header 'Access-Control-Allow-Origin' '*';
158+
add_header Cache-Control no-cache;
159+
}
160+
161+
location / {
162+
chunked_transfer_encoding on;
163+
root html/;
164+
}
165+
}
166+
}
167+

0 commit comments

Comments
 (0)