AC3FrameScanner.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #ifndef ANDROID_AUDIO_AC3_FRAME_SCANNER_H
  17. #define ANDROID_AUDIO_AC3_FRAME_SCANNER_H
  18. #include <stdint.h>
  19. #include <system/audio.h>
  20. #include <audio_utils/spdif/FrameScanner.h>
  21. namespace android {
  22. #define AC3_NUM_SAMPLE_RATE_TABLE_ENTRIES 3
  23. #define AC3_NUM_FRAME_SIZE_TABLE_ENTRIES 38
  24. #define AC3_PCM_FRAMES_PER_BLOCK 256
  25. #define AC3_MAX_BLOCKS_PER_SYNC_FRAME_BLOCK 6
  26. #define EAC3_RATE_MULTIPLIER 4
  27. #define EAC3_NUM_SAMPLE_RATE_TABLE_ENTRIES 3
  28. #define EAC3_NUM_BLOCKS_PER_FRAME_TABLE_ENTRIES 38
  29. #define EAC3_MAX_SUBSTREAMS 8
  30. class AC3FrameScanner : public FrameScanner
  31. {
  32. public:
  33. explicit AC3FrameScanner(audio_format_t format);
  34. virtual ~AC3FrameScanner();
  35. virtual int getMaxChannels() const { return 5 + 1; } // 5.1 surround
  36. virtual int getMaxSampleFramesPerSyncFrame() const { return EAC3_RATE_MULTIPLIER
  37. * AC3_MAX_BLOCKS_PER_SYNC_FRAME_BLOCK * AC3_PCM_FRAMES_PER_BLOCK; }
  38. virtual int getSampleFramesPerSyncFrame() const;
  39. virtual bool isFirstInBurst();
  40. virtual bool isLastInBurst();
  41. virtual void resetBurst();
  42. virtual uint16_t convertBytesToLengthCode(uint16_t numBytes) const;
  43. protected:
  44. // Keep track of how many of each substream blocks have been accumulated.
  45. // We need all of each substream before sending block data burst.
  46. uint8_t mSubstreamBlockCounts[EAC3_MAX_SUBSTREAMS];
  47. int mAudioBlocksPerSyncFrame;
  48. // The type of EAC3 stream as per EAC3 spec paragraph 2.3.1.1
  49. uint32_t mStreamType;
  50. // substream index
  51. uint32_t mSubstreamID;
  52. audio_format_t mFormat;
  53. // used to recognize the start of an AC3 sync frame
  54. static const uint8_t kSyncBytes[];
  55. // sample rates from AC3 spec table 5.1
  56. static const uint16_t kAC3SampleRateTable[AC3_NUM_SAMPLE_RATE_TABLE_ENTRIES];
  57. // frame sizes from AC3 spec table 5.13
  58. static const uint16_t kAC3FrameSizeTable[AC3_NUM_FRAME_SIZE_TABLE_ENTRIES]
  59. [AC3_NUM_SAMPLE_RATE_TABLE_ENTRIES];
  60. // sample rates from EAC3 spec table E2.3
  61. static const uint16_t kEAC3ReducedSampleRateTable[AC3_NUM_SAMPLE_RATE_TABLE_ENTRIES];
  62. // audio blocks per frame from EAC3 spec table E2.4
  63. static const uint16_t kEAC3BlocksPerFrameTable[EAC3_NUM_BLOCKS_PER_FRAME_TABLE_ENTRIES];
  64. virtual bool parseHeader();
  65. };
  66. } // namespace android
  67. #endif // ANDROID_AUDIO_AC3_FRAME_SCANNER_H