mirror of
https://github.com/zotanmew/nginx-rtmp-module.git
synced 2024-05-15 00:11:08 +02:00
reimplemented amf0 callbacks from arrays to chains to enable async processing
This commit is contained in:
parent
fa6d9fc84f
commit
bcd601832a
|
@ -9,6 +9,10 @@
|
|||
#include "ngx_rtmp_cmd_module.h"
|
||||
|
||||
|
||||
static ngx_rtmp_publish_pt next_publish;
|
||||
static ngx_rtmp_play_pt next_play;
|
||||
|
||||
|
||||
#define NGX_RTMP_ACCESS_PUBLISH 0x01
|
||||
#define NGX_RTMP_ACCESS_PLAY 0x02
|
||||
|
||||
|
@ -389,47 +393,36 @@ ngx_rtmp_access_rule(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_access_connect(ngx_rtmp_session_t *s)
|
||||
ngx_rtmp_access_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v)
|
||||
{
|
||||
return ngx_rtmp_access(s, NGX_RTMP_ACCESS_PUBLISH) == NGX_OK
|
||||
|| ngx_rtmp_access(s, NGX_RTMP_ACCESS_PLAY) == NGX_OK
|
||||
? NGX_OK
|
||||
: NGX_ERROR;
|
||||
if (ngx_rtmp_access(s, NGX_RTMP_ACCESS_PUBLISH) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
return next_publish(s, v);
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_access_publish(ngx_rtmp_session_t *s,
|
||||
ngx_str_t *name, ngx_int_t type)
|
||||
ngx_rtmp_access_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v)
|
||||
{
|
||||
return ngx_rtmp_access(s, NGX_RTMP_ACCESS_PUBLISH);
|
||||
}
|
||||
if (ngx_rtmp_access(s, NGX_RTMP_ACCESS_PLAY) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_access_play(ngx_rtmp_session_t *s,
|
||||
ngx_str_t *name, uint32_t start, uint32_t duration, ngx_int_t reset)
|
||||
{
|
||||
return ngx_rtmp_access(s, NGX_RTMP_ACCESS_PLAY);
|
||||
return next_play(s, v);
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_access_postconfiguration(ngx_conf_t *cf)
|
||||
{
|
||||
ngx_rtmp_cmd_main_conf_t *dmcf;
|
||||
void *ch;
|
||||
/* chain handlers */
|
||||
next_publish = ngx_rtmp_publish;
|
||||
ngx_rtmp_publish = ngx_rtmp_access_publish;
|
||||
|
||||
dmcf = ngx_rtmp_conf_get_module_main_conf(cf, ngx_rtmp_cmd_module);
|
||||
|
||||
ch = ngx_array_push(&dmcf->connect);
|
||||
*(ngx_rtmp_cmd_connect_pt*)ch = ngx_rtmp_access_connect;
|
||||
|
||||
ch = ngx_array_push(&dmcf->publish);
|
||||
*(ngx_rtmp_cmd_publish_pt*)ch = ngx_rtmp_access_publish;
|
||||
|
||||
ch = ngx_array_push(&dmcf->play);
|
||||
*(ngx_rtmp_cmd_play_pt*)ch = ngx_rtmp_access_play;
|
||||
next_play = ngx_rtmp_play;
|
||||
ngx_rtmp_play = ngx_rtmp_access_play;
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,38 +2,100 @@
|
|||
* Copyright (c) 2012 Roman Arutyunyan
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _NGX_RTMP_CMD_H_INCLUDED_
|
||||
#define _NGX_RTMP_CMD_H_INCLUDED_
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_event.h>
|
||||
#include "ngx_rtmp.h"
|
||||
|
||||
|
||||
/* publish types */
|
||||
#define NGX_RTMP_CMD_PUBLISH_RECORD 1
|
||||
#define NGX_RTMP_CMD_PUBLISH_APPEND 2
|
||||
#define NGX_RTMP_CMD_PUBLISH_LIVE 3
|
||||
/* Basic RTMP call support */
|
||||
|
||||
/* TODO: improve string sizes */
|
||||
|
||||
typedef ngx_int_t (*ngx_rtmp_cmd_connect_pt)(ngx_rtmp_session_t *s);
|
||||
typedef ngx_int_t (*ngx_rtmp_cmd_publish_pt)(ngx_rtmp_session_t *s,
|
||||
ngx_str_t *name, ngx_int_t type);
|
||||
typedef ngx_int_t (*ngx_rtmp_cmd_play_pt)(ngx_rtmp_session_t *s,
|
||||
ngx_str_t *name, uint32_t start, uint32_t duration, ngx_int_t reset);
|
||||
typedef ngx_int_t (*ngx_rtmp_cmd_close_pt)(ngx_rtmp_session_t *s);
|
||||
typedef struct {
|
||||
u_char app[1024];
|
||||
u_char flashver[1024];
|
||||
u_char swf_url[1024];
|
||||
u_char tc_url[1024];
|
||||
double acodecs;
|
||||
double vcodecs;
|
||||
u_char page_url[1024];
|
||||
} ngx_rtmp_connect_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_array_t connect;
|
||||
ngx_array_t publish;
|
||||
ngx_array_t play;
|
||||
ngx_array_t close;
|
||||
} ngx_rtmp_cmd_main_conf_t;
|
||||
double trans;
|
||||
double stream;
|
||||
} ngx_rtmp_create_stream_t;
|
||||
|
||||
|
||||
extern ngx_module_t ngx_rtmp_cmd_module;
|
||||
typedef struct {
|
||||
double stream;
|
||||
} ngx_rtmp_delete_stream_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
u_char name[1024];
|
||||
u_char type[1024];
|
||||
} ngx_rtmp_publish_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
u_char name[1024];
|
||||
} ngx_rtmp_fcpublish_t;
|
||||
|
||||
|
||||
typedef ngx_rtmp_fcpublish_t ngx_rtmp_fcunpublish_t;
|
||||
typedef ngx_rtmp_fcpublish_t ngx_rtmp_fcsubscribe_t;
|
||||
typedef ngx_rtmp_fcpublish_t ngx_rtmp_fcunsubscribe_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
u_char name[1024];
|
||||
double start;
|
||||
double duration;
|
||||
int reset;
|
||||
} ngx_rtmp_play_t;
|
||||
|
||||
|
||||
typedef ngx_int_t (*ngx_rtmp_connect_pt)(ngx_rtmp_session_t *s,
|
||||
ngx_rtmp_connect_t *v);
|
||||
typedef ngx_int_t (*ngx_rtmp_create_stream_pt)(ngx_rtmp_session_t *s,
|
||||
ngx_rtmp_create_stream_t *v);
|
||||
typedef ngx_int_t (*ngx_rtmp_delete_stream_pt)(ngx_rtmp_session_t *s,
|
||||
ngx_rtmp_delete_stream_t *v);
|
||||
|
||||
typedef ngx_int_t (*ngx_rtmp_publish_pt)(ngx_rtmp_session_t *s,
|
||||
ngx_rtmp_publish_t *v);
|
||||
typedef ngx_int_t (*ngx_rtmp_fcpublish_pt)(ngx_rtmp_session_t *s,
|
||||
ngx_rtmp_fcpublish_t *v);
|
||||
typedef ngx_int_t (*ngx_rtmp_fcunpublish_pt)(ngx_rtmp_session_t *s,
|
||||
ngx_rtmp_fcunpublish_t *v);
|
||||
|
||||
typedef ngx_int_t (*ngx_rtmp_play_pt)(ngx_rtmp_session_t *s,
|
||||
ngx_rtmp_play_t *v);
|
||||
typedef ngx_int_t (*ngx_rtmp_fcsubscribe_pt)(ngx_rtmp_session_t *s,
|
||||
ngx_rtmp_fcsubscribe_t *v);
|
||||
typedef ngx_int_t (*ngx_rtmp_fcunsubscribe_pt)(ngx_rtmp_session_t *s,
|
||||
ngx_rtmp_fcunsubscribe_t *v);
|
||||
|
||||
|
||||
extern ngx_rtmp_connect_pt ngx_rtmp_connect;
|
||||
extern ngx_rtmp_create_stream_pt ngx_rtmp_create_stream;
|
||||
extern ngx_rtmp_delete_stream_pt ngx_rtmp_delete_stream;
|
||||
|
||||
extern ngx_rtmp_publish_pt ngx_rtmp_publish;
|
||||
extern ngx_rtmp_fcpublish_pt ngx_rtmp_fcpublish;
|
||||
extern ngx_rtmp_fcunpublish_pt ngx_rtmp_fcunpublish;
|
||||
|
||||
extern ngx_rtmp_play_pt ngx_rtmp_play;
|
||||
extern ngx_rtmp_fcsubscribe_pt ngx_rtmp_fcsubscribe;
|
||||
extern ngx_rtmp_fcunsubscribe_pt ngx_rtmp_fcunsubscribe;
|
||||
|
||||
|
||||
#endif /*_NGX_RTMP_CMD_H_INCLUDED_ */
|
||||
|
|
|
@ -9,6 +9,11 @@
|
|||
#include "ngx_rtmp_cmd_module.h"
|
||||
|
||||
|
||||
static ngx_rtmp_publish_pt next_publish;
|
||||
static ngx_rtmp_play_pt next_play;
|
||||
static ngx_rtmp_delete_stream_pt next_delete_stream;
|
||||
|
||||
|
||||
/* Chunk stream ids for output */
|
||||
#define NGX_RTMP_LIVE_CSID_AUDIO 6
|
||||
#define NGX_RTMP_LIVE_CSID_VIDEO 7
|
||||
|
@ -159,7 +164,7 @@ ngx_rtmp_live_get_head(ngx_rtmp_session_t *s)
|
|||
|
||||
|
||||
static void
|
||||
ngx_rtmp_live_join(ngx_rtmp_session_t *s, ngx_str_t *stream,
|
||||
ngx_rtmp_live_join(ngx_rtmp_session_t *s, u_char *name,
|
||||
ngx_uint_t flags)
|
||||
{
|
||||
ngx_connection_t *c;
|
||||
|
@ -180,9 +185,13 @@ ngx_rtmp_live_join(ngx_rtmp_session_t *s, ngx_str_t *stream,
|
|||
}
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, c->log, 0,
|
||||
"live: join '%V'", stream);
|
||||
"live: join '%s'", name);
|
||||
|
||||
ctx->stream.len = ngx_strlen(name);
|
||||
ctx->stream.data = ngx_palloc(s->connection->pool,
|
||||
ctx->stream.len);
|
||||
ngx_memcpy(ctx->stream.data, name, ctx->stream.len);
|
||||
|
||||
ctx->stream = *stream;
|
||||
hctx = ngx_rtmp_live_get_head(s);
|
||||
if (hctx == NULL) {
|
||||
return;
|
||||
|
@ -194,7 +203,7 @@ ngx_rtmp_live_join(ngx_rtmp_session_t *s, ngx_str_t *stream,
|
|||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_live_close(ngx_rtmp_session_t *s)
|
||||
ngx_rtmp_live_delete_stream(ngx_rtmp_session_t *s, ngx_rtmp_delete_stream_t *v)
|
||||
{
|
||||
ngx_connection_t *c;
|
||||
ngx_rtmp_live_ctx_t *ctx, **hctx;
|
||||
|
@ -203,7 +212,7 @@ ngx_rtmp_live_close(ngx_rtmp_session_t *s)
|
|||
|
||||
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_live_module);
|
||||
if (ctx == NULL) {
|
||||
return NGX_OK;
|
||||
goto next;
|
||||
}
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, c->log, 0,
|
||||
|
@ -222,7 +231,8 @@ ngx_rtmp_live_close(ngx_rtmp_session_t *s)
|
|||
}
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
next:
|
||||
return next_delete_stream(s, v);
|
||||
}
|
||||
|
||||
|
||||
|
@ -353,48 +363,49 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
|||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_live_publish(ngx_rtmp_session_t *s, ngx_str_t *name,
|
||||
ngx_int_t type)
|
||||
ngx_rtmp_live_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v)
|
||||
{
|
||||
ngx_rtmp_live_app_conf_t *lacf;
|
||||
|
||||
lacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_live_module);
|
||||
|
||||
if (lacf == NULL || !lacf->live) {
|
||||
return NGX_OK;
|
||||
goto next;
|
||||
}
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||
"live: publish: name='%V' type=%d",
|
||||
name, type);
|
||||
"live: publish: name='%s' type='%s'",
|
||||
v->name, v->type);
|
||||
|
||||
/* join stream as publisher */
|
||||
ngx_rtmp_live_join(s, name, NGX_RTMP_LIVE_PUBLISHING);
|
||||
ngx_rtmp_live_join(s, v->name, NGX_RTMP_LIVE_PUBLISHING);
|
||||
|
||||
return NGX_OK;
|
||||
next:
|
||||
return next_publish(s, v);
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_live_play(ngx_rtmp_session_t *s, ngx_str_t *name,
|
||||
uint32_t start, uint32_t duration, ngx_int_t reset)
|
||||
ngx_rtmp_live_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v)
|
||||
{
|
||||
ngx_rtmp_live_app_conf_t *lacf;
|
||||
|
||||
lacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_live_module);
|
||||
|
||||
if (lacf == NULL || !lacf->live) {
|
||||
return NGX_OK;
|
||||
goto next;
|
||||
}
|
||||
|
||||
ngx_log_debug4(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||
"live: play: name='%V' start=%uD duration=%uD reset=%d",
|
||||
name, start, duration, reset);
|
||||
"live: play: name='%s' start=%uD duration=%uD reset=%d",
|
||||
v->name, (uint32_t)v->start,
|
||||
(uint32_t)v->duration, (uint32_t)v->reset);
|
||||
|
||||
/* join stream as player */
|
||||
ngx_rtmp_live_join(s, name, NGX_RTMP_LIVE_PLAYING);
|
||||
ngx_rtmp_live_join(s, v->name, NGX_RTMP_LIVE_PLAYING);
|
||||
|
||||
return NGX_OK;
|
||||
next:
|
||||
return next_play(s, v);
|
||||
}
|
||||
|
||||
|
||||
|
@ -402,9 +413,7 @@ static ngx_int_t
|
|||
ngx_rtmp_live_postconfiguration(ngx_conf_t *cf)
|
||||
{
|
||||
ngx_rtmp_core_main_conf_t *cmcf;
|
||||
ngx_rtmp_cmd_main_conf_t *dmcf;
|
||||
ngx_rtmp_handler_pt *h;
|
||||
void *ch;
|
||||
|
||||
/* register raw event handlers */
|
||||
cmcf = ngx_rtmp_conf_get_module_main_conf(cf, ngx_rtmp_core_module);
|
||||
|
@ -415,17 +424,15 @@ ngx_rtmp_live_postconfiguration(ngx_conf_t *cf)
|
|||
h = ngx_array_push(&cmcf->events[NGX_RTMP_MSG_VIDEO]);
|
||||
*h = ngx_rtmp_live_av;
|
||||
|
||||
/* register command handlers */
|
||||
dmcf = ngx_rtmp_conf_get_module_main_conf(cf, ngx_rtmp_cmd_module);
|
||||
/* chain handlers */
|
||||
next_publish = ngx_rtmp_publish;
|
||||
ngx_rtmp_publish = ngx_rtmp_live_publish;
|
||||
|
||||
ch = ngx_array_push(&dmcf->publish);
|
||||
*(ngx_rtmp_cmd_publish_pt*)ch = ngx_rtmp_live_publish;
|
||||
next_play = ngx_rtmp_play;
|
||||
ngx_rtmp_play = ngx_rtmp_live_play;
|
||||
|
||||
ch = ngx_array_push(&dmcf->play);
|
||||
*(ngx_rtmp_cmd_play_pt*)ch = ngx_rtmp_live_play;
|
||||
|
||||
ch = ngx_array_push(&dmcf->close);
|
||||
*(ngx_rtmp_cmd_close_pt*)ch = ngx_rtmp_live_close;
|
||||
next_delete_stream = ngx_rtmp_delete_stream;
|
||||
ngx_rtmp_delete_stream = ngx_rtmp_live_delete_stream;
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,10 @@
|
|||
#include "ngx_rtmp_cmd_module.h"
|
||||
|
||||
|
||||
static ngx_rtmp_publish_pt next_publish;
|
||||
static ngx_rtmp_delete_stream_pt next_delete_stream;
|
||||
|
||||
|
||||
static ngx_int_t ngx_rtmp_record_postconfiguration(ngx_conf_t *cf);
|
||||
static void * ngx_rtmp_record_create_app_conf(ngx_conf_t *cf);
|
||||
static char * ngx_rtmp_record_merge_app_conf(ngx_conf_t *cf,
|
||||
|
@ -134,8 +138,7 @@ ngx_rtmp_record_write_header(ngx_file_t *file)
|
|||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_record_publish(ngx_rtmp_session_t *s,
|
||||
ngx_str_t *name, ngx_int_t type)
|
||||
ngx_rtmp_record_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v)
|
||||
{
|
||||
ngx_rtmp_record_app_conf_t *racf;
|
||||
ngx_rtmp_record_ctx_t *ctx;
|
||||
|
@ -145,7 +148,7 @@ ngx_rtmp_record_publish(ngx_rtmp_session_t *s,
|
|||
racf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_record_module);
|
||||
|
||||
if (racf == NULL || racf->root.len == 0) {
|
||||
return NGX_OK;
|
||||
goto next;
|
||||
}
|
||||
|
||||
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_record_module);
|
||||
|
@ -208,7 +211,12 @@ ngx_rtmp_record_publish(ngx_rtmp_session_t *s,
|
|||
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||
"record: opened '%V'", &ctx->path);
|
||||
|
||||
return ngx_rtmp_record_write_header(&ctx->file);
|
||||
if (ngx_rtmp_record_write_header(&ctx->file) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
next:
|
||||
return next_publish(s, v);
|
||||
}
|
||||
|
||||
|
||||
|
@ -239,6 +247,18 @@ ngx_rtmp_record_close(ngx_rtmp_session_t *s)
|
|||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_record_delete_stream(ngx_rtmp_session_t *s,
|
||||
ngx_rtmp_delete_stream_t *v)
|
||||
{
|
||||
if (ngx_rtmp_record_close(s) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
return next_delete_stream(s, v);
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_record_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
||||
ngx_chain_t *in)
|
||||
|
@ -342,9 +362,7 @@ static ngx_int_t
|
|||
ngx_rtmp_record_postconfiguration(ngx_conf_t *cf)
|
||||
{
|
||||
ngx_rtmp_core_main_conf_t *cmcf;
|
||||
ngx_rtmp_cmd_main_conf_t *dmcf;
|
||||
ngx_rtmp_handler_pt *h;
|
||||
void *ch;
|
||||
|
||||
cmcf = ngx_rtmp_conf_get_module_main_conf(cf, ngx_rtmp_core_module);
|
||||
|
||||
|
@ -355,14 +373,12 @@ ngx_rtmp_record_postconfiguration(ngx_conf_t *cf)
|
|||
h = ngx_array_push(&cmcf->events[NGX_RTMP_MSG_VIDEO]);
|
||||
*h = ngx_rtmp_record_av;
|
||||
|
||||
/* register command handlers */
|
||||
dmcf = ngx_rtmp_conf_get_module_main_conf(cf, ngx_rtmp_cmd_module);
|
||||
/* chain handlers */
|
||||
next_publish = ngx_rtmp_publish;
|
||||
ngx_rtmp_publish = ngx_rtmp_record_publish;
|
||||
|
||||
ch = ngx_array_push(&dmcf->publish);
|
||||
*(ngx_rtmp_cmd_publish_pt*)ch = ngx_rtmp_record_publish;
|
||||
|
||||
ch = ngx_array_push(&dmcf->close);
|
||||
*(ngx_rtmp_cmd_close_pt*)ch = ngx_rtmp_record_close;
|
||||
next_delete_stream = ngx_rtmp_delete_stream;
|
||||
ngx_rtmp_delete_stream = ngx_rtmp_record_delete_stream;
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue