Populate singe-audio track header correctly

This commit is contained in:
Chris Wiggins 2016-04-14 06:48:30 +12:00
parent c11797815d
commit 86cfd20b28

View file

@ -171,14 +171,8 @@ ngx_rtmp_mpegts_write_file(ngx_rtmp_mpegts_file_t *file, u_char *in,
return NGX_OK;
}
static ngx_int_t
ngx_rtmp_mpegts_write_header(ngx_rtmp_mpegts_file_t *file, ngx_rtmp_codec_ctx_t *codec_ctx, ngx_uint_t mpegts_cc)
{
ngx_int_t rc;
//If there's both audio and video present
if (codec_ctx->audio_codec_id && codec_ctx->video_codec_id)
ngx_int_t
ngx_rtmp_mpegts_set_audio_header(ngx_rtmp_codec_ctx_t *codec_ctx, ngx_uint_t mpegts_cc)
{
if (codec_ctx->audio_codec_id == NGX_RTMP_AUDIO_AAC) {
ngx_memcpy(ngx_rtmp_mpegts_header+210, ngx_rtmp_mpegts_header_aac,
@ -196,6 +190,21 @@ ngx_rtmp_mpegts_write_header(ngx_rtmp_mpegts_file_t *file, ngx_rtmp_codec_ctx_t
ngx_rtmp_mpegts_header[3] = (ngx_rtmp_mpegts_header[3] & 0xf0) + (u_char)mpegts_cc;
ngx_rtmp_mpegts_header[191] = (ngx_rtmp_mpegts_header[191] & 0xf0) + (u_char)mpegts_cc;
return NGX_OK;
}
static ngx_int_t
ngx_rtmp_mpegts_write_header(ngx_rtmp_mpegts_file_t *file, ngx_rtmp_codec_ctx_t *codec_ctx, ngx_uint_t mpegts_cc)
{
ngx_int_t rc;
//If there's both audio and video present
if (codec_ctx->audio_codec_id && codec_ctx->video_codec_id)
{
/* Write the audio headers */
ngx_rtmp_mpegts_set_audio_header(codec_ctx, mpegts_cc);
rc = ngx_rtmp_mpegts_write_file(file, ngx_rtmp_mpegts_header,
sizeof(ngx_rtmp_mpegts_header));
}
@ -214,6 +223,9 @@ ngx_rtmp_mpegts_write_header(ngx_rtmp_mpegts_file_t *file, ngx_rtmp_codec_ctx_t
/* Set the PCR PID to the audio PID */
buf[202] = 0x01;
/* Write the audio headers */
ngx_rtmp_mpegts_set_audio_header(codec_ctx, mpegts_cc);
/* Move the audio description over the video description */
ngx_memcpy(buf + 205, buf + 210, 5);
@ -225,7 +237,7 @@ ngx_rtmp_mpegts_write_header(ngx_rtmp_mpegts_file_t *file, ngx_rtmp_codec_ctx_t
}
else
{
/* Fix the CRC partially overwriting the audio description */
/* Fix the CRC partially overwriting the video description */
buf[210] = 0x15;
buf[211] = 0xbd;
buf[212] = 0x4d;