Skip to content

Commit 3a5f9ee

Browse files
committed
added aac-he & aac-hev2 support
1 parent 18fa7a5 commit 3a5f9ee

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

ngx_rtmp_codec_module.c

+33-5
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,11 @@ ngx_rtmp_codec_parse_aac_header(ngx_rtmp_session_t *s, ngx_chain_t *in)
292292
ngx_rtmp_bit_read(&br, 16);
293293

294294
ctx->aac_profile = (ngx_uint_t) ngx_rtmp_bit_read(&br, 5);
295-
296295
if (ctx->aac_profile == 31) {
297296
ctx->aac_profile = (ngx_uint_t) ngx_rtmp_bit_read(&br, 6) + 32;
298297
}
299298

300299
idx = (ngx_uint_t) ngx_rtmp_bit_read(&br, 4);
301-
302300
if (idx == 15) {
303301
ctx->sample_rate = (ngx_uint_t) ngx_rtmp_bit_read(&br, 24);
304302
} else {
@@ -307,15 +305,45 @@ ngx_rtmp_codec_parse_aac_header(ngx_rtmp_session_t *s, ngx_chain_t *in)
307305

308306
ctx->aac_chan_conf = (ngx_uint_t) ngx_rtmp_bit_read(&br, 4);
309307

308+
if (ctx->aac_profile == 5 || ctx->aac_profile == 29) {
309+
310+
if (ctx->aac_profile == 29) {
311+
ctx->aac_ps = 1;
312+
}
313+
314+
ctx->aac_sbr = 1;
315+
316+
idx = (ngx_uint_t) ngx_rtmp_bit_read(&br, 4);
317+
if (idx == 15) {
318+
ctx->sample_rate = (ngx_uint_t) ngx_rtmp_bit_read(&br, 24);
319+
} else {
320+
ctx->sample_rate = aac_sample_rates[idx];
321+
}
322+
323+
ctx->aac_profile = (ngx_uint_t) ngx_rtmp_bit_read(&br, 5);
324+
if (ctx->aac_profile == 31) {
325+
ctx->aac_profile = (ngx_uint_t) ngx_rtmp_bit_read(&br, 6) + 32;
326+
}
327+
}
328+
310329
/* MPEG-4 Audio Specific Config
311330
312331
5 bits: object type
313332
if (object type == 31)
314-
6 bits + 32: object type
315-
--->4 bits: frequency index
333+
6 bits + 32: object type
334+
4 bits: frequency index
316335
if (frequency index == 15)
317-
24 bits: frequency
336+
24 bits: frequency
318337
4 bits: channel configuration
338+
339+
if (object_type == 5)
340+
4 bits: frequency index
341+
if (frequency index == 15)
342+
24 bits: frequency
343+
5 bits: object type
344+
if (object type == 31)
345+
6 bits + 32: object type
346+
319347
var bits: AOT Specific Config
320348
*/
321349

ngx_rtmp_codec_module.h

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ typedef struct {
6060
ngx_uint_t audio_codec_id;
6161
ngx_uint_t aac_profile;
6262
ngx_uint_t aac_chan_conf;
63+
ngx_uint_t aac_sbr;
64+
ngx_uint_t aac_ps;
6365
ngx_uint_t avc_profile;
6466
ngx_uint_t avc_compat;
6567
ngx_uint_t avc_level;

ngx_rtmp_stat_module.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -363,16 +363,24 @@ ngx_rtmp_stat_client(ngx_http_request_t *r, ngx_chain_t ***lll,
363363

364364

365365
static char *
366-
ngx_rtmp_stat_get_aac_profile(ngx_uint_t p) {
366+
ngx_rtmp_stat_get_aac_profile(ngx_uint_t p, ngx_uint_t sbr, ngx_uint_t ps) {
367367
switch (p) {
368368
case 1:
369369
return "Main";
370370
case 2:
371+
if (ps) {
372+
return "HEv2";
373+
}
374+
if (sbr) {
375+
return "HE";
376+
}
371377
return "LC";
372378
case 3:
373379
return "SSR";
374380
case 4:
375381
return "LTP";
382+
case 5:
383+
return "SBR";
376384
default:
377385
return "";
378386
}
@@ -526,7 +534,9 @@ ngx_rtmp_stat_live(ngx_http_request_t *r, ngx_chain_t ***lll,
526534
if (codec->aac_profile) {
527535
NGX_RTMP_STAT_L("<profile>");
528536
NGX_RTMP_STAT_CS(
529-
ngx_rtmp_stat_get_aac_profile(codec->aac_profile));
537+
ngx_rtmp_stat_get_aac_profile(codec->aac_profile,
538+
codec->aac_sbr,
539+
codec->aac_ps));
530540
NGX_RTMP_STAT_L("</profile>");
531541
}
532542
if (codec->aac_chan_conf) {

0 commit comments

Comments
 (0)