OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/cdm/cenc_utils.h" | 5 #include "media/cdm/cenc_utils.h" |
6 | 6 |
7 #include "base/stl_util.h" | |
8 #include "media/formats/mp4/box_definitions.h" | 7 #include "media/formats/mp4/box_definitions.h" |
9 #include "media/formats/mp4/box_reader.h" | 8 #include "media/formats/mp4/box_reader.h" |
10 | 9 |
11 namespace media { | 10 namespace media { |
12 | 11 |
13 // The initialization data for encrypted media files using the ISO Common | 12 // The initialization data for encrypted media files using the ISO Common |
14 // Encryption ('cenc') protection scheme may contain one or more protection | 13 // Encryption ('cenc') protection scheme may contain one or more protection |
15 // system specific header ('pssh') boxes. | 14 // system specific header ('pssh') boxes. |
16 // ref: https://w3c.github.io/encrypted-media/cenc-format.html | 15 // ref: https://w3c.github.io/encrypted-media/cenc-format.html |
17 | 16 |
(...skipping 13 matching lines...) Expand all Loading... |
31 DCHECK(!input.empty()); | 30 DCHECK(!input.empty()); |
32 | 31 |
33 // Verify that |input| contains only 'pssh' boxes. | 32 // Verify that |input| contains only 'pssh' boxes. |
34 // ReadAllChildrenAndCheckFourCC() is templated, so it checks that each | 33 // ReadAllChildrenAndCheckFourCC() is templated, so it checks that each |
35 // box in |input| matches the box type of the parameter (in this case | 34 // box in |input| matches the box type of the parameter (in this case |
36 // mp4::ProtectionSystemSpecificHeader is a 'pssh' box). | 35 // mp4::ProtectionSystemSpecificHeader is a 'pssh' box). |
37 // mp4::ProtectionSystemSpecificHeader doesn't validate the 'pssh' contents, | 36 // mp4::ProtectionSystemSpecificHeader doesn't validate the 'pssh' contents, |
38 // so this simply verifies that |input| only contains 'pssh' boxes and | 37 // so this simply verifies that |input| only contains 'pssh' boxes and |
39 // nothing else. | 38 // nothing else. |
40 scoped_ptr<mp4::BoxReader> input_reader( | 39 scoped_ptr<mp4::BoxReader> input_reader( |
41 mp4::BoxReader::ReadConcatentatedBoxes( | 40 mp4::BoxReader::ReadConcatentatedBoxes(input.data(), input.size())); |
42 vector_as_array(&input), input.size())); | |
43 std::vector<mp4::ProtectionSystemSpecificHeader> raw_pssh_boxes; | 41 std::vector<mp4::ProtectionSystemSpecificHeader> raw_pssh_boxes; |
44 if (!input_reader->ReadAllChildrenAndCheckFourCC(&raw_pssh_boxes)) | 42 if (!input_reader->ReadAllChildrenAndCheckFourCC(&raw_pssh_boxes)) |
45 return false; | 43 return false; |
46 | 44 |
47 // Now that we have |input| parsed into |raw_pssh_boxes|, reparse each one | 45 // Now that we have |input| parsed into |raw_pssh_boxes|, reparse each one |
48 // into a mp4::FullProtectionSystemSpecificHeader, which extracts all the | 46 // into a mp4::FullProtectionSystemSpecificHeader, which extracts all the |
49 // relevant fields from the box. Since there may be unparseable 'pssh' boxes | 47 // relevant fields from the box. Since there may be unparseable 'pssh' boxes |
50 // (due to unsupported version, for example), this is done one by one, | 48 // (due to unsupported version, for example), this is done one by one, |
51 // ignoring any boxes that can't be parsed. | 49 // ignoring any boxes that can't be parsed. |
52 for (const auto& raw_pssh_box : raw_pssh_boxes) { | 50 for (const auto& raw_pssh_box : raw_pssh_boxes) { |
53 scoped_ptr<mp4::BoxReader> raw_pssh_reader( | 51 scoped_ptr<mp4::BoxReader> raw_pssh_reader( |
54 mp4::BoxReader::ReadConcatentatedBoxes( | 52 mp4::BoxReader::ReadConcatentatedBoxes(raw_pssh_box.raw_box.data(), |
55 vector_as_array(&raw_pssh_box.raw_box), | 53 raw_pssh_box.raw_box.size())); |
56 raw_pssh_box.raw_box.size())); | |
57 // ReadAllChildren() appends any successfully parsed box onto it's | 54 // ReadAllChildren() appends any successfully parsed box onto it's |
58 // parameter, so |pssh_boxes| will contain the collection of successfully | 55 // parameter, so |pssh_boxes| will contain the collection of successfully |
59 // parsed 'pssh' boxes. If an error occurs, try the next box. | 56 // parsed 'pssh' boxes. If an error occurs, try the next box. |
60 if (!raw_pssh_reader->ReadAllChildrenAndCheckFourCC(pssh_boxes)) | 57 if (!raw_pssh_reader->ReadAllChildrenAndCheckFourCC(pssh_boxes)) |
61 continue; | 58 continue; |
62 } | 59 } |
63 | 60 |
64 // Must have successfully parsed at least one 'pssh' box. | 61 // Must have successfully parsed at least one 'pssh' box. |
65 return pssh_boxes->size() > 0; | 62 return pssh_boxes->size() > 0; |
66 } | 63 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 pssh_data->assign(child.data.begin(), child.data.end()); | 115 pssh_data->assign(child.data.begin(), child.data.end()); |
119 return true; | 116 return true; |
120 } | 117 } |
121 } | 118 } |
122 | 119 |
123 // No matching 'pssh' box found. | 120 // No matching 'pssh' box found. |
124 return false; | 121 return false; |
125 } | 122 } |
126 | 123 |
127 } // namespace media | 124 } // namespace media |
OLD | NEW |