Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/formats/webm/webm_tracks_parser.h" | 5 #include "media/formats/webm/webm_tracks_parser.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "media/base/media_util.h" | 10 #include "media/base/media_util.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 mult /= timecode_scale_in_us; | 40 mult /= timecode_scale_in_us; |
| 41 if (mult == 0) | 41 if (mult == 0) |
| 42 return kNoTimestamp(); | 42 return kNoTimestamp(); |
| 43 | 43 |
| 44 mult = static_cast<double>(mult) * timecode_scale_in_us; | 44 mult = static_cast<double>(mult) * timecode_scale_in_us; |
| 45 return base::TimeDelta::FromMicroseconds(mult); | 45 return base::TimeDelta::FromMicroseconds(mult); |
| 46 } | 46 } |
| 47 | 47 |
| 48 WebMTracksParser::WebMTracksParser(const scoped_refptr<MediaLog>& media_log, | 48 WebMTracksParser::WebMTracksParser(const scoped_refptr<MediaLog>& media_log, |
| 49 bool ignore_text_tracks) | 49 bool ignore_text_tracks) |
| 50 : track_type_(-1), | 50 : ignore_text_tracks_(ignore_text_tracks), |
| 51 track_num_(-1), | |
| 52 seek_preroll_(-1), | |
| 53 codec_delay_(-1), | |
| 54 default_duration_(-1), | |
| 55 audio_track_num_(-1), | |
| 56 audio_default_duration_(-1), | |
| 57 video_track_num_(-1), | |
| 58 video_default_duration_(-1), | |
| 59 ignore_text_tracks_(ignore_text_tracks), | |
| 60 media_log_(media_log), | 51 media_log_(media_log), |
| 61 audio_client_(media_log), | 52 audio_client_(media_log), |
| 62 video_client_(media_log) { | 53 video_client_(media_log) { |
| 54 Reset(); | |
| 63 } | 55 } |
| 64 | 56 |
| 65 WebMTracksParser::~WebMTracksParser() {} | 57 WebMTracksParser::~WebMTracksParser() {} |
| 66 | 58 |
| 67 int WebMTracksParser::Parse(const uint8_t* buf, int size) { | 59 void WebMTracksParser::Reset() { |
| 68 track_type_ =-1; | 60 ResetTrackEntry(); |
| 69 track_num_ = -1; | |
| 70 default_duration_ = -1; | |
| 71 track_name_.clear(); | |
| 72 track_language_.clear(); | |
| 73 audio_track_num_ = -1; | 61 audio_track_num_ = -1; |
| 74 audio_default_duration_ = -1; | 62 audio_default_duration_ = -1; |
| 75 audio_decoder_config_ = AudioDecoderConfig(); | 63 audio_decoder_config_ = AudioDecoderConfig(); |
| 76 video_track_num_ = -1; | 64 video_track_num_ = -1; |
| 77 video_default_duration_ = -1; | 65 video_default_duration_ = -1; |
| 78 video_decoder_config_ = VideoDecoderConfig(); | 66 video_decoder_config_ = VideoDecoderConfig(); |
| 79 text_tracks_.clear(); | 67 text_tracks_.clear(); |
| 80 ignored_tracks_.clear(); | 68 ignored_tracks_.clear(); |
| 81 media_tracks_.reset(new MediaTracks()); | 69 media_tracks_.reset(new MediaTracks()); |
| 70 } | |
| 82 | 71 |
| 72 void WebMTracksParser::ResetTrackEntry() { | |
| 73 track_type_ = -1; | |
| 74 track_num_ = -1; | |
| 75 track_name_.clear(); | |
| 76 track_language_.clear(); | |
| 77 codec_id_ = ""; | |
| 78 codec_private_.clear(); | |
| 79 seek_preroll_ = -1; | |
| 80 codec_delay_ = -1; | |
| 81 default_duration_ = -1; | |
| 82 audio_client_.Reset(); | |
| 83 video_client_.Reset(); | |
| 84 } | |
| 85 | |
| 86 int WebMTracksParser::Parse(const uint8_t* buf, int size) { | |
| 83 WebMListParser parser(kWebMIdTracks, this); | 87 WebMListParser parser(kWebMIdTracks, this); |
|
wolenetz
2016/03/28 20:45:07
Note, this works without invoking Reset() here too
wolenetz
2016/03/28 20:53:44
From quick chat, I've added usage of a flag here t
| |
| 84 int result = parser.Parse(buf, size); | 88 int result = parser.Parse(buf, size); |
| 85 | 89 |
| 86 if (result <= 0) | 90 if (result <= 0) |
| 87 return result; | 91 return result; |
| 88 | 92 |
| 89 // For now we do all or nothing parsing. | 93 // For now we do all or nothing parsing. |
| 90 return parser.IsParsingComplete() ? result : 0; | 94 return parser.IsParsingComplete() ? result : 0; |
| 91 } | 95 } |
| 92 | 96 |
| 93 base::TimeDelta WebMTracksParser::GetAudioDefaultDuration( | 97 base::TimeDelta WebMTracksParser::GetAudioDefaultDuration( |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 104 | 108 |
| 105 WebMParserClient* WebMTracksParser::OnListStart(int id) { | 109 WebMParserClient* WebMTracksParser::OnListStart(int id) { |
| 106 if (id == kWebMIdContentEncodings) { | 110 if (id == kWebMIdContentEncodings) { |
| 107 DCHECK(!track_content_encodings_client_.get()); | 111 DCHECK(!track_content_encodings_client_.get()); |
| 108 track_content_encodings_client_.reset( | 112 track_content_encodings_client_.reset( |
| 109 new WebMContentEncodingsClient(media_log_)); | 113 new WebMContentEncodingsClient(media_log_)); |
| 110 return track_content_encodings_client_->OnListStart(id); | 114 return track_content_encodings_client_->OnListStart(id); |
| 111 } | 115 } |
| 112 | 116 |
| 113 if (id == kWebMIdTrackEntry) { | 117 if (id == kWebMIdTrackEntry) { |
| 114 track_type_ = -1; | 118 ResetTrackEntry(); |
| 115 track_num_ = -1; | |
| 116 default_duration_ = -1; | |
| 117 track_name_.clear(); | |
| 118 track_language_.clear(); | |
| 119 codec_id_ = ""; | |
| 120 codec_private_.clear(); | |
| 121 audio_client_.Reset(); | |
| 122 video_client_.Reset(); | |
| 123 return this; | 119 return this; |
| 124 } | 120 } |
| 125 | 121 |
| 126 if (id == kWebMIdAudio) | 122 if (id == kWebMIdAudio) |
| 127 return &audio_client_; | 123 return &audio_client_; |
| 128 | 124 |
| 129 if (id == kWebMIdVideo) | 125 if (id == kWebMIdVideo) |
| 130 return &video_client_; | 126 return &video_client_; |
| 131 | 127 |
| 132 return this; | 128 return this; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 } else { | 351 } else { |
| 356 track_language_ = str; | 352 track_language_ = str; |
| 357 } | 353 } |
| 358 return true; | 354 return true; |
| 359 } | 355 } |
| 360 | 356 |
| 361 return true; | 357 return true; |
| 362 } | 358 } |
| 363 | 359 |
| 364 } // namespace media | 360 } // namespace media |
| OLD | NEW |