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

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: 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;
140 } else if (id == kWebMIdBlockAdditions) { 142 } else if (id == kWebMIdBlockAdditions) {
141 block_add_id_ = -1; 143 block_add_id_ = -1;
142 block_additional_data_.reset(); 144 block_additional_data_.reset();
143 block_additional_data_size_ = -1; 145 block_additional_data_size_ = -1;
144 } 146 }
145 147
146 return this; 148 return this;
147 } 149 }
148 150
149 bool WebMClusterParser::OnListEnd(int id) { 151 bool WebMClusterParser::OnListEnd(int id) {
150 if (id != kWebMIdBlockGroup) 152 if (id != kWebMIdBlockGroup)
151 return true; 153 return true;
152 154
153 // Make sure the BlockGroup actually had a Block. 155 // Make sure the BlockGroup actually had a Block.
154 if (block_data_size_ == -1) { 156 if (block_data_size_ == -1) {
155 MEDIA_LOG(log_cb_) << "Block missing from BlockGroup."; 157 MEDIA_LOG(log_cb_) << "Block missing from BlockGroup.";
156 return false; 158 return false;
157 } 159 }
158 160
159 bool result = ParseBlock(false, block_data_.get(), block_data_size_, 161 bool result = ParseBlock(false, block_data_.get(), block_data_size_,
160 block_additional_data_.get(), 162 block_additional_data_.get(),
161 block_additional_data_size_, block_duration_); 163 block_additional_data_size_, block_duration_,
164 discard_padding_);
162 block_data_.reset(); 165 block_data_.reset();
163 block_data_size_ = -1; 166 block_data_size_ = -1;
164 block_duration_ = -1; 167 block_duration_ = -1;
165 block_add_id_ = -1; 168 block_add_id_ = -1;
166 block_additional_data_.reset(); 169 block_additional_data_.reset();
167 block_additional_data_size_ = -1; 170 block_additional_data_size_ = -1;
171 discard_padding_ = -1;
168 return result; 172 return result;
169 } 173 }
170 174
171 bool WebMClusterParser::OnUInt(int id, int64 val) { 175 bool WebMClusterParser::OnUInt(int id, int64 val) {
172 int64* dst; 176 int64* dst;
173 switch (id) { 177 switch (id) {
174 case kWebMIdTimecode: 178 case kWebMIdTimecode:
175 dst = &cluster_timecode_; 179 dst = &cluster_timecode_;
176 break; 180 break;
177 case kWebMIdBlockDuration: 181 case kWebMIdBlockDuration:
178 dst = &block_duration_; 182 dst = &block_duration_;
179 break; 183 break;
180 case kWebMIdBlockAddID: 184 case kWebMIdBlockAddID:
181 dst = &block_add_id_; 185 dst = &block_add_id_;
182 break; 186 break;
187 case kWebMIdDiscardPadding:
188 dst = &discard_padding_;
189 break;
183 default: 190 default:
184 return true; 191 return true;
185 } 192 }
186 if (*dst != -1) 193 if (*dst != -1)
187 return false; 194 return false;
188 *dst = val; 195 *dst = val;
189 return true; 196 return true;
190 } 197 }
191 198
192 bool WebMClusterParser::ParseBlock(bool is_simple_block, const uint8* buf, 199 bool WebMClusterParser::ParseBlock(bool is_simple_block, const uint8* buf,
193 int size, const uint8* additional, 200 int size, const uint8* additional,
194 int additional_size, int duration) { 201 int additional_size, int duration,
202 int64 discard_padding) {
195 if (size < 4) 203 if (size < 4)
196 return false; 204 return false;
197 205
198 // Return an error if the trackNum > 127. We just aren't 206 // Return an error if the trackNum > 127. We just aren't
199 // going to support large track numbers right now. 207 // going to support large track numbers right now.
200 if (!(buf[0] & 0x80)) { 208 if (!(buf[0] & 0x80)) {
201 MEDIA_LOG(log_cb_) << "TrackNumber over 127 not supported"; 209 MEDIA_LOG(log_cb_) << "TrackNumber over 127 not supported";
202 return false; 210 return false;
203 } 211 }
204 212
205 int track_num = buf[0] & 0x7f; 213 int track_num = buf[0] & 0x7f;
206 int timecode = buf[1] << 8 | buf[2]; 214 int timecode = buf[1] << 8 | buf[2];
207 int flags = buf[3] & 0xff; 215 int flags = buf[3] & 0xff;
208 int lacing = (flags >> 1) & 0x3; 216 int lacing = (flags >> 1) & 0x3;
209 217
210 if (lacing) { 218 if (lacing) {
211 MEDIA_LOG(log_cb_) << "Lacing " << lacing << " is not supported yet."; 219 MEDIA_LOG(log_cb_) << "Lacing " << lacing << " is not supported yet.";
212 return false; 220 return false;
213 } 221 }
214 222
215 // Sign extend negative timecode offsets. 223 // Sign extend negative timecode offsets.
216 if (timecode & 0x8000) 224 if (timecode & 0x8000)
217 timecode |= ~0xffff; 225 timecode |= ~0xffff;
218 226
219 const uint8* frame_data = buf + 4; 227 const uint8* frame_data = buf + 4;
220 int frame_size = size - (frame_data - buf); 228 int frame_size = size - (frame_data - buf);
221 return OnBlock(is_simple_block, track_num, timecode, duration, flags, 229 return OnBlock(is_simple_block, track_num, timecode, duration, flags,
222 frame_data, frame_size, additional, additional_size); 230 frame_data, frame_size, additional, additional_size,
231 discard_padding);
223 } 232 }
224 233
225 bool WebMClusterParser::OnBinary(int id, const uint8* data, int size) { 234 bool WebMClusterParser::OnBinary(int id, const uint8* data, int size) {
226 switch (id) { 235 switch (id) {
227 case kWebMIdSimpleBlock: 236 case kWebMIdSimpleBlock:
228 return ParseBlock(true, data, size, NULL, -1, -1); 237 return ParseBlock(true, data, size, NULL, -1, -1, -1);
229 238
230 case kWebMIdBlock: 239 case kWebMIdBlock:
231 if (block_data_) { 240 if (block_data_) {
232 MEDIA_LOG(log_cb_) << "More than 1 Block in a BlockGroup is not " 241 MEDIA_LOG(log_cb_) << "More than 1 Block in a BlockGroup is not "
233 "supported."; 242 "supported.";
234 return false; 243 return false;
235 } 244 }
236 block_data_.reset(new uint8[size]); 245 block_data_.reset(new uint8[size]);
237 memcpy(block_data_.get(), data, size); 246 memcpy(block_data_.get(), data, size);
238 block_data_size_ = size; 247 block_data_size_ = size;
(...skipping 24 matching lines...) Expand all
263 default: 272 default:
264 return true; 273 return true;
265 } 274 }
266 } 275 }
267 276
268 bool WebMClusterParser::OnBlock(bool is_simple_block, int track_num, 277 bool WebMClusterParser::OnBlock(bool is_simple_block, int track_num,
269 int timecode, 278 int timecode,
270 int block_duration, 279 int block_duration,
271 int flags, 280 int flags,
272 const uint8* data, int size, 281 const uint8* data, int size,
273 const uint8* additional, int additional_size) { 282 const uint8* additional, int additional_size,
283 int64 discard_padding) {
274 DCHECK_GE(size, 0); 284 DCHECK_GE(size, 0);
275 if (cluster_timecode_ == -1) { 285 if (cluster_timecode_ == -1) {
276 MEDIA_LOG(log_cb_) << "Got a block before cluster timecode."; 286 MEDIA_LOG(log_cb_) << "Got a block before cluster timecode.";
277 return false; 287 return false;
278 } 288 }
279 289
280 // TODO(acolwell): Should relative negative timecode offsets be rejected? Or 290 // TODO(acolwell): Should relative negative timecode offsets be rejected? Or
281 // only when the absolute timecode is negative? See http://crbug.com/271794 291 // only when the absolute timecode is negative? See http://crbug.com/271794
282 if (timecode < 0) { 292 if (timecode < 0) {
283 MEDIA_LOG(log_cb_) << "Got a block with negative timecode offset " 293 MEDIA_LOG(log_cb_) << "Got a block with negative timecode offset "
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 353
344 buffer->set_timestamp(timestamp); 354 buffer->set_timestamp(timestamp);
345 if (cluster_start_time_ == kNoTimestamp()) 355 if (cluster_start_time_ == kNoTimestamp())
346 cluster_start_time_ = timestamp; 356 cluster_start_time_ = timestamp;
347 357
348 if (block_duration >= 0) { 358 if (block_duration >= 0) {
349 buffer->set_duration(base::TimeDelta::FromMicroseconds( 359 buffer->set_duration(base::TimeDelta::FromMicroseconds(
350 block_duration * timecode_multiplier_)); 360 block_duration * timecode_multiplier_));
351 } 361 }
352 362
363 if (discard_padding >= 0) {
364 buffer->set_discard_padding(discard_padding);
365 }
366
353 return track->AddBuffer(buffer); 367 return track->AddBuffer(buffer);
354 } 368 }
355 369
356 WebMClusterParser::Track::Track(int track_num, bool is_video) 370 WebMClusterParser::Track::Track(int track_num, bool is_video)
357 : track_num_(track_num), 371 : track_num_(track_num),
358 is_video_(is_video) { 372 is_video_(is_video) {
359 } 373 }
360 374
361 WebMClusterParser::Track::~Track() {} 375 WebMClusterParser::Track::~Track() {}
362 376
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 WebMClusterParser::FindTextTrack(int track_num) { 425 WebMClusterParser::FindTextTrack(int track_num) {
412 const TextTrackMap::iterator it = text_track_map_.find(track_num); 426 const TextTrackMap::iterator it = text_track_map_.find(track_num);
413 427
414 if (it == text_track_map_.end()) 428 if (it == text_track_map_.end())
415 return NULL; 429 return NULL;
416 430
417 return &it->second; 431 return &it->second;
418 } 432 }
419 433
420 } // namespace media 434 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698