1 /* 2 * Copyright 2014, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_AUDIO_AC3_FRAME_SCANNER_H 18 #define ANDROID_AUDIO_AC3_FRAME_SCANNER_H 19 20 #include <stdint.h> 21 #include <audio_utils/spdif/FrameScanner.h> 22 23 namespace android { 24 25 #define AC3_NUM_SAMPLE_RATE_TABLE_ENTRIES 3 26 #define AC3_NUM_FRAME_SIZE_TABLE_ENTRIES 38 27 #define AC3_PCM_FRAMES_PER_BLOCK 256 28 #define AC3_MAX_BLOCKS_PER_SYNC_FRAME_BLOCK 6 29 #define EAC3_RATE_MULTIPLIER 4 30 #define EAC3_NUM_SAMPLE_RATE_TABLE_ENTRIES 3 31 #define EAC3_NUM_BLOCKS_PER_FRAME_TABLE_ENTRIES 38 32 #define EAC3_MAX_SUBSTREAMS 8 33 34 class AC3FrameScanner : public FrameScanner 35 { 36 public: 37 AC3FrameScanner(); 38 virtual ~AC3FrameScanner(); 39 getMaxChannels()40 virtual int getMaxChannels() const { return 5 + 1; } // 5.1 surround 41 getMaxSampleFramesPerSyncFrame()42 virtual int getMaxSampleFramesPerSyncFrame() const { return EAC3_RATE_MULTIPLIER 43 * AC3_MAX_BLOCKS_PER_SYNC_FRAME_BLOCK * AC3_PCM_FRAMES_PER_BLOCK; } 44 virtual int getSampleFramesPerSyncFrame() const; 45 46 virtual bool isFirstInBurst(); 47 virtual bool isLastInBurst(); 48 virtual void resetBurst(); 49 50 virtual uint16_t convertBytesToLengthCode(uint16_t numBytes) const; 51 52 protected: 53 // Keep track of how many of each substream blocks have been accumulated. 54 // We need all of each substream before sending block data burst. 55 uint8_t mSubstreamBlockCounts[EAC3_MAX_SUBSTREAMS]; 56 int mAudioBlocksPerSyncFrame; 57 // The type of EAC3 stream as per EAC3 spec paragraph 2.3.1.1 58 uint32_t mStreamType; 59 // substream index 60 uint32_t mSubstreamID; 61 62 // used to recognize the start of an AC3 sync frame 63 static const uint8_t kSyncBytes[]; 64 // sample rates from AC3 spec table 5.1 65 static const uint16_t kAC3SampleRateTable[AC3_NUM_SAMPLE_RATE_TABLE_ENTRIES]; 66 // frame sizes from AC3 spec table 5.13 67 static const uint16_t kAC3FrameSizeTable[AC3_NUM_FRAME_SIZE_TABLE_ENTRIES] 68 [AC3_NUM_SAMPLE_RATE_TABLE_ENTRIES]; 69 // sample rates from EAC3 spec table E2.3 70 static const uint16_t kEAC3ReducedSampleRateTable[AC3_NUM_SAMPLE_RATE_TABLE_ENTRIES]; 71 // audio blocks per frame from EAC3 spec table E2.4 72 static const uint16_t kEAC3BlocksPerFrameTable[EAC3_NUM_BLOCKS_PER_FRAME_TABLE_ENTRIES]; 73 74 virtual bool parseHeader(); 75 }; 76 77 } // namespace android 78 79 #endif // ANDROID_AUDIO_AC3_FRAME_SCANNER_H 80