| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/webm/webm_info_parser.h" | 5 #include "media/webm/webm_info_parser.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "media/webm/webm_constants.h" | 8 #include "media/webm/webm_constants.h" |
| 9 | 9 |
| 10 namespace media { | 10 namespace media { |
| 11 | 11 |
| 12 WebMInfoParser::WebMInfoParser() | 12 WebMInfoParser::WebMInfoParser() |
| 13 : timecode_scale_(-1), | 13 : timecode_scale_(-1), |
| 14 duration_(-1) { | 14 duration_(-1) { |
| 15 } | 15 } |
| 16 | 16 |
| 17 WebMInfoParser::~WebMInfoParser() {} | 17 WebMInfoParser::~WebMInfoParser() {} |
| 18 | 18 |
| 19 int WebMInfoParser::Parse(const uint8* buf, int size) { | 19 int WebMInfoParser::Parse(const uint8* buf, int size) { |
| 20 return WebMParseListElement(buf, size, kWebMIdInfo, 1, this); | 20 timecode_scale_ = -1; |
| 21 duration_ = -1; |
| 22 |
| 23 WebMListParser parser(kWebMIdInfo); |
| 24 int result = parser.Parse(buf, size, this); |
| 25 |
| 26 if (result <= 0) |
| 27 return result; |
| 28 |
| 29 // For now we do all or nothing parsing. |
| 30 return parser.IsParsingComplete() ? result : 0; |
| 21 } | 31 } |
| 22 | 32 |
| 23 bool WebMInfoParser::OnListStart(int id) { return true; } | 33 bool WebMInfoParser::OnListStart(int id) { return true; } |
| 24 | 34 |
| 25 bool WebMInfoParser::OnListEnd(int id) { | 35 bool WebMInfoParser::OnListEnd(int id) { |
| 26 if (id == kWebMIdInfo && timecode_scale_ == -1) { | 36 if (id == kWebMIdInfo && timecode_scale_ == -1) { |
| 27 // Set timecode scale to default value if it isn't present in | 37 // Set timecode scale to default value if it isn't present in |
| 28 // the Info element. | 38 // the Info element. |
| 29 timecode_scale_ = kWebMDefaultTimecodeScale; | 39 timecode_scale_ = kWebMDefaultTimecodeScale; |
| 30 } | 40 } |
| 31 return true; | 41 return true; |
| 32 } | 42 } |
| 33 | 43 |
| 34 bool WebMInfoParser::OnUInt(int id, int64 val) { | 44 bool WebMInfoParser::OnUInt(int id, int64 val) { |
| 35 if (id != kWebMIdTimecodeScale) | 45 if (id != kWebMIdTimecodeScale) |
| 36 return true; | 46 return true; |
| 37 | 47 |
| 38 if (timecode_scale_ != -1) { | 48 if (timecode_scale_ != -1) { |
| 39 VLOG(1) << "Multiple values for id " << std::hex << id << " specified"; | 49 DVLOG(1) << "Multiple values for id " << std::hex << id << " specified"; |
| 40 return false; | 50 return false; |
| 41 } | 51 } |
| 42 | 52 |
| 43 timecode_scale_ = val; | 53 timecode_scale_ = val; |
| 44 return true; | 54 return true; |
| 45 } | 55 } |
| 46 | 56 |
| 47 bool WebMInfoParser::OnFloat(int id, double val) { | 57 bool WebMInfoParser::OnFloat(int id, double val) { |
| 48 if (id != kWebMIdDuration) { | 58 if (id != kWebMIdDuration) { |
| 49 VLOG(1) << "Unexpected float for id" << std::hex << id; | 59 DVLOG(1) << "Unexpected float for id" << std::hex << id; |
| 50 return false; | 60 return false; |
| 51 } | 61 } |
| 52 | 62 |
| 53 if (duration_ != -1) { | 63 if (duration_ != -1) { |
| 54 VLOG(1) << "Multiple values for duration."; | 64 DVLOG(1) << "Multiple values for duration."; |
| 55 return false; | 65 return false; |
| 56 } | 66 } |
| 57 | 67 |
| 58 duration_ = val; | 68 duration_ = val; |
| 59 return true; | 69 return true; |
| 60 } | 70 } |
| 61 | 71 |
| 62 bool WebMInfoParser::OnBinary(int id, const uint8* data, int size) { | 72 bool WebMInfoParser::OnBinary(int id, const uint8* data, int size) { |
| 63 return true; | 73 return true; |
| 64 } | 74 } |
| 65 | 75 |
| 66 bool WebMInfoParser::OnString(int id, const std::string& str) { | 76 bool WebMInfoParser::OnString(int id, const std::string& str) { |
| 67 return true; | 77 return true; |
| 68 } | 78 } |
| 69 | 79 |
| 70 bool WebMInfoParser::OnSimpleBlock(int track_num, int timecode, int flags, | 80 bool WebMInfoParser::OnSimpleBlock(int track_num, int timecode, int flags, |
| 71 const uint8* data, int size) { | 81 const uint8* data, int size) { |
| 72 return false; | 82 return false; |
| 73 } | 83 } |
| 74 | 84 |
| 75 } // namespace media | 85 } // namespace media |
| OLD | NEW |