moved out queue params to config

This commit is contained in:
Roman Arutyunyan 2012-06-14 19:53:21 +04:00
parent 358f7680e2
commit 7c99cfba0a
4 changed files with 36 additions and 29 deletions

View file

@ -148,12 +148,6 @@ typedef struct {
#define NGX_RTMP_MAX_CHUNK_HEADER 18
/* Output buffer queue */
#define NGX_RTMP_OUT_QUEUE 256
#define NGX_RTMP_OUT_QUEUE_LOWAT 32
typedef struct {
uint32_t csid; /* chunk stream id */
uint32_t timestamp; /* timestamp (delta) */
@ -229,7 +223,9 @@ typedef struct {
ngx_chain_t *out_chain;
u_char *out_bpos;
unsigned out_buffer:1;
ngx_chain_t *out[NGX_RTMP_OUT_QUEUE];
size_t out_queue;
size_t out_cork;
ngx_chain_t *out[0];
} ngx_rtmp_session_t;
@ -279,10 +275,11 @@ typedef struct ngx_rtmp_core_srv_conf_s {
ngx_pool_t *pool;
ngx_chain_t *free;
ngx_chain_t *free_hs;
size_t max_queue;
size_t max_message;
ngx_flag_t play_time_fix;
ngx_flag_t publish_time_fix;
size_t out_queue;
size_t out_cork;
ngx_rtmp_conf_ctx_t *ctx;
} ngx_rtmp_core_srv_conf_t;

View file

@ -106,13 +106,6 @@ static ngx_command_t ngx_rtmp_core_commands[] = {
offsetof(ngx_rtmp_core_srv_conf_t, chunk_size),
NULL },
{ ngx_string("max_queue"),
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
NGX_RTMP_SRV_CONF_OFFSET,
offsetof(ngx_rtmp_core_srv_conf_t, max_queue),
NULL },
{ ngx_string("max_message"),
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
@ -120,6 +113,20 @@ static ngx_command_t ngx_rtmp_core_commands[] = {
offsetof(ngx_rtmp_core_srv_conf_t, max_message),
NULL },
{ ngx_string("out_queue"),
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
NGX_RTMP_SRV_CONF_OFFSET,
offsetof(ngx_rtmp_core_srv_conf_t, out_queue),
NULL },
{ ngx_string("out_cork"),
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
NGX_RTMP_SRV_CONF_OFFSET,
offsetof(ngx_rtmp_core_srv_conf_t, out_cork),
NULL },
/* time fixes are needed for flash clients */
{ ngx_string("play_time_fix"),
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1,
@ -220,8 +227,9 @@ ngx_rtmp_core_create_srv_conf(ngx_conf_t *cf)
conf->max_streams = NGX_CONF_UNSET;
conf->chunk_size = NGX_CONF_UNSET;
conf->ack_window = NGX_CONF_UNSET;
conf->max_queue = NGX_CONF_UNSET;
conf->max_message = NGX_CONF_UNSET;
conf->out_queue = NGX_CONF_UNSET;
conf->out_cork = NGX_CONF_UNSET;
conf->play_time_fix = NGX_CONF_UNSET;
conf->publish_time_fix = NGX_CONF_UNSET;
@ -243,9 +251,10 @@ ngx_rtmp_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_value(conf->max_streams, prev->max_streams, 32);
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_queue, prev->max_queue, 256);
ngx_conf_merge_size_value(conf->max_message, prev->max_message,
1 * 1024 * 1024);
ngx_conf_merge_size_value(conf->out_queue, prev->out_queue, 256);
ngx_conf_merge_size_value(conf->out_cork, prev->out_cork, 32);
ngx_conf_merge_value(conf->play_time_fix, prev->play_time_fix, 1);
ngx_conf_merge_value(conf->publish_time_fix, prev->publish_time_fix, 1);

View file

@ -524,7 +524,7 @@ ngx_rtmp_send(ngx_event_t *wev)
cscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_core_module);
ngx_rtmp_free_shared_chain(cscf, s->out[s->out_pos]);
++s->out_pos;
s->out_pos %= NGX_RTMP_OUT_QUEUE;
s->out_pos %= s->out_queue;
if (s->out_pos == s->out_last) {
break;
}
@ -688,13 +688,13 @@ ngx_int_t
ngx_rtmp_send_message(ngx_rtmp_session_t *s, ngx_chain_t *out,
ngx_uint_t priority)
{
ngx_int_t nmsg;
ngx_uint_t nmsg;
nmsg = (s->out_last - s->out_pos) % NGX_RTMP_OUT_QUEUE + 1;
nmsg = (s->out_last - s->out_pos) % s->out_queue + 1;
/* drop packet?
* Note we always leave 1 slot free */
if (nmsg + priority * 8 >= NGX_RTMP_OUT_QUEUE) {
if (nmsg + priority * s->out_queue / 16 >= s->out_queue) {
ngx_log_debug2(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"RTMP drop message bufs=%ui, priority=%ui",
nmsg, priority);
@ -702,7 +702,7 @@ ngx_rtmp_send_message(ngx_rtmp_session_t *s, ngx_chain_t *out,
}
s->out[s->out_last++] = out;
s->out_last %= NGX_RTMP_OUT_QUEUE;
s->out_last %= s->out_queue;
ngx_rtmp_acquire_shared_chain(out);
@ -710,9 +710,7 @@ ngx_rtmp_send_message(ngx_rtmp_session_t *s, ngx_chain_t *out,
"RTMP send nmsg=%ui, priority=%ui #%ui",
nmsg, priority, s->out_last);
if (priority && s->out_buffer
&& nmsg < NGX_RTMP_OUT_QUEUE_LOWAT)
{
if (priority && s->out_buffer && nmsg < s->out_cork) {
return NGX_OK;
}

View file

@ -123,7 +123,9 @@ ngx_rtmp_init_session(ngx_connection_t *c, ngx_rtmp_addr_conf_t *addr_conf)
ngx_rtmp_core_srv_conf_t *cscf;
ngx_rtmp_log_ctx_t *ctx;
s = ngx_pcalloc(c->pool, sizeof(ngx_rtmp_session_t));
s = ngx_pcalloc(c->pool, sizeof(ngx_rtmp_session_t) +
((ngx_rtmp_core_srv_conf_t *)addr_conf->ctx->srv_conf)->out_queue
* sizeof(ngx_chain_t *));
if (s == NULL) {
ngx_rtmp_close_connection(c);
return NULL;
@ -153,15 +155,16 @@ ngx_rtmp_init_session(ngx_connection_t *c, ngx_rtmp_addr_conf_t *addr_conf)
c->log_error = NGX_ERROR_INFO;
cscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_core_module);
s->ctx = ngx_pcalloc(c->pool, sizeof(void *) * ngx_rtmp_max_module);
if (s->ctx == NULL) {
ngx_rtmp_close_connection(c);
return NULL;
}
cscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_core_module);
s->out_queue = cscf->out_queue;
s->out_cork = cscf->out_cork;
s->in_streams = ngx_pcalloc(c->pool, sizeof(ngx_rtmp_stream_t)
* cscf->max_streams);
if (s->in_streams == NULL) {
@ -262,7 +265,7 @@ ngx_rtmp_close_session_handler(ngx_event_t *e)
while (s->out_pos != s->out_last) {
ngx_rtmp_free_shared_chain(cscf, s->out[s->out_pos++]);
s->out_pos %= NGX_RTMP_OUT_QUEUE;
s->out_pos %= s->out_queue;
}
}