From fd3cca76c0eef854cfe4406cfb7204e38f1adc48 Mon Sep 17 00:00:00 2001 From: Phil Burk Date: Wed, 8 Jul 2015 11:39:07 -0700 Subject: SPDIFEncoder: EAC3 fixes from NVidia These fixes were suggested by NVidia https://android-review.googlesource.com/#/c/158460/1 Bug: 22351015 Change-Id: I4da4885360b191e1835c0f2762efc32f51942d66 Signed-off-by: Phil Burk --- audio_utils/include/audio_utils/spdif/FrameScanner.h | 5 +++++ audio_utils/spdif/AC3FrameScanner.cpp | 11 ++++++++++- audio_utils/spdif/AC3FrameScanner.h | 2 ++ audio_utils/spdif/SPDIFEncoder.cpp | 6 +++--- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/audio_utils/include/audio_utils/spdif/FrameScanner.h b/audio_utils/include/audio_utils/spdif/FrameScanner.h index 7b88ae23..6d391eed 100644 --- a/audio_utils/include/audio_utils/spdif/FrameScanner.h +++ b/audio_utils/include/audio_utils/spdif/FrameScanner.h @@ -97,6 +97,11 @@ public: */ virtual bool isLastInBurst() = 0; + /** + * Most compression types use a lengthCode expressed in bits. + */ + virtual uint16_t convertBytesToLengthCode(uint16_t numBytes) const { return numBytes * 8; } + protected: uint32_t mBytesSkipped; // how many bytes were skipped looking for the start of a frame const uint8_t *mSyncBytes; // pointer to the sync word specific to a format diff --git a/audio_utils/spdif/AC3FrameScanner.cpp b/audio_utils/spdif/AC3FrameScanner.cpp index 7f8068d0..ffbedb52 100644 --- a/audio_utils/spdif/AC3FrameScanner.cpp +++ b/audio_utils/spdif/AC3FrameScanner.cpp @@ -126,6 +126,12 @@ void AC3FrameScanner::resetBurst() } } +// Per IEC 61973-3:5.3.3, for E-AC3 burst-length shall be in bytes. +uint16_t AC3FrameScanner::convertBytesToLengthCode(uint16_t numBytes) const +{ + return (mDataType == SPDIF_DATA_TYPE_E_AC3) ? numBytes : numBytes * 8; +} + // per IEC 61973-3 Paragraph 5.3.3 // We have to send 6 audio blocks on all active substreams. // Substream zero must be the first. @@ -204,7 +210,10 @@ bool AC3FrameScanner::parseHeader() // Keep track of how many audio blocks we have for each substream. // This should be safe because mSubstreamID is ANDed with 0x07 above. // And the array is allocated as [8]. - mSubstreamBlockCounts[mSubstreamID] += mAudioBlocksPerSyncFrame; + if ((mStreamType == AC3_STREAM_TYPE_0) + || (mStreamType == AC3_STREAM_TYPE_2)) { + mSubstreamBlockCounts[mSubstreamID] += mAudioBlocksPerSyncFrame; + } // Print enough so we can see all the substreams. ALOGD_IF((mFormatDumpCount < 3*8 ), diff --git a/audio_utils/spdif/AC3FrameScanner.h b/audio_utils/spdif/AC3FrameScanner.h index f944dcc0..1ef56108 100644 --- a/audio_utils/spdif/AC3FrameScanner.h +++ b/audio_utils/spdif/AC3FrameScanner.h @@ -47,6 +47,8 @@ public: virtual bool isLastInBurst(); virtual void resetBurst(); + virtual uint16_t convertBytesToLengthCode(uint16_t numBytes) const; + protected: // Keep track of how many of each substream blocks have been accumulated. // We need all of each substream before sending block data burst. diff --git a/audio_utils/spdif/SPDIFEncoder.cpp b/audio_utils/spdif/SPDIFEncoder.cpp index 7a546276..2eeeba66 100644 --- a/audio_utils/spdif/SPDIFEncoder.cpp +++ b/audio_utils/spdif/SPDIFEncoder.cpp @@ -175,9 +175,9 @@ void SPDIFEncoder::flushBurstBuffer() { const int preambleSize = 4 * sizeof(uint16_t); if (mByteCursor > preambleSize) { - // Set number of bits for valid payload before zeroPad. - uint16_t lengthCode = (mByteCursor - preambleSize) * 8; - mBurstBuffer[3] = lengthCode; + // Set lengthCode for valid payload before zeroPad. + uint16_t numBytes = (mByteCursor - preambleSize); + mBurstBuffer[3] = mFramer->convertBytesToLengthCode(numBytes); sendZeroPad(); writeOutput(mBurstBuffer, mByteCursor); -- cgit v1.2.3