| 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_tracks_parser.h" | 5 #include "media/webm/webm_tracks_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 WebMTracksParser::WebMTracksParser(int64 timecode_scale) | 12 WebMTracksParser::WebMTracksParser(int64 timecode_scale) |
| 13 : timecode_scale_(timecode_scale), | 13 : timecode_scale_(timecode_scale), |
| 14 track_type_(-1), | 14 track_type_(-1), |
| 15 track_num_(-1), | 15 track_num_(-1), |
| 16 track_default_duration_(-1), | 16 track_default_duration_(-1), |
| 17 audio_track_num_(-1), | 17 audio_track_num_(-1), |
| 18 audio_default_duration_(base::TimeDelta::FromMicroseconds(-1)), | 18 video_track_num_(-1) { |
| 19 video_track_num_(-1), | |
| 20 video_default_duration_(base::TimeDelta::FromMicroseconds(-1)) { | |
| 21 } | 19 } |
| 22 | 20 |
| 23 WebMTracksParser::~WebMTracksParser() {} | 21 WebMTracksParser::~WebMTracksParser() {} |
| 24 | 22 |
| 25 int WebMTracksParser::Parse(const uint8* buf, int size) { | 23 int WebMTracksParser::Parse(const uint8* buf, int size) { |
| 26 return WebMParseListElement(buf, size, kWebMIdTracks, 1, this); | 24 track_type_ =-1; |
| 25 track_num_ = -1; |
| 26 track_default_duration_ = -1; |
| 27 audio_track_num_ = -1; |
| 28 audio_default_duration_ = base::TimeDelta(); |
| 29 video_track_num_ = -1; |
| 30 video_default_duration_ = base::TimeDelta(); |
| 31 |
| 32 WebMListParser parser(kWebMIdTracks); |
| 33 int result = parser.Parse(buf, size, this); |
| 34 |
| 35 if (result <= 0) |
| 36 return result; |
| 37 |
| 38 // For now we do all or nothing parsing. |
| 39 return parser.IsParsingComplete() ? result : 0; |
| 27 } | 40 } |
| 28 | 41 |
| 29 | 42 |
| 30 bool WebMTracksParser::OnListStart(int id) { | 43 bool WebMTracksParser::OnListStart(int id) { |
| 31 if (id == kWebMIdTrackEntry) { | 44 if (id == kWebMIdTrackEntry) { |
| 32 track_type_ = -1; | 45 track_type_ = -1; |
| 33 track_num_ = -1; | 46 track_num_ = -1; |
| 34 track_default_duration_ = -1; | 47 track_default_duration_ = -1; |
| 35 } | 48 } |
| 36 | 49 |
| 37 return true; | 50 return true; |
| 38 } | 51 } |
| 39 | 52 |
| 40 bool WebMTracksParser::OnListEnd(int id) { | 53 bool WebMTracksParser::OnListEnd(int id) { |
| 41 if (id == kWebMIdTrackEntry) { | 54 if (id == kWebMIdTrackEntry) { |
| 42 if (track_type_ == -1 || track_num_ == -1) { | 55 if (track_type_ == -1 || track_num_ == -1) { |
| 43 VLOG(1) << "Missing TrackEntry data" | 56 DVLOG(1) << "Missing TrackEntry data" |
| 44 << " TrackType " << track_type_ | 57 << " TrackType " << track_type_ |
| 45 << " TrackNum " << track_num_; | 58 << " TrackNum " << track_num_; |
| 46 return false; | 59 return false; |
| 47 } | 60 } |
| 48 | 61 |
| 49 // Convert nanoseconds to base::TimeDelta. | 62 base::TimeDelta default_duration; |
| 50 base::TimeDelta default_duration = base::TimeDelta::FromMicroseconds( | 63 |
| 51 track_default_duration_ / 1000.0); | 64 if (track_default_duration_ > 0) { |
| 65 // Convert nanoseconds to base::TimeDelta. |
| 66 default_duration= base::TimeDelta::FromMicroseconds( |
| 67 track_default_duration_ / 1000.0); |
| 68 } |
| 52 | 69 |
| 53 if (track_type_ == kWebMTrackTypeVideo) { | 70 if (track_type_ == kWebMTrackTypeVideo) { |
| 54 video_track_num_ = track_num_; | 71 video_track_num_ = track_num_; |
| 55 video_default_duration_ = default_duration; | 72 video_default_duration_ = default_duration; |
| 56 } else if (track_type_ == kWebMTrackTypeAudio) { | 73 } else if (track_type_ == kWebMTrackTypeAudio) { |
| 57 audio_track_num_ = track_num_; | 74 audio_track_num_ = track_num_; |
| 58 audio_default_duration_ = default_duration; | 75 audio_default_duration_ = default_duration; |
| 59 } else { | 76 } else { |
| 60 VLOG(1) << "Unexpected TrackType " << track_type_; | 77 DVLOG(1) << "Unexpected TrackType " << track_type_; |
| 61 return false; | 78 return false; |
| 62 } | 79 } |
| 63 | 80 |
| 64 track_type_ = -1; | 81 track_type_ = -1; |
| 65 track_num_ = -1; | 82 track_num_ = -1; |
| 66 } | 83 } |
| 67 | 84 |
| 68 return true; | 85 return true; |
| 69 } | 86 } |
| 70 | 87 |
| 71 bool WebMTracksParser::OnUInt(int id, int64 val) { | 88 bool WebMTracksParser::OnUInt(int id, int64 val) { |
| 72 int64* dst = NULL; | 89 int64* dst = NULL; |
| 73 | 90 |
| 74 switch (id) { | 91 switch (id) { |
| 75 case kWebMIdTrackNumber: | 92 case kWebMIdTrackNumber: |
| 76 dst = &track_num_; | 93 dst = &track_num_; |
| 77 break; | 94 break; |
| 78 case kWebMIdTrackType: | 95 case kWebMIdTrackType: |
| 79 dst = &track_type_; | 96 dst = &track_type_; |
| 80 break; | 97 break; |
| 81 case kWebMIdDefaultDuration: | 98 case kWebMIdDefaultDuration: |
| 82 dst = &track_default_duration_; | 99 dst = &track_default_duration_; |
| 83 break; | 100 break; |
| 84 default: | 101 default: |
| 85 return true; | 102 return true; |
| 86 } | 103 } |
| 87 | 104 |
| 88 if (*dst != -1) { | 105 if (*dst != -1) { |
| 89 VLOG(1) << "Multiple values for id " << std::hex << id << " specified"; | 106 DVLOG(1) << "Multiple values for id " << std::hex << id << " specified"; |
| 90 return false; | 107 return false; |
| 91 } | 108 } |
| 92 | 109 |
| 93 *dst = val; | 110 *dst = val; |
| 94 return true; | 111 return true; |
| 95 } | 112 } |
| 96 | 113 |
| 97 bool WebMTracksParser::OnFloat(int id, double val) { | 114 bool WebMTracksParser::OnFloat(int id, double val) { |
| 98 VLOG(1) << "Unexpected float for id" << std::hex << id; | 115 DVLOG(1) << "Unexpected float for id" << std::hex << id; |
| 99 return false; | 116 return false; |
| 100 } | 117 } |
| 101 | 118 |
| 102 bool WebMTracksParser::OnBinary(int id, const uint8* data, int size) { | 119 bool WebMTracksParser::OnBinary(int id, const uint8* data, int size) { |
| 103 return true; | 120 return true; |
| 104 } | 121 } |
| 105 | 122 |
| 106 bool WebMTracksParser::OnString(int id, const std::string& str) { | 123 bool WebMTracksParser::OnString(int id, const std::string& str) { |
| 107 if (id != kWebMIdCodecID) | 124 if (id != kWebMIdCodecID) |
| 108 return false; | 125 return false; |
| 109 | 126 |
| 110 if (str != "A_VORBIS" && str != "V_VP8") { | 127 if (str != "A_VORBIS" && str != "V_VP8") { |
| 111 VLOG(1) << "Unexpected CodecID " << str; | 128 DVLOG(1) << "Unexpected CodecID " << str; |
| 112 return false; | 129 return false; |
| 113 } | 130 } |
| 114 | 131 |
| 115 return true; | 132 return true; |
| 116 } | 133 } |
| 117 | 134 |
| 118 bool WebMTracksParser::OnSimpleBlock(int track_num, int timecode, int flags, | 135 bool WebMTracksParser::OnSimpleBlock(int track_num, int timecode, int flags, |
| 119 const uint8* data, int size) { | 136 const uint8* data, int size) { |
| 120 return false; | 137 return false; |
| 121 } | 138 } |
| 122 | 139 |
| 123 } // namespace media | 140 } // namespace media |
| OLD | NEW |