Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: media/formats/webm/webm_tracks_parser.cc

Issue 1842503002: MSE: Cleanup WebM tracks parser initialization (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Future-proof with conditional re-Reset() Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/formats/webm/webm_tracks_parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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; 61 reset_on_next_parse_ = false;
70 default_duration_ = -1;
71 track_name_.clear();
72 track_language_.clear();
73 audio_track_num_ = -1; 62 audio_track_num_ = -1;
74 audio_default_duration_ = -1; 63 audio_default_duration_ = -1;
75 audio_decoder_config_ = AudioDecoderConfig(); 64 audio_decoder_config_ = AudioDecoderConfig();
76 video_track_num_ = -1; 65 video_track_num_ = -1;
77 video_default_duration_ = -1; 66 video_default_duration_ = -1;
78 video_decoder_config_ = VideoDecoderConfig(); 67 video_decoder_config_ = VideoDecoderConfig();
79 text_tracks_.clear(); 68 text_tracks_.clear();
80 ignored_tracks_.clear(); 69 ignored_tracks_.clear();
81 media_tracks_.reset(new MediaTracks()); 70 media_tracks_.reset(new MediaTracks());
71 }
72
73 void WebMTracksParser::ResetTrackEntry() {
74 track_type_ = -1;
75 track_num_ = -1;
76 track_name_.clear();
77 track_language_.clear();
78 codec_id_ = "";
79 codec_private_.clear();
80 seek_preroll_ = -1;
81 codec_delay_ = -1;
82 default_duration_ = -1;
83 audio_client_.Reset();
84 video_client_.Reset();
85 }
86
87 int WebMTracksParser::Parse(const uint8_t* buf, int size) {
88 if (reset_on_next_parse_)
89 Reset();
90
91 reset_on_next_parse_ = true;
82 92
83 WebMListParser parser(kWebMIdTracks, this); 93 WebMListParser parser(kWebMIdTracks, this);
84 int result = parser.Parse(buf, size); 94 int result = parser.Parse(buf, size);
85 95
86 if (result <= 0) 96 if (result <= 0)
87 return result; 97 return result;
88 98
89 // For now we do all or nothing parsing. 99 // For now we do all or nothing parsing.
90 return parser.IsParsingComplete() ? result : 0; 100 return parser.IsParsingComplete() ? result : 0;
91 } 101 }
(...skipping 12 matching lines...) Expand all
104 114
105 WebMParserClient* WebMTracksParser::OnListStart(int id) { 115 WebMParserClient* WebMTracksParser::OnListStart(int id) {
106 if (id == kWebMIdContentEncodings) { 116 if (id == kWebMIdContentEncodings) {
107 DCHECK(!track_content_encodings_client_.get()); 117 DCHECK(!track_content_encodings_client_.get());
108 track_content_encodings_client_.reset( 118 track_content_encodings_client_.reset(
109 new WebMContentEncodingsClient(media_log_)); 119 new WebMContentEncodingsClient(media_log_));
110 return track_content_encodings_client_->OnListStart(id); 120 return track_content_encodings_client_->OnListStart(id);
111 } 121 }
112 122
113 if (id == kWebMIdTrackEntry) { 123 if (id == kWebMIdTrackEntry) {
114 track_type_ = -1; 124 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; 125 return this;
124 } 126 }
125 127
126 if (id == kWebMIdAudio) 128 if (id == kWebMIdAudio)
127 return &audio_client_; 129 return &audio_client_;
128 130
129 if (id == kWebMIdVideo) 131 if (id == kWebMIdVideo)
130 return &video_client_; 132 return &video_client_;
131 133
132 return this; 134 return this;
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 } else { 357 } else {
356 track_language_ = str; 358 track_language_ = str;
357 } 359 }
358 return true; 360 return true;
359 } 361 }
360 362
361 return true; 363 return true;
362 } 364 }
363 365
364 } // namespace media 366 } // namespace media
OLDNEW
« no previous file with comments | « media/formats/webm/webm_tracks_parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698