mirror of
https://github.com/zotanmew/nginx-rtmp-module.git
synced 2024-05-20 18:01:08 +02:00
implemented double headers aac/avc: live(prepared) & flv(unprepared)
This commit is contained in:
parent
9a118b612e
commit
ebc47f03a4
|
@ -116,6 +116,16 @@ ngx_rtmp_codec_disconnect(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
||||||
ctx->aac_header = NULL;
|
ctx->aac_header = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ctx->avc_pheader) {
|
||||||
|
ngx_rtmp_free_shared_chain(cscf, ctx->avc_pheader);
|
||||||
|
ctx->avc_pheader = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx->aac_pheader) {
|
||||||
|
ngx_rtmp_free_shared_chain(cscf, ctx->aac_pheader);
|
||||||
|
ctx->aac_pheader = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +136,7 @@ ngx_rtmp_codec_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
||||||
{
|
{
|
||||||
ngx_rtmp_core_srv_conf_t *cscf;
|
ngx_rtmp_core_srv_conf_t *cscf;
|
||||||
ngx_rtmp_codec_ctx_t *ctx;
|
ngx_rtmp_codec_ctx_t *ctx;
|
||||||
ngx_chain_t **header;
|
ngx_chain_t **header, **pheader;
|
||||||
uint8_t fmt;
|
uint8_t fmt;
|
||||||
ngx_rtmp_header_t ch, lh;
|
ngx_rtmp_header_t ch, lh;
|
||||||
|
|
||||||
|
@ -155,12 +165,14 @@ ngx_rtmp_codec_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
||||||
if (h->type == NGX_RTMP_MSG_AUDIO) {
|
if (h->type == NGX_RTMP_MSG_AUDIO) {
|
||||||
if (((fmt & 0xf0) >> 4) == NGX_RTMP_AUDIO_AAC) {
|
if (((fmt & 0xf0) >> 4) == NGX_RTMP_AUDIO_AAC) {
|
||||||
header = &ctx->aac_header;
|
header = &ctx->aac_header;
|
||||||
|
pheader = &ctx->aac_pheader;
|
||||||
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||||
"codec: AAC header arrived");
|
"codec: AAC header arrived");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((fmt & 0x0f) == NGX_RTMP_VIDEO_H264) {
|
if ((fmt & 0x0f) == NGX_RTMP_VIDEO_H264) {
|
||||||
header = &ctx->avc_header;
|
header = &ctx->avc_header;
|
||||||
|
pheader = &ctx->avc_pheader;
|
||||||
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||||
"codec: AVC/H264 header arrived");
|
"codec: AVC/H264 header arrived");
|
||||||
}
|
}
|
||||||
|
@ -174,6 +186,10 @@ ngx_rtmp_codec_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
||||||
ngx_rtmp_free_shared_chain(cscf, *header);
|
ngx_rtmp_free_shared_chain(cscf, *header);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (*pheader) {
|
||||||
|
ngx_rtmp_free_shared_chain(cscf, *pheader);
|
||||||
|
}
|
||||||
|
|
||||||
/* equal headers; timeout diff is zero */
|
/* equal headers; timeout diff is zero */
|
||||||
ngx_memzero(&ch, sizeof(ch));
|
ngx_memzero(&ch, sizeof(ch));
|
||||||
ngx_memzero(&lh, sizeof(lh));
|
ngx_memzero(&lh, sizeof(lh));
|
||||||
|
@ -185,7 +201,8 @@ ngx_rtmp_codec_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
||||||
: NGX_RTMP_LIVE_CSID_AUDIO);
|
: NGX_RTMP_LIVE_CSID_AUDIO);
|
||||||
lh = ch;
|
lh = ch;
|
||||||
*header = ngx_rtmp_append_shared_bufs(cscf, NULL, in);
|
*header = ngx_rtmp_append_shared_bufs(cscf, NULL, in);
|
||||||
ngx_rtmp_prepare_message(s, &ch, &lh, *header);
|
*pheader = ngx_rtmp_append_shared_bufs(cscf, NULL, in);
|
||||||
|
ngx_rtmp_prepare_message(s, &ch, &lh, *pheader);
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,10 @@ u_char * ngx_rtmp_get_video_codec_name(ngx_uint_t id);
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ngx_chain_t *avc_header;
|
ngx_chain_t *avc_header;
|
||||||
ngx_chain_t *aac_header;
|
ngx_chain_t *aac_header;
|
||||||
|
|
||||||
|
/* prepared headers (for live streaming) */
|
||||||
|
ngx_chain_t *avc_pheader;
|
||||||
|
ngx_chain_t *aac_pheader;
|
||||||
} ngx_rtmp_codec_ctx_t;
|
} ngx_rtmp_codec_ctx_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -374,14 +374,14 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
||||||
if (codec_ctx) {
|
if (codec_ctx) {
|
||||||
peer_out = NULL;
|
peer_out = NULL;
|
||||||
if (h->type == NGX_RTMP_MSG_AUDIO) {
|
if (h->type == NGX_RTMP_MSG_AUDIO) {
|
||||||
if (codec_ctx->aac_header) {
|
if (codec_ctx->aac_pheader) {
|
||||||
peer_out = codec_ctx->aac_header;
|
peer_out = codec_ctx->aac_pheader;
|
||||||
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, ss->connection->log,
|
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, ss->connection->log,
|
||||||
0, "live: sending AAC header");
|
0, "live: sending AAC header");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (codec_ctx->avc_header) {
|
if (codec_ctx->avc_pheader) {
|
||||||
peer_out = codec_ctx->avc_header;
|
peer_out = codec_ctx->avc_pheader;
|
||||||
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, ss->connection->log,
|
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, ss->connection->log,
|
||||||
0, "live: sending AVC/H264 header");
|
0, "live: sending AVC/H264 header");
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,11 +240,6 @@ ngx_rtmp_record_open(ngx_rtmp_session_t *s)
|
||||||
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||||
"record: opened '%s'", ctx->path);
|
"record: opened '%s'", ctx->path);
|
||||||
|
|
||||||
if (ngx_rtmp_record_write_header(&ctx->file) != NGX_OK) {
|
|
||||||
ngx_rtmp_record_close(s);
|
|
||||||
return NGX_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -581,11 +576,17 @@ ngx_rtmp_record_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
||||||
if (ctx->file.offset == 0) {
|
if (ctx->file.offset == 0) {
|
||||||
ctx->epoch = h->timestamp;
|
ctx->epoch = h->timestamp;
|
||||||
|
|
||||||
|
if (ngx_rtmp_record_write_header(&ctx->file) != NGX_OK) {
|
||||||
|
ngx_rtmp_record_close(s);
|
||||||
|
return NGX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
codec_ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_codec_module);
|
codec_ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_codec_module);
|
||||||
if (codec_ctx) {
|
if (codec_ctx) {
|
||||||
ch = *h;
|
ch = *h;
|
||||||
|
|
||||||
if (codec_ctx->aac_header) {
|
if (codec_ctx->aac_header && (racf->flags & NGX_RTMP_RECORD_AUDIO))
|
||||||
|
{
|
||||||
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||||
"record: writing AAC header");
|
"record: writing AAC header");
|
||||||
ch.type = NGX_RTMP_MSG_AUDIO;
|
ch.type = NGX_RTMP_MSG_AUDIO;
|
||||||
|
@ -597,7 +598,9 @@ ngx_rtmp_record_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (codec_ctx->avc_header) {
|
if (codec_ctx->avc_header && (racf->flags
|
||||||
|
& (NGX_RTMP_RECORD_VIDEO|NGX_RTMP_RECORD_KEYFRAMES)))
|
||||||
|
{
|
||||||
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||||
"record: writing AVC header");
|
"record: writing AVC header");
|
||||||
ch.type = NGX_RTMP_MSG_VIDEO;
|
ch.type = NGX_RTMP_MSG_VIDEO;
|
||||||
|
|
Loading…
Reference in a new issue