1 /* 2 * Copyright 2023, 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 #pragma once 18 19 #include <stdint.h> 20 #include <system/audio.h> 21 #include <audio_utils/spdif/FrameScanner.h> 22 #include <audio_utils/spdif/SPDIF.h> 23 24 namespace android { 25 26 inline constexpr uint32_t kEac3PcmFramesPerBlock = 256u; 27 inline constexpr uint32_t kEac3MaxBlocksPerSyncFrame = 6u; 28 29 // Scanner for IEC61937 streams. 30 class SPDIFFrameScanner : public FrameScanner { 31 public: 32 explicit SPDIFFrameScanner(audio_format_t format); 33 getMaxChannels()34 virtual int getMaxChannels() const { return kSpdifEncodedChannelCount; } // IEC61937 35 getMaxSampleFramesPerSyncFrame()36 virtual int getMaxSampleFramesPerSyncFrame() const { 37 return kSpdifRateMultiplierEac3 * kEac3MaxBlocksPerSyncFrame 38 * kEac3PcmFramesPerBlock; 39 } 40 getSampleFramesPerSyncFrame()41 virtual int getSampleFramesPerSyncFrame() const { 42 return mRateMultiplier * kEac3MaxBlocksPerSyncFrame * kEac3PcmFramesPerBlock; 43 } 44 isFirstInBurst()45 virtual bool isFirstInBurst() { return true; } isLastInBurst()46 virtual bool isLastInBurst() { return true; } resetBurst()47 virtual void resetBurst() { } 48 49 protected: 50 // used to recognize the start of an IEC61937 frame 51 static const uint8_t kSyncBytes[]; 52 53 virtual bool parseHeader(); 54 }; 55 56 } // namespace android 57