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

Side by Side Diff: media/webm/webm_cluster_parser.cc

Issue 23014009: media: Opus support for WebM in Media Source (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase and addressing comments Created 7 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_cluster_parser.h" 5 #include "media/webm/webm_cluster_parser.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/sys_byteorder.h" 10 #include "base/sys_byteorder.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 : timecode_multiplier_(timecode_scale / 1000.0), 57 : timecode_multiplier_(timecode_scale / 1000.0),
58 ignored_tracks_(ignored_tracks), 58 ignored_tracks_(ignored_tracks),
59 audio_encryption_key_id_(audio_encryption_key_id), 59 audio_encryption_key_id_(audio_encryption_key_id),
60 video_encryption_key_id_(video_encryption_key_id), 60 video_encryption_key_id_(video_encryption_key_id),
61 parser_(kWebMIdCluster, this), 61 parser_(kWebMIdCluster, this),
62 last_block_timecode_(-1), 62 last_block_timecode_(-1),
63 block_data_size_(-1), 63 block_data_size_(-1),
64 block_duration_(-1), 64 block_duration_(-1),
65 block_add_id_(-1), 65 block_add_id_(-1),
66 block_additional_data_size_(-1), 66 block_additional_data_size_(-1),
67 discard_padding_(-1),
67 cluster_timecode_(-1), 68 cluster_timecode_(-1),
68 cluster_start_time_(kNoTimestamp()), 69 cluster_start_time_(kNoTimestamp()),
69 cluster_ended_(false), 70 cluster_ended_(false),
70 audio_(audio_track_num, false), 71 audio_(audio_track_num, false),
71 video_(video_track_num, true), 72 video_(video_track_num, true),
72 log_cb_(log_cb) { 73 log_cb_(log_cb) {
73 for (WebMTracksParser::TextTracks::const_iterator it = text_tracks.begin(); 74 for (WebMTracksParser::TextTracks::const_iterator it = text_tracks.begin();
74 it != text_tracks.end(); 75 it != text_tracks.end();
75 ++it) { 76 ++it) {
76 text_track_map_.insert(std::make_pair(it->first, Track(it->first, false))); 77 text_track_map_.insert(std::make_pair(it->first, Track(it->first, false)));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 131 }
131 132
132 WebMParserClient* WebMClusterParser::OnListStart(int id) { 133 WebMParserClient* WebMClusterParser::OnListStart(int id) {
133 if (id == kWebMIdCluster) { 134 if (id == kWebMIdCluster) {
134 cluster_timecode_ = -1; 135 cluster_timecode_ = -1;
135 cluster_start_time_ = kNoTimestamp(); 136 cluster_start_time_ = kNoTimestamp();
136 } else if (id == kWebMIdBlockGroup) { 137 } else if (id == kWebMIdBlockGroup) {
137 block_data_.reset(); 138 block_data_.reset();
138 block_data_size_ = -1; 139 block_data_size_ = -1;
139 block_duration_ = -1; 140 block_duration_ = -1;
141 discard_padding_ = -1;
142 discard_padding_set_ = false;
140 } else if (id == kWebMIdBlockAdditions) { 143 } else if (id == kWebMIdBlockAdditions) {
141 block_add_id_ = -1; 144 block_add_id_ = -1;
142 block_additional_data_.reset(); 145 block_additional_data_.reset();
143 block_additional_data_size_ = -1; 146 block_additional_data_size_ = -1;
144 } 147 }
145 148
146 return this; 149 return this;
147 } 150 }
148 151
149 bool WebMClusterParser::OnListEnd(int id) { 152 bool WebMClusterParser::OnListEnd(int id) {
150 if (id != kWebMIdBlockGroup) 153 if (id != kWebMIdBlockGroup)
151 return true; 154 return true;
152 155
153 // Make sure the BlockGroup actually had a Block. 156 // Make sure the BlockGroup actually had a Block.
154 if (block_data_size_ == -1) { 157 if (block_data_size_ == -1) {
155 MEDIA_LOG(log_cb_) << "Block missing from BlockGroup."; 158 MEDIA_LOG(log_cb_) << "Block missing from BlockGroup.";
156 return false; 159 return false;
157 } 160 }
158 161
159 bool result = ParseBlock(false, block_data_.get(), block_data_size_, 162 bool result = ParseBlock(false, block_data_.get(), block_data_size_,
160 block_additional_data_.get(), 163 block_additional_data_.get(),
161 block_additional_data_size_, block_duration_); 164 block_additional_data_size_, block_duration_,
165 discard_padding_);
162 block_data_.reset(); 166 block_data_.reset();
163 block_data_size_ = -1; 167 block_data_size_ = -1;
164 block_duration_ = -1; 168 block_duration_ = -1;
165 block_add_id_ = -1; 169 block_add_id_ = -1;
166 block_additional_data_.reset(); 170 block_additional_data_.reset();
167 block_additional_data_size_ = -1; 171 block_additional_data_size_ = -1;
172 discard_padding_ = discard_padding_set_ ? discard_padding_ : 0;
acolwell GONE FROM CHROMIUM 2013/09/04 20:08:43 nit: Sorry if I wasn't clear. I meant to place thi
vignesh 2013/09/04 20:27:46 Done.
173 discard_padding_set_ = false;
168 return result; 174 return result;
169 } 175 }
170 176
171 bool WebMClusterParser::OnUInt(int id, int64 val) { 177 bool WebMClusterParser::OnUInt(int id, int64 val) {
172 int64* dst; 178 int64* dst;
173 switch (id) { 179 switch (id) {
174 case kWebMIdTimecode: 180 case kWebMIdTimecode:
175 dst = &cluster_timecode_; 181 dst = &cluster_timecode_;
176 break; 182 break;
177 case kWebMIdBlockDuration: 183 case kWebMIdBlockDuration:
178 dst = &block_duration_; 184 dst = &block_duration_;
179 break; 185 break;
180 case kWebMIdBlockAddID: 186 case kWebMIdBlockAddID:
181 dst = &block_add_id_; 187 dst = &block_add_id_;
182 break; 188 break;
189 case kWebMIdDiscardPadding:
190 if (discard_padding_set_)
191 return false;
192 discard_padding_set_ = true;
193 discard_padding_ = val;
194 return true;
183 default: 195 default:
184 return true; 196 return true;
185 } 197 }
186 if (*dst != -1) 198 if (*dst != -1)
187 return false; 199 return false;
188 *dst = val; 200 *dst = val;
189 return true; 201 return true;
190 } 202 }
191 203
192 bool WebMClusterParser::ParseBlock(bool is_simple_block, const uint8* buf, 204 bool WebMClusterParser::ParseBlock(bool is_simple_block, const uint8* buf,
193 int size, const uint8* additional, 205 int size, const uint8* additional,
194 int additional_size, int duration) { 206 int additional_size, int duration,
207 int64 discard_padding) {
195 if (size < 4) 208 if (size < 4)
196 return false; 209 return false;
197 210
198 // Return an error if the trackNum > 127. We just aren't 211 // Return an error if the trackNum > 127. We just aren't
199 // going to support large track numbers right now. 212 // going to support large track numbers right now.
200 if (!(buf[0] & 0x80)) { 213 if (!(buf[0] & 0x80)) {
201 MEDIA_LOG(log_cb_) << "TrackNumber over 127 not supported"; 214 MEDIA_LOG(log_cb_) << "TrackNumber over 127 not supported";
202 return false; 215 return false;
203 } 216 }
204 217
205 int track_num = buf[0] & 0x7f; 218 int track_num = buf[0] & 0x7f;
206 int timecode = buf[1] << 8 | buf[2]; 219 int timecode = buf[1] << 8 | buf[2];
207 int flags = buf[3] & 0xff; 220 int flags = buf[3] & 0xff;
208 int lacing = (flags >> 1) & 0x3; 221 int lacing = (flags >> 1) & 0x3;
209 222
210 if (lacing) { 223 if (lacing) {
211 MEDIA_LOG(log_cb_) << "Lacing " << lacing << " is not supported yet."; 224 MEDIA_LOG(log_cb_) << "Lacing " << lacing << " is not supported yet.";
212 return false; 225 return false;
213 } 226 }
214 227
215 // Sign extend negative timecode offsets. 228 // Sign extend negative timecode offsets.
216 if (timecode & 0x8000) 229 if (timecode & 0x8000)
217 timecode |= ~0xffff; 230 timecode |= ~0xffff;
218 231
219 const uint8* frame_data = buf + 4; 232 const uint8* frame_data = buf + 4;
220 int frame_size = size - (frame_data - buf); 233 int frame_size = size - (frame_data - buf);
221 return OnBlock(is_simple_block, track_num, timecode, duration, flags, 234 return OnBlock(is_simple_block, track_num, timecode, duration, flags,
222 frame_data, frame_size, additional, additional_size); 235 frame_data, frame_size, additional, additional_size,
236 discard_padding);
223 } 237 }
224 238
225 bool WebMClusterParser::OnBinary(int id, const uint8* data, int size) { 239 bool WebMClusterParser::OnBinary(int id, const uint8* data, int size) {
226 switch (id) { 240 switch (id) {
227 case kWebMIdSimpleBlock: 241 case kWebMIdSimpleBlock:
228 return ParseBlock(true, data, size, NULL, -1, -1); 242 return ParseBlock(true, data, size, NULL, -1, -1, -1);
229 243
230 case kWebMIdBlock: 244 case kWebMIdBlock:
231 if (block_data_) { 245 if (block_data_) {
232 MEDIA_LOG(log_cb_) << "More than 1 Block in a BlockGroup is not " 246 MEDIA_LOG(log_cb_) << "More than 1 Block in a BlockGroup is not "
233 "supported."; 247 "supported.";
234 return false; 248 return false;
235 } 249 }
236 block_data_.reset(new uint8[size]); 250 block_data_.reset(new uint8[size]);
237 memcpy(block_data_.get(), data, size); 251 memcpy(block_data_.get(), data, size);
238 block_data_size_ = size; 252 block_data_size_ = size;
(...skipping 24 matching lines...) Expand all
263 default: 277 default:
264 return true; 278 return true;
265 } 279 }
266 } 280 }
267 281
268 bool WebMClusterParser::OnBlock(bool is_simple_block, int track_num, 282 bool WebMClusterParser::OnBlock(bool is_simple_block, int track_num,
269 int timecode, 283 int timecode,
270 int block_duration, 284 int block_duration,
271 int flags, 285 int flags,
272 const uint8* data, int size, 286 const uint8* data, int size,
273 const uint8* additional, int additional_size) { 287 const uint8* additional, int additional_size,
288 int64 discard_padding) {
274 DCHECK_GE(size, 0); 289 DCHECK_GE(size, 0);
275 if (cluster_timecode_ == -1) { 290 if (cluster_timecode_ == -1) {
276 MEDIA_LOG(log_cb_) << "Got a block before cluster timecode."; 291 MEDIA_LOG(log_cb_) << "Got a block before cluster timecode.";
277 return false; 292 return false;
278 } 293 }
279 294
280 // TODO(acolwell): Should relative negative timecode offsets be rejected? Or 295 // TODO(acolwell): Should relative negative timecode offsets be rejected? Or
281 // only when the absolute timecode is negative? See http://crbug.com/271794 296 // only when the absolute timecode is negative? See http://crbug.com/271794
282 if (timecode < 0) { 297 if (timecode < 0) {
283 MEDIA_LOG(log_cb_) << "Got a block with negative timecode offset " 298 MEDIA_LOG(log_cb_) << "Got a block with negative timecode offset "
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 358
344 buffer->set_timestamp(timestamp); 359 buffer->set_timestamp(timestamp);
345 if (cluster_start_time_ == kNoTimestamp()) 360 if (cluster_start_time_ == kNoTimestamp())
346 cluster_start_time_ = timestamp; 361 cluster_start_time_ = timestamp;
347 362
348 if (block_duration >= 0) { 363 if (block_duration >= 0) {
349 buffer->set_duration(base::TimeDelta::FromMicroseconds( 364 buffer->set_duration(base::TimeDelta::FromMicroseconds(
350 block_duration * timecode_multiplier_)); 365 block_duration * timecode_multiplier_));
351 } 366 }
352 367
368 if (discard_padding != 0) {
369 buffer->set_discard_padding(base::TimeDelta::FromMicroseconds(
370 discard_padding / 1000));
371 }
372
353 return track->AddBuffer(buffer); 373 return track->AddBuffer(buffer);
354 } 374 }
355 375
356 WebMClusterParser::Track::Track(int track_num, bool is_video) 376 WebMClusterParser::Track::Track(int track_num, bool is_video)
357 : track_num_(track_num), 377 : track_num_(track_num),
358 is_video_(is_video) { 378 is_video_(is_video) {
359 } 379 }
360 380
361 WebMClusterParser::Track::~Track() {} 381 WebMClusterParser::Track::~Track() {}
362 382
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 WebMClusterParser::FindTextTrack(int track_num) { 431 WebMClusterParser::FindTextTrack(int track_num) {
412 const TextTrackMap::iterator it = text_track_map_.find(track_num); 432 const TextTrackMap::iterator it = text_track_map_.find(track_num);
413 433
414 if (it == text_track_map_.end()) 434 if (it == text_track_map_.end())
415 return NULL; 435 return NULL;
416 436
417 return &it->second; 437 return &it->second;
418 } 438 }
419 439
420 } // namespace media 440 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698