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

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: remove test data Created 5 years 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 kDescriptorTagRegistration = 5,
22 kDescriptorTagCA = 9,
23 kDescriptorTagPrivateDataIndicator = 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 descriptors_.clear();
48 if (!size)
49 return true;
50 int initial_bits_read = reader->bits_read();
51 int bits_read = 0;
52 int bits_available = reader->bits_available();
53 if (size > 0) {
54 int size_in_bits = 8 * size;
55 if (size_in_bits > bits_available)
56 return false;
57 bits_available = size_in_bits;
58 }
59 do {
60 int tag;
61 size_t length;
62 RCHECK(reader->ReadBits(8, &tag));
63 RCHECK(reader->ReadBits(8, &length));
64 char data[256];
65 for (size_t i = 0; i < length; i++) {
66 RCHECK(reader->ReadBits(8, &data[i]));
67 }
68 descriptors_.insert(Descriptor(tag, std::string(data, length)));
69 bits_read = reader->bits_read() - initial_bits_read;
70 } while (bits_read < bits_available);
71 return bits_read == bits_available;
72 }
73
74 bool Descriptors::HasRegistrationDescriptor(
75 int64* format_identifier,
76 std::string* additional_info) const {
77 DCHECK(format_identifier);
78 auto search = descriptors_.find(kDescriptorTagRegistration);
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);
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(kDescriptorTagCA);
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 int system_id;
112 std::string private_data;
113 if (!HasCADescriptor(&system_id, ca_pid, &private_data))
114 return false;
115 if (system_id != kCASystemIdCenc)
116 return false;
117 StringBitReader reader(private_data);
118 int64 scheme_type;
119 int64 scheme_version;
120 int num_systems;
121 int encryption_algorithm;
122 char pssh_system_id[16];
123 // TODO(dougsteed). Currently we don't check many of the following values.
124 // When we flesh out this implementation to cover all of ISO/IEC 23001-9 we
125 // will need to use and check these values.
126 RCHECK(reader.ReadBits(32, &scheme_type));
127 RCHECK(reader.ReadBits(32, &scheme_version));
128 RCHECK(reader.ReadBits(8, &num_systems));
129 RCHECK(num_systems == 1);
130 RCHECK(reader.ReadBits(24, &encryption_algorithm));
131 for (size_t i = 0; i < 16; i++) {
132 RCHECK(reader.ReadBits(8, &pssh_system_id[i]));
133 }
134 RCHECK(reader.ReadBits(13, pssh_pid));
135 return true;
136 }
137
138 bool Descriptors::HasPrivateDataIndicator(int64 value) const {
139 int64 private_data_indicator;
140 auto search = descriptors_.find(kDescriptorTagPrivateDataIndicator);
141 if (search == descriptors_.end())
142 return false;
143 const std::string& data = search->second;
144 StringBitReader reader(data);
145 RCHECK(reader.ReadBits(32, &private_data_indicator));
146 RCHECK(reader.bits_available() == 0);
147 return private_data_indicator = value;
yucliu1 2015/12/11 21:34:55 I think the "=" here should be "==".
dougsteed 2015/12/14 22:51:46 Good catch.
148 }
149
150 } // namespace mp2t
151 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698