aboutsummaryrefslogtreecommitdiffstats
path: root/libMpegTPEnc/src/tpenc_asc.cpp
diff options
context:
space:
mode:
authorFraunhofer IIS FDK <audio-fdk@iis.fraunhofer.de>2018-02-26 20:17:00 +0100
committerJean-Michel Trivi <jmtrivi@google.com>2018-04-19 11:21:15 -0700
commit6cfabd35363c3ef5e3b209b867169a500b3ccc3c (patch)
tree01c0a19f2735e8b5d2407555fe992d4230d089eb /libMpegTPEnc/src/tpenc_asc.cpp
parent6288a1e34c4dede4c2806beb1736ece6580558c7 (diff)
downloadfdk-aac-6cfabd35363c3ef5e3b209b867169a500b3ccc3c.tar.gz
fdk-aac-6cfabd35363c3ef5e3b209b867169a500b3ccc3c.tar.bz2
fdk-aac-6cfabd35363c3ef5e3b209b867169a500b3ccc3c.zip
Upgrade to FDKv2
Bug: 71430241 Test: CTS DecoderTest and DecoderTestAacDrc original-Change-Id: Iaa20f749b8a04d553b20247cfe1a8930ebbabe30 Apply clang-format also on header files. original-Change-Id: I14de1ef16bbc79ec0283e745f98356a10efeb2e4 Fixes for MPEG-D DRC original-Change-Id: If1de2d74bbbac84b3f67de3b88b83f6a23b8a15c Catch unsupported tw_mdct at an early stage original-Change-Id: Ied9dd00d754162a0e3ca1ae3e6b854315d818afe Fixing PVC transition frames original-Change-Id: Ib75725abe39252806c32d71176308f2c03547a4e Move qmf bands sanity check original-Change-Id: Iab540c3013c174d9490d2ae100a4576f51d8dbc4 Initialize scaling variable original-Change-Id: I3c4087101b70e998c71c1689b122b0d7762e0f9e Add 16 qmf band configuration to getSlotNrgHQ() original-Change-Id: I49a5d30f703a1b126ff163df9656db2540df21f1 Always apply byte alignment at the end of the AudioMuxElement original-Change-Id: I42d560287506d65d4c3de8bfe3eb9a4ebeb4efc7 Setup SBR element only if no parse error exists original-Change-Id: I1915b73704bc80ab882b9173d6bec59cbd073676 Additional array index check in HCR original-Change-Id: I18cc6e501ea683b5009f1bbee26de8ddd04d8267 Fix fade-in index selection in concealment module original-Change-Id: Ibf802ed6ed8c05e9257e1f3b6d0ac1162e9b81c1 Enable explicit backward compatible parser for AAC_LD original-Change-Id: I27e9c678dcb5d40ed760a6d1e06609563d02482d Skip spatial specific config in explicit backward compatible ASC original-Change-Id: Iff7cc365561319e886090cedf30533f562ea4d6e Update flags description in decoder API original-Change-Id: I9a5b4f8da76bb652f5580cbd3ba9760425c43830 Add QMF domain reset function original-Change-Id: I4f89a8a2c0277d18103380134e4ed86996e9d8d6 DRC upgrade v2.1.0 original-Change-Id: I5731c0540139dab220094cd978ef42099fc45b74 Fix integer overflow in sqrtFixp_lookup() original-Change-Id: I429a6f0d19aa2cc957e0f181066f0ca73968c914 Fix integer overflow in invSqrtNorm2() original-Change-Id: I84de5cbf9fb3adeb611db203fe492fabf4eb6155 Fix integer overflow in GenerateRandomVector() original-Change-Id: I3118a641008bd9484d479e5b0b1ee2b5d7d44d74 Fix integer overflow in adjustTimeSlot_EldGrid() original-Change-Id: I29d503c247c5c8282349b79df940416a512fb9d5 Fix integer overflow in FDKsbrEnc_codeEnvelope() original-Change-Id: I6b34b61ebb9d525b0c651ed08de2befc1f801449 Follow-up on: Fix integer overflow in adjustTimeSlot_EldGrid() original-Change-Id: I6f8f578cc7089e5eb7c7b93e580b72ca35ad689a Fix integer overflow in get_pk_v2() original-Change-Id: I63375bed40d45867f6eeaa72b20b1f33e815938c Fix integer overflow in Syn_filt_zero() original-Change-Id: Ie0c02fdfbe03988f9d3b20d10cd9fe4c002d1279 Fix integer overflow in CFac_CalcFacSignal() original-Change-Id: Id2d767c40066c591b51768e978eb8af3b803f0c5 Fix integer overflow in FDKaacEnc_FDKaacEnc_calcPeNoAH() original-Change-Id: Idcbd0f4a51ae2550ed106aa6f3d678d1f9724841 Fix integer overflow in sbrDecoder_calculateGainVec() original-Change-Id: I7081bcbe29c5cede9821b38d93de07c7add2d507 Fix integer overflow in CLpc_SynthesisLattice() original-Change-Id: I4a95ddc18de150102352d4a1845f06094764c881 Fix integer overflow in Pred_Lt4() original-Change-Id: I4dbd012b2de7d07c3e70a47b92e3bfae8dbc750a Fix integer overflow in FDKsbrEnc_InitSbrFastTransientDetector() original-Change-Id: I788cbec1a4a00f44c2f3a72ad7a4afa219807d04 Fix unsigned integer overflow in FDKaacEnc_WriteBitstream() original-Change-Id: I68fc75166e7d2cd5cd45b18dbe3d8c2a92f1822a Fix unsigned integer overflow in FDK_MetadataEnc_Init() original-Change-Id: Ie8d025f9bcdb2442c704bd196e61065c03c10af4 Fix overflow in pseudo random number generators original-Change-Id: I3e2551ee01356297ca14e3788436ede80bd5513c Fix unsigned integer overflow in sbrDecoder_Parse() original-Change-Id: I3f231b2f437e9c37db4d5b964164686710eee971 Fix unsigned integer overflow in longsub() original-Change-Id: I73c2bc50415cac26f1f5a29e125bbe75f9180a6e Fix unsigned integer overflow in CAacDecoder_DecodeFrame() original-Change-Id: Ifce2db4b1454b46fa5f887e9d383f1cc43b291e4 Fix overflow at CLpdChannelStream_Read() original-Change-Id: Idb9d822ce3a4272e4794b643644f5434e2d4bf3f Fix unsigned integer overflow in Hcr_State_BODY_SIGN_ESC__ESC_WORD() original-Change-Id: I1ccf77c0015684b85534c5eb97162740a870b71c Fix unsigned integer overflow in UsacConfig_Parse() original-Change-Id: Ie6d27f84b6ae7eef092ecbff4447941c77864d9f Fix unsigned integer overflow in aacDecoder_drcParse() original-Change-Id: I713f28e883eea3d70b6fa56a7b8f8c22bcf66ca0 Fix unsigned integer overflow in aacDecoder_drcReadCompression() original-Change-Id: Ia34dfeb88c4705c558bce34314f584965cafcf7a Fix unsigned integer overflow in CDataStreamElement_Read() original-Change-Id: Iae896cc1d11f0a893d21be6aa90bd3e60a2c25f0 Fix unsigned integer overflow in transportDec_AdjustEndOfAccessUnit() original-Change-Id: I64cf29a153ee784bb4a16fdc088baabebc0007dc Fix unsigned integer overflow in transportDec_GetAuBitsRemaining() original-Change-Id: I975b3420faa9c16a041874ba0db82e92035962e4 Fix unsigned integer overflow in extractExtendedData() original-Change-Id: I2a59eb09e2053cfb58dfb75fcecfad6b85a80a8f Fix signed integer overflow in CAacDecoder_ExtPayloadParse() original-Change-Id: I4ad5ca4e3b83b5d964f1c2f8c5e7b17c477c7929 Fix unsigned integer overflow in CAacDecoder_DecodeFrame() original-Change-Id: I29a39df77d45c52a0c9c5c83c1ba81f8d0f25090 Follow-up on: Fix integer overflow in CLpc_SynthesisLattice() original-Change-Id: I8fb194ffc073a3432a380845be71036a272d388f Fix signed integer overflow in _interpolateDrcGain() original-Change-Id: I879ec9ab14005069a7c47faf80e8bc6e03d22e60 Fix unsigned integer overflow in FDKreadBits() original-Change-Id: I1f47a6a8037ff70375aa8844947d5681bb4287ad Fix unsigned integer overflow in FDKbyteAlign() original-Change-Id: Id5f3a11a0c9e50fc6f76ed6c572dbd4e9f2af766 Fix unsigned integer overflow in FDK_get32() original-Change-Id: I9d33b8e97e3d38cbb80629cb859266ca0acdce96 Fix unsigned integer overflow in FDK_pushBack() original-Change-Id: Ic87f899bc8c6acf7a377a8ca7f3ba74c3a1e1c19 Fix unsigned integer overflow in FDK_pushForward() original-Change-Id: I3b754382f6776a34be1602e66694ede8e0b8effc Fix unsigned integer overflow in ReadPsData() original-Change-Id: I25361664ba8139e32bbbef2ca8c106a606ce9c37 Fix signed integer overflow in E_UTIL_residu() original-Change-Id: I8c3abd1f437ee869caa8fb5903ce7d3d641b6aad REVERT: Follow-up on: Integer overflow in CLpc_SynthesisLattice(). original-Change-Id: I3d340099acb0414795c8dfbe6362bc0a8f045f9b Follow-up on: Fix integer overflow in CLpc_SynthesisLattice() original-Change-Id: I4aedb8b3a187064e9f4d985175aa55bb99cc7590 Follow-up on: Fix unsigned integer overflow in aacDecoder_drcParse() original-Change-Id: I2aa2e13916213bf52a67e8b0518e7bf7e57fb37d Fix integer overflow in acelp original-Change-Id: Ie6390c136d84055f8b728aefbe4ebef6e029dc77 Fix unsigned integer overflow in aacDecoder_UpdateBitStreamCounters() original-Change-Id: I391ffd97ddb0b2c184cba76139bfb356a3b4d2e2 Adjust concealment default settings original-Change-Id: I6a95db935a327c47df348030bcceafcb29f54b21 Saturate estimatedStartPos original-Change-Id: I27be2085e0ae83ec9501409f65e003f6bcba1ab6 Negative shift exponent in _interpolateDrcGain() original-Change-Id: I18edb26b26d002aafd5e633d4914960f7a359c29 Negative shift exponent in calculateICC() original-Change-Id: I3dcd2ae98d2eb70ee0d59750863cbb2a6f4f8aba Too large shift exponent in FDK_put() original-Change-Id: Ib7d9aaa434d2d8de4a13b720ca0464b31ca9b671 Too large shift exponent in CalcInvLdData() original-Change-Id: I43e6e78d4cd12daeb1dcd5d82d1798bdc2550262 Member access within null pointer of type SBR_CHANNEL original-Change-Id: Idc5e4ea8997810376d2f36bbdf628923b135b097 Member access within null pointer of type CpePersistentData original-Change-Id: Ib6c91cb0d37882768e5baf63324e429589de0d9d Member access within null pointer FDKaacEnc_psyMain() original-Change-Id: I7729b7f4479970531d9dc823abff63ca52e01997 Member access within null pointer FDKaacEnc_GetPnsParam() original-Change-Id: I9aa3b9f3456ae2e0f7483dbd5b3dde95fc62da39 Member access within null pointer FDKsbrEnc_EnvEncodeFrame() original-Change-Id: I67936f90ea714e90b3e81bc0dd1472cc713eb23a Add HCR sanity check original-Change-Id: I6c1d9732ebcf6af12f50b7641400752f74be39f7 Fix memory issue for HBE edge case with 8:3 SBR original-Change-Id: I11ea58a61e69fbe8bf75034b640baee3011e63e9 Additional SBR parametrization sanity check for ELD original-Change-Id: Ie26026fbfe174c2c7b3691f6218b5ce63e322140 Add MPEG-D DRC channel layout check original-Change-Id: Iea70a74f171b227cce636a9eac4ba662777a2f72 Additional out-of-bounds checks in MPEG-D DRC original-Change-Id: Ife4a8c3452c6fde8a0a09e941154a39a769777d4 Change-Id: Ic63cb2f628720f54fe9b572b0cb528e2599c624e
Diffstat (limited to 'libMpegTPEnc/src/tpenc_asc.cpp')
-rw-r--r--libMpegTPEnc/src/tpenc_asc.cpp1026
1 files changed, 723 insertions, 303 deletions
diff --git a/libMpegTPEnc/src/tpenc_asc.cpp b/libMpegTPEnc/src/tpenc_asc.cpp
index bc4302e..ce4e364 100644
--- a/libMpegTPEnc/src/tpenc_asc.cpp
+++ b/libMpegTPEnc/src/tpenc_asc.cpp
@@ -1,74 +1,85 @@
-
-/* -----------------------------------------------------------------------------------------------------------
+/* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
-© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
- All rights reserved.
+© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
+Forschung e.V. All rights reserved.
1. INTRODUCTION
-The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
-the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
-This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
-
-AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
-audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
-independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
-of the MPEG specifications.
-
-Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
-may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
-individually for the purpose of encoding or decoding bit streams in products that are compliant with
-the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
-these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
-software may already be covered under those patent licenses when it is used for those licensed purposes only.
-
-Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
-are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
-applications information and documentation.
+The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
+that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
+scheme for digital audio. This FDK AAC Codec software is intended to be used on
+a wide variety of Android devices.
+
+AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
+general perceptual audio codecs. AAC-ELD is considered the best-performing
+full-bandwidth communications codec by independent studies and is widely
+deployed. AAC has been standardized by ISO and IEC as part of the MPEG
+specifications.
+
+Patent licenses for necessary patent claims for the FDK AAC Codec (including
+those of Fraunhofer) may be obtained through Via Licensing
+(www.vialicensing.com) or through the respective patent owners individually for
+the purpose of encoding or decoding bit streams in products that are compliant
+with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
+Android devices already license these patent claims through Via Licensing or
+directly from the patent owners, and therefore FDK AAC Codec software may
+already be covered under those patent licenses when it is used for those
+licensed purposes only.
+
+Commercially-licensed AAC software libraries, including floating-point versions
+with enhanced sound quality, are also available from Fraunhofer. Users are
+encouraged to check the Fraunhofer website for additional applications
+information and documentation.
2. COPYRIGHT LICENSE
-Redistribution and use in source and binary forms, with or without modification, are permitted without
-payment of copyright license fees provided that you satisfy the following conditions:
+Redistribution and use in source and binary forms, with or without modification,
+are permitted without payment of copyright license fees provided that you
+satisfy the following conditions:
-You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
-your modifications thereto in source code form.
+You must retain the complete text of this software license in redistributions of
+the FDK AAC Codec or your modifications thereto in source code form.
-You must retain the complete text of this software license in the documentation and/or other materials
-provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
-You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
+You must retain the complete text of this software license in the documentation
+and/or other materials provided with redistributions of the FDK AAC Codec or
+your modifications thereto in binary form. You must make available free of
+charge copies of the complete source code of the FDK AAC Codec and your
modifications thereto to recipients of copies in binary form.
-The name of Fraunhofer may not be used to endorse or promote products derived from this library without
-prior written permission.
+The name of Fraunhofer may not be used to endorse or promote products derived
+from this library without prior written permission.
-You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
-software or your modifications thereto.
+You may not charge copyright license fees for anyone to use, copy or distribute
+the FDK AAC Codec software or your modifications thereto.
-Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
-and the date of any change. For modified versions of the FDK AAC Codec, the term
-"Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
-"Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
+Your modified versions of the FDK AAC Codec must carry prominent notices stating
+that you changed the software and the date of any change. For modified versions
+of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
+must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
+AAC Codec Library for Android."
3. NO PATENT LICENSE
-NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
-ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
-respect to this software.
+NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
+limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
+Fraunhofer provides no warranty of patent non-infringement with respect to this
+software.
-You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
-by appropriate patent licenses.
+You may use this FDK AAC Codec software or modifications thereto only for
+purposes that are authorized by appropriate patent licenses.
4. DISCLAIMER
-This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
-"AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
-of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
-including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
-or business interruption, however caused and on any theory of liability, whether in contract, strict
-liability, or tort (including negligence), arising in any way out of the use of this software, even if
-advised of the possibility of such damage.
+This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
+holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
+including but not limited to the implied warranties of merchantability and
+fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
+or consequential damages, including but not limited to procurement of substitute
+goods or services; loss of use, data, or profits, or business interruption,
+however caused and on any theory of liability, whether in contract, strict
+liability, or tort (including negligence), arising in any way out of the use of
+this software, even if advised of the possibility of such damage.
5. CONTACT INFORMATION
@@ -79,14 +90,15 @@ Am Wolfsmantel 33
www.iis.fraunhofer.de/amm
amm-info@iis.fraunhofer.de
------------------------------------------------------------------------------------------------------------ */
+----------------------------------------------------------------------------- */
-/***************************** MPEG-4 AAC Encoder **************************
+/******************* MPEG transport format encoder library *********************
Author(s):
+
Description:
-******************************************************************************/
+*******************************************************************************/
#include "tp_data.h"
@@ -95,70 +107,162 @@ amm-info@iis.fraunhofer.de
#include "FDK_bitstream.h"
#include "genericStds.h"
-#define PCE_MAX_ELEMENTS 8
+#include "FDK_crc.h"
+
+#define PCE_HEIGHT_EXT_SYNC (0xAC)
+#define HEIGHT_NORMAL 0
+#define HEIGHT_TOP 1
+#define HEIGHT_BOTTOM 2
+#define MAX_FRONT_ELEMENTS 8
+#define MAX_SIDE_ELEMENTS 3
+#define MAX_BACK_ELEMENTS 4
/**
- * Describe a PCE based on placed channel elements and element type sequence.
+ * Describe additional PCE height information for front, side and back channel
+ * elements.
*/
typedef struct {
+ UCHAR
+ num_front_height_channel_elements[2]; /*!< Number of front channel
+ elements in top [0] and bottom
+ [1] plane. */
+ UCHAR num_side_height_channel_elements[2]; /*!< Number of side channel
+ elements in top [0] and bottom
+ [1] plane. */
+ UCHAR num_back_height_channel_elements[2]; /*!< Number of back channel
+ elements in top [0] and bottom
+ [1] plane. */
+} PCE_HEIGHT_NUM;
- UCHAR num_front_channel_elements; /*!< Number of front channel elements. */
- UCHAR num_side_channel_elements; /*!< Number of side channel elements. */
- UCHAR num_back_channel_elements; /*!< Number of back channel elements. */
- UCHAR num_lfe_channel_elements; /*!< Number of lfe channel elements. */
- MP4_ELEMENT_ID el_list[PCE_MAX_ELEMENTS];/*!< List contains sequence describing the elements
- in present channel mode. (MPEG order) */
+/**
+ * Describe a PCE based on placed channel elements and element type sequence.
+ */
+typedef struct {
+ UCHAR num_front_channel_elements; /*!< Number of front channel elements. */
+ UCHAR num_side_channel_elements; /*!< Number of side channel elements. */
+ UCHAR num_back_channel_elements; /*!< Number of back channel elements. */
+ UCHAR num_lfe_channel_elements; /*!< Number of lfe channel elements. */
+ const MP4_ELEMENT_ID
+ *pEl_type; /*!< List contains sequence describing the elements
+ in present channel mode. (MPEG order) */
+ const PCE_HEIGHT_NUM *pHeight_num;
} PCE_CONFIGURATION;
-
/**
* Map an incoming channel mode to a existing PCE configuration entry.
*/
typedef struct {
-
- CHANNEL_MODE channel_mode; /*!< Present channel mode. */
- PCE_CONFIGURATION pce_configuration; /*!< Program config element description. */
+ CHANNEL_MODE channel_mode; /*!< Present channel mode. */
+ PCE_CONFIGURATION
+ pce_configuration; /*!< Program config element description. */
} CHANNEL_CONFIGURATION;
-
/**
- * \brief Table contains all supported channel modes and according PCE configuration description.
- *
- * The number of channel element parameter describes the kind of consecutively elements.
- * E.g. MODE_1_2_2_2_1 means:
- * - First 3 elements (SCE,CPE,CPE) are front channel elements.
- * - Next element (CPE) is a back channel element.
- * - Last element (LFE) is a lfe channel element.
+ * The following arrays provide the IDs of the consecutive elements for each
+ * mode.
*/
-static const CHANNEL_CONFIGURATION pceConfigTab[] =
-{
- { MODE_1, { 1, 0, 0, 0, { ID_SCE, ID_NONE, ID_NONE, ID_NONE, ID_NONE, ID_NONE, ID_NONE, ID_NONE } } },
- { MODE_2, { 1, 0, 0, 0, { ID_CPE, ID_NONE, ID_NONE, ID_NONE, ID_NONE, ID_NONE, ID_NONE, ID_NONE } } },
- { MODE_1_2, { 2, 0, 0, 0, { ID_SCE, ID_CPE, ID_NONE, ID_NONE, ID_NONE, ID_NONE, ID_NONE, ID_NONE } } },
- { MODE_1_2_1, { 2, 0, 1, 0, { ID_SCE, ID_CPE, ID_SCE, ID_NONE, ID_NONE, ID_NONE, ID_NONE, ID_NONE } } },
- { MODE_1_2_2, { 2, 0, 1, 0, { ID_SCE, ID_CPE, ID_CPE, ID_NONE, ID_NONE, ID_NONE, ID_NONE, ID_NONE } } },
- { MODE_1_2_2_1, { 2, 0, 1, 1, { ID_SCE, ID_CPE, ID_CPE, ID_LFE, ID_NONE, ID_NONE, ID_NONE, ID_NONE } } },
- { MODE_1_2_2_2_1, { 3, 0, 1, 1, { ID_SCE, ID_CPE, ID_CPE, ID_CPE, ID_LFE, ID_NONE, ID_NONE, ID_NONE } } },
-
+static const MP4_ELEMENT_ID elType_1[] = {ID_SCE};
+static const MP4_ELEMENT_ID elType_2[] = {ID_CPE};
+static const MP4_ELEMENT_ID elType_1_2[] = {ID_SCE, ID_CPE};
+static const MP4_ELEMENT_ID elType_1_2_1[] = {ID_SCE, ID_CPE, ID_SCE};
+static const MP4_ELEMENT_ID elType_1_2_2[] = {ID_SCE, ID_CPE, ID_CPE};
+static const MP4_ELEMENT_ID elType_1_2_2_1[] = {ID_SCE, ID_CPE, ID_CPE, ID_LFE};
+static const MP4_ELEMENT_ID elType_1_2_2_2_1[] = {ID_SCE, ID_CPE, ID_CPE,
+ ID_CPE, ID_LFE};
+static const MP4_ELEMENT_ID elType_6_1[] = {ID_SCE, ID_CPE, ID_CPE, ID_SCE,
+ ID_LFE};
+static const MP4_ELEMENT_ID elType_7_1_back[] = {ID_SCE, ID_CPE, ID_CPE, ID_CPE,
+ ID_LFE};
+static const MP4_ELEMENT_ID elType_7_1_top_front[] = {ID_SCE, ID_CPE, ID_CPE,
+ ID_LFE, ID_CPE};
+static const MP4_ELEMENT_ID elType_7_1_rear_surround[] = {
+ ID_SCE, ID_CPE, ID_CPE, ID_CPE, ID_LFE};
+static const MP4_ELEMENT_ID elType_7_1_front_center[] = {ID_SCE, ID_CPE, ID_CPE,
+ ID_CPE, ID_LFE};
- { MODE_1_1, { 2, 0, 0, 0, { ID_SCE, ID_SCE, ID_NONE, ID_NONE, ID_NONE, ID_NONE, ID_NONE, ID_NONE } } },
- { MODE_1_1_1_1, { 2, 2, 0, 0, { ID_SCE, ID_SCE, ID_SCE, ID_SCE, ID_NONE, ID_NONE, ID_NONE, ID_NONE } } },
- { MODE_1_1_1_1_1_1, { 2, 2, 2, 0, { ID_SCE, ID_SCE, ID_SCE, ID_SCE, ID_SCE, ID_SCE, ID_NONE, ID_NONE } } },
- { MODE_1_1_1_1_1_1_1_1, { 3, 2, 3, 0, { ID_SCE, ID_SCE, ID_SCE, ID_SCE, ID_SCE, ID_SCE, ID_SCE, ID_SCE } } },
-
- { MODE_2_2, { 1, 0, 1, 0, { ID_CPE, ID_CPE, ID_NONE, ID_NONE, ID_NONE, ID_NONE, ID_NONE, ID_NONE } } },
- { MODE_2_2_2, { 1, 1, 1, 0, { ID_CPE, ID_CPE, ID_CPE, ID_NONE, ID_NONE, ID_NONE, ID_NONE, ID_NONE } } },
- { MODE_2_2_2_2, { 4, 0, 0, 0, { ID_CPE, ID_CPE, ID_CPE, ID_CPE, ID_NONE, ID_NONE, ID_NONE, ID_NONE } } },
-
- { MODE_2_1, { 1, 0, 1, 0, { ID_CPE, ID_SCE, ID_NONE, ID_NONE, ID_NONE, ID_NONE, ID_NONE, ID_NONE } } },
-
- { MODE_7_1_REAR_SURROUND, { 2, 0, 2, 1, { ID_SCE, ID_CPE, ID_CPE, ID_CPE, ID_LFE, ID_NONE, ID_NONE, ID_NONE } } },
- { MODE_7_1_FRONT_CENTER, { 3, 0, 1, 1, { ID_SCE, ID_CPE, ID_CPE, ID_CPE, ID_LFE, ID_NONE, ID_NONE, ID_NONE } } },
+/**
+ * The following arrays provide information on how many front, side and back
+ * elements are assigned to the top or bottom plane for each mode that comprises
+ * height information.
+ */
+static const PCE_HEIGHT_NUM heightNum_7_1_top_front = {{1, 0}, {0, 0}, {0, 0}};
+/**
+ * \brief Table contains all supported channel modes and according PCE
+ configuration description.
+ *
+ * The mode identifier is followed by the number of front, side, back, and LFE
+ elements.
+ * These are followed by a pointer to the IDs of the consecutive elements
+ (ID_SCE, ID_CPE, ID_LFE).
+ *
+ * For some modes (MODE_7_1_TOP_FRONT and MODE_22_2) additional height
+ information is transmitted.
+ * In this case the additional pointer provides information on how many front,
+ side and back elements
+ * are assigned to the top or bottom plane.The elements are arranged in the
+ following order: normal height (front, side, back, LFE), top height (front,
+ side, back), bottom height (front, side, back).
+ *
+ *
+ * E.g. MODE_7_1_TOP_FRONT means:
+ * - 3 elements are front channel elements.
+ * - 0 elements are side channel elements.
+ * - 1 element is back channel element.
+ * - 1 element is an LFE channel element.
+ * - the element order is ID_SCE, ID_CPE, ID_CPE,
+ ID_LFE, ID_CPE.
+ * - 1 of the front elements is in the top plane.
+ *
+ * This leads to the following mapping for the cconsecutive elements in the
+ MODE_7_1_TOP_FRONT bitstream:
+ * - ID_SCE -> normal height front,
+ - ID_CPE -> normal height front,
+ - ID_CPE -> normal height back,
+ - ID_LFE -> normal height LFE,
+ - ID_CPE -> top height front.
+ */
+static const CHANNEL_CONFIGURATION pceConfigTab[] = {
+ {MODE_1,
+ {1, 0, 0, 0, elType_1,
+ NULL}}, /* don't transmit height information in this mode */
+ {MODE_2,
+ {1, 0, 0, 0, elType_2,
+ NULL}}, /* don't transmit height information in this mode */
+ {MODE_1_2,
+ {2, 0, 0, 0, elType_1_2,
+ NULL}}, /* don't transmit height information in this mode */
+ {MODE_1_2_1,
+ {2, 0, 1, 0, elType_1_2_1,
+ NULL}}, /* don't transmit height information in this mode */
+ {MODE_1_2_2,
+ {2, 0, 1, 0, elType_1_2_2,
+ NULL}}, /* don't transmit height information in this mode */
+ {MODE_1_2_2_1,
+ {2, 0, 1, 1, elType_1_2_2_1,
+ NULL}}, /* don't transmit height information in this mode */
+ {MODE_1_2_2_2_1,
+ {3, 0, 1, 1, elType_1_2_2_2_1,
+ NULL}}, /* don't transmit height information in this mode */
+
+ {MODE_6_1,
+ {2, 0, 2, 1, elType_6_1,
+ NULL}}, /* don't transmit height information in this mode */
+ {MODE_7_1_BACK,
+ {2, 0, 2, 1, elType_7_1_back,
+ NULL}}, /* don't transmit height information in this mode */
+ {MODE_7_1_TOP_FRONT,
+ {3, 0, 1, 1, elType_7_1_top_front, &heightNum_7_1_top_front}},
+
+ {MODE_7_1_REAR_SURROUND,
+ {2, 0, 2, 1, elType_7_1_rear_surround,
+ NULL}}, /* don't transmit height information in this mode */
+ {MODE_7_1_FRONT_CENTER,
+ {3, 0, 1, 1, elType_7_1_front_center,
+ NULL}} /* don't transmit height information in this mode */
};
-
/**
* \brief Get program config element description for existing channel mode.
*
@@ -168,123 +272,260 @@ static const CHANNEL_CONFIGURATION pceConfigTab[] =
* - Pointer to PCE_CONFIGURATION entry, on success.
* - NULL, on failure.
*/
-static const PCE_CONFIGURATION* getPceEntry(
- const CHANNEL_MODE channel_mode
- )
-{
+static const PCE_CONFIGURATION *getPceEntry(const CHANNEL_MODE channel_mode) {
UINT i;
const PCE_CONFIGURATION *pce_config = NULL;
- for (i=0; i < (sizeof(pceConfigTab)/sizeof(CHANNEL_CONFIGURATION)); i++) {
+ for (i = 0; i < (sizeof(pceConfigTab) / sizeof(CHANNEL_CONFIGURATION)); i++) {
if (pceConfigTab[i].channel_mode == channel_mode) {
pce_config = &pceConfigTab[i].pce_configuration;
+ break;
}
}
return pce_config;
}
-int getChannelConfig( CHANNEL_MODE channel_mode )
-{
+int getChannelConfig(const CHANNEL_MODE channel_mode,
+ const UCHAR channel_config_zero) {
INT chan_config = 0;
- switch(channel_mode) {
- case MODE_1: chan_config = 1; break;
- case MODE_2: chan_config = 2; break;
- case MODE_1_2: chan_config = 3; break;
- case MODE_1_2_1: chan_config = 4; break;
- case MODE_1_2_2: chan_config = 5; break;
- case MODE_1_2_2_1: chan_config = 6; break;
- case MODE_1_2_2_2_1: chan_config = 7; break;
-
- default: chan_config = 0;
+ if (channel_config_zero != 0) {
+ chan_config = 0;
+ } else {
+ switch (channel_mode) {
+ case MODE_1:
+ chan_config = 1;
+ break;
+ case MODE_2:
+ chan_config = 2;
+ break;
+ case MODE_1_2:
+ chan_config = 3;
+ break;
+ case MODE_1_2_1:
+ chan_config = 4;
+ break;
+ case MODE_1_2_2:
+ chan_config = 5;
+ break;
+ case MODE_1_2_2_1:
+ chan_config = 6;
+ break;
+ case MODE_1_2_2_2_1:
+ chan_config = 7;
+ break;
+ case MODE_6_1:
+ chan_config = 11;
+ break;
+ case MODE_7_1_BACK:
+ chan_config = 12;
+ break;
+ case MODE_7_1_TOP_FRONT:
+ chan_config = 14;
+ break;
+ default:
+ chan_config = 0;
+ }
}
return chan_config;
}
-CHANNEL_MODE transportEnc_GetChannelMode( int noChannels )
-{
+CHANNEL_MODE transportEnc_GetChannelMode(int noChannels) {
CHANNEL_MODE chMode;
if (noChannels <= 8 && noChannels > 0)
- chMode = (CHANNEL_MODE)((noChannels == 8) ? 7 : noChannels); /* see : iso/mpeg4 v1 audio subpart1*/
+ chMode = (CHANNEL_MODE)(
+ (noChannels == 8) ? 7
+ : noChannels); /* see : iso/mpeg4 v1 audio subpart1*/
else
chMode = MODE_UNKNOWN;
return chMode;
}
-#ifdef TP_PCE_ENABLE
-int transportEnc_writePCE(HANDLE_FDK_BITSTREAM hBs,
- CHANNEL_MODE channelMode,
- INT sampleRate,
- int instanceTagPCE,
- int profile,
- int matrixMixdownA,
- int pseudoSurroundEnable,
- UINT alignAnchor)
-{
+int transportEnc_writePCE(HANDLE_FDK_BITSTREAM hBs, CHANNEL_MODE channelMode,
+ INT sampleRate, int instanceTagPCE, int profile,
+ int matrixMixdownA, int pseudoSurroundEnable,
+ UINT alignAnchor) {
int sampleRateIndex, i;
- const PCE_CONFIGURATION* config = NULL;
- const MP4_ELEMENT_ID* pEl_list = NULL;
- UCHAR cpeCnt=0, sceCnt=0, lfeCnt=0;
-
- sampleRateIndex = getSamplingRateIndex(sampleRate);
+ const PCE_CONFIGURATION *config = NULL;
+ const MP4_ELEMENT_ID *pEl_list = NULL;
+ UCHAR cpeCnt = 0, sceCnt = 0, lfeCnt = 0, frntCnt = 0, sdCnt = 0, bckCnt = 0,
+ isCpe = 0, tag = 0, normalFrontEnd = 0, normalSideEnd = 0,
+ normalBackEnd = 0, topFrontEnd = 0, topSideEnd = 0, topBackEnd = 0,
+ bottomFrontEnd = 0, bottomSideEnd = 0;
+#ifdef FDK_ASSERT_ENABLE
+ UCHAR bottomBackEnd = 0;
+#endif
+ enum elementDepth { FRONT, SIDE, BACK } elDepth;
+
+ sampleRateIndex = getSamplingRateIndex(sampleRate, 4);
if (sampleRateIndex == 15) {
return -1;
}
- if ((config=getPceEntry(channelMode))==NULL) {
+ if ((config = getPceEntry(channelMode)) == NULL) {
return -1;
}
- /* Pointer to first element in element list. */
- pEl_list = &config->el_list[0];
+ FDK_ASSERT(config->num_front_channel_elements <= MAX_FRONT_ELEMENTS);
+ FDK_ASSERT(config->num_side_channel_elements <= MAX_SIDE_ELEMENTS);
+ FDK_ASSERT(config->num_back_channel_elements <= MAX_BACK_ELEMENTS);
+
+ UCHAR frontIsCpe[MAX_FRONT_ELEMENTS] = {0},
+ frontTag[MAX_FRONT_ELEMENTS] = {0}, sideIsCpe[MAX_SIDE_ELEMENTS] = {0},
+ sideTag[MAX_SIDE_ELEMENTS] = {0}, backIsCpe[MAX_BACK_ELEMENTS] = {0},
+ backTag[MAX_BACK_ELEMENTS] = {0};
+
+ /* Write general information */
+
+ FDKwriteBits(hBs, instanceTagPCE, 4); /* Element instance tag */
+ FDKwriteBits(hBs, profile, 2); /* Object type */
+ FDKwriteBits(hBs, sampleRateIndex, 4); /* Sample rate index*/
+
+ FDKwriteBits(hBs, config->num_front_channel_elements,
+ 4); /* Front channel Elements */
+ FDKwriteBits(hBs, config->num_side_channel_elements,
+ 4); /* No Side Channel Elements */
+ FDKwriteBits(hBs, config->num_back_channel_elements,
+ 4); /* No Back channel Elements */
+ FDKwriteBits(hBs, config->num_lfe_channel_elements,
+ 2); /* No Lfe channel elements */
+
+ FDKwriteBits(hBs, 0, 3); /* No assoc data elements */
+ FDKwriteBits(hBs, 0, 4); /* No valid cc elements */
+ FDKwriteBits(hBs, 0, 1); /* Mono mixdown present */
+ FDKwriteBits(hBs, 0, 1); /* Stereo mixdown present */
+
+ if (matrixMixdownA != 0 &&
+ ((channelMode == MODE_1_2_2) || (channelMode == MODE_1_2_2_1))) {
+ FDKwriteBits(hBs, 1, 1); /* Matrix mixdown present */
+ FDKwriteBits(hBs, (matrixMixdownA - 1) & 0x3, 2); /* matrix_mixdown_idx */
+ FDKwriteBits(hBs, (pseudoSurroundEnable) ? 1 : 0,
+ 1); /* pseudo_surround_enable */
+ } else {
+ FDKwriteBits(hBs, 0, 1); /* Matrix mixdown not present */
+ }
- FDKwriteBits(hBs, instanceTagPCE, 4); /* Element instance tag */
- FDKwriteBits(hBs, profile, 2); /* Object type */
- FDKwriteBits(hBs, sampleRateIndex, 4); /* Sample rate index*/
+ if (config->pHeight_num != NULL) {
+ /* we have up to three different height levels, and in each height level we
+ * may have front, side and back channels. We need to know where each
+ * section ends to correctly count the tags */
+ normalFrontEnd = config->num_front_channel_elements -
+ config->pHeight_num->num_front_height_channel_elements[0] -
+ config->pHeight_num->num_front_height_channel_elements[1];
+ normalSideEnd = normalFrontEnd + config->num_side_channel_elements -
+ config->pHeight_num->num_side_height_channel_elements[0] -
+ config->pHeight_num->num_side_height_channel_elements[1];
+ normalBackEnd = normalSideEnd + config->num_back_channel_elements -
+ config->pHeight_num->num_back_height_channel_elements[0] -
+ config->pHeight_num->num_back_height_channel_elements[1];
+
+ topFrontEnd =
+ normalBackEnd + config->num_lfe_channel_elements +
+ config->pHeight_num->num_front_height_channel_elements[0]; /* only
+ normal
+ height
+ LFEs
+ assumed */
+ topSideEnd =
+ topFrontEnd + config->pHeight_num->num_side_height_channel_elements[0];
+ topBackEnd =
+ topSideEnd + config->pHeight_num->num_back_height_channel_elements[0];
+
+ bottomFrontEnd =
+ topBackEnd + config->pHeight_num->num_front_height_channel_elements[1];
+ bottomSideEnd = bottomFrontEnd +
+ config->pHeight_num->num_side_height_channel_elements[1];
+#ifdef FDK_ASSERT_ENABLE
+ bottomBackEnd = bottomSideEnd +
+ config->pHeight_num->num_back_height_channel_elements[1];
+#endif
+
+ } else {
+ /* we have only one height level, so we don't care about top or bottom */
+ normalFrontEnd = config->num_front_channel_elements;
+ normalSideEnd = normalFrontEnd + config->num_side_channel_elements;
+ normalBackEnd = normalSideEnd + config->num_back_channel_elements;
+ }
- FDKwriteBits(hBs, config->num_front_channel_elements, 4); /* Front channel Elements */
- FDKwriteBits(hBs, config->num_side_channel_elements , 4); /* No Side Channel Elements */
- FDKwriteBits(hBs, config->num_back_channel_elements , 4); /* No Back channel Elements */
- FDKwriteBits(hBs, config->num_lfe_channel_elements , 2); /* No Lfe channel elements */
+ /* assign cpe and tag information to either front, side or back channels */
- FDKwriteBits(hBs, 0, 3); /* No assoc data elements */
- FDKwriteBits(hBs, 0, 4); /* No valid cc elements */
- FDKwriteBits(hBs, 0, 1); /* Mono mixdown present */
- FDKwriteBits(hBs, 0, 1); /* Stereo mixdown present */
+ pEl_list = config->pEl_type;
- if ( matrixMixdownA!=0 && ((channelMode==MODE_1_2_2)||(channelMode==MODE_1_2_2_1)) ) {
- FDKwriteBits(hBs, 1, 1); /* Matrix mixdown present */
- FDKwriteBits(hBs, (matrixMixdownA-1)&0x3, 2); /* matrix_mixdown_idx */
- FDKwriteBits(hBs, (pseudoSurroundEnable)?1:0, 1); /* pseudo_surround_enable */
- }
- else {
- FDKwriteBits(hBs, 0, 1); /* Matrix mixdown not present */
+ for (i = 0; i < config->num_front_channel_elements +
+ config->num_side_channel_elements +
+ config->num_back_channel_elements +
+ config->num_lfe_channel_elements;
+ i++) {
+ if (*pEl_list == ID_LFE) {
+ pEl_list++;
+ continue;
+ }
+ isCpe = (*pEl_list++ == ID_CPE) ? 1 : 0;
+ tag = (isCpe) ? cpeCnt++ : sceCnt++;
+
+ if (i < normalFrontEnd)
+ elDepth = FRONT;
+ else if (i < normalSideEnd)
+ elDepth = SIDE;
+ else if (i < normalBackEnd)
+ elDepth = BACK;
+ else if (i < topFrontEnd)
+ elDepth = FRONT;
+ else if (i < topSideEnd)
+ elDepth = SIDE;
+ else if (i < topBackEnd)
+ elDepth = BACK;
+ else if (i < bottomFrontEnd)
+ elDepth = FRONT;
+ else if (i < bottomSideEnd)
+ elDepth = SIDE;
+ else {
+ elDepth = BACK;
+ FDK_ASSERT(i < bottomBackEnd); /* won't fail if implementation of pce
+ configuration table is correct */
+ }
+
+ switch (elDepth) {
+ case FRONT:
+ FDK_ASSERT(frntCnt < config->num_front_channel_elements);
+ frontIsCpe[frntCnt] = isCpe;
+ frontTag[frntCnt++] = tag;
+ break;
+ case SIDE:
+ FDK_ASSERT(sdCnt < config->num_side_channel_elements);
+ sideIsCpe[sdCnt] = isCpe;
+ sideTag[sdCnt++] = tag;
+ break;
+ case BACK:
+ FDK_ASSERT(bckCnt < config->num_back_channel_elements);
+ backIsCpe[bckCnt] = isCpe;
+ backTag[bckCnt++] = tag;
+ break;
+ }
}
- for(i=0; i<config->num_front_channel_elements; i++) {
- UCHAR isCpe = (*pEl_list++==ID_CPE) ? 1 : 0;
- UCHAR tag = (isCpe) ? cpeCnt++ : sceCnt++;
- FDKwriteBits(hBs, isCpe, 1); /* Front channel Elements is CPE? */
- FDKwriteBits(hBs, tag, 4); /* Front channel Instance Tag.*/
+ /* Write front channel isCpe and tags */
+ for (i = 0; i < config->num_front_channel_elements; i++) {
+ FDKwriteBits(hBs, frontIsCpe[i], 1);
+ FDKwriteBits(hBs, frontTag[i], 4);
}
- for(i=0; i<config->num_side_channel_elements; i++) {
- UCHAR isCpe = (*pEl_list++==ID_CPE) ? 1 : 0;
- UCHAR tag = (isCpe) ? cpeCnt++ : sceCnt++;
- FDKwriteBits(hBs, isCpe, 1); /* Front channel Elements is CPE? */
- FDKwriteBits(hBs, tag, 4); /* Front channel Instance Tag.*/
+ /* Write side channel isCpe and tags */
+ for (i = 0; i < config->num_side_channel_elements; i++) {
+ FDKwriteBits(hBs, sideIsCpe[i], 1);
+ FDKwriteBits(hBs, sideTag[i], 4);
}
- for(i=0; i<config->num_back_channel_elements; i++) {
- UCHAR isCpe = (*pEl_list++==ID_CPE) ? 1 : 0;
- UCHAR tag = (isCpe) ? cpeCnt++ : sceCnt++;
- FDKwriteBits(hBs, isCpe, 1); /* Front channel Elements is CPE? */
- FDKwriteBits(hBs, tag, 4); /* Front channel Instance Tag.*/
+ /* Write back channel isCpe and tags */
+ for (i = 0; i < config->num_back_channel_elements; i++) {
+ FDKwriteBits(hBs, backIsCpe[i], 1);
+ FDKwriteBits(hBs, backTag[i], 4);
}
- for(i=0; i<config->num_lfe_channel_elements; i++) {
- FDKwriteBits(hBs, lfeCnt++, 4); /* LFE channel Instance Tag. */
+ /* Write LFE information */
+ for (i = 0; i < config->num_lfe_channel_elements; i++) {
+ FDKwriteBits(hBs, lfeCnt++, 4); /* LFE channel Instance Tag. */
}
/* - num_valid_cc_elements always 0.
@@ -294,167 +535,348 @@ int transportEnc_writePCE(HANDLE_FDK_BITSTREAM hBs,
ADTS: align with respect to the first bit of the raw_data_block()
ADIF: align with respect to the first bit of the header
LATM: align with respect to the first bit of the ASC */
- FDKbyteAlign(hBs, alignAnchor); /* Alignment */
-
- FDKwriteBits(hBs, 0 ,8); /* Do no write any comment. */
-
- /* - comment_field_bytes always 0. */
+ FDKbyteAlign(hBs, alignAnchor); /* Alignment */
+
+ /* Write comment information */
+
+ if (config->pHeight_num != NULL) {
+ /* embed height information in comment field */
+
+ INT commentBytes =
+ 1 /* PCE_HEIGHT_EXT_SYNC */
+ + ((((config->num_front_channel_elements +
+ config->num_side_channel_elements +
+ config->num_back_channel_elements)
+ << 1) +
+ 7) >>
+ 3) /* 2 bit height info per element, round up to full bytes */
+ + 1; /* CRC */
+
+ FDKwriteBits(hBs, commentBytes, 8); /* comment size. */
+
+ FDK_CRCINFO crcInfo; /* CRC state info */
+ INT crcReg;
+
+ FDKcrcInit(&crcInfo, 0x07, 0xFF, 8);
+ crcReg = FDKcrcStartReg(&crcInfo, hBs, 0);
+
+ FDKwriteBits(hBs, PCE_HEIGHT_EXT_SYNC, 8); /* indicate height extension */
+
+ /* front channel height information */
+ for (i = 0;
+ i < config->num_front_channel_elements -
+ config->pHeight_num->num_front_height_channel_elements[0] -
+ config->pHeight_num->num_front_height_channel_elements[1];
+ i++)
+ FDKwriteBits(hBs, HEIGHT_NORMAL, 2);
+ for (i = 0; i < config->pHeight_num->num_front_height_channel_elements[0];
+ i++)
+ FDKwriteBits(hBs, HEIGHT_TOP, 2);
+ for (i = 0; i < config->pHeight_num->num_front_height_channel_elements[1];
+ i++)
+ FDKwriteBits(hBs, HEIGHT_BOTTOM, 2);
+
+ /* side channel height information */
+ for (i = 0;
+ i < config->num_side_channel_elements -
+ config->pHeight_num->num_side_height_channel_elements[0] -
+ config->pHeight_num->num_side_height_channel_elements[1];
+ i++)
+ FDKwriteBits(hBs, HEIGHT_NORMAL, 2);
+ for (i = 0; i < config->pHeight_num->num_side_height_channel_elements[0];
+ i++)
+ FDKwriteBits(hBs, HEIGHT_TOP, 2);
+ for (i = 0; i < config->pHeight_num->num_side_height_channel_elements[1];
+ i++)
+ FDKwriteBits(hBs, HEIGHT_BOTTOM, 2);
+
+ /* back channel height information */
+ for (i = 0;
+ i < config->num_back_channel_elements -
+ config->pHeight_num->num_back_height_channel_elements[0] -
+ config->pHeight_num->num_back_height_channel_elements[1];
+ i++)
+ FDKwriteBits(hBs, HEIGHT_NORMAL, 2);
+ for (i = 0; i < config->pHeight_num->num_back_height_channel_elements[0];
+ i++)
+ FDKwriteBits(hBs, HEIGHT_TOP, 2);
+ for (i = 0; i < config->pHeight_num->num_back_height_channel_elements[1];
+ i++)
+ FDKwriteBits(hBs, HEIGHT_BOTTOM, 2);
+
+ FDKbyteAlign(hBs, alignAnchor); /* Alignment */
+
+ FDKcrcEndReg(&crcInfo, hBs, crcReg);
+ FDKwriteBits(hBs, FDKcrcGetCRC(&crcInfo), 8);
+
+ } else {
+ FDKwriteBits(hBs, 0,
+ 8); /* Do no write any comment or height information. */
+ }
return 0;
}
-int transportEnc_GetPCEBits(CHANNEL_MODE channelMode,
- int matrixMixdownA,
- int bits)
-{
- const PCE_CONFIGURATION* config = NULL;
+int transportEnc_GetPCEBits(CHANNEL_MODE channelMode, int matrixMixdownA,
+ int bits) {
+ const PCE_CONFIGURATION *config = NULL;
- if ((config=getPceEntry(channelMode))==NULL) {
- return -1; /* unsupported channelmapping */
+ if ((config = getPceEntry(channelMode)) == NULL) {
+ return -1; /* unsupported channelmapping */
}
- bits += 4 + 2 + 4; /* Element instance tag + Object type + Sample rate index */
- bits += 4 + 4 + 4 + 2; /* No (front + side + back + lfe channel) elements */
- bits += 3 + 4; /* No (assoc data + valid cc) elements */
- bits += 1 + 1 + 1 ; /* Mono + Stereo + Matrix mixdown present */
+ bits +=
+ 4 + 2 + 4; /* Element instance tag + Object type + Sample rate index */
+ bits += 4 + 4 + 4 + 2; /* No (front + side + back + lfe channel) elements */
+ bits += 3 + 4; /* No (assoc data + valid cc) elements */
+ bits += 1 + 1 + 1; /* Mono + Stereo + Matrix mixdown present */
- if ( matrixMixdownA!=0 && ((channelMode==MODE_1_2_2)||(channelMode==MODE_1_2_2_1)) ) {
- bits +=3; /* matrix_mixdown_idx + pseudo_surround_enable */
+ if (matrixMixdownA != 0 &&
+ ((channelMode == MODE_1_2_2) || (channelMode == MODE_1_2_2_1))) {
+ bits += 3; /* matrix_mixdown_idx + pseudo_surround_enable */
}
- bits += (1+4) * (INT)config->num_front_channel_elements;
- bits += (1+4) * (INT)config->num_side_channel_elements;
- bits += (1+4) * (INT)config->num_back_channel_elements;
- bits += (4) * (INT)config->num_lfe_channel_elements;
+ bits += (1 + 4) * (INT)config->num_front_channel_elements;
+ bits += (1 + 4) * (INT)config->num_side_channel_elements;
+ bits += (1 + 4) * (INT)config->num_back_channel_elements;
+ bits += (4) * (INT)config->num_lfe_channel_elements;
/* - num_valid_cc_elements always 0.
- num_assoc_data_elements always 0. */
- if ((bits%8) != 0) {
- bits += (8 - (bits%8)); /* Alignment */
+ if ((bits % 8) != 0) {
+ bits += (8 - (bits % 8)); /* Alignment */
}
- bits += 8; /* Comment field bytes */
+ bits += 8; /* Comment field bytes */
+
+ if (config->pHeight_num != NULL) {
+ /* Comment field (height extension) */
+
+ bits +=
+ 8 /* PCE_HEIGHT_EXT_SYNC */
+ +
+ ((config->num_front_channel_elements +
+ config->num_side_channel_elements + config->num_back_channel_elements)
+ << 1) /* 2 bit height info per element */
+ + 8; /* CRC */
- /* - comment_field_bytes alwys 0. */
+ if ((bits % 8) != 0) {
+ bits += (8 - (bits % 8)); /* Alignment */
+ }
+ }
return bits;
}
-#endif /* TP_PCE_ENABLE */
-static void writeAot(HANDLE_FDK_BITSTREAM hBitstreamBuffer, AUDIO_OBJECT_TYPE aot)
-{
- int tmp = (int) aot;
+static void writeAot(HANDLE_FDK_BITSTREAM hBitstreamBuffer,
+ AUDIO_OBJECT_TYPE aot) {
+ int tmp = (int)aot;
- if (tmp > 31) {
- FDKwriteBits( hBitstreamBuffer, AOT_ESCAPE, 5 );
- FDKwriteBits( hBitstreamBuffer, tmp-32, 6 ); /* AudioObjectType */
- } else {
- FDKwriteBits( hBitstreamBuffer, tmp, 5 );
- }
+ if (tmp > 31) {
+ FDKwriteBits(hBitstreamBuffer, AOT_ESCAPE, 5);
+ FDKwriteBits(hBitstreamBuffer, tmp - 32, 6); /* AudioObjectType */
+ } else {
+ FDKwriteBits(hBitstreamBuffer, tmp, 5);
+ }
}
-static void writeSampleRate(HANDLE_FDK_BITSTREAM hBitstreamBuffer, int sampleRate)
-{
- int sampleRateIndex = getSamplingRateIndex(sampleRate);
+static void writeSampleRate(HANDLE_FDK_BITSTREAM hBs, int sampleRate,
+ int nBits) {
+ int srIdx = getSamplingRateIndex(sampleRate, nBits);
- FDKwriteBits( hBitstreamBuffer, sampleRateIndex, 4 );
- if( sampleRateIndex == 15 ) {
- FDKwriteBits( hBitstreamBuffer, sampleRate, 24 );
+ FDKwriteBits(hBs, srIdx, nBits);
+ if (srIdx == (1 << nBits) - 1) {
+ FDKwriteBits(hBs, sampleRate, 24);
}
}
-#ifdef TP_GA_ENABLE
-static
-int transportEnc_writeGASpecificConfig(
- HANDLE_FDK_BITSTREAM asc,
- CODER_CONFIG *config,
- int extFlg,
- UINT alignAnchor
- )
-{
+static int transportEnc_writeGASpecificConfig(HANDLE_FDK_BITSTREAM asc,
+ CODER_CONFIG *config, int extFlg,
+ UINT alignAnchor) {
int aot = config->aot;
int samplesPerFrame = config->samplesPerFrame;
/* start of GASpecificConfig according to ISO/IEC 14496-3 Subpart 4, 4.4.1 */
- FDKwriteBits( asc, ((samplesPerFrame==960 || samplesPerFrame==480)?1:0), 1); /* frameLengthFlag: 1 for a 960/480 (I)MDCT, 0 for a 1024/512 (I)MDCT*/
- FDKwriteBits( asc, 0, 1); /* dependsOnCoreCoder: Sampling Rate Coder Specific, see in ISO/IEC 14496-3 Subpart 4, 4.4.1 */
- FDKwriteBits( asc, extFlg, 1 ); /* Extension Flag: Shall be 1 for aot = 17,19,20,21,22,23 */
+ FDKwriteBits(asc,
+ ((samplesPerFrame == 960 || samplesPerFrame == 480) ? 1 : 0),
+ 1); /* frameLengthFlag: 1 for a 960/480 (I)MDCT, 0 for a 1024/512
+ (I)MDCT*/
+ FDKwriteBits(asc, 0,
+ 1); /* dependsOnCoreCoder: Sampling Rate Coder Specific, see in
+ ISO/IEC 14496-3 Subpart 4, 4.4.1 */
+ FDKwriteBits(asc, extFlg,
+ 1); /* Extension Flag: Shall be 1 for aot = 17,19,20,21,22,23 */
/* Write PCE if channel config is not 1-7 */
- if (getChannelConfig(config->channelMode) == 0) {
- transportEnc_writePCE(asc, config->channelMode, config->samplingRate, 0, 1, config->matrixMixdownA, (config->flags&CC_PSEUDO_SURROUND)?1:0, alignAnchor);
+ if (getChannelConfig(config->channelMode, config->channelConfigZero) == 0) {
+ transportEnc_writePCE(asc, config->channelMode, config->samplingRate, 0, 1,
+ config->matrixMixdownA,
+ (config->flags & CC_PSEUDO_SURROUND) ? 1 : 0,
+ alignAnchor);
+ }
+ if ((aot == AOT_AAC_SCAL) || (aot == AOT_ER_AAC_SCAL)) {
+ FDKwriteBits(asc, 0, 3); /* layerNr */
}
if (extFlg) {
if (aot == AOT_ER_BSAC) {
- FDKwriteBits( asc, config->BSACnumOfSubFrame, 5 ); /* numOfSubFrame */
- FDKwriteBits( asc, config->BSAClayerLength, 11 ); /* layer_length */
+ FDKwriteBits(asc, config->BSACnumOfSubFrame, 5); /* numOfSubFrame */
+ FDKwriteBits(asc, config->BSAClayerLength, 11); /* layer_length */
}
- if ((aot == AOT_ER_AAC_LC) || (aot == AOT_ER_AAC_LTP) ||
- (aot == AOT_ER_AAC_SCAL) || (aot == AOT_ER_AAC_LD))
- {
- FDKwriteBits( asc, (config->flags & CC_VCB11) ? 1 : 0, 1 ); /* aacSectionDataResillienceFlag */
- FDKwriteBits( asc, (config->flags & CC_RVLC) ? 1 : 0, 1 ); /* aacScaleFactorDataResillienceFlag */
- FDKwriteBits( asc, (config->flags & CC_HCR) ? 1 : 0, 1 ); /* aacSpectralDataResillienceFlag */
+ if ((aot == AOT_ER_AAC_LC) || (aot == AOT_ER_AAC_LTP) ||
+ (aot == AOT_ER_AAC_SCAL) || (aot == AOT_ER_AAC_LD)) {
+ FDKwriteBits(asc, (config->flags & CC_VCB11) ? 1 : 0,
+ 1); /* aacSectionDataResillienceFlag */
+ FDKwriteBits(asc, (config->flags & CC_RVLC) ? 1 : 0,
+ 1); /* aacScaleFactorDataResillienceFlag */
+ FDKwriteBits(asc, (config->flags & CC_HCR) ? 1 : 0,
+ 1); /* aacSpectralDataResillienceFlag */
}
- FDKwriteBits( asc, 0, 1 ); /* extensionFlag3: reserved. Shall be '0' */
+ FDKwriteBits(asc, 0, 1); /* extensionFlag3: reserved. Shall be '0' */
}
return 0;
}
-#endif /* TP_GA_ENABLE */
-
-#ifdef TP_ELD_ENABLE
-
-static
-int transportEnc_writeELDSpecificConfig(
- HANDLE_FDK_BITSTREAM hBs,
- CODER_CONFIG *config,
- int epConfig,
- CSTpCallBacks *cb
- )
-{
- /* ELD specific config */
- if (config->channelMode == MODE_1_1) {
- return -1;
+
+static int transportEnc_writeELDSpecificConfig(HANDLE_FDK_BITSTREAM hBs,
+ CODER_CONFIG *config,
+ int epConfig,
+ CSTpCallBacks *cb) {
+ UINT frameLengthFlag = 0;
+ switch (config->samplesPerFrame) {
+ case 512:
+ case 256:
+ case 128:
+ case 64:
+ frameLengthFlag = 0;
+ break;
+ case 480:
+ case 240:
+ case 160:
+ case 120:
+ case 60:
+ frameLengthFlag = 1;
+ break;
}
- FDKwriteBits(hBs, (config->samplesPerFrame == 480) ? 1 : 0, 1);
- FDKwriteBits(hBs, (config->flags & CC_VCB11 ) ? 1:0, 1);
- FDKwriteBits(hBs, (config->flags & CC_RVLC ) ? 1:0, 1);
- FDKwriteBits(hBs, (config->flags & CC_HCR ) ? 1:0, 1);
+ FDKwriteBits(hBs, frameLengthFlag, 1);
+
+ FDKwriteBits(hBs, (config->flags & CC_VCB11) ? 1 : 0, 1);
+ FDKwriteBits(hBs, (config->flags & CC_RVLC) ? 1 : 0, 1);
+ FDKwriteBits(hBs, (config->flags & CC_HCR) ? 1 : 0, 1);
- FDKwriteBits(hBs, (config->flags & CC_SBR) ? 1:0, 1); /* SBR header flag */
- if ( (config->flags & CC_SBR) ) {
- FDKwriteBits(hBs, (config->samplingRate == config->extSamplingRate) ? 0:1, 1); /* Samplerate Flag */
- FDKwriteBits(hBs, (config->flags & CC_SBRCRC) ? 1:0, 1); /* SBR CRC flag*/
+ FDKwriteBits(hBs, (config->flags & CC_SBR) ? 1 : 0, 1); /* SBR header flag */
+ if ((config->flags & CC_SBR)) {
+ FDKwriteBits(hBs, (config->samplingRate == config->extSamplingRate) ? 0 : 1,
+ 1); /* Samplerate Flag */
+ FDKwriteBits(hBs, (config->flags & CC_SBRCRC) ? 1 : 0, 1); /* SBR CRC flag*/
if (cb->cbSbr != NULL) {
const PCE_CONFIGURATION *pPce;
- int e;
+ int e, sbrElementIndex = 0;
pPce = getPceEntry(config->channelMode);
- for (e=0; e<PCE_MAX_ELEMENTS && pPce->el_list[e] != ID_NONE; e++ ) {
- if ( (pPce->el_list[e] == ID_SCE) || (pPce->el_list[e] == ID_CPE) ) {
- cb->cbSbr(cb->cbSbrData, hBs, 0, 0, 0, config->aot, pPce->el_list[e], e);
+ for (e = 0; e < pPce->num_front_channel_elements +
+ pPce->num_side_channel_elements +
+ pPce->num_back_channel_elements +
+ pPce->num_lfe_channel_elements;
+ e++) {
+ if ((pPce->pEl_type[e] == ID_SCE) || (pPce->pEl_type[e] == ID_CPE)) {
+ cb->cbSbr(cb->cbSbrData, hBs, 0, 0, 0, config->aot, pPce->pEl_type[e],
+ sbrElementIndex, 0, 0, 0, NULL, 1);
+ sbrElementIndex++;
}
}
}
}
- FDKwriteBits(hBs, 0, 4); /* ELDEXT_TERM */
+ if ((config->flags & CC_SAC) && (cb->cbSsc != NULL)) {
+ FDKwriteBits(hBs, ELDEXT_LDSAC, 4);
+
+ const INT eldExtLen =
+ (cb->cbSsc(cb->cbSscData, NULL, config->aot, config->extSamplingRate, 0,
+ 0, 0, 0, NULL) +
+ 7) >>
+ 3;
+ INT cnt = eldExtLen;
+
+ if (cnt < 0xF) {
+ FDKwriteBits(hBs, cnt, 4);
+ } else {
+ FDKwriteBits(hBs, 0xF, 4);
+ cnt -= 0xF;
+
+ if (cnt < 0xFF) {
+ FDKwriteBits(hBs, cnt, 8);
+ } else {
+ FDKwriteBits(hBs, 0xFF, 8);
+ cnt -= 0xFF;
+
+ FDK_ASSERT(cnt <= 0xFFFF);
+ FDKwriteBits(hBs, cnt, 16);
+ }
+ }
+
+ cb->cbSsc(cb->cbSscData, hBs, config->aot, config->extSamplingRate, 0, 0, 0,
+ 0, NULL);
+ }
+
+ if (config->downscaleSamplingRate != 0 &&
+ config->downscaleSamplingRate != config->extSamplingRate) {
+ /* downscale active */
+
+ /* eldExtLenDsc: Number of bytes for the ELD downscale extension (srIdx
+ needs 1 byte
+ + downscaleSamplingRate needs additional 3 bytes) */
+ int eldExtLenDsc = 1;
+ int downscaleSamplingRate = config->downscaleSamplingRate;
+ FDKwriteBits(hBs, ELDEXT_DOWNSCALEINFO, 4); /* ELDEXT_DOWNSCALEINFO */
+
+ if ((downscaleSamplingRate != 96000) && (downscaleSamplingRate != 88200) &&
+ (downscaleSamplingRate != 64000) && (downscaleSamplingRate != 48000) &&
+ (downscaleSamplingRate != 44100) && (downscaleSamplingRate != 32000) &&
+ (downscaleSamplingRate != 24000) && (downscaleSamplingRate != 22050) &&
+ (downscaleSamplingRate != 16000) && (downscaleSamplingRate != 12000) &&
+ (downscaleSamplingRate != 11025) && (downscaleSamplingRate != 8000) &&
+ (downscaleSamplingRate != 7350)) {
+ eldExtLenDsc = 4; /* length extends to 4 if downscaleSamplingRate's value
+ is not one of the listed values */
+ }
+
+ FDKwriteBits(hBs, eldExtLenDsc, 4);
+ writeSampleRate(hBs, downscaleSamplingRate, 4);
+ FDKwriteBits(hBs, 0x0, 4); /* fill_nibble */
+ }
+
+ FDKwriteBits(hBs, ELDEXT_TERM, 4); /* ELDEXT_TERM */
return 0;
}
-#endif /* TP_ELD_ENABLE */
+static int transportEnc_writeUsacSpecificConfig(HANDLE_FDK_BITSTREAM hBs,
+ int extFlag, CODER_CONFIG *cc,
+ CSTpCallBacks *cb) {
+ FDK_BITSTREAM usacConf;
+ int usacConfigBits = cc->rawConfigBits;
+
+ if ((usacConfigBits <= 0) ||
+ ((usacConfigBits + 7) / 8 > (int)sizeof(cc->rawConfig))) {
+ return TRANSPORTENC_UNSUPPORTED_FORMAT;
+ }
+ FDKinitBitStream(&usacConf, cc->rawConfig, BUFSIZE_DUMMY_VALUE,
+ usacConfigBits, BS_READER);
+
+ for (; usacConfigBits > 0; usacConfigBits--) {
+ UINT tmp = FDKreadBit(&usacConf);
+ FDKwriteBits(hBs, tmp, 1);
+ }
+ FDKsyncCache(hBs);
+
+ return TRANSPORTENC_OK;
+}
-int transportEnc_writeASC (
- HANDLE_FDK_BITSTREAM asc,
- CODER_CONFIG *config,
- CSTpCallBacks *cb
- )
-{
+int transportEnc_writeASC(HANDLE_FDK_BITSTREAM asc, CODER_CONFIG *config,
+ CSTpCallBacks *cb) {
UINT extFlag = 0;
int err;
int epConfig = 0;
@@ -472,37 +894,35 @@ int transportEnc_writeASC (
case AOT_ER_AAC_LD:
case AOT_ER_AAC_ELD:
case AOT_USAC:
- extFlag = 1;
- break;
+ extFlag = 1;
+ break;
default:
- break;
+ break;
}
- if (config->sbrSignaling==SIG_EXPLICIT_HIERARCHICAL && config->sbrPresent)
+ if (config->sbrSignaling == SIG_EXPLICIT_HIERARCHICAL && config->sbrPresent)
writeAot(asc, config->extAOT);
else
writeAot(asc, config->aot);
- {
- writeSampleRate(asc, config->samplingRate);
- }
+ /* In case of USAC it is the output not the core sampling rate */
+ writeSampleRate(asc, config->samplingRate, 4);
/* Try to guess a reasonable channel mode if not given */
if (config->channelMode == MODE_INVALID) {
config->channelMode = transportEnc_GetChannelMode(config->noChannels);
- if (config->channelMode == MODE_INVALID)
- return -1;
+ if (config->channelMode == MODE_INVALID) return -1;
}
- FDKwriteBits( asc, getChannelConfig(config->channelMode), 4 );
+ FDKwriteBits(
+ asc, getChannelConfig(config->channelMode, config->channelConfigZero), 4);
- if (config->sbrSignaling==SIG_EXPLICIT_HIERARCHICAL && config->sbrPresent) {
- writeSampleRate(asc, config->extSamplingRate);
+ if (config->sbrSignaling == SIG_EXPLICIT_HIERARCHICAL && config->sbrPresent) {
+ writeSampleRate(asc, config->extSamplingRate, 4);
writeAot(asc, config->aot);
}
switch (config->aot) {
-#ifdef TP_GA_ENABLE
case AOT_AAC_MAIN:
case AOT_AAC_LC:
case AOT_AAC_SSR:
@@ -515,18 +935,20 @@ int transportEnc_writeASC (
case AOT_ER_TWIN_VQ:
case AOT_ER_BSAC:
case AOT_ER_AAC_LD:
- err = transportEnc_writeGASpecificConfig(asc, config, extFlag, alignAnchor);
- if (err)
- return err;
+ err =
+ transportEnc_writeGASpecificConfig(asc, config, extFlag, alignAnchor);
+ if (err) return err;
break;
-#endif /* TP_GA_ENABLE */
-#ifdef TP_ELD_ENABLE
case AOT_ER_AAC_ELD:
err = transportEnc_writeELDSpecificConfig(asc, config, epConfig, cb);
- if (err)
+ if (err) return err;
+ break;
+ case AOT_USAC:
+ err = transportEnc_writeUsacSpecificConfig(asc, extFlag, config, cb);
+ if (err) {
return err;
+ }
break;
-#endif /* TP_ELD_ENABLE */
default:
return -1;
}
@@ -543,34 +965,32 @@ int transportEnc_writeASC (
case AOT_ER_HILN:
case AOT_ER_PARA:
case AOT_ER_AAC_ELD:
- FDKwriteBits( asc, 0, 2 ); /* epconfig 0 */
+ FDKwriteBits(asc, 0, 2); /* epconfig 0 */
break;
default:
break;
}
/* backward compatible explicit signaling of extension AOT */
- if (config->sbrSignaling==SIG_EXPLICIT_BW_COMPATIBLE)
- {
+ if (config->sbrSignaling == SIG_EXPLICIT_BW_COMPATIBLE) {
TP_ASC_EXTENSION_ID ascExtId = ASCEXT_UNKOWN;
if (config->sbrPresent) {
- ascExtId=ASCEXT_SBR;
- FDKwriteBits( asc, ascExtId, 11 );
+ ascExtId = ASCEXT_SBR;
+ FDKwriteBits(asc, ascExtId, 11);
writeAot(asc, config->extAOT);
- FDKwriteBits( asc, 1, 1 ); /* sbrPresentFlag=1 */
- writeSampleRate(asc, config->extSamplingRate);
+ FDKwriteBits(asc, 1, 1); /* sbrPresentFlag=1 */
+ writeSampleRate(asc, config->extSamplingRate, 4);
if (config->psPresent) {
- ascExtId=ASCEXT_PS;
- FDKwriteBits( asc, ascExtId, 11 );
- FDKwriteBits( asc, 1, 1 ); /* psPresentFlag=1 */
+ ascExtId = ASCEXT_PS;
+ FDKwriteBits(asc, ascExtId, 11);
+ FDKwriteBits(asc, 1, 1); /* psPresentFlag=1 */
}
}
-
}
/* Make sure all bits are sync'ed */
- FDKsyncCache( asc );
+ FDKsyncCache(asc);
return 0;
}