Skip to content

Commit

Permalink
1.fix extend timestamp when using librtmp; 2.add rpm packet script;
Browse files Browse the repository at this point in the history
  • Loading branch information
im-pingo committed Apr 15, 2021
1 parent 4386a19 commit 76a1a65
Show file tree
Hide file tree
Showing 17 changed files with 793 additions and 16 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
docker/*.tar*
openresty/
nginx/
.git/
*.code-workspace
.DS_Store
h5player/
.vscode/
nginx/
source/
rpmbuild/
14 changes: 14 additions & 0 deletions config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
df_path=$1
service=$2

install_path=$df_path"/usr/local/"$service

cp -rf ./deps/* $install_path"/sbin"

cp ./resource/conf-template/nginx.conf $install_path"/conf/nginx.conf"

cp ./resource/stat.xsl $install_path"/html/stat.xsl"

cp ./resource/crossdomain.xml $install_path"/html/crossdomain.xml"

cp -r ./h5player $install_path"/html/"
Binary file added deps/ffmpeg
Binary file not shown.
1 change: 1 addition & 0 deletions modules/nginx-rtmp-module/ngx_rtmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ typedef struct {
uint32_t dtime;
uint32_t len; /* current fragment length */
uint8_t ext;
uint32_t last_extimestamp;
ngx_chain_t *in;
} ngx_rtmp_stream_t;

Expand Down
2 changes: 1 addition & 1 deletion modules/nginx-rtmp-module/ngx_rtmp_core_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ ngx_rtmp_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_msec_value(conf->ping_timeout, prev->ping_timeout, 30000);

