From 345c56655245ea3ba5bf7a610e40bcba675fb312 Mon Sep 17 00:00:00 2001
From: Edward Hervey <edward@centricular.com>
Date: Tue, 4 Apr 2017 17:55:13 +0200
Subject: [PATCH] aacparse: Handle Parametric Stereo with HE-AAC(v2)

According to ISO/IEC:14496-2:2009 , in the case of HE-AACv2 (audioObjecType
29) parametric stereo is used (a single mono track is used and then
transformations are applied to it to provide a stereo output).

We therefore report two channels in the case where there is one reported
in the audioChannelConfiguration.

Fixes the various issues where a demuxer would report two channels, but
then the parser would say there's only one channel, and then the decoder
would output two channels.
---
 gst/audioparsers/gstaacparse.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gst/audioparsers/gstaacparse.c b/gst/audioparsers/gstaacparse.c
index bf424b2794..21b8c8c5fd 100644
--- a/gst/audioparsers/gstaacparse.c
+++ b/gst/audioparsers/gstaacparse.c
@@ -564,8 +564,13 @@ gst_aac_parse_read_loas_audio_specific_config (GstAacParse * aacparse,
   if (audio_object_type == 5 || audio_object_type == 29) {
     extension_audio_object_type = 5;
     sbr = TRUE;
-    if (audio_object_type == 29)
+    if (audio_object_type == 29) {
       ps = TRUE;
+      /* Parametric stereo. If we have a one-channel configuration, we can
+       * override it to stereo */
+      if (*channels == 1)
+        *channels = 2;
+    }
 
     GST_LOG_OBJECT (aacparse,
         "Audio object type 5 or 29, so rereading sampling rate...");