Skip to content

Commit c0bf381

Browse files
committed
fixed rtmp as a dynamic module
1 parent cb54ed4 commit c0bf381

5 files changed

+108
-38
lines changed

config

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ RTMP_CORE_MODULES=" \
1515
ngx_rtmp_relay_module \
1616
ngx_rtmp_exec_module \
1717
ngx_rtmp_auto_push_module \
18+
ngx_rtmp_auto_push_index_module \
1819
ngx_rtmp_notify_module \
1920
ngx_rtmp_log_module \
2021
ngx_rtmp_limit_module \

ngx_rtmp.c

+29-14
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ ngx_rtmp_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
8787
ngx_uint_t i, m, mi, s;
8888
ngx_conf_t pcf;
8989
ngx_array_t ports;
90+
ngx_module_t **modules;
9091
ngx_rtmp_listen_t *listen;
9192
ngx_rtmp_module_t *module;
9293
ngx_rtmp_conf_ctx_t *ctx;
@@ -102,6 +103,12 @@ ngx_rtmp_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
102103

103104
/* count the number of the rtmp modules and set up their indices */
104105

106+
#if (nginx_version >= 1009011)
107+
108+
ngx_rtmp_max_module = ngx_count_modules(cf->cycle, NGX_RTMP_MODULE);
109+
110+
#else
111+
105112
ngx_rtmp_max_module = 0;
106113
for (m = 0; ngx_modules[m]; m++) {
107114
if (ngx_modules[m]->type != NGX_RTMP_MODULE) {
@@ -111,6 +118,8 @@ ngx_rtmp_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
111118
ngx_modules[m]->ctx_index = ngx_rtmp_max_module++;
112119
}
113120

121+
#endif
122+
114123

115124
/* the rtmp main_conf context, it is the same in the all rtmp contexts */
116125

@@ -148,13 +157,19 @@ ngx_rtmp_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
148157
* of the all rtmp modules
149158
*/
150159

151-
for (m = 0; ngx_modules[m]; m++) {
152-
if (ngx_modules[m]->type != NGX_RTMP_MODULE) {
160+
#if (nginx_version >= 1009011)
161+
modules = cf->cycle->modules;
162+
#else
163+
modules = ngx_modules;
164+
#endif
165+
166+
for (m = 0; modules[m]; m++) {
167+
if (modules[m]->type != NGX_RTMP_MODULE) {
153168
continue;
154169
}
155170

156-
module = ngx_modules[m]->ctx;
157-
mi = ngx_modules[m]->ctx_index;
171+
module = modules[m]->ctx;
172+
mi = modules[m]->ctx_index;
158173

159174
if (module->create_main_conf) {
160175
ctx->main_conf[mi] = module->create_main_conf(cf);
@@ -181,12 +196,12 @@ ngx_rtmp_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
181196
pcf = *cf;
182197
cf->ctx = ctx;
183198

184-
for (m = 0; ngx_modules[m]; m++) {
185-
if (ngx_modules[m]->type != NGX_RTMP_MODULE) {
199+
for (m = 0; modules[m]; m++) {
200+
if (modules[m]->type != NGX_RTMP_MODULE) {
186201
continue;
187202
}
188203

189-
module = ngx_modules[m]->ctx;
204+
module = modules[m]->ctx;
190205

191206
if (module->preconfiguration) {
192207
if (module->preconfiguration(cf) != NGX_OK) {
@@ -212,13 +227,13 @@ ngx_rtmp_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
212227
cmcf = ctx->main_conf[ngx_rtmp_core_module.ctx_index];
213228
cscfp = cmcf->servers.elts;
214229

215-
for (m = 0; ngx_modules[m]; m++) {
216-
if (ngx_modules[m]->type != NGX_RTMP_MODULE) {
230+
for (m = 0; modules[m]; m++) {
231+
if (modules[m]->type != NGX_RTMP_MODULE) {
217232
continue;
218233
}
219234

220-
module = ngx_modules[m]->ctx;
221-
mi = ngx_modules[m]->ctx_index;
235+
module = modules[m]->ctx;
236+
mi = modules[m]->ctx_index;
222237

223238
/* init rtmp{} main_conf's */
224239

@@ -283,12 +298,12 @@ ngx_rtmp_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
283298
return NGX_CONF_ERROR;
284299
}
285300

286-
for (m = 0; ngx_modules[m]; m++) {
287-
if (ngx_modules[m]->type != NGX_RTMP_MODULE) {
301+
for (m = 0; modules[m]; m++) {
302+
if (modules[m]->type != NGX_RTMP_MODULE) {
288303
continue;
289304
}
290305

291-
module = ngx_modules[m]->ctx;
306+
module = modules[m]->ctx;
292307

293308
if (module->postconfiguration) {
294309
if (module->postconfiguration(cf) != NGX_OK) {

ngx_rtmp_auto_push_module.c

+33-5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,34 @@ ngx_module_t ngx_rtmp_auto_push_module = {
9393
};
9494

9595

96+
static ngx_rtmp_module_t ngx_rtmp_auto_push_index_module_ctx = {
97+
NULL, /* preconfiguration */
98+
NULL, /* postconfiguration */
99+
NULL, /* create main configuration */
100+
NULL, /* init main configuration */
101+
NULL, /* create server configuration */
102+
NULL, /* merge server configuration */
103+
NULL, /* create app configuration */
104+
NULL /* merge app configuration */
105+
};
106+
107+
108+
ngx_module_t ngx_rtmp_auto_push_index_module = {
109+
NGX_MODULE_V1,
110+
&ngx_rtmp_auto_push_index_module_ctx, /* module context */
111+
NULL, /* module directives */
112+
NGX_RTMP_MODULE, /* module type */
113+
NULL, /* init master */
114+
NULL, /* init module */
115+
NULL, /* init process */
116+
NULL, /* init thread */
117+
NULL, /* exit thread */
118+
NULL, /* exit process */
119+
NULL, /* exit master */
120+
NGX_MODULE_V1_PADDING
121+
};
122+
123+
96124
#define NGX_RTMP_AUTO_PUSH_SOCKNAME "nginx-rtmp"
97125

98126

@@ -324,7 +352,7 @@ ngx_rtmp_auto_push_reconnect(ngx_event_t *ev)
324352

325353
apcf = (ngx_rtmp_auto_push_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx,
326354
ngx_rtmp_auto_push_module);
327-
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_auto_push_module);
355+
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_auto_push_index_module);
328356
if (ctx == NULL) {
329357
return;
330358
}
@@ -461,14 +489,14 @@ ngx_rtmp_auto_push_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v)
461489
goto next;
462490
}
463491

464-
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_auto_push_module);
492+
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_auto_push_index_module);
465493
if (ctx == NULL) {
466494
ctx = ngx_palloc(s->connection->pool,
467495
sizeof(ngx_rtmp_auto_push_ctx_t));
468496
if (ctx == NULL) {
469497
goto next;
470498
}
471-
ngx_rtmp_set_ctx(s, ctx, ngx_rtmp_auto_push_module);
499+
ngx_rtmp_set_ctx(s, ctx, ngx_rtmp_auto_push_index_module);
472500

473501
}
474502
ngx_memzero(ctx, sizeof(*ctx));
@@ -508,7 +536,7 @@ ngx_rtmp_auto_push_delete_stream(ngx_rtmp_session_t *s,
508536
goto next;
509537
}
510538

511-
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_auto_push_module);
539+
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_auto_push_index_module);
512540
if (ctx) {
513541
if (ctx->push_evt.timer_set) {
514542
ngx_del_timer(&ctx->push_evt);
@@ -532,7 +560,7 @@ ngx_rtmp_auto_push_delete_stream(ngx_rtmp_session_t *s,
532560
slot, &rctx->app, &rctx->name);
533561

534562
pctx = ngx_rtmp_get_module_ctx(rctx->publish->session,
535-
ngx_rtmp_auto_push_module);
563+
ngx_rtmp_auto_push_index_module);
536564
if (pctx == NULL) {
537565
goto next;
538566
}

ngx_rtmp_core_module.c

+33-13
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ ngx_rtmp_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
332332
void *mconf;
333333
ngx_uint_t m;
334334
ngx_conf_t pcf;
335+
ngx_module_t **modules;
335336
ngx_rtmp_module_t *module;
336337
ngx_rtmp_conf_ctx_t *ctx, *rtmp_ctx;
337338
ngx_rtmp_core_srv_conf_t *cscf, **cscfp;
@@ -357,20 +358,26 @@ ngx_rtmp_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
357358
return NGX_CONF_ERROR;
358359
}
359360

360-
for (m = 0; ngx_modules[m]; m++) {
361-
if (ngx_modules[m]->type != NGX_RTMP_MODULE) {
361+
#if (nginx_version >= 1009011)
362+
modules = cf->cycle->modules;
363+
#else
364+
modules = ngx_modules;
365+
#endif
366+
367+
for (m = 0; modules[m]; m++) {
368+
if (modules[m]->type != NGX_RTMP_MODULE) {
362369
continue;
363370
}
364371

365-
module = ngx_modules[m]->ctx;
372+
module = modules[m]->ctx;
366373

367374
if (module->create_srv_conf) {
368375
mconf = module->create_srv_conf(cf);
369376
if (mconf == NULL) {
370377
return NGX_CONF_ERROR;
371378
}
372379

373-
ctx->srv_conf[ngx_modules[m]->ctx_index] = mconf;
380+
ctx->srv_conf[modules[m]->ctx_index] = mconf;
374381
}
375382

376383
if (module->create_app_conf) {
@@ -379,7 +386,7 @@ ngx_rtmp_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
379386
return NGX_CONF_ERROR;
380387
}
381388

382-
ctx->app_conf[ngx_modules[m]->ctx_index] = mconf;
389+
ctx->app_conf[modules[m]->ctx_index] = mconf;
383390
}
384391
}
385392

@@ -419,6 +426,7 @@ ngx_rtmp_core_application(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
419426
ngx_int_t i;
420427
ngx_str_t *value;
421428
ngx_conf_t save;
429+
ngx_module_t **modules;
422430
ngx_rtmp_module_t *module;
423431
ngx_rtmp_conf_ctx_t *ctx, *pctx;
424432
ngx_rtmp_core_srv_conf_t *cscf;
@@ -438,17 +446,22 @@ ngx_rtmp_core_application(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
438446
return NGX_CONF_ERROR;
439447
}
440448

441-
for (i = 0; ngx_modules[i]; i++) {
442-
if (ngx_modules[i]->type != NGX_RTMP_MODULE) {
449+
#if (nginx_version >= 1009011)
450+
modules = cf->cycle->modules;
451+
#else
452+
modules = ngx_modules;
453+
#endif
454+
455+
for (i = 0; modules[i]; i++) {
456+
if (modules[i]->type != NGX_RTMP_MODULE) {
443457
continue;
444458
}
445459

446-
module = ngx_modules[i]->ctx;
460+
module = modules[i]->ctx;
447461

448462
if (module->create_app_conf) {
449-
ctx->app_conf[ngx_modules[i]->ctx_index] =
450-
module->create_app_conf(cf);
451-
if (ctx->app_conf[ngx_modules[i]->ctx_index] == NULL) {
463+
ctx->app_conf[modules[i]->ctx_index] = module->create_app_conf(cf);
464+
if (ctx->app_conf[modules[i]->ctx_index] == NULL) {
452465
return NGX_CONF_ERROR;
453466
}
454467
}
@@ -489,6 +502,7 @@ ngx_rtmp_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
489502
ngx_str_t *value;
490503
ngx_url_t u;
491504
ngx_uint_t i, m;
505+
ngx_module_t **modules;
492506
struct sockaddr *sa;
493507
ngx_rtmp_listen_t *ls;
494508
struct sockaddr_in *sin;
@@ -573,8 +587,14 @@ ngx_rtmp_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
573587
ls->wildcard = u.wildcard;
574588
ls->ctx = cf->ctx;
575589

576-
for (m = 0; ngx_modules[m]; m++) {
577-
if (ngx_modules[m]->type != NGX_RTMP_MODULE) {
590+
#if (nginx_version >= 1009011)
591+
modules = cf->cycle->modules;
592+
#else
593+
modules = ngx_modules;
594+
#endif
595+
596+
for (m = 0; modules[m]; m++) {
597+
if (modules[m]->type != NGX_RTMP_MODULE) {
578598
continue;
579599
}
580600
}

ngx_rtmp_record_module.c

+12-6
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,7 @@ ngx_rtmp_record_recorder(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
11951195
ngx_int_t i;
11961196
ngx_str_t *value;
11971197
ngx_conf_t save;
1198+
ngx_module_t **modules;
11981199
ngx_rtmp_module_t *module;
11991200
ngx_rtmp_core_app_conf_t *cacf, **pcacf, *rcacf;
12001201
ngx_rtmp_record_app_conf_t *racf, **pracf, *rracf;
@@ -1221,17 +1222,22 @@ ngx_rtmp_record_recorder(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
12211222
return NGX_CONF_ERROR;
12221223
}
12231224

1224-
for (i = 0; ngx_modules[i]; i++) {
1225-
if (ngx_modules[i]->type != NGX_RTMP_MODULE) {
1225+
#if (nginx_version >= 1009011)
1226+
modules = cf->cycle->modules;
1227+
#else
1228+
modules = ngx_modules;
1229+
#endif
1230+
1231+
for (i = 0; modules[i]; i++) {
1232+
if (modules[i]->type != NGX_RTMP_MODULE) {
12261233
continue;
12271234
}
12281235

1229-
module = ngx_modules[i]->ctx;
1236+
module = modules[i]->ctx;
12301237

12311238
if (module->create_app_conf) {
1232-
ctx->app_conf[ngx_modules[i]->ctx_index] =
1233-
module->create_app_conf(cf);
1234-
if (ctx->app_conf[ngx_modules[i]->ctx_index] == NULL) {
1239+
ctx->app_conf[modules[i]->ctx_index] = module->create_app_conf(cf);
1240+
if (ctx->app_conf[modules[i]->ctx_index] == NULL) {
12351241
return NGX_CONF_ERROR;
12361242
}
12371243
}

0 commit comments

Comments
 (0)