ngx_conf_merge_value(conf->so_keepalive, prev->so_keepalive, 0);
ngx_conf_merge_value(conf->max_streams, prev->max_streams, 32);
ngx_conf_merge_value(conf->max_streams, prev->max_streams, 64);
ngx_conf_merge_value(conf->chunk_size, prev->chunk_size, 4096);
ngx_conf_merge_uint_value(conf->ack_window, prev->ack_window, 5000000);
ngx_conf_merge_size_value(conf->max_message, prev->max_message,
Expand Down
32 changes: 22 additions & 10 deletions modules/nginx-rtmp-module/ngx_rtmp_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ ngx_rtmp_recv(ngx_event_t *rev)
u_char *p, *pp, *old_pos;
size_t size, fsize, old_size;
uint8_t fmt, ext;
uint32_t csid, timestamp;
uint32_t csid, timestamp, extimestamp = 0;

c = rev->data;
s = c->data;
Expand Down Expand Up @@ -243,7 +243,7 @@ ngx_rtmp_recv(ngx_event_t *rev)

if (old_size) {

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

b->pos = b->start;
Expand Down Expand Up @@ -284,7 +284,7 @@ ngx_rtmp_recv(ngx_event_t *rev)
s->in_bytes += n;

if (s->in_bytes >= 0xf0000000) {
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->log, 0,
ngx_log_error(NGX_LOG_DEBUG, s->log, 0,
"resetting byte counter");
s->in_bytes = 0;
s->in_last_ack = 0;
Expand All @@ -294,7 +294,7 @@ ngx_rtmp_recv(ngx_event_t *rev)

s->in_last_ack = s->in_bytes;

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

if (ngx_rtmp_send_ack(s, s->in_bytes)) {
Expand Down Expand Up @@ -329,7 +329,7 @@ ngx_rtmp_recv(ngx_event_t *rev)
csid += (uint32_t)256 * (*(uint8_t*)p++);
}

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

Expand Down Expand Up @@ -405,14 +405,22 @@ ngx_rtmp_recv(ngx_event_t *rev)
}

/* extended header */
extimestamp = 0;
if (ext) {
if (b->last - p < 4)
continue;
pp = (u_char*)&timestamp;
pp = (u_char*)&extimestamp;
pp[3] = *p++;
pp[2] = *p++;
pp[1] = *p++;
pp[0] = *p++;
if (extimestamp != st->last_extimestamp && fmt == 3) {
p -= 4;
ext = 0;
} else {
st->last_extimestamp = extimestamp;
timestamp = extimestamp;
}
}

if (st->len == 0) {
Expand All @@ -430,11 +438,14 @@ ngx_rtmp_recv(ngx_event_t *rev)
}
}

ngx_log_debug8(NGX_LOG_DEBUG_RTMP, s->log, 0,
#ifdef NGX_DEBUG
ngx_log_debug(NGX_LOG_DEBUG_RTMP, s->log, 0,
"RTMP mheader fmt=%d %s (%d) "
"time=%uD+%uD mlen=%D len=%D msid=%D",
"time=%uD+%uD mlen=%D len=%D msid=%D bsize=%D extime=%uD",
(int)fmt, ngx_rtmp_message_type(h->type), (int)h->type,
h->timestamp, st->dtime, h->mlen, st->len, h->msid);
h->timestamp, st->dtime, h->mlen, st->len, h->msid,
b->last - b->pos, extimestamp);
#endif

/* header done */
b->pos = p;
Expand Down Expand Up @@ -551,10 +562,12 @@ ngx_rtmp_prepare_out_chain(ngx_rtmp_session_t *s)

hsize = hdrsize[fmt];

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

ext_timestamp = 0;
if (timestamp >= 0x00ffffff) {
Expand Down Expand Up @@ -951,4 +964,3 @@ ngx_rtmp_finalize_set_chunk_size(ngx_rtmp_session_t *s)
return NGX_OK;
}


10 changes: 7 additions & 3 deletions modules/nginx-rtmp-module/ngx_rtmp_notify_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,16 +907,20 @@ ngx_rtmp_notify_init_master_netcall(ngx_cycle_t *cycle)
{
ngx_rtmp_notify_main_conf_t *omcf;
ngx_rtmp_notify_event_t *event;
ngx_rtmp_conf_ctx_t *ctx;
ngx_netcall_ctx_t *nctx;
ngx_event_t *ev;
ngx_rtmp_conf_ctx_t *ctx;
ngx_netcall_ctx_t *nctx;
ngx_event_t *ev;

if (ngx_process != NGX_PROCESS_WORKER &&
ngx_process != NGX_PROCESS_SINGLE)
{
return NGX_OK;
}

if (ngx_worker != 0) {
return NGX_OK;
}

if (ngx_rtmp_core_main_conf == NULL) {
return NGX_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ then
if [ ! -d $WWW_ROOT"/h5player" ]
then
cd $WWW_ROOT
git clone https://github.com/im-pingo/h5player.git
git clone https://github.com/pingostack/h5player.git
cd $OPWD
fi
fi
Expand Down
167 changes: 167 additions & 0 deletions resource/conf-template/nginx-core.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
user root;
daemon on;
master_process on;
worker_processes 1;
#worker_rlimit 4g;

#error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;

worker_rlimit_nofile 102400;
worker_rlimit_core 2G;
working_directory /tmp;

#pid logs/nginx.pid;

events {
# use epoll;
worker_connections 1024;
multi_listen unix:/tmp/http 6080;
multi_listen unix:/tmp/rtmp 6035;
dynamic_refresh_interval 5s;
dynamic_domain_buckets 1001;
resolver 114.114.114.114 valid=10s;
resolver_timeout 30s;
}

stream_zone buckets=1024 streams=4096;

rtmp {
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;
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"}';
access_log logs/bandwidth.log log_bandwidth trunc=10s;

server {
listen 6035;
serverid pms-mmm;
out_queue 2048;
server_name localhost;

application * {
idle_streams on;
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;
on_meta http://{control_addr}/control/meta stage=start,update,done update=2 args=serverId=$serverid&scheme=$scheme&announceIp=live.pingos.io&$metadata;

rtmp_auto_pull off;
rtmp_auto_pull_port unix:/tmp/rtmp;

# live_record on;
# live_record_path /tmp/record;

# recorder r1{
# record all;
# record_path /tmp/record;
# }

# exec_publish bash -c "ffmepg -i rtmp://127.0.0.1/live/$name -c copy /tmp/mp4/$name-$starttime.mp4";

live on;
hls on;
hls_path /tmp/hls;
hls_fragment 4000ms;
# hls_max_fragment 6000ms;
hls_playlist_length 12000ms;

hls2memory on;
mpegts_cache_time 20s;

hls2_fragment 1300ms;
hls2_max_fragment 1600ms;
hls2_playlist_length 3900ms;

wait_key on;
wait_video on;
cache_time 1s;
low_latency off;
fix_timestamp 0s;
# h265 codecid, default 12
hevc_codecid 12;
}
}
}

http {
include mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_X-Forwarded-For" "$http_X-Real-IP" "$host"';


access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#reset_server_name www.test1.com www.test2.com;
#gzip on;
server {
listen 6080;
location /rtmp_stat {
rtmp_stat all;
rtmp_stat_stylesheet /stat.xsl;
}

location /xstat {
rtmp_stat all;
}

location /sys_stat {
sys_stat;
}

location /proxy/ {
rewrite ^/proxy/(.*) /sys_stat break;
proxy_pass http://$1:;
}

location /bs {
broadcast unix:/tmp/http /proxy;
broadcast_rewrite_prefix " " [;
broadcast_suffix ];
}

location /control {
rtmp_control all;
}

location /flv {
flv_live 6035;
chunked_transfer_encoding off;
add_header 'Access-Control-Allow-Origin' '*';
add_header Cache-Control no-cache;
}

location /ts {
ts_live 6035 app=live;
}

location /hls {
# Serve HLS fragments
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
add_header 'Access-Control-Allow-Origin' '*';
}

location /hls2 {
hls2_live 6035 app=live;
add_header 'Access-Control-Allow-Origin' '*';
add_header Cache-Control no-cache;
}

location / {
chunked_transfer_encoding on;
root html/;
}
}
}

Loading

0 comments on commit 76a1a65

Please sign in to comment.