1 /*
2  * Copyright (C) 2018 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 AC4_PARSER_H_
18 #define AC4_PARSER_H_
19 
20 #include <cstdint>
21 #include <map>
22 #include <string>
23 
24 #include <media/stagefright/foundation/ABitReader.h>
25 
26 namespace android {
27 
28 class AC4Parser {
29 public:
30     AC4Parser();
~AC4Parser()31     virtual ~AC4Parser() { }
32 
33     virtual bool parse() = 0;
34 
35     struct AC4Presentation {
36         int32_t mChannelMode = -1;
37         int32_t mProgramID = -1;
38         int32_t mGroupIndex = -1;
39 
40         // TS 103 190-1 v1.2.1 4.3.3.8.1
41         enum ContentClassifiers {
42             kCompleteMain,
43             kMusicAndEffects,
44             kVisuallyImpaired,
45             kHearingImpaired,
46             kDialog,
47             kCommentary,
48             kEmergency,
49             kVoiceOver
50         };
51 
52         uint32_t mContentClassifier = kCompleteMain;
53 
54         // ETSI TS 103 190-2 V1.1.1 (2015-09) Table 79: channel_mode
55         enum InputChannelMode {
56             kChannelMode_Mono,
57             kChannelMode_Stereo,
58             kChannelMode_3_0,
59             kChannelMode_5_0,
60             kChannelMode_5_1,
61             kChannelMode_7_0_34,
62             kChannelMode_7_1_34,
63             kChannelMode_7_0_52,
64             kChannelMode_7_1_52,
65             kChannelMode_7_0_322,
66             kChannelMode_7_1_322,
67             kChannelMode_7_0_4,
68             kChannelMode_7_1_4,
69             kChannelMode_9_0_4,
70             kChannelMode_9_1_4,
71             kChannelMode_22_2,
72             kChannelMode_Reserved,
73         };
74 
75         bool mHasDialogEnhancements = false;
76         bool mPreVirtualized = false;
77         bool mEnabled = true;
78 
79         std::string mLanguage;
80         std::string mDescription;
81     };
82     typedef std::map<uint32_t, AC4Presentation> AC4Presentations;
83 
getPresentations()84     const AC4Presentations& getPresentations() const { return mPresentations; }
85 
86 protected:
87     AC4Presentations mPresentations;
88 };
89 
90 class AC4DSIParser: public AC4Parser {
91 public:
92     explicit AC4DSIParser(ABitReader &br);
~AC4DSIParser()93     virtual ~AC4DSIParser() { }
94 
95     bool parse();
96 
97 private:
98     bool parseSubstreamDSI(uint32_t presentationID, uint32_t substreamID);
99     bool parseSubstreamGroupDSI(uint32_t presentationID, uint32_t groupID);
100     bool parseLanguageTag(uint32_t presentationID, uint32_t substreamID);
101     bool parseBitrateDsi();
102 
103     uint64_t mDSISize;
104     ABitReader& mBitReader;
105 };
106 
107 };
108 
109 #endif  // AC4_PARSER_H_
110