summaryrefslogtreecommitdiffstats
path: root/audio_utils/spdif/AC3FrameScanner.h
blob: f944dcc0d7c458c14982a3fdd631bc1a3145944d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Copyright 2014, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_AUDIO_AC3_FRAME_SCANNER_H
#define ANDROID_AUDIO_AC3_FRAME_SCANNER_H

#include <stdint.h>
#include <audio_utils/spdif/FrameScanner.h>

namespace android {

#define AC3_NUM_SAMPLE_RATE_TABLE_ENTRIES          3
#define AC3_NUM_FRAME_SIZE_TABLE_ENTRIES          38
#define AC3_PCM_FRAMES_PER_BLOCK                 256
#define AC3_MAX_BLOCKS_PER_SYNC_FRAME_BLOCK        6
#define EAC3_RATE_MULTIPLIER                       4
#define EAC3_NUM_SAMPLE_RATE_TABLE_ENTRIES         3
#define EAC3_NUM_BLOCKS_PER_FRAME_TABLE_ENTRIES   38
#define EAC3_MAX_SUBSTREAMS                        8

class AC3FrameScanner : public FrameScanner
{
public:
    AC3FrameScanner();
    virtual ~AC3FrameScanner();

    virtual int getMaxChannels()   const { return 5 + 1; } // 5.1 surround

    virtual int getMaxSampleFramesPerSyncFrame() const { return EAC3_RATE_MULTIPLIER
            * AC3_MAX_BLOCKS_PER_SYNC_FRAME_BLOCK * AC3_PCM_FRAMES_PER_BLOCK; }
    virtual int getSampleFramesPerSyncFrame() const;

    virtual bool isFirstInBurst();
    virtual bool isLastInBurst();
    virtual void resetBurst();

protected:
    // Keep track of how many of each substream blocks have been accumulated.
    // We need all of each substream before sending block data burst.
    uint8_t   mSubstreamBlockCounts[EAC3_MAX_SUBSTREAMS];
    int       mAudioBlocksPerSyncFrame;
    // The type of EAC3 stream as per EAC3 spec paragraph 2.3.1.1
    uint32_t  mStreamType;
    // substream index
    uint32_t  mSubstreamID;

    // used to recognize the start of an AC3 sync frame
    static const uint8_t  kSyncBytes[];
    // sample rates from AC3 spec table 5.1
    static const uint16_t kAC3SampleRateTable[AC3_NUM_SAMPLE_RATE_TABLE_ENTRIES];
    // frame sizes from AC3 spec table 5.13
    static const uint16_t kAC3FrameSizeTable[AC3_NUM_FRAME_SIZE_TABLE_ENTRIES]
            [AC3_NUM_SAMPLE_RATE_TABLE_ENTRIES];
    // sample rates from EAC3 spec table E2.3
    static const uint16_t kEAC3ReducedSampleRateTable[AC3_NUM_SAMPLE_RATE_TABLE_ENTRIES];
    // audio blocks per frame from EAC3 spec table E2.4
    static const uint16_t kEAC3BlocksPerFrameTable[EAC3_NUM_BLOCKS_PER_FRAME_TABLE_ENTRIES];

    virtual bool parseHeader();
};

}  // namespace android

#endif  // ANDROID_AUDIO_AC3_FRAME_SCANNER_H