Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: media/formats/mp2t/descriptors.cc

Issue 1517473002: Support HLS MPEG2 TS with SAMPLE-AES encryption. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@encryption_scheme
Patch Set: move some gn defs Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/formats/mp2t/descriptors.h"
6
7 #include <vector>
8
9 #include "base/logging.h"
10 #include "media/base/bit_reader.h"
11 #include "media/formats/mp2t/mp2t_common.h"
12
13 namespace media {
14 namespace mp2t {
15
16 namespace {
17
18 // Tag values for various kinds of descriptors for which there is specific
19 // parsing support herein.
20 enum DescriptorTag {
21 DESCRIPTOR_TAG_REGISTRATION = 5,
22 DESCRIPTOR_TAG_CA = 9,
23 DESCRIPTOR_TAG_PRIVATE_DATA_INDICATOR = 15,
24 };
25
26 const int kCASystemIdCenc = 0x6365; // 'ce'
27
28 class StringBitReader : public BitReader {
29 public:
30 StringBitReader(const std::string& input);
31 ~StringBitReader() override;
32 };
33
34 StringBitReader::StringBitReader(const std::string& input)
35 : BitReader(reinterpret_cast<const uint8_t*>(input.data()), input.size()) {}
36
37 StringBitReader::~StringBitReader() {}
38
39 } // namespace
40
41 Descriptors::Descriptors() {}
42
43 Descriptors::~Descriptors() {}
44
45 bool Descriptors::Read(BitReader* reader, int size) {
46 DCHECK(reader);
47 DCHECK(size >= 0);
48 descriptors_.clear();
49 if (size == 0)
50 return true;
51 int initial_bits_read = reader->bits_read();
52 int bits_read = 0;
53 int bits_available = reader->bits_available();
54 int size_in_bits = 8 * size;
55 if (size_in_bits > bits_available)
56 return false;
57 bits_available = size_in_bits;
58 do {
59 int tag;
60 size_t length;
61 RCHECK(reader->ReadBits(8, &tag));
62 RCHECK(reader->ReadBits(8, &length));
63 char data[256];
64 for (size_t i = 0; i < length; i++) {
65 RCHECK(reader->ReadBits(8, &data[i]));
66 }
67 descriptors_.insert(Descriptor(tag, std::string(data, length)));
68 bits_read = reader->bits_read() - initial_bits_read;
69 } while (bits_read < bits_available);
70 return bits_read == bits_available;
71 }
72
73 bool Descriptors::HasRegistrationDescriptor(
74 int64_t* format_identifier,
75 std::string* additional_info) const {
76 DCHECK(format_identifier);
77 DCHECK(additional_info);
78 auto search = descriptors_.find(DESCRIPTOR_TAG_REGISTRATION);
79 if (search == descriptors_.end())
80 return false;
81 const std::string& data = search->second;
82 StringBitReader reader(data);
83 RCHECK(reader.ReadBits(32, format_identifier));
84 size_t extra_bits = reader.bits_available();
85 RCHECK(extra_bits % 8 == 0);
ddorwin 2016/04/12 00:40:47 You might also need to check that it's > 0 if you
dougsteed 2016/05/08 23:18:44 Done.
86 RCHECK(reader.ReadString(extra_bits, additional_info));
87 return true;
88 }
89
90 bool Descriptors::HasCADescriptor(int* system_id,
91 int* pid,
92 std::string* private_data) const {
93 DCHECK(system_id);
94 DCHECK(pid);
95 DCHECK(private_data);
96 auto search = descriptors_.find(DESCRIPTOR_TAG_CA);
97 if (search == descriptors_.end())
98 return false;
99 const std::string& data = search->second;
100 StringBitReader reader(data);
101 RCHECK(reader.ReadBits(16, system_id));
102 RCHECK(reader.SkipBits(3));
103 RCHECK(reader.ReadBits(13, pid));
104 size_t extra_bits = reader.bits_available();
105 RCHECK(extra_bits % 8 == 0);
106 RCHECK(reader.ReadString(extra_bits, private_data));
107 return true;
108 }
109
110 bool Descriptors::HasCADescriptorCenc(int* ca_pid, int* pssh_pid) const {
111 DCHECK(ca_pid);
112 DCHECK(pssh_pid);
113 int system_id;
114 std::string private_data;
115 if (!HasCADescriptor(&system_id, ca_pid, &private_data))
116 return false;
117 if (system_id != kCASystemIdCenc)
118 return false;
119 StringBitReader reader(private_data);
120 uint32_t scheme_type;
121 uint32_t scheme_version;
122 int num_systems;
123 int encryption_algorithm;
124 char pssh_system_id[16];
125 // TODO(dougsteed). Currently we don't check many of the following values.
126 // When we flesh out this implementation to cover all of ISO/IEC 23001-9 we
127 // will need to use and check these values.
128 RCHECK(reader.ReadBits(32, &scheme_type));
129 RCHECK(reader.ReadBits(32, &scheme_version));
130 RCHECK(reader.ReadBits(8, &num_systems));
131 RCHECK(num_systems == 1);
132 RCHECK(reader.ReadBits(24, &encryption_algorithm));
133 for (size_t i = 0; i < 16; i++) {
134 RCHECK(reader.ReadBits(8, &pssh_system_id[i]));
135 }
136 RCHECK(reader.ReadBits(13, pssh_pid));
137 return true;
138 }
139
140 bool Descriptors::HasPrivateDataIndicator(int64_t value) const {
141 int64_t private_data_indicator;
142 auto search = descriptors_.find(DESCRIPTOR_TAG_PRIVATE_DATA_INDICATOR);
143 if (search == descriptors_.end())
144 return false;
145 const std::string& data = search->second;
146 StringBitReader reader(data);
147 RCHECK(reader.ReadBits(32, &private_data_indicator));
148 RCHECK(reader.bits_available() == 0);
149 return private_data_indicator == value;
150 }
151
152 } // namespace mp2t
153 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698