| 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" | 7 #include "base/stl_util.h" |
| 8 #include "media/formats/mp4/box_definitions.h" | 8 #include "media/formats/mp4/box_definitions.h" |
| 9 #include "media/formats/mp4/box_reader.h" | 9 #include "media/formats/mp4/box_reader.h" |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 // Returns true if |input| contains only 1 or more valid 'pssh' boxes, false | 24 // Returns true if |input| contains only 1 or more valid 'pssh' boxes, false |
| 25 // otherwise. |pssh_boxes| is updated as the set of parsed 'pssh' boxes. | 25 // otherwise. |pssh_boxes| is updated as the set of parsed 'pssh' boxes. |
| 26 // Note: All boxes in |input| must be 'pssh' boxes. However, if they can't be | 26 // Note: All boxes in |input| must be 'pssh' boxes. However, if they can't be |
| 27 // properly parsed (e.g. unsupported version), then they will be skipped. | 27 // properly parsed (e.g. unsupported version), then they will be skipped. |
| 28 static bool ReadAllPsshBoxes( | 28 static bool ReadAllPsshBoxes( |
| 29 const std::vector<uint8_t>& input, | 29 const std::vector<uint8_t>& input, |
| 30 std::vector<mp4::FullProtectionSystemSpecificHeader>* pssh_boxes) { | 30 std::vector<mp4::FullProtectionSystemSpecificHeader>* pssh_boxes) { |
| 31 DCHECK(!input.empty()); | 31 DCHECK(!input.empty()); |
| 32 | 32 |
| 33 // Verify that |input| contains only 'pssh' boxes. ReadAllChildren() is | 33 // Verify that |input| contains only 'pssh' boxes. |
| 34 // templated, so it checks that each box in |input| matches the box type of | 34 // ReadAllChildrenAndCheckFourCC() is templated, so it checks that each |
| 35 // the parameter (in this case mp4::ProtectionSystemSpecificHeader is a | 35 // box in |input| matches the box type of the parameter (in this case |
| 36 // 'pssh' box). mp4::ProtectionSystemSpecificHeader doesn't validate the | 36 // mp4::ProtectionSystemSpecificHeader is a 'pssh' box). |
| 37 // 'pssh' contents, so this simply verifies that |input| only contains | 37 // mp4::ProtectionSystemSpecificHeader doesn't validate the 'pssh' contents, |
| 38 // 'pssh' boxes and nothing else. | 38 // so this simply verifies that |input| only contains 'pssh' boxes and |
| 39 // nothing else. |
| 39 scoped_ptr<mp4::BoxReader> input_reader( | 40 scoped_ptr<mp4::BoxReader> input_reader( |
| 40 mp4::BoxReader::ReadConcatentatedBoxes( | 41 mp4::BoxReader::ReadConcatentatedBoxes( |
| 41 vector_as_array(&input), input.size())); | 42 vector_as_array(&input), input.size())); |
| 42 std::vector<mp4::ProtectionSystemSpecificHeader> raw_pssh_boxes; | 43 std::vector<mp4::ProtectionSystemSpecificHeader> raw_pssh_boxes; |
| 43 if (!input_reader->ReadAllChildren(&raw_pssh_boxes)) | 44 if (!input_reader->ReadAllChildrenAndCheckFourCC(&raw_pssh_boxes)) |
| 44 return false; | 45 return false; |
| 45 | 46 |
| 46 // Now that we have |input| parsed into |raw_pssh_boxes|, reparse each one | 47 // Now that we have |input| parsed into |raw_pssh_boxes|, reparse each one |
| 47 // into a mp4::FullProtectionSystemSpecificHeader, which extracts all the | 48 // into a mp4::FullProtectionSystemSpecificHeader, which extracts all the |
| 48 // relevant fields from the box. Since there may be unparseable 'pssh' boxes | 49 // relevant fields from the box. Since there may be unparseable 'pssh' boxes |
| 49 // (due to unsupported version, for example), this is done one by one, | 50 // (due to unsupported version, for example), this is done one by one, |
| 50 // ignoring any boxes that can't be parsed. | 51 // ignoring any boxes that can't be parsed. |
| 51 for (const auto& raw_pssh_box : raw_pssh_boxes) { | 52 for (const auto& raw_pssh_box : raw_pssh_boxes) { |
| 52 scoped_ptr<mp4::BoxReader> raw_pssh_reader( | 53 scoped_ptr<mp4::BoxReader> raw_pssh_reader( |
| 53 mp4::BoxReader::ReadConcatentatedBoxes( | 54 mp4::BoxReader::ReadConcatentatedBoxes( |
| 54 vector_as_array(&raw_pssh_box.raw_box), | 55 vector_as_array(&raw_pssh_box.raw_box), |
| 55 raw_pssh_box.raw_box.size())); | 56 raw_pssh_box.raw_box.size())); |
| 56 // ReadAllChildren() appends any successfully parsed box onto it's | 57 // ReadAllChildren() appends any successfully parsed box onto it's |
| 57 // parameter, so |pssh_boxes| will contain the collection of successfully | 58 // parameter, so |pssh_boxes| will contain the collection of successfully |
| 58 // parsed 'pssh' boxes. If an error occurs, try the next box. | 59 // parsed 'pssh' boxes. If an error occurs, try the next box. |
| 59 if (!raw_pssh_reader->ReadAllChildren(pssh_boxes)) | 60 if (!raw_pssh_reader->ReadAllChildrenAndCheckFourCC(pssh_boxes)) |
| 60 continue; | 61 continue; |
| 61 } | 62 } |
| 62 | 63 |
| 63 // Must have successfully parsed at least one 'pssh' box. | 64 // Must have successfully parsed at least one 'pssh' box. |
| 64 return pssh_boxes->size() > 0; | 65 return pssh_boxes->size() > 0; |
| 65 } | 66 } |
| 66 | 67 |
| 67 bool ValidatePsshInput(const std::vector<uint8_t>& input) { | 68 bool ValidatePsshInput(const std::vector<uint8_t>& input) { |
| 68 // No 'pssh' boxes is considered valid. | 69 // No 'pssh' boxes is considered valid. |
| 69 if (input.empty()) | 70 if (input.empty()) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 pssh_data->assign(child.data.begin(), child.data.end()); | 118 pssh_data->assign(child.data.begin(), child.data.end()); |
| 118 return true; | 119 return true; |
| 119 } | 120 } |
| 120 } | 121 } |
| 121 | 122 |
| 122 // No matching 'pssh' box found. | 123 // No matching 'pssh' box found. |
| 123 return false; | 124 return false; |
| 124 } | 125 } |
| 125 | 126 |
| 126 } // namespace media | 127 } // namespace media |
| OLD | NEW |