1 /*
2  * Copyright (C) 2017 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 //#define LOG_NDEBUG 0
18 
19 #include "ATSParser.h"
20 #include <utils/KeyedVector.h>
21 #include <set>
22 
23 namespace android {
24 namespace hardware {
25 namespace cas {
26 namespace native {
27 namespace V1_0 {
28 struct IDescrambler;
29 }}}}
30 using hardware::cas::native::V1_0::IDescrambler;
31 
32 struct ATSParser::CasManager : public RefBase {
33     CasManager();
34     virtual ~CasManager();
35 
36     status_t setMediaCas(const sp<ICas> &cas);
37 
38     bool addProgram(
39             unsigned programNumber, const CADescriptor &descriptor);
40 
41     bool addStream(
42             unsigned programNumber, unsigned elementaryPID,
43             const CADescriptor &descriptor);
44 
45     bool getCasInfo(
46             unsigned programNumber, unsigned elementaryPID,
47             int32_t *systemId, sp<IDescrambler> *descrambler,
48             std::vector<uint8_t> *sessionId) const;
49 
50     bool isCAPid(unsigned pid);
51 
52     bool parsePID(ABitReader *br, unsigned pid);
53 
54 private:
55     typedef KeyedVector<unsigned, std::vector<uint8_t> > PidToSessionMap;
56     struct ProgramCasManager;
57 
58     bool setSystemId(int32_t CA_system_ID);
59 
60     int32_t mSystemId;
61     sp<ICas> mICas;
62     KeyedVector<unsigned, sp<ProgramCasManager> > mProgramCasMap;
63     PidToSessionMap mCAPidToSessionIdMap;
64     std::set<uint32_t> mCAPidSet;
65 };
66 
67 }  // namespace android
68