From 3a5f9eea78fc8d11e8be922aea9ac349b9dcbfc2 Mon Sep 17 00:00:00 2001 From: Roman Arutyunyan Date: Sat, 21 Dec 2013 09:29:39 +0400 Subject: [PATCH] added aac-he & aac-hev2 support --- ngx_rtmp_codec_module.c | 38 +++++++++++++++++++++++++++++++++----- ngx_rtmp_codec_module.h | 2 ++ ngx_rtmp_stat_module.c | 14 ++++++++++++-- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/ngx_rtmp_codec_module.c b/ngx_rtmp_codec_module.c index 8fd26d6..ae9c35e 100644 --- a/ngx_rtmp_codec_module.c +++ b/ngx_rtmp_codec_module.c @@ -292,13 +292,11 @@ ngx_rtmp_codec_parse_aac_header(ngx_rtmp_session_t *s, ngx_chain_t *in) ngx_rtmp_bit_read(&br, 16); ctx->aac_profile = (ngx_uint_t) ngx_rtmp_bit_read(&br, 5); - if (ctx->aac_profile == 31) { ctx->aac_profile = (ngx_uint_t) ngx_rtmp_bit_read(&br, 6) + 32; } idx = (ngx_uint_t) ngx_rtmp_bit_read(&br, 4); - if (idx == 15) { ctx->sample_rate = (ngx_uint_t) ngx_rtmp_bit_read(&br, 24); } else { @@ -307,15 +305,45 @@ ngx_rtmp_codec_parse_aac_header(ngx_rtmp_session_t *s, ngx_chain_t *in) ctx->aac_chan_conf = (ngx_uint_t) ngx_rtmp_bit_read(&br, 4); + if (ctx->aac_profile == 5 || ctx->aac_profile == 29) { + + if (ctx->aac_profile == 29) { + ctx->aac_ps = 1; + } + + ctx->aac_sbr = 1; + + idx = (ngx_uint_t) ngx_rtmp_bit_read(&br, 4); + if (idx == 15) { + ctx->sample_rate = (ngx_uint_t) ngx_rtmp_bit_read(&br, 24); + } else { + ctx->sample_rate = aac_sample_rates[idx]; + } + + ctx->aac_profile = (ngx_uint_t) ngx_rtmp_bit_read(&br, 5); + if (ctx->aac_profile == 31) { + ctx->aac_profile = (ngx_uint_t) ngx_rtmp_bit_read(&br, 6) + 32; + } + } + /* MPEG-4 Audio Specific Config 5 bits: object type if (object type == 31) - 6 bits + 32: object type - --->4 bits: frequency index + 6 bits + 32: object type + 4 bits: frequency index if (frequency index == 15) - 24 bits: frequency + 24 bits: frequency 4 bits: channel configuration + + if (object_type == 5) + 4 bits: frequency index + if (frequency index == 15) + 24 bits: frequency + 5 bits: object type + if (object type == 31) + 6 bits + 32: object type + var bits: AOT Specific Config */ diff --git a/ngx_rtmp_codec_module.h b/ngx_rtmp_codec_module.h index de417da..ee48c1c 100644 --- a/ngx_rtmp_codec_module.h +++ b/ngx_rtmp_codec_module.h @@ -60,6 +60,8 @@ typedef struct { ngx_uint_t audio_codec_id; ngx_uint_t aac_profile; ngx_uint_t aac_chan_conf; + ngx_uint_t aac_sbr; + ngx_uint_t aac_ps; ngx_uint_t avc_profile; ngx_uint_t avc_compat; ngx_uint_t avc_level; diff --git a/ngx_rtmp_stat_module.c b/ngx_rtmp_stat_module.c index 85dce4e..8b64705 100644 --- a/ngx_rtmp_stat_module.c +++ b/ngx_rtmp_stat_module.c @@ -363,16 +363,24 @@ ngx_rtmp_stat_client(ngx_http_request_t *r, ngx_chain_t ***lll, static char * -ngx_rtmp_stat_get_aac_profile(ngx_uint_t p) { +ngx_rtmp_stat_get_aac_profile(ngx_uint_t p, ngx_uint_t sbr, ngx_uint_t ps) { switch (p) { case 1: return "Main"; case 2: + if (ps) { + return "HEv2"; + } + if (sbr) { + return "HE"; + } return "LC"; case 3: return "SSR"; case 4: return "LTP"; + case 5: + return "SBR"; default: return ""; } @@ -526,7 +534,9 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll, if (codec->aac_profile) { NGX_RTMP_STAT_L(""); NGX_RTMP_STAT_CS( - ngx_rtmp_stat_get_aac_profile(codec->aac_profile)); + ngx_rtmp_stat_get_aac_profile(codec->aac_profile, + codec->aac_sbr, + codec->aac_ps)); NGX_RTMP_STAT_L(""); } if (codec->aac_chan_conf) {