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

Side by Side Diff: third_party/WebKit/Source/modules/mediasource/SourceBuffer.cpp

Issue 2395543002: reflow comments in modules/[mediasource,plugins] (Closed)
Patch Set: Created 4 years, 2 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 const AtomicString& SourceBuffer::sequenceKeyword() { 173 const AtomicString& SourceBuffer::sequenceKeyword() {
174 DEFINE_STATIC_LOCAL(const AtomicString, sequence, ("sequence")); 174 DEFINE_STATIC_LOCAL(const AtomicString, sequence, ("sequence"));
175 return sequence; 175 return sequence;
176 } 176 }
177 177
178 void SourceBuffer::setMode(const AtomicString& newMode, 178 void SourceBuffer::setMode(const AtomicString& newMode,
179 ExceptionState& exceptionState) { 179 ExceptionState& exceptionState) {
180 BLINK_SBLOG << __func__ << " this=" << this << " newMode=" << newMode; 180 BLINK_SBLOG << __func__ << " this=" << this << " newMode=" << newMode;
181 // Section 3.1 On setting mode attribute steps. 181 // Section 3.1 On setting mode attribute steps.
182 // 1. Let new mode equal the new value being assigned to this attribute. 182 // 1. Let new mode equal the new value being assigned to this attribute.
183 // 2. If this object has been removed from the sourceBuffers attribute of the parent media source, then throw 183 // 2. If this object has been removed from the sourceBuffers attribute of the
184 // an INVALID_STATE_ERR exception and abort these steps. 184 // parent media source, then throw an INVALID_STATE_ERR exception and abort
185 // 3. If the updating attribute equals true, then throw an INVALID_STATE_ERR e xception and abort these steps. 185 // these steps.
186 // 3. If the updating attribute equals true, then throw an INVALID_STATE_ERR
187 // exception and abort these steps.
186 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, 188 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating,
187 exceptionState)) 189 exceptionState))
188 return; 190 return;
189 191
190 // 4. If the readyState attribute of the parent media source is in the "ended" state then run the following steps: 192 // 4. If the readyState attribute of the parent media source is in the "ended"
193 // state then run the following steps:
191 // 4.1 Set the readyState attribute of the parent media source to "open" 194 // 4.1 Set the readyState attribute of the parent media source to "open"
192 // 4.2 Queue a task to fire a simple event named sourceopen at the parent medi a source. 195 // 4.2 Queue a task to fire a simple event named sourceopen at the parent
196 // media source.
193 m_source->openIfInEndedState(); 197 m_source->openIfInEndedState();
194 198
195 // 5. If the append state equals PARSING_MEDIA_SEGMENT, then throw an INVALID_ STATE_ERR and abort these steps. 199 // 5. If the append state equals PARSING_MEDIA_SEGMENT, then throw an
196 // 6. If the new mode equals "sequence", then set the group start timestamp to the highest presentation end timestamp. 200 // INVALID_STATE_ERR and abort these steps.
201 // 6. If the new mode equals "sequence", then set the group start timestamp to
202 // the highest presentation end timestamp.
197 WebSourceBuffer::AppendMode appendMode = WebSourceBuffer::AppendModeSegments; 203 WebSourceBuffer::AppendMode appendMode = WebSourceBuffer::AppendModeSegments;
198 if (newMode == sequenceKeyword()) 204 if (newMode == sequenceKeyword())
199 appendMode = WebSourceBuffer::AppendModeSequence; 205 appendMode = WebSourceBuffer::AppendModeSequence;
200 if (!m_webSourceBuffer->setMode(appendMode)) { 206 if (!m_webSourceBuffer->setMode(appendMode)) {
201 MediaSource::logAndThrowDOMException(exceptionState, InvalidStateError, 207 MediaSource::logAndThrowDOMException(exceptionState, InvalidStateError,
202 "The mode may not be set while the " 208 "The mode may not be set while the "
203 "SourceBuffer's append state is " 209 "SourceBuffer's append state is "
204 "'PARSING_MEDIA_SEGMENT'."); 210 "'PARSING_MEDIA_SEGMENT'.");
205 return; 211 return;
206 } 212 }
207 213
208 // 7. Update the attribute to new mode. 214 // 7. Update the attribute to new mode.
209 m_mode = newMode; 215 m_mode = newMode;
210 } 216 }
211 217
212 TimeRanges* SourceBuffer::buffered(ExceptionState& exceptionState) const { 218 TimeRanges* SourceBuffer::buffered(ExceptionState& exceptionState) const {
213 // Section 3.1 buffered attribute steps. 219 // Section 3.1 buffered attribute steps.
214 // 1. If this object has been removed from the sourceBuffers attribute of the parent media source then throw an 220 // 1. If this object has been removed from the sourceBuffers attribute of the
215 // InvalidStateError exception and abort these steps. 221 // parent media source then throw an InvalidStateError exception and abort
222 // these steps.
216 if (isRemoved()) { 223 if (isRemoved()) {
217 MediaSource::logAndThrowDOMException( 224 MediaSource::logAndThrowDOMException(
218 exceptionState, InvalidStateError, 225 exceptionState, InvalidStateError,
219 "This SourceBuffer has been removed from the parent media source."); 226 "This SourceBuffer has been removed from the parent media source.");
220 return nullptr; 227 return nullptr;
221 } 228 }
222 229
223 // 2. Return a new static normalized TimeRanges object for the media segments buffered. 230 // 2. Return a new static normalized TimeRanges object for the media segments
231 // buffered.
224 return TimeRanges::create(m_webSourceBuffer->buffered()); 232 return TimeRanges::create(m_webSourceBuffer->buffered());
225 } 233 }
226 234
227 double SourceBuffer::timestampOffset() const { 235 double SourceBuffer::timestampOffset() const {
228 return m_timestampOffset; 236 return m_timestampOffset;
229 } 237 }
230 238
231 void SourceBuffer::setTimestampOffset(double offset, 239 void SourceBuffer::setTimestampOffset(double offset,
232 ExceptionState& exceptionState) { 240 ExceptionState& exceptionState) {
233 BLINK_SBLOG << __func__ << " this=" << this << " offset=" << offset; 241 BLINK_SBLOG << __func__ << " this=" << this << " offset=" << offset;
234 // Section 3.1 timestampOffset attribute setter steps. 242 // Section 3.1 timestampOffset attribute setter steps.
235 // https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.ht ml#widl-SourceBuffer-timestampOffset 243 // https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.ht ml#widl-SourceBuffer-timestampOffset
236 // 1. Let new timestamp offset equal the new value being assigned to this attr ibute. 244 // 1. Let new timestamp offset equal the new value being assigned to this
237 // 2. If this object has been removed from the sourceBuffers attribute of the parent media source, then throw an 245 // attribute.
238 // InvalidStateError exception and abort these steps. 246 // 2. If this object has been removed from the sourceBuffers attribute of the
239 // 3. If the updating attribute equals true, then throw an InvalidStateError e xception and abort these steps. 247 // parent media source, then throw an InvalidStateError exception and abort
248 // these steps.
249 // 3. If the updating attribute equals true, then throw an InvalidStateError
250 // exception and abort these steps.
240 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, 251 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating,
241 exceptionState)) 252 exceptionState))
242 return; 253 return;
243 254
244 // 4. If the readyState attribute of the parent media source is in the "ended" state then run the following steps: 255 // 4. If the readyState attribute of the parent media source is in the "ended"
256 // state then run the following steps:
245 // 4.1 Set the readyState attribute of the parent media source to "open" 257 // 4.1 Set the readyState attribute of the parent media source to "open"
246 // 4.2 Queue a task to fire a simple event named sourceopen at the parent medi a source. 258 // 4.2 Queue a task to fire a simple event named sourceopen at the parent
259 // media source.
247 m_source->openIfInEndedState(); 260 m_source->openIfInEndedState();
248 261
249 // 5. If the append state equals PARSING_MEDIA_SEGMENT, then throw an INVALID_ STATE_ERR and abort these steps. 262 // 5. If the append state equals PARSING_MEDIA_SEGMENT, then throw an
250 // 6. If the mode attribute equals "sequence", then set the group start timest amp to new timestamp offset. 263 // INVALID_STATE_ERR and abort these steps.
264 // 6. If the mode attribute equals "sequence", then set the group start
265 // timestamp to new timestamp offset.
251 if (!m_webSourceBuffer->setTimestampOffset(offset)) { 266 if (!m_webSourceBuffer->setTimestampOffset(offset)) {
252 MediaSource::logAndThrowDOMException(exceptionState, InvalidStateError, 267 MediaSource::logAndThrowDOMException(exceptionState, InvalidStateError,
253 "The timestamp offset may not be set " 268 "The timestamp offset may not be set "
254 "while the SourceBuffer's append " 269 "while the SourceBuffer's append "
255 "state is 'PARSING_MEDIA_SEGMENT'."); 270 "state is 'PARSING_MEDIA_SEGMENT'.");
256 return; 271 return;
257 } 272 }
258 273
259 // 7. Update the attribute to new timestamp offset. 274 // 7. Update the attribute to new timestamp offset.
260 m_timestampOffset = offset; 275 m_timestampOffset = offset;
(...skipping 11 matching lines...) Expand all
272 287
273 double SourceBuffer::appendWindowStart() const { 288 double SourceBuffer::appendWindowStart() const {
274 return m_appendWindowStart; 289 return m_appendWindowStart;
275 } 290 }
276 291
277 void SourceBuffer::setAppendWindowStart(double start, 292 void SourceBuffer::setAppendWindowStart(double start,
278 ExceptionState& exceptionState) { 293 ExceptionState& exceptionState) {
279 BLINK_SBLOG << __func__ << " this=" << this << " start=" << start; 294 BLINK_SBLOG << __func__ << " this=" << this << " start=" << start;
280 // Section 3.1 appendWindowStart attribute setter steps. 295 // Section 3.1 appendWindowStart attribute setter steps.
281 // https://www.w3.org/TR/media-source/#widl-SourceBuffer-appendWindowStart 296 // https://www.w3.org/TR/media-source/#widl-SourceBuffer-appendWindowStart
282 // 1. If this object has been removed from the sourceBuffers attribute of the parent media source then throw an 297 // 1. If this object has been removed from the sourceBuffers attribute of the
283 // InvalidStateError exception and abort these steps. 298 // parent media source then throw an InvalidStateError exception and abort
284 // 2. If the updating attribute equals true, then throw an InvalidStateError e xception and abort these steps. 299 // these steps.
300 // 2. If the updating attribute equals true, then throw an InvalidStateError
301 // exception and abort these steps.
285 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, 302 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating,
286 exceptionState)) 303 exceptionState))
287 return; 304 return;
288 305
289 // 3. If the new value is less than 0 or greater than or equal to appendWindow End then throw a TypeError 306 // 3. If the new value is less than 0 or greater than or equal to
290 // exception and abort these steps. 307 // appendWindowEnd then throw a TypeError exception and abort these steps.
291 if (start < 0 || start >= m_appendWindowEnd) { 308 if (start < 0 || start >= m_appendWindowEnd) {
292 MediaSource::logAndThrowTypeError( 309 MediaSource::logAndThrowTypeError(
293 exceptionState, 310 exceptionState,
294 ExceptionMessages::indexOutsideRange( 311 ExceptionMessages::indexOutsideRange(
295 "value", start, 0.0, ExceptionMessages::ExclusiveBound, 312 "value", start, 0.0, ExceptionMessages::ExclusiveBound,
296 m_appendWindowEnd, ExceptionMessages::InclusiveBound)); 313 m_appendWindowEnd, ExceptionMessages::InclusiveBound));
297 return; 314 return;
298 } 315 }
299 316
300 m_webSourceBuffer->setAppendWindowStart(start); 317 m_webSourceBuffer->setAppendWindowStart(start);
301 318
302 // 4. Update the attribute to the new value. 319 // 4. Update the attribute to the new value.
303 m_appendWindowStart = start; 320 m_appendWindowStart = start;
304 } 321 }
305 322
306 double SourceBuffer::appendWindowEnd() const { 323 double SourceBuffer::appendWindowEnd() const {
307 return m_appendWindowEnd; 324 return m_appendWindowEnd;
308 } 325 }
309 326
310 void SourceBuffer::setAppendWindowEnd(double end, 327 void SourceBuffer::setAppendWindowEnd(double end,
311 ExceptionState& exceptionState) { 328 ExceptionState& exceptionState) {
312 BLINK_SBLOG << __func__ << " this=" << this << " end=" << end; 329 BLINK_SBLOG << __func__ << " this=" << this << " end=" << end;
313 // Section 3.1 appendWindowEnd attribute setter steps. 330 // Section 3.1 appendWindowEnd attribute setter steps.
314 // https://www.w3.org/TR/media-source/#widl-SourceBuffer-appendWindowEnd 331 // https://www.w3.org/TR/media-source/#widl-SourceBuffer-appendWindowEnd
315 // 1. If this object has been removed from the sourceBuffers attribute of the parent media source then throw an 332 // 1. If this object has been removed from the sourceBuffers attribute of the
316 // InvalidStateError exception and abort these steps. 333 // parent media source then throw an InvalidStateError exception and abort
317 // 2. If the updating attribute equals true, then throw an InvalidStateError e xception and abort these steps. 334 // these steps.
335 // 2. If the updating attribute equals true, then throw an InvalidStateError
336 // exception and abort these steps.
318 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, 337 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating,
319 exceptionState)) 338 exceptionState))
320 return; 339 return;
321 340
322 // 3. If the new value equals NaN, then throw a TypeError and abort these step s. 341 // 3. If the new value equals NaN, then throw a TypeError and abort these
342 // steps.
323 if (std::isnan(end)) { 343 if (std::isnan(end)) {
324 MediaSource::logAndThrowTypeError(exceptionState, 344 MediaSource::logAndThrowTypeError(exceptionState,
325 ExceptionMessages::notAFiniteNumber(end)); 345 ExceptionMessages::notAFiniteNumber(end));
326 return; 346 return;
327 } 347 }
328 // 4. If the new value is less than or equal to appendWindowStart then throw a TypeError 348 // 4. If the new value is less than or equal to appendWindowStart then throw a
329 // exception and abort these steps. 349 // TypeError exception and abort these steps.
330 if (end <= m_appendWindowStart) { 350 if (end <= m_appendWindowStart) {
331 MediaSource::logAndThrowTypeError( 351 MediaSource::logAndThrowTypeError(
332 exceptionState, ExceptionMessages::indexExceedsMinimumBound( 352 exceptionState, ExceptionMessages::indexExceedsMinimumBound(
333 "value", end, m_appendWindowStart)); 353 "value", end, m_appendWindowStart));
334 return; 354 return;
335 } 355 }
336 356
337 m_webSourceBuffer->setAppendWindowEnd(end); 357 m_webSourceBuffer->setAppendWindowEnd(end);
338 358
339 // 5. Update the attribute to the new value. 359 // 5. Update the attribute to the new value.
(...skipping 30 matching lines...) Expand all
370 BLINK_SBLOG << __func__ << " this=" << this << " maxSize=" << maxSize; 390 BLINK_SBLOG << __func__ << " this=" << this << " maxSize=" << maxSize;
371 m_streamMaxSizeValid = maxSize > 0; 391 m_streamMaxSizeValid = maxSize > 0;
372 if (m_streamMaxSizeValid) 392 if (m_streamMaxSizeValid)
373 m_streamMaxSize = maxSize; 393 m_streamMaxSize = maxSize;
374 appendStreamInternal(stream, exceptionState); 394 appendStreamInternal(stream, exceptionState);
375 } 395 }
376 396
377 void SourceBuffer::abort(ExceptionState& exceptionState) { 397 void SourceBuffer::abort(ExceptionState& exceptionState) {
378 BLINK_SBLOG << __func__ << " this=" << this; 398 BLINK_SBLOG << __func__ << " this=" << this;
379 // http://w3c.github.io/media-source/#widl-SourceBuffer-abort-void 399 // http://w3c.github.io/media-source/#widl-SourceBuffer-abort-void
380 // 1. If this object has been removed from the sourceBuffers attribute of the parent media source 400 // 1. If this object has been removed from the sourceBuffers attribute of the
381 // then throw an InvalidStateError exception and abort these steps. 401 // parent media source then throw an InvalidStateError exception and abort
382 // 2. If the readyState attribute of the parent media source is not in the "op en" state 402 // these steps.
383 // then throw an InvalidStateError exception and abort these steps. 403 // 2. If the readyState attribute of the parent media source is not in the
404 // "open" state then throw an InvalidStateError exception and abort these
405 // steps.
384 if (isRemoved()) { 406 if (isRemoved()) {
385 MediaSource::logAndThrowDOMException( 407 MediaSource::logAndThrowDOMException(
386 exceptionState, InvalidStateError, 408 exceptionState, InvalidStateError,
387 "This SourceBuffer has been removed from the parent media source."); 409 "This SourceBuffer has been removed from the parent media source.");
388 return; 410 return;
389 } 411 }
390 if (!m_source->isOpen()) { 412 if (!m_source->isOpen()) {
391 MediaSource::logAndThrowDOMException( 413 MediaSource::logAndThrowDOMException(
392 exceptionState, InvalidStateError, 414 exceptionState, InvalidStateError,
393 "The parent media source's readyState is not 'open'."); 415 "The parent media source's readyState is not 'open'.");
(...skipping 12 matching lines...) Expand all
406 exceptionState, InvalidStateError, 428 exceptionState, InvalidStateError,
407 "Aborting asynchronous remove() operation is disallowed."); 429 "Aborting asynchronous remove() operation is disallowed.");
408 return; 430 return;
409 } 431 }
410 432
411 Deprecation::countDeprecation(m_source->mediaElement()->document(), 433 Deprecation::countDeprecation(m_source->mediaElement()->document(),
412 UseCounter::MediaSourceAbortRemove); 434 UseCounter::MediaSourceAbortRemove);
413 cancelRemove(); 435 cancelRemove();
414 } 436 }
415 437
416 // 4. If the sourceBuffer.updating attribute equals true, then run the followi ng steps: ... 438 // 4. If the sourceBuffer.updating attribute equals true, then run the
439 // following steps: ...
417 abortIfUpdating(); 440 abortIfUpdating();
418 441
419 // 5. Run the reset parser state algorithm. 442 // 5. Run the reset parser state algorithm.
420 m_webSourceBuffer->resetParserState(); 443 m_webSourceBuffer->resetParserState();
421 444
422 // 6. Set appendWindowStart to 0. 445 // 6. Set appendWindowStart to 0.
423 setAppendWindowStart(0, exceptionState); 446 setAppendWindowStart(0, exceptionState);
424 447
425 // 7. Set appendWindowEnd to positive Infinity. 448 // 7. Set appendWindowEnd to positive Infinity.
426 setAppendWindowEnd(std::numeric_limits<double>::infinity(), exceptionState); 449 setAppendWindowEnd(std::numeric_limits<double>::infinity(), exceptionState);
427 } 450 }
428 451
429 void SourceBuffer::remove(double start, 452 void SourceBuffer::remove(double start,
430 double end, 453 double end,
431 ExceptionState& exceptionState) { 454 ExceptionState& exceptionState) {
432 BLINK_SBLOG << __func__ << " this=" << this << " start=" << start 455 BLINK_SBLOG << __func__ << " this=" << this << " start=" << start
433 << " end=" << end; 456 << " end=" << end;
434 457
435 // Section 3.2 remove() method steps. 458 // Section 3.2 remove() method steps.
436 // https://www.w3.org/TR/media-source/#widl-SourceBuffer-remove-void-double-st art-unrestricted-double-end 459 // https://www.w3.org/TR/media-source/#widl-SourceBuffer-remove-void-double-st art-unrestricted-double-end
437 // 1. If this object has been removed from the sourceBuffers attribute of the parent media source then throw an 460 // 1. If this object has been removed from the sourceBuffers attribute of the
438 // InvalidStateError exception and abort these steps. 461 // parent media source then throw an InvalidStateError exception and abort
439 // 2. If the updating attribute equals true, then throw an InvalidStateError e xception and abort these steps. 462 // these steps.
463 // 2. If the updating attribute equals true, then throw an InvalidStateError
464 // exception and abort these steps.
440 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, 465 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating,
441 exceptionState)) 466 exceptionState))
442 return; 467 return;
443 468
444 // 3. If duration equals NaN, then throw a TypeError exception and abort these steps. 469 // 3. If duration equals NaN, then throw a TypeError exception and abort these
445 // 4. If start is negative or greater than duration, then throw a TypeError ex ception and abort these steps. 470 // steps.
471 // 4. If start is negative or greater than duration, then throw a TypeError
472 // exception and abort these steps.
446 if (start < 0 || std::isnan(m_source->duration()) || 473 if (start < 0 || std::isnan(m_source->duration()) ||
447 start > m_source->duration()) { 474 start > m_source->duration()) {
448 MediaSource::logAndThrowTypeError( 475 MediaSource::logAndThrowTypeError(
449 exceptionState, 476 exceptionState,
450 ExceptionMessages::indexOutsideRange( 477 ExceptionMessages::indexOutsideRange(
451 "start", start, 0.0, ExceptionMessages::ExclusiveBound, 478 "start", start, 0.0, ExceptionMessages::ExclusiveBound,
452 std::isnan(m_source->duration()) ? 0 : m_source->duration(), 479 std::isnan(m_source->duration()) ? 0 : m_source->duration(),
453 ExceptionMessages::ExclusiveBound)); 480 ExceptionMessages::ExclusiveBound));
454 return; 481 return;
455 } 482 }
456 483
457 // 5. If end is less than or equal to start or end equals NaN, then throw a Ty peError exception and abort these steps. 484 // 5. If end is less than or equal to start or end equals NaN, then throw a
485 // TypeError exception and abort these steps.
458 if (end <= start || std::isnan(end)) { 486 if (end <= start || std::isnan(end)) {
459 MediaSource::logAndThrowTypeError( 487 MediaSource::logAndThrowTypeError(
460 exceptionState, 488 exceptionState,
461 "The end value provided (" + String::number(end) + 489 "The end value provided (" + String::number(end) +
462 ") must be greater than the start value provided (" + 490 ") must be greater than the start value provided (" +
463 String::number(start) + ")."); 491 String::number(start) + ").");
464 return; 492 return;
465 } 493 }
466 494
467 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::remove", this); 495 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::remove", this);
468 496
469 // 6. If the readyState attribute of the parent media source is in the "ended" state then run the following steps: 497 // 6. If the readyState attribute of the parent media source is in the "ended"
498 // state then run the following steps:
470 // 6.1. Set the readyState attribute of the parent media source to "open" 499 // 6.1. Set the readyState attribute of the parent media source to "open"
471 // 6.2. Queue a task to fire a simple event named sourceopen at the parent med ia source . 500 // 6.2. Queue a task to fire a simple event named sourceopen at the parent
501 // media source .
472 m_source->openIfInEndedState(); 502 m_source->openIfInEndedState();
473 503
474 // 7. Run the range removal algorithm with start and end as the start and end of the removal range. 504 // 7. Run the range removal algorithm with start and end as the start and end
505 // of the removal range.
475 // 7.3. Set the updating attribute to true. 506 // 7.3. Set the updating attribute to true.
476 m_updating = true; 507 m_updating = true;
477 508
478 // 7.4. Queue a task to fire a simple event named updatestart at this SourceBu ffer object. 509 // 7.4. Queue a task to fire a simple event named updatestart at this
510 // SourceBuffer object.
479 scheduleEvent(EventTypeNames::updatestart); 511 scheduleEvent(EventTypeNames::updatestart);
480 512
481 // 7.5. Return control to the caller and run the rest of the steps asynchronou sly. 513 // 7.5. Return control to the caller and run the rest of the steps
514 // asynchronously.
482 m_pendingRemoveStart = start; 515 m_pendingRemoveStart = start;
483 m_pendingRemoveEnd = end; 516 m_pendingRemoveEnd = end;
484 m_removeAsyncPartRunner->runAsync(); 517 m_removeAsyncPartRunner->runAsync();
485 } 518 }
486 519
487 void SourceBuffer::setTrackDefaults(TrackDefaultList* trackDefaults, 520 void SourceBuffer::setTrackDefaults(TrackDefaultList* trackDefaults,
488 ExceptionState& exceptionState) { 521 ExceptionState& exceptionState) {
489 // Per 02 Dec 2014 Editor's Draft 522 // Per 02 Dec 2014 Editor's Draft
490 // http://w3c.github.io/media-source/#widl-SourceBuffer-trackDefaults 523 // http://w3c.github.io/media-source/#widl-SourceBuffer-trackDefaults
491 // 1. If this object has been removed from the sourceBuffers attribute of 524 // 1. If this object has been removed from the sourceBuffers attribute of
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 559
527 DCHECK_EQ(m_pendingRemoveStart, -1); 560 DCHECK_EQ(m_pendingRemoveStart, -1);
528 561
529 const char* traceEventName = 0; 562 const char* traceEventName = 0;
530 if (m_stream) { 563 if (m_stream) {
531 traceEventName = "SourceBuffer::appendStream"; 564 traceEventName = "SourceBuffer::appendStream";
532 } else { 565 } else {
533 traceEventName = "SourceBuffer::appendBuffer"; 566 traceEventName = "SourceBuffer::appendBuffer";
534 } 567 }
535 568
536 // 4.1. Abort the buffer append and stream append loop algorithms if they are running. 569 // 4.1. Abort the buffer append and stream append loop algorithms if they are
570 // running.
537 m_appendBufferAsyncPartRunner->stop(); 571 m_appendBufferAsyncPartRunner->stop();
538 m_pendingAppendData.clear(); 572 m_pendingAppendData.clear();
539 m_pendingAppendDataOffset = 0; 573 m_pendingAppendDataOffset = 0;
540 574
541 m_appendStreamAsyncPartRunner->stop(); 575 m_appendStreamAsyncPartRunner->stop();
542 clearAppendStreamState(); 576 clearAppendStreamState();
543 577
544 // 4.2. Set the updating attribute to false. 578 // 4.2. Set the updating attribute to false.
545 m_updating = false; 579 m_updating = false;
546 580
547 // 4.3. Queue a task to fire a simple event named abort at this SourceBuffer o bject. 581 // 4.3. Queue a task to fire a simple event named abort at this SourceBuffer
582 // object.
548 scheduleEvent(EventTypeNames::abort); 583 scheduleEvent(EventTypeNames::abort);
549 584
550 // 4.4. Queue a task to fire a simple event named updateend at this SourceBuff er object. 585 // 4.4. Queue a task to fire a simple event named updateend at this
586 // SourceBuffer object.
551 scheduleEvent(EventTypeNames::updateend); 587 scheduleEvent(EventTypeNames::updateend);
552 588
553 TRACE_EVENT_ASYNC_END0("media", traceEventName, this); 589 TRACE_EVENT_ASYNC_END0("media", traceEventName, this);
554 } 590 }
555 591
556 void SourceBuffer::removedFromMediaSource() { 592 void SourceBuffer::removedFromMediaSource() {
557 if (isRemoved()) 593 if (isRemoved())
558 return; 594 return;
559 595
560 BLINK_SBLOG << __func__ << " this=" << this; 596 BLINK_SBLOG << __func__ << " this=" << this;
(...skipping 20 matching lines...) Expand all
581 double SourceBuffer::highestPresentationTimestamp() { 617 double SourceBuffer::highestPresentationTimestamp() {
582 DCHECK(!isRemoved()); 618 DCHECK(!isRemoved());
583 619
584 double pts = m_webSourceBuffer->highestPresentationTimestamp(); 620 double pts = m_webSourceBuffer->highestPresentationTimestamp();
585 BLINK_SBLOG << __func__ << " this=" << this << ", pts=" << pts; 621 BLINK_SBLOG << __func__ << " this=" << this << ", pts=" << pts;
586 return pts; 622 return pts;
587 } 623 }
588 624
589 void SourceBuffer::removeMediaTracks() { 625 void SourceBuffer::removeMediaTracks() {
590 DCHECK(RuntimeEnabledFeatures::audioVideoTracksEnabled()); 626 DCHECK(RuntimeEnabledFeatures::audioVideoTracksEnabled());
591 // Spec: http://w3c.github.io/media-source/#widl-MediaSource-removeSourceBuffe r-void-SourceBuffer-sourceBuffer 627 // Spec:
628 // http://w3c.github.io/media-source/#widl-MediaSource-removeSourceBuffer-void -SourceBuffer-sourceBuffer
592 DCHECK(m_source); 629 DCHECK(m_source);
593 630
594 HTMLMediaElement* mediaElement = m_source->mediaElement(); 631 HTMLMediaElement* mediaElement = m_source->mediaElement();
595 DCHECK(mediaElement); 632 DCHECK(mediaElement);
596 // 3. Let SourceBuffer audioTracks list equal the AudioTrackList object return ed by sourceBuffer.audioTracks. 633 // 3. Let SourceBuffer audioTracks list equal the AudioTrackList object
597 // 4. If the SourceBuffer audioTracks list is not empty, then run the followin g steps: 634 // returned by sourceBuffer.audioTracks.
598 // 4.1 Let HTMLMediaElement audioTracks list equal the AudioTrackList object r eturned by the audioTracks attribute on the HTMLMediaElement. 635 // 4. If the SourceBuffer audioTracks list is not empty, then run the
636 // following steps:
637 // 4.1 Let HTMLMediaElement audioTracks list equal the AudioTrackList object
638 // returned by the audioTracks attribute on the HTMLMediaElement.
599 // 4.2 Let the removed enabled audio track flag equal false. 639 // 4.2 Let the removed enabled audio track flag equal false.
600 bool removedEnabledAudioTrack = false; 640 bool removedEnabledAudioTrack = false;
601 // 4.3 For each AudioTrack object in the SourceBuffer audioTracks list, run th e following steps: 641 // 4.3 For each AudioTrack object in the SourceBuffer audioTracks list, run
642 // the following steps:
602 while (audioTracks().length() > 0) { 643 while (audioTracks().length() > 0) {
603 AudioTrack* audioTrack = audioTracks().anonymousIndexedGetter(0); 644 AudioTrack* audioTrack = audioTracks().anonymousIndexedGetter(0);
604 // 4.3.1 Set the sourceBuffer attribute on the AudioTrack object to null. 645 // 4.3.1 Set the sourceBuffer attribute on the AudioTrack object to null.
605 SourceBufferTrackBaseSupplement::setSourceBuffer(*audioTrack, nullptr); 646 SourceBufferTrackBaseSupplement::setSourceBuffer(*audioTrack, nullptr);
606 // 4.3.2 If the enabled attribute on the AudioTrack object is true, then set the removed enabled audio track flag to true. 647 // 4.3.2 If the enabled attribute on the AudioTrack object is true, then set
648 // the removed enabled audio track flag to true.
607 if (audioTrack->enabled()) 649 if (audioTrack->enabled())
608 removedEnabledAudioTrack = true; 650 removedEnabledAudioTrack = true;
609 // 4.3.3 Remove the AudioTrack object from the HTMLMediaElement audioTracks list. 651 // 4.3.3 Remove the AudioTrack object from the HTMLMediaElement audioTracks
610 // 4.3.4 Queue a task to fire a trusted event named removetrack, that does n ot bubble and is not cancelable, and that uses the TrackEvent interface, at the HTMLMediaElement audioTracks list. 652 // list.
653 // 4.3.4 Queue a task to fire a trusted event named removetrack, that does
654 // not bubble and is not cancelable, and that uses the TrackEvent
655 // interface, at the HTMLMediaElement audioTracks list.
611 mediaElement->audioTracks().remove(audioTrack->id()); 656 mediaElement->audioTracks().remove(audioTrack->id());
612 // 4.3.5 Remove the AudioTrack object from the SourceBuffer audioTracks list . 657 // 4.3.5 Remove the AudioTrack object from the SourceBuffer audioTracks
613 // 4.3.6 Queue a task to fire a trusted event named removetrack, that does n ot bubble and is not cancelable, and that uses the TrackEvent interface, at the SourceBuffer audioTracks list. 658 // list.
659 // 4.3.6 Queue a task to fire a trusted event named removetrack, that does
660 // not bubble and is not cancelable, and that uses the TrackEvent
661 // interface, at the SourceBuffer audioTracks list.
614 audioTracks().remove(audioTrack->id()); 662 audioTracks().remove(audioTrack->id());
615 } 663 }
616 // 4.4 If the removed enabled audio track flag equals true, then queue a task to fire a simple event named change at the HTMLMediaElement audioTracks list. 664 // 4.4 If the removed enabled audio track flag equals true, then queue a task
665 // to fire a simple event named change at the HTMLMediaElement audioTracks
666 // list.
617 if (removedEnabledAudioTrack) { 667 if (removedEnabledAudioTrack) {
618 Event* event = Event::create(EventTypeNames::change); 668 Event* event = Event::create(EventTypeNames::change);
619 event->setTarget(&mediaElement->audioTracks()); 669 event->setTarget(&mediaElement->audioTracks());
620 mediaElement->scheduleEvent(event); 670 mediaElement->scheduleEvent(event);
621 } 671 }
622 672
623 // 5. Let SourceBuffer videoTracks list equal the VideoTrackList object return ed by sourceBuffer.videoTracks. 673 // 5. Let SourceBuffer videoTracks list equal the VideoTrackList object
624 // 6. If the SourceBuffer videoTracks list is not empty, then run the followin g steps: 674 // returned by sourceBuffer.videoTracks.
625 // 6.1 Let HTMLMediaElement videoTracks list equal the VideoTrackList object r eturned by the videoTracks attribute on the HTMLMediaElement. 675 // 6. If the SourceBuffer videoTracks list is not empty, then run the
676 // following steps:
677 // 6.1 Let HTMLMediaElement videoTracks list equal the VideoTrackList object
678 // returned by the videoTracks attribute on the HTMLMediaElement.
626 // 6.2 Let the removed selected video track flag equal false. 679 // 6.2 Let the removed selected video track flag equal false.
627 bool removedSelectedVideoTrack = false; 680 bool removedSelectedVideoTrack = false;
628 // 6.3 For each VideoTrack object in the SourceBuffer videoTracks list, run th e following steps: 681 // 6.3 For each VideoTrack object in the SourceBuffer videoTracks list, run
682 // the following steps:
629 while (videoTracks().length() > 0) { 683 while (videoTracks().length() > 0) {
630 VideoTrack* videoTrack = videoTracks().anonymousIndexedGetter(0); 684 VideoTrack* videoTrack = videoTracks().anonymousIndexedGetter(0);
631 // 6.3.1 Set the sourceBuffer attribute on the VideoTrack object to null. 685 // 6.3.1 Set the sourceBuffer attribute on the VideoTrack object to null.
632 SourceBufferTrackBaseSupplement::setSourceBuffer(*videoTrack, nullptr); 686 SourceBufferTrackBaseSupplement::setSourceBuffer(*videoTrack, nullptr);
633 // 6.3.2 If the selected attribute on the VideoTrack object is true, then se t the removed selected video track flag to true. 687 // 6.3.2 If the selected attribute on the VideoTrack object is true, then
688 // set the removed selected video track flag to true.
634 if (videoTrack->selected()) 689 if (videoTrack->selected())
635 removedSelectedVideoTrack = true; 690 removedSelectedVideoTrack = true;
636 // 6.3.3 Remove the VideoTrack object from the HTMLMediaElement videoTracks list. 691 // 6.3.3 Remove the VideoTrack object from the HTMLMediaElement videoTracks
637 // 6.3.4 Queue a task to fire a trusted event named removetrack, that does n ot bubble and is not cancelable, and that uses the TrackEvent interface, at the HTMLMediaElement videoTracks list. 692 // list.
693 // 6.3.4 Queue a task to fire a trusted event named removetrack, that does
694 // not bubble and is not cancelable, and that uses the TrackEvent
695 // interface, at the HTMLMediaElement videoTracks list.
638 mediaElement->videoTracks().remove(videoTrack->id()); 696 mediaElement->videoTracks().remove(videoTrack->id());
639 // 6.3.5 Remove the VideoTrack object from the SourceBuffer videoTracks list . 697 // 6.3.5 Remove the VideoTrack object from the SourceBuffer videoTracks
640 // 6.3.6 Queue a task to fire a trusted event named removetrack, that does n ot bubble and is not cancelable, and that uses the TrackEvent interface, at the SourceBuffer videoTracks list. 698 // list.
699 // 6.3.6 Queue a task to fire a trusted event named removetrack, that does
700 // not bubble and is not cancelable, and that uses the TrackEvent
701 // interface, at the SourceBuffer videoTracks list.
641 videoTracks().remove(videoTrack->id()); 702 videoTracks().remove(videoTrack->id());
642 } 703 }
643 // 6.4 If the removed selected video track flag equals true, then queue a task to fire a simple event named change at the HTMLMediaElement videoTracks list. 704 // 6.4 If the removed selected video track flag equals true, then queue a task
705 // to fire a simple event named change at the HTMLMediaElement videoTracks
706 // list.
644 if (removedSelectedVideoTrack) { 707 if (removedSelectedVideoTrack) {
645 Event* event = Event::create(EventTypeNames::change); 708 Event* event = Event::create(EventTypeNames::change);
646 event->setTarget(&mediaElement->videoTracks()); 709 event->setTarget(&mediaElement->videoTracks());
647 mediaElement->scheduleEvent(event); 710 mediaElement->scheduleEvent(event);
648 } 711 }
649 712
650 // 7-8. TODO(servolk): Remove text tracks once SourceBuffer has text tracks. 713 // 7-8. TODO(servolk): Remove text tracks once SourceBuffer has text tracks.
651 } 714 }
652 715
653 template <class T> 716 template <class T>
654 T* findExistingTrackById(const TrackListBase<T>& trackList, const String& id) { 717 T* findExistingTrackById(const TrackListBase<T>& trackList, const String& id) {
655 // According to MSE specification (https://w3c.github.io/media-source/#sourceb uffer-init-segment-received) step 3.1: 718 // According to MSE specification
656 // > If more than one track for a single type are present (ie 2 audio tracks), then the Track IDs match the ones in the first initialization segment. 719 // (https://w3c.github.io/media-source/#sourcebuffer-init-segment-received)
657 // I.e. we only need to search by TrackID if there is more than one track, oth erwise we can assume that the only 720 // step 3.1:
658 // track of the given type is the same one that we had in previous init segmen ts. 721 // > If more than one track for a single type are present (ie 2 audio tracks),
722 // then the Track IDs match the ones in the first initialization segment.
723 // I.e. we only need to search by TrackID if there is more than one track,
724 // otherwise we can assume that the only track of the given type is the same
725 // one that we had in previous init segments.
659 if (trackList.length() == 1) 726 if (trackList.length() == 1)
660 return trackList.anonymousIndexedGetter(0); 727 return trackList.anonymousIndexedGetter(0);
661 return trackList.getTrackById(id); 728 return trackList.getTrackById(id);
662 } 729 }
663 730
664 const TrackDefault* SourceBuffer::getTrackDefault( 731 const TrackDefault* SourceBuffer::getTrackDefault(
665 const AtomicString& trackType, 732 const AtomicString& trackType,
666 const AtomicString& byteStreamTrackID) const { 733 const AtomicString& byteStreamTrackID) const {
667 // This is a helper for implementation of default track label and default trac k language algorithms. 734 // This is a helper for implementation of default track label and default
668 // defaultTrackLabel spec: https://w3c.github.io/media-source/#sourcebuffer-de fault-track-label 735 // track language algorithms.
669 // defaultTrackLanguage spec: https://w3c.github.io/media-source/#sourcebuffer -default-track-language 736 // defaultTrackLabel spec:
737 // https://w3c.github.io/media-source/#sourcebuffer-default-track-label
738 // defaultTrackLanguage spec:
739 // https://w3c.github.io/media-source/#sourcebuffer-default-track-language
670 740
671 // 1. If trackDefaults contains a TrackDefault object with a type attribute eq ual to type and a byteStreamTrackID attribute equal to byteStreamTrackID, 741 // 1. If trackDefaults contains a TrackDefault object with a type attribute
672 // then return the value of the label/language attribute on this matching obje ct and abort these steps. 742 // equal to type and a byteStreamTrackID attribute equal to byteStreamTrack ID,
673 // 2. If trackDefaults contains a TrackDefault object with a type attribute eq ual to type and a byteStreamTrackID attribute equal to an empty string, 743 // then return the value of the label/language attribute on this matching
674 // then return the value of the label/language attribute on this matching obje ct and abort these steps. 744 // object and abort these steps.
745 // 2. If trackDefaults contains a TrackDefault object with a type attribute
746 // equal to type and a byteStreamTrackID attribute equal to an empty
747 // string, then return the value of the label/language attribute on this
748 // matching object and abort these steps.
675 // 3. Return an empty string to the caller 749 // 3. Return an empty string to the caller
676 const TrackDefault* trackDefaultWithEmptyBytestreamId = nullptr; 750 const TrackDefault* trackDefaultWithEmptyBytestreamId = nullptr;
677 for (unsigned i = 0; i < m_trackDefaults->length(); ++i) { 751 for (unsigned i = 0; i < m_trackDefaults->length(); ++i) {
678 const TrackDefault* trackDefault = m_trackDefaults->item(i); 752 const TrackDefault* trackDefault = m_trackDefaults->item(i);
679 if (trackDefault->type() != trackType) 753 if (trackDefault->type() != trackType)
680 continue; 754 continue;
681 if (trackDefault->byteStreamTrackID() == byteStreamTrackID) 755 if (trackDefault->byteStreamTrackID() == byteStreamTrackID)
682 return trackDefault; 756 return trackDefault;
683 if (!trackDefaultWithEmptyBytestreamId && 757 if (!trackDefaultWithEmptyBytestreamId &&
684 trackDefault->byteStreamTrackID() == "") 758 trackDefault->byteStreamTrackID() == "")
685 trackDefaultWithEmptyBytestreamId = trackDefault; 759 trackDefaultWithEmptyBytestreamId = trackDefault;
686 } 760 }
687 return trackDefaultWithEmptyBytestreamId; 761 return trackDefaultWithEmptyBytestreamId;
688 } 762 }
689 763
690 AtomicString SourceBuffer::defaultTrackLabel( 764 AtomicString SourceBuffer::defaultTrackLabel(
691 const AtomicString& trackType, 765 const AtomicString& trackType,
692 const AtomicString& byteStreamTrackID) const { 766 const AtomicString& byteStreamTrackID) const {
693 // Spec: https://w3c.github.io/media-source/#sourcebuffer-default-track-label 767 // Spec: https://w3c.github.io/media-source/#sourcebuffer-default-track-label
694 const TrackDefault* trackDefault = 768 const TrackDefault* trackDefault =
695 getTrackDefault(trackType, byteStreamTrackID); 769 getTrackDefault(trackType, byteStreamTrackID);
696 return trackDefault ? AtomicString(trackDefault->label()) : ""; 770 return trackDefault ? AtomicString(trackDefault->label()) : "";
697 } 771 }
698 772
699 AtomicString SourceBuffer::defaultTrackLanguage( 773 AtomicString SourceBuffer::defaultTrackLanguage(
700 const AtomicString& trackType, 774 const AtomicString& trackType,
701 const AtomicString& byteStreamTrackID) const { 775 const AtomicString& byteStreamTrackID) const {
702 // Spec: https://w3c.github.io/media-source/#sourcebuffer-default-track-langua ge 776 // Spec:
777 // https://w3c.github.io/media-source/#sourcebuffer-default-track-language
703 const TrackDefault* trackDefault = 778 const TrackDefault* trackDefault =
704 getTrackDefault(trackType, byteStreamTrackID); 779 getTrackDefault(trackType, byteStreamTrackID);
705 return trackDefault ? AtomicString(trackDefault->language()) : ""; 780 return trackDefault ? AtomicString(trackDefault->language()) : "";
706 } 781 }
707 782
708 bool SourceBuffer::initializationSegmentReceived( 783 bool SourceBuffer::initializationSegmentReceived(
709 const WebVector<MediaTrackInfo>& newTracks) { 784 const WebVector<MediaTrackInfo>& newTracks) {
710 BLINK_SBLOG << __func__ << " this=" << this << " tracks=" << newTracks.size(); 785 BLINK_SBLOG << __func__ << " this=" << this << " tracks=" << newTracks.size();
711 DCHECK(m_source); 786 DCHECK(m_source);
712 DCHECK(m_source->mediaElement()); 787 DCHECK(m_source->mediaElement());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 << " byteStreamTrackID=" << String(trackInfo.byteStreamTrackID) 832 << " byteStreamTrackID=" << String(trackInfo.byteStreamTrackID)
758 << " kind=" << String(trackInfo.kind) 833 << " kind=" << String(trackInfo.kind)
759 << " label=" << String(trackInfo.label) 834 << " label=" << String(trackInfo.label)
760 << " language=" << String(trackInfo.language); 835 << " language=" << String(trackInfo.language);
761 #endif 836 #endif
762 } 837 }
763 838
764 // 1. Update the duration attribute if it currently equals NaN: 839 // 1. Update the duration attribute if it currently equals NaN:
765 // TODO(servolk): Pass also stream duration into initSegmentReceived. 840 // TODO(servolk): Pass also stream duration into initSegmentReceived.
766 841
767 // 2. If the initialization segment has no audio, video, or text tracks, then run the append error algorithm with the decode error parameter set to true and a bort these steps. 842 // 2. If the initialization segment has no audio, video, or text tracks, then
843 // run the append error algorithm with the decode error parameter set to
844 // true and abort these steps.
768 if (newTracks.size() == 0) { 845 if (newTracks.size() == 0) {
769 BLINK_SBLOG << __func__ << " this=" << this 846 BLINK_SBLOG << __func__ << " this=" << this
770 << " failed: no tracks found in the init segment."; 847 << " failed: no tracks found in the init segment.";
771 // The append error algorithm will be called at the top level after we retur n false here to indicate failure. 848 // The append error algorithm will be called at the top level after we
849 // return false here to indicate failure.
772 return false; 850 return false;
773 } 851 }
774 852
775 // 3. If the first initialization segment received flag is true, then run the following steps: 853 // 3. If the first initialization segment received flag is true, then run the
854 // following steps:
776 if (m_firstInitializationSegmentReceived) { 855 if (m_firstInitializationSegmentReceived) {
777 // 3.1 Verify the following properties. If any of the checks fail then run t he append error algorithm with the decode error parameter set to true and abort these steps. 856 // 3.1 Verify the following properties. If any of the checks fail then run
857 // the append error algorithm with the decode error parameter set to
858 // true and abort these steps.
778 bool tracksMatchFirstInitSegment = true; 859 bool tracksMatchFirstInitSegment = true;
779 // - The number of audio, video, and text tracks match what was in the first initialization segment. 860 // - The number of audio, video, and text tracks match what was in the first
861 // initialization segment.
780 if (newAudioTracks.size() != audioTracks().length() || 862 if (newAudioTracks.size() != audioTracks().length() ||
781 newVideoTracks.size() != videoTracks().length()) { 863 newVideoTracks.size() != videoTracks().length()) {
782 tracksMatchFirstInitSegment = false; 864 tracksMatchFirstInitSegment = false;
783 } 865 }
784 // - The codecs for each track, match what was specified in the first initia lization segment. 866 // - The codecs for each track, match what was specified in the first
867 // initialization segment.
785 // This is currently done in MediaSourceState::OnNewConfigs. 868 // This is currently done in MediaSourceState::OnNewConfigs.
786 // - If more than one track for a single type are present (ie 2 audio tracks ), then the Track IDs match the ones in the first initialization segment. 869 // - If more than one track for a single type are present (ie 2 audio
870 // tracks), then the Track IDs match the ones in the first initialization
871 // segment.
787 if (tracksMatchFirstInitSegment && newAudioTracks.size() > 1) { 872 if (tracksMatchFirstInitSegment && newAudioTracks.size() > 1) {
788 for (size_t i = 0; i < newAudioTracks.size(); ++i) { 873 for (size_t i = 0; i < newAudioTracks.size(); ++i) {
789 const String& newTrackId = newVideoTracks[i].id; 874 const String& newTrackId = newVideoTracks[i].id;
790 if (newTrackId != 875 if (newTrackId !=
791 String(audioTracks().anonymousIndexedGetter(i)->id())) { 876 String(audioTracks().anonymousIndexedGetter(i)->id())) {
792 tracksMatchFirstInitSegment = false; 877 tracksMatchFirstInitSegment = false;
793 break; 878 break;
794 } 879 }
795 } 880 }
796 } 881 }
797 882
798 if (tracksMatchFirstInitSegment && newVideoTracks.size() > 1) { 883 if (tracksMatchFirstInitSegment && newVideoTracks.size() > 1) {
799 for (size_t i = 0; i < newVideoTracks.size(); ++i) { 884 for (size_t i = 0; i < newVideoTracks.size(); ++i) {
800 const String& newTrackId = newVideoTracks[i].id; 885 const String& newTrackId = newVideoTracks[i].id;
801 if (newTrackId != 886 if (newTrackId !=
802 String(videoTracks().anonymousIndexedGetter(i)->id())) { 887 String(videoTracks().anonymousIndexedGetter(i)->id())) {
803 tracksMatchFirstInitSegment = false; 888 tracksMatchFirstInitSegment = false;
804 break; 889 break;
805 } 890 }
806 } 891 }
807 } 892 }
808 893
809 if (!tracksMatchFirstInitSegment) { 894 if (!tracksMatchFirstInitSegment) {
810 BLINK_SBLOG << __func__ << " this=" << this 895 BLINK_SBLOG << __func__ << " this=" << this
811 << " failed: tracks mismatch the first init segment."; 896 << " failed: tracks mismatch the first init segment.";
812 // The append error algorithm will be called at the top level after we ret urn false here to indicate failure. 897 // The append error algorithm will be called at the top level after we
898 // return false here to indicate failure.
813 return false; 899 return false;
814 } 900 }
815 901
816 // 3.2 Add the appropriate track descriptions from this initialization segme nt to each of the track buffers. 902 // 3.2 Add the appropriate track descriptions from this initialization
817 // This is done in Chromium code in stream parsers and demuxer implementatio ns. 903 // segment to each of the track buffers. This is done in Chromium code
904 // in stream parsers and demuxer implementations.
818 905
819 // 3.3 Set the need random access point flag on all track buffers to true. 906 // 3.3 Set the need random access point flag on all track buffers to true.
820 // This is done in Chromium code, see MediaSourceState::OnNewConfigs. 907 // This is done in Chromium code, see MediaSourceState::OnNewConfigs.
821 } 908 }
822 909
823 // 4. Let active track flag equal false. 910 // 4. Let active track flag equal false.
824 bool activeTrack = false; 911 bool activeTrack = false;
825 912
826 // 5. If the first initialization segment received flag is false, then run the following steps: 913 // 5. If the first initialization segment received flag is false, then run the
914 // following steps:
827 if (!m_firstInitializationSegmentReceived) { 915 if (!m_firstInitializationSegmentReceived) {
828 // 5.1 If the initialization segment contains tracks with codecs the user ag ent does not support, then run the append error algorithm with the decode error parameter set to true and abort these steps. 916 // 5.1 If the initialization segment contains tracks with codecs the user
917 // agent does not support, then run the append error algorithm with the
918 // decode error parameter set to true and abort these steps.
829 // This is done in Chromium code, see MediaSourceState::OnNewConfigs. 919 // This is done in Chromium code, see MediaSourceState::OnNewConfigs.
830 920
831 // 5.2 For each audio track in the initialization segment, run following ste ps: 921 // 5.2 For each audio track in the initialization segment, run following
922 // steps:
832 for (const MediaTrackInfo& trackInfo : newAudioTracks) { 923 for (const MediaTrackInfo& trackInfo : newAudioTracks) {
833 // 5.2.1 Let audio byte stream track ID be the Track ID for the current tr ack being processed. 924 // 5.2.1 Let audio byte stream track ID be the Track ID for the current
925 // track being processed.
834 const auto& byteStreamTrackID = trackInfo.byteStreamTrackID; 926 const auto& byteStreamTrackID = trackInfo.byteStreamTrackID;
835 // 5.2.2 Let audio language be a BCP 47 language tag for the language spec ified in the initialization segment for this track or an empty string if no lang uage info is present. 927 // 5.2.2 Let audio language be a BCP 47 language tag for the language
928 // specified in the initialization segment for this track or an
929 // empty string if no language info is present.
836 WebString language = trackInfo.language; 930 WebString language = trackInfo.language;
837 // 5.2.3 If audio language equals an empty string or the 'und' BCP 47 valu e, then run the default track language algorithm with byteStreamTrackID set to 931 // 5.2.3 If audio language equals an empty string or the 'und' BCP 47
838 // audio byte stream track ID and type set to "audio" and assign the value returned by the algorithm to audio language. 932 // value, then run the default track language algorithm with
933 // byteStreamTrackID set to audio byte stream track ID and type set
934 // to "audio" and assign the value returned by the algorithm to
935 // audio language.
839 if (language.isEmpty() || language == "und") 936 if (language.isEmpty() || language == "und")
840 language = defaultTrackLanguage(TrackDefault::audioKeyword(), 937 language = defaultTrackLanguage(TrackDefault::audioKeyword(),
841 byteStreamTrackID); 938 byteStreamTrackID);
842 // 5.2.4 Let audio label be a label specified in the initialization segmen t for this track or an empty string if no label info is present. 939 // 5.2.4 Let audio label be a label specified in the initialization
940 // segment for this track or an empty string if no label info is pre sent.
843 WebString label = trackInfo.label; 941 WebString label = trackInfo.label;
844 // 5.3.5 If audio label equals an empty string, then run the default track label algorithm with byteStreamTrackID set to audio byte stream track ID and 942 // 5.3.5 If audio label equals an empty string, then run the default track
845 // type set to "audio" and assign the value returned by the algorithm to a udio label. 943 // label algorithm with byteStreamTrackID set to audio byte stream
944 // track ID and type set to "audio" and assign the value returned by
945 // the algorithm to audio label.
846 if (label.isEmpty()) 946 if (label.isEmpty())
847 label = 947 label =
848 defaultTrackLabel(TrackDefault::audioKeyword(), byteStreamTrackID); 948 defaultTrackLabel(TrackDefault::audioKeyword(), byteStreamTrackID);
849 // 5.2.6 Let audio kinds be an array of kind strings specified in the init ialization segment for this track or an empty array if no kind information is pr ovided. 949 // 5.2.6 Let audio kinds be an array of kind strings specified in the
950 // initialization segment for this track or an empty array if no
951 // kind information is provided.
850 const auto& kind = trackInfo.kind; 952 const auto& kind = trackInfo.kind;
851 // 5.2.7 TODO(servolk): Implement track kind processing. 953 // 5.2.7 TODO(servolk): Implement track kind processing.
852 // 5.2.8.2 Let new audio track be a new AudioTrack object. 954 // 5.2.8.2 Let new audio track be a new AudioTrack object.
853 AudioTrack* audioTrack = 955 AudioTrack* audioTrack =
854 AudioTrack::create(trackInfo.id, kind, label, language, false); 956 AudioTrack::create(trackInfo.id, kind, label, language, false);
855 SourceBufferTrackBaseSupplement::setSourceBuffer(*audioTrack, this); 957 SourceBufferTrackBaseSupplement::setSourceBuffer(*audioTrack, this);
856 // 5.2.8.7 If audioTracks.length equals 0, then run the following steps: 958 // 5.2.8.7 If audioTracks.length equals 0, then run the following steps:
857 if (audioTracks().length() == 0) { 959 if (audioTracks().length() == 0) {
858 // 5.2.8.7.1 Set the enabled property on new audio track to true. 960 // 5.2.8.7.1 Set the enabled property on new audio track to true.
859 audioTrack->setEnabled(true); 961 audioTrack->setEnabled(true);
860 // 5.2.8.7.2 Set active track flag to true. 962 // 5.2.8.7.2 Set active track flag to true.
861 activeTrack = true; 963 activeTrack = true;
862 } 964 }
863 // 5.2.8.8 Add new audio track to the audioTracks attribute on this Source Buffer object. 965 // 5.2.8.8 Add new audio track to the audioTracks attribute on this
864 // 5.2.8.9 Queue a task to fire a trusted event named addtrack, that does not bubble and is not cancelable, and that uses the TrackEvent interface, at the AudioTrackList object referenced by the audioTracks attribute on this SourceBuf fer object. 966 // SourceBuffer object.
967 // 5.2.8.9 Queue a task to fire a trusted event named addtrack, that does
968 // not bubble and is not cancelable, and that uses the TrackEvent
969 // interface, at the AudioTrackList object referenced by the
970 // audioTracks attribute on this SourceBuffer object.
865 audioTracks().add(audioTrack); 971 audioTracks().add(audioTrack);
866 // 5.2.8.10 Add new audio track to the audioTracks attribute on the HTMLMe diaElement. 972 // 5.2.8.10 Add new audio track to the audioTracks attribute on the
867 // 5.2.8.11 Queue a task to fire a trusted event named addtrack, that does not bubble and is not cancelable, and that uses the TrackEvent interface, at th e AudioTrackList object referenced by the audioTracks attribute on the HTMLMedia Element. 973 // HTMLMediaElement.
974 // 5.2.8.11 Queue a task to fire a trusted event named addtrack, that does
975 // not bubble and is not cancelable, and that uses the TrackEvent
976 // interface, at the AudioTrackList object referenced by the
977 // audioTracks attribute on the HTMLMediaElement.
868 m_source->mediaElement()->audioTracks().add(audioTrack); 978 m_source->mediaElement()->audioTracks().add(audioTrack);
869 } 979 }
870 980
871 // 5.3. For each video track in the initialization segment, run following st eps: 981 // 5.3. For each video track in the initialization segment, run following
982 // steps:
872 for (const MediaTrackInfo& trackInfo : newVideoTracks) { 983 for (const MediaTrackInfo& trackInfo : newVideoTracks) {
873 // 5.3.1 Let video byte stream track ID be the Track ID for the current tr ack being processed. 984 // 5.3.1 Let video byte stream track ID be the Track ID for the current
985 // track being processed.
874 const auto& byteStreamTrackID = trackInfo.byteStreamTrackID; 986 const auto& byteStreamTrackID = trackInfo.byteStreamTrackID;
875 // 5.3.2 Let video language be a BCP 47 language tag for the language spec ified in the initialization segment for this track or an empty string if no lang uage info is present. 987 // 5.3.2 Let video language be a BCP 47 language tag for the language
988 // specified in the initialization segment for this track or an
989 // empty string if no language info is present.
876 WebString language = trackInfo.language; 990 WebString language = trackInfo.language;
877 // 5.3.3 If video language equals an empty string or the 'und' BCP 47 valu e, then run the default track language algorithm with byteStreamTrackID set to 991 // 5.3.3 If video language equals an empty string or the 'und' BCP 47
878 // video byte stream track ID and type set to "video" and assign the value returned by the algorithm to video language. 992 // value, then run the default track language algorithm with
993 // byteStreamTrackID set to video byte stream track ID and type set
994 // to "video" and assign the value returned by the algorithm to
995 // video language.
879 if (language.isEmpty() || language == "und") 996 if (language.isEmpty() || language == "und")
880 language = defaultTrackLanguage(TrackDefault::videoKeyword(), 997 language = defaultTrackLanguage(TrackDefault::videoKeyword(),
881 byteStreamTrackID); 998 byteStreamTrackID);
882 // 5.3.4 Let video label be a label specified in the initialization segmen t for this track or an empty string if no label info is present. 999 // 5.3.4 Let video label be a label specified in the initialization
1000 // segment for this track or an empty string if no label info is pre sent.
883 WebString label = trackInfo.label; 1001 WebString label = trackInfo.label;
884 // 5.3.5 If video label equals an empty string, then run the default track label algorithm with byteStreamTrackID set to video byte stream track ID and 1002 // 5.3.5 If video label equals an empty string, then run the default track
885 // type set to "video" and assign the value returned by the algorithm to v ideo label. 1003 // label algorithm with byteStreamTrackID set to video byte stream
1004 // track ID and type set to "video" and assign the value returned by
1005 // the algorithm to video label.
886 if (label.isEmpty()) 1006 if (label.isEmpty())
887 label = 1007 label =
888 defaultTrackLabel(TrackDefault::videoKeyword(), byteStreamTrackID); 1008 defaultTrackLabel(TrackDefault::videoKeyword(), byteStreamTrackID);
889 // 5.3.6 Let video kinds be an array of kind strings specified in the init ialization segment for this track or an empty array if no kind information is pr ovided. 1009 // 5.3.6 Let video kinds be an array of kind strings specified in the
1010 // initialization segment for this track or an empty array if no
1011 // kind information is provided.
890 const auto& kind = trackInfo.kind; 1012 const auto& kind = trackInfo.kind;
891 // 5.3.7 TODO(servolk): Implement track kind processing. 1013 // 5.3.7 TODO(servolk): Implement track kind processing.
892 // 5.3.8.2 Let new video track be a new VideoTrack object. 1014 // 5.3.8.2 Let new video track be a new VideoTrack object.
893 VideoTrack* videoTrack = 1015 VideoTrack* videoTrack =
894 VideoTrack::create(trackInfo.id, kind, label, language, false); 1016 VideoTrack::create(trackInfo.id, kind, label, language, false);
895 SourceBufferTrackBaseSupplement::setSourceBuffer(*videoTrack, this); 1017 SourceBufferTrackBaseSupplement::setSourceBuffer(*videoTrack, this);
896 // 5.3.8.7 If videoTracks.length equals 0, then run the following steps: 1018 // 5.3.8.7 If videoTracks.length equals 0, then run the following steps:
897 if (videoTracks().length() == 0) { 1019 if (videoTracks().length() == 0) {
898 // 5.3.8.7.1 Set the selected property on new audio track to true. 1020 // 5.3.8.7.1 Set the selected property on new audio track to true.
899 videoTrack->setSelected(true); 1021 videoTrack->setSelected(true);
900 // 5.3.8.7.2 Set active track flag to true. 1022 // 5.3.8.7.2 Set active track flag to true.
901 activeTrack = true; 1023 activeTrack = true;
902 } 1024 }
903 // 5.3.8.8 Add new video track to the videoTracks attribute on this Source Buffer object. 1025 // 5.3.8.8 Add new video track to the videoTracks attribute on this
904 // 5.3.8.9 Queue a task to fire a trusted event named addtrack, that does not bubble and is not cancelable, and that uses the TrackEvent interface, at the VideoTrackList object referenced by the videoTracks attribute on this SourceBuf fer object. 1026 // SourceBuffer object.
1027 // 5.3.8.9 Queue a task to fire a trusted event named addtrack, that does
1028 // not bubble and is not cancelable, and that uses the TrackEvent
1029 // interface, at the VideoTrackList object referenced by the
1030 // videoTracks attribute on this SourceBuffer object.
905 videoTracks().add(videoTrack); 1031 videoTracks().add(videoTrack);
906 // 5.3.8.10 Add new video track to the videoTracks attribute on the HTMLMe diaElement. 1032 // 5.3.8.10 Add new video track to the videoTracks attribute on the
907 // 5.3.8.11 Queue a task to fire a trusted event named addtrack, that does not bubble and is not cancelable, and that uses the TrackEvent interface, at th e VideoTrackList object referenced by the videoTracks attribute on the HTMLMedia Element. 1033 // HTMLMediaElement.
1034 // 5.3.8.11 Queue a task to fire a trusted event named addtrack, that does
1035 // not bubble and is not cancelable, and that uses the TrackEvent
1036 // interface, at the VideoTrackList object referenced by the
1037 // videoTracks attribute on the HTMLMediaElement.
908 m_source->mediaElement()->videoTracks().add(videoTrack); 1038 m_source->mediaElement()->videoTracks().add(videoTrack);
909 } 1039 }
910 1040
911 // 5.4 TODO(servolk): Add text track processing here. 1041 // 5.4 TODO(servolk): Add text track processing here.
912 1042
913 // 5.5 If active track flag equals true, then run the following steps: 1043 // 5.5 If active track flag equals true, then run the following steps:
914 // activesourcebuffers. 1044 // activesourcebuffers.
915 if (activeTrack) { 1045 if (activeTrack) {
916 // 5.5.1 Add this SourceBuffer to activeSourceBuffers. 1046 // 5.5.1 Add this SourceBuffer to activeSourceBuffers.
917 // 5.5.2 Queue a task to fire a simple event named addsourcebuffer at acti veSourceBuffers 1047 // 5.5.2 Queue a task to fire a simple event named addsourcebuffer at
1048 // activeSourceBuffers
918 m_source->setSourceBufferActive(this, true); 1049 m_source->setSourceBufferActive(this, true);
919 } 1050 }
920 1051
921 // 5.6. Set first initialization segment received flag to true. 1052 // 5.6. Set first initialization segment received flag to true.
922 m_firstInitializationSegmentReceived = true; 1053 m_firstInitializationSegmentReceived = true;
923 } 1054 }
924 1055
925 return true; 1056 return true;
926 } 1057 }
927 1058
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 event->setTarget(this); 1097 event->setTarget(this);
967 1098
968 m_asyncEventQueue->enqueueEvent(event); 1099 m_asyncEventQueue->enqueueEvent(event);
969 } 1100 }
970 1101
971 bool SourceBuffer::prepareAppend(size_t newDataSize, 1102 bool SourceBuffer::prepareAppend(size_t newDataSize,
972 ExceptionState& exceptionState) { 1103 ExceptionState& exceptionState) {
973 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::prepareAppend", this); 1104 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::prepareAppend", this);
974 // http://w3c.github.io/media-source/#sourcebuffer-prepare-append 1105 // http://w3c.github.io/media-source/#sourcebuffer-prepare-append
975 // 3.5.4 Prepare Append Algorithm 1106 // 3.5.4 Prepare Append Algorithm
976 // 1. If the SourceBuffer has been removed from the sourceBuffers attribute of the parent media source then throw an InvalidStateError exception and abort the se steps. 1107 // 1. If the SourceBuffer has been removed from the sourceBuffers attribute of
977 // 2. If the updating attribute equals true, then throw an InvalidStateError e xception and abort these steps. 1108 // the parent media source then throw an InvalidStateError exception and
1109 // abort these steps.
1110 // 2. If the updating attribute equals true, then throw an InvalidStateError
1111 // exception and abort these steps.
978 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, 1112 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating,
979 exceptionState)) { 1113 exceptionState)) {
980 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::prepareAppend", this); 1114 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::prepareAppend", this);
981 return false; 1115 return false;
982 } 1116 }
983 1117
984 // 3. If the HTMLMediaElement.error attribute is not null, then throw an Inval idStateError exception and abort these steps. 1118 // 3. If the HTMLMediaElement.error attribute is not null, then throw an
1119 // InvalidStateError exception and abort these steps.
985 DCHECK(m_source); 1120 DCHECK(m_source);
986 DCHECK(m_source->mediaElement()); 1121 DCHECK(m_source->mediaElement());
987 if (m_source->mediaElement()->error()) { 1122 if (m_source->mediaElement()->error()) {
988 MediaSource::logAndThrowDOMException( 1123 MediaSource::logAndThrowDOMException(
989 exceptionState, InvalidStateError, 1124 exceptionState, InvalidStateError,
990 "The HTMLMediaElement.error attribute is not null."); 1125 "The HTMLMediaElement.error attribute is not null.");
991 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::prepareAppend", this); 1126 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::prepareAppend", this);
992 return false; 1127 return false;
993 } 1128 }
994 1129
995 // 4. If the readyState attribute of the parent media source is in the "ended" state then run the following steps: 1130 // 4. If the readyState attribute of the parent media source is in the "ended"
1131 // state then run the following steps:
996 // 1. Set the readyState attribute of the parent media source to "open" 1132 // 1. Set the readyState attribute of the parent media source to "open"
997 // 2. Queue a task to fire a simple event named sourceopen at the parent me dia source. 1133 // 2. Queue a task to fire a simple event named sourceopen at the parent
1134 // media source.
998 m_source->openIfInEndedState(); 1135 m_source->openIfInEndedState();
999 1136
1000 // 5. Run the coded frame eviction algorithm. 1137 // 5. Run the coded frame eviction algorithm.
1001 if (!evictCodedFrames(newDataSize)) { 1138 if (!evictCodedFrames(newDataSize)) {
1002 // 6. If the buffer full flag equals true, then throw a QUOTA_EXCEEDED_ERR e xception and abort these steps. 1139 // 6. If the buffer full flag equals true, then throw a QUOTA_EXCEEDED_ERR
1140 // exception and abort these steps.
1003 BLINK_SBLOG << __func__ << " this=" << this 1141 BLINK_SBLOG << __func__ << " this=" << this
1004 << " -> throw QuotaExceededError"; 1142 << " -> throw QuotaExceededError";
1005 MediaSource::logAndThrowDOMException(exceptionState, QuotaExceededError, 1143 MediaSource::logAndThrowDOMException(exceptionState, QuotaExceededError,
1006 "The SourceBuffer is full, and cannot " 1144 "The SourceBuffer is full, and cannot "
1007 "free space to append additional " 1145 "free space to append additional "
1008 "buffers."); 1146 "buffers.");
1009 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::prepareAppend", this); 1147 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::prepareAppend", this);
1010 return false; 1148 return false;
1011 } 1149 }
1012 1150
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 1184
1047 // 2. Add data to the end of the input buffer. 1185 // 2. Add data to the end of the input buffer.
1048 DCHECK(data || size == 0); 1186 DCHECK(data || size == 0);
1049 if (data) 1187 if (data)
1050 m_pendingAppendData.append(data, size); 1188 m_pendingAppendData.append(data, size);
1051 m_pendingAppendDataOffset = 0; 1189 m_pendingAppendDataOffset = 0;
1052 1190
1053 // 3. Set the updating attribute to true. 1191 // 3. Set the updating attribute to true.
1054 m_updating = true; 1192 m_updating = true;
1055 1193
1056 // 4. Queue a task to fire a simple event named updatestart at this SourceBuff er object. 1194 // 4. Queue a task to fire a simple event named updatestart at this
1195 // SourceBuffer object.
1057 scheduleEvent(EventTypeNames::updatestart); 1196 scheduleEvent(EventTypeNames::updatestart);
1058 1197
1059 // 5. Asynchronously run the buffer append algorithm. 1198 // 5. Asynchronously run the buffer append algorithm.
1060 m_appendBufferAsyncPartRunner->runAsync(); 1199 m_appendBufferAsyncPartRunner->runAsync();
1061 1200
1062 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendBuffer", this, 1201 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendBuffer", this,
1063 "initialDelay"); 1202 "initialDelay");
1064 } 1203 }
1065 1204
1066 void SourceBuffer::appendBufferAsyncPart() { 1205 void SourceBuffer::appendBufferAsyncPart() {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendBuffer", this, 1249 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendBuffer", this,
1111 "nextPieceDelay"); 1250 "nextPieceDelay");
1112 return; 1251 return;
1113 } 1252 }
1114 1253
1115 // 3. Set the updating attribute to false. 1254 // 3. Set the updating attribute to false.
1116 m_updating = false; 1255 m_updating = false;
1117 m_pendingAppendData.clear(); 1256 m_pendingAppendData.clear();
1118 m_pendingAppendDataOffset = 0; 1257 m_pendingAppendDataOffset = 0;
1119 1258
1120 // 4. Queue a task to fire a simple event named update at this SourceBuffer object. 1259 // 4. Queue a task to fire a simple event named update at this SourceBuffer
1260 // object.
1121 scheduleEvent(EventTypeNames::update); 1261 scheduleEvent(EventTypeNames::update);
1122 1262
1123 // 5. Queue a task to fire a simple event named updateend at this SourceBuff er object. 1263 // 5. Queue a task to fire a simple event named updateend at this
1264 // SourceBuffer object.
1124 scheduleEvent(EventTypeNames::updateend); 1265 scheduleEvent(EventTypeNames::updateend);
1125 } 1266 }
1126 1267
1127 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendBuffer", this); 1268 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendBuffer", this);
1128 BLINK_SBLOG << __func__ << " done. this=" << this << " buffered=" 1269 BLINK_SBLOG << __func__ << " done. this=" << this << " buffered="
1129 << webTimeRangesToString(m_webSourceBuffer->buffered()); 1270 << webTimeRangesToString(m_webSourceBuffer->buffered());
1130 } 1271 }
1131 1272
1132 void SourceBuffer::removeAsyncPart() { 1273 void SourceBuffer::removeAsyncPart() {
1133 DCHECK(m_updating); 1274 DCHECK(m_updating);
1134 DCHECK_GE(m_pendingRemoveStart, 0); 1275 DCHECK_GE(m_pendingRemoveStart, 0);
1135 DCHECK_LT(m_pendingRemoveStart, m_pendingRemoveEnd); 1276 DCHECK_LT(m_pendingRemoveStart, m_pendingRemoveEnd);
1136 1277
1137 // Section 3.2 remove() method steps 1278 // Section 3.2 remove() method steps
1138 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sourc e.html#widl-SourceBuffer-remove-void-double-start-double-end 1279 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sourc e.html#widl-SourceBuffer-remove-void-double-start-double-end
1139 1280
1140 // 9. Run the coded frame removal algorithm with start and end as the start an d end of the removal range. 1281 // 9. Run the coded frame removal algorithm with start and end as the start
1282 // and end of the removal range.
1141 m_webSourceBuffer->remove(m_pendingRemoveStart, m_pendingRemoveEnd); 1283 m_webSourceBuffer->remove(m_pendingRemoveStart, m_pendingRemoveEnd);
1142 1284
1143 // 10. Set the updating attribute to false. 1285 // 10. Set the updating attribute to false.
1144 m_updating = false; 1286 m_updating = false;
1145 m_pendingRemoveStart = -1; 1287 m_pendingRemoveStart = -1;
1146 m_pendingRemoveEnd = -1; 1288 m_pendingRemoveEnd = -1;
1147 1289
1148 // 11. Queue a task to fire a simple event named update at this SourceBuffer o bject. 1290 // 11. Queue a task to fire a simple event named update at this SourceBuffer
1291 // object.
1149 scheduleEvent(EventTypeNames::update); 1292 scheduleEvent(EventTypeNames::update);
1150 1293
1151 // 12. Queue a task to fire a simple event named updateend at this SourceBuffe r object. 1294 // 12. Queue a task to fire a simple event named updateend at this
1295 // SourceBuffer object.
1152 scheduleEvent(EventTypeNames::updateend); 1296 scheduleEvent(EventTypeNames::updateend);
1153 } 1297 }
1154 1298
1155 void SourceBuffer::appendStreamInternal(Stream* stream, 1299 void SourceBuffer::appendStreamInternal(Stream* stream,
1156 ExceptionState& exceptionState) { 1300 ExceptionState& exceptionState) {
1157 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::appendStream", this); 1301 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::appendStream", this);
1158 1302
1159 // Section 3.2 appendStream() 1303 // Section 3.2 appendStream()
1160 // http://w3c.github.io/media-source/#widl-SourceBuffer-appendStream-void-Read ableStream-stream-unsigned-long-long-maxSize 1304 // http://w3c.github.io/media-source/#widl-SourceBuffer-appendStream-void-Read ableStream-stream-unsigned-long-long-maxSize
1161 // (0. If the stream has been neutered, then throw an InvalidAccessError excep tion and abort these steps.) 1305 // (0. If the stream has been neutered, then throw an InvalidAccessError
1306 // exception and abort these steps.)
1162 if (stream->isNeutered()) { 1307 if (stream->isNeutered()) {
1163 MediaSource::logAndThrowDOMException( 1308 MediaSource::logAndThrowDOMException(
1164 exceptionState, InvalidAccessError, 1309 exceptionState, InvalidAccessError,
1165 "The stream provided has been neutered."); 1310 "The stream provided has been neutered.");
1166 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); 1311 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this);
1167 return; 1312 return;
1168 } 1313 }
1169 1314
1170 // 1. Run the prepare append algorithm. 1315 // 1. Run the prepare append algorithm.
1171 size_t newDataSize = m_streamMaxSizeValid ? m_streamMaxSize : 0; 1316 size_t newDataSize = m_streamMaxSizeValid ? m_streamMaxSize : 0;
1172 if (!prepareAppend(newDataSize, exceptionState)) { 1317 if (!prepareAppend(newDataSize, exceptionState)) {
1173 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); 1318 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this);
1174 return; 1319 return;
1175 } 1320 }
1176 1321
1177 // 2. Set the updating attribute to true. 1322 // 2. Set the updating attribute to true.
1178 m_updating = true; 1323 m_updating = true;
1179 1324
1180 // 3. Queue a task to fire a simple event named updatestart at this SourceBuff er object. 1325 // 3. Queue a task to fire a simple event named updatestart at this
1326 // SourceBuffer object.
1181 scheduleEvent(EventTypeNames::updatestart); 1327 scheduleEvent(EventTypeNames::updatestart);
1182 1328
1183 // 4. Asynchronously run the stream append loop algorithm with stream and maxS ize. 1329 // 4. Asynchronously run the stream append loop algorithm with stream and
1330 // maxSize.
1184 stream->neuter(); 1331 stream->neuter();
1185 m_loader = FileReaderLoader::create(FileReaderLoader::ReadByClient, this); 1332 m_loader = FileReaderLoader::create(FileReaderLoader::ReadByClient, this);
1186 m_stream = stream; 1333 m_stream = stream;
1187 m_appendStreamAsyncPartRunner->runAsync(); 1334 m_appendStreamAsyncPartRunner->runAsync();
1188 } 1335 }
1189 1336
1190 void SourceBuffer::appendStreamAsyncPart() { 1337 void SourceBuffer::appendStreamAsyncPart() {
1191 DCHECK(m_updating); 1338 DCHECK(m_updating);
1192 DCHECK(m_loader); 1339 DCHECK(m_loader);
1193 DCHECK(m_stream); 1340 DCHECK(m_stream);
1194 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendStream", this, 1341 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendStream", this,
1195 "appendStreamAsyncPart"); 1342 "appendStreamAsyncPart");
1196 1343
1197 // Section 3.5.6 Stream Append Loop 1344 // Section 3.5.6 Stream Append Loop
1198 // http://w3c.github.io/media-source/#sourcebuffer-stream-append-loop 1345 // http://w3c.github.io/media-source/#sourcebuffer-stream-append-loop
1199 1346
1200 // 1. If maxSize is set, then let bytesLeft equal maxSize. 1347 // 1. If maxSize is set, then let bytesLeft equal maxSize.
1201 // 2. Loop Top: If maxSize is set and bytesLeft equals 0, then jump to the loo p done step below. 1348 // 2. Loop Top: If maxSize is set and bytesLeft equals 0, then jump to the
1349 // loop done step below.
1202 if (m_streamMaxSizeValid && !m_streamMaxSize) { 1350 if (m_streamMaxSizeValid && !m_streamMaxSize) {
1203 appendStreamDone(NoError); 1351 appendStreamDone(NoError);
1204 return; 1352 return;
1205 } 1353 }
1206 1354
1207 // Steps 3-11 are handled by m_loader. 1355 // Steps 3-11 are handled by m_loader.
1208 // Note: Passing 0 here signals that maxSize was not set. (i.e. Read all the d ata in the stream). 1356 // Note: Passing 0 here signals that maxSize was not set. (i.e. Read all the
1357 // data in the stream).
1209 m_loader->start(getExecutionContext(), *m_stream, 1358 m_loader->start(getExecutionContext(), *m_stream,
1210 m_streamMaxSizeValid ? m_streamMaxSize : 0); 1359 m_streamMaxSizeValid ? m_streamMaxSize : 0);
1211 } 1360 }
1212 1361
1213 void SourceBuffer::appendStreamDone(AppendStreamDoneAction action) { 1362 void SourceBuffer::appendStreamDone(AppendStreamDoneAction action) {
1214 DCHECK(m_updating); 1363 DCHECK(m_updating);
1215 DCHECK(m_loader); 1364 DCHECK(m_loader);
1216 DCHECK(m_stream); 1365 DCHECK(m_stream);
1217 1366
1218 clearAppendStreamState(); 1367 clearAppendStreamState();
1219 1368
1220 if (action != NoError) { 1369 if (action != NoError) {
1221 if (action == RunAppendErrorWithNoDecodeError) { 1370 if (action == RunAppendErrorWithNoDecodeError) {
1222 appendError(NoDecodeError); 1371 appendError(NoDecodeError);
1223 } else { 1372 } else {
1224 DCHECK_EQ(action, RunAppendErrorWithDecodeError); 1373 DCHECK_EQ(action, RunAppendErrorWithDecodeError);
1225 appendError(DecodeError); 1374 appendError(DecodeError);
1226 } 1375 }
1227 1376
1228 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); 1377 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this);
1229 return; 1378 return;
1230 } 1379 }
1231 1380
1232 // Section 3.5.6 Stream Append Loop 1381 // Section 3.5.6 Stream Append Loop
1233 // Steps 1-11 are handled by appendStreamAsyncPart(), |m_loader|, and |m_webSo urceBuffer|. 1382 // Steps 1-11 are handled by appendStreamAsyncPart(), |m_loader|, and
1383 // |m_webSourceBuffer|.
1234 1384
1235 // 12. Loop Done: Set the updating attribute to false. 1385 // 12. Loop Done: Set the updating attribute to false.
1236 m_updating = false; 1386 m_updating = false;
1237 1387
1238 // 13. Queue a task to fire a simple event named update at this SourceBuffer o bject. 1388 // 13. Queue a task to fire a simple event named update at this SourceBuffer
1389 // object.
1239 scheduleEvent(EventTypeNames::update); 1390 scheduleEvent(EventTypeNames::update);
1240 1391
1241 // 14. Queue a task to fire a simple event named updateend at this SourceBuffe r object. 1392 // 14. Queue a task to fire a simple event named updateend at this
1393 // SourceBuffer object.
1242 scheduleEvent(EventTypeNames::updateend); 1394 scheduleEvent(EventTypeNames::updateend);
1243 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); 1395 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this);
1244 BLINK_SBLOG << __func__ << " ended. this=" << this << " buffered=" 1396 BLINK_SBLOG << __func__ << " ended. this=" << this << " buffered="
1245 << webTimeRangesToString(m_webSourceBuffer->buffered()); 1397 << webTimeRangesToString(m_webSourceBuffer->buffered());
1246 } 1398 }
1247 1399
1248 void SourceBuffer::clearAppendStreamState() { 1400 void SourceBuffer::clearAppendStreamState() {
1249 m_streamMaxSizeValid = false; 1401 m_streamMaxSizeValid = false;
1250 m_streamMaxSize = 0; 1402 m_streamMaxSize = 0;
1251 m_loader.reset(); 1403 m_loader.reset();
1252 m_stream = nullptr; 1404 m_stream = nullptr;
1253 } 1405 }
1254 1406
1255 void SourceBuffer::appendError(AppendError err) { 1407 void SourceBuffer::appendError(AppendError err) {
1256 BLINK_SBLOG << __func__ << " this=" << this << " AppendError=" << err; 1408 BLINK_SBLOG << __func__ << " this=" << this << " AppendError=" << err;
1257 // Section 3.5.3 Append Error Algorithm 1409 // Section 3.5.3 Append Error Algorithm
1258 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sourc e.html#sourcebuffer-append-error 1410 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sourc e.html#sourcebuffer-append-error
1259 1411
1260 // 1. Run the reset parser state algorithm. 1412 // 1. Run the reset parser state algorithm.
1261 m_webSourceBuffer->resetParserState(); 1413 m_webSourceBuffer->resetParserState();
1262 1414
1263 // 2. Set the updating attribute to false. 1415 // 2. Set the updating attribute to false.
1264 m_updating = false; 1416 m_updating = false;
1265 1417
1266 // 3. Queue a task to fire a simple event named error at this SourceBuffer obj ect. 1418 // 3. Queue a task to fire a simple event named error at this SourceBuffer
1419 // object.
1267 scheduleEvent(EventTypeNames::error); 1420 scheduleEvent(EventTypeNames::error);
1268 1421
1269 // 4. Queue a task to fire a simple event named updateend at this SourceBuffer object. 1422 // 4. Queue a task to fire a simple event named updateend at this SourceBuffer
1423 // object.
1270 scheduleEvent(EventTypeNames::updateend); 1424 scheduleEvent(EventTypeNames::updateend);
1271 1425
1272 // 5. If decode error is true, then run the end of stream algorithm with the 1426 // 5. If decode error is true, then run the end of stream algorithm with the
1273 // error parameter set to "decode". 1427 // error parameter set to "decode".
1274 if (err == DecodeError) { 1428 if (err == DecodeError) {
1275 m_source->endOfStream("decode", ASSERT_NO_EXCEPTION); 1429 m_source->endOfStream("decode", ASSERT_NO_EXCEPTION);
1276 } else { 1430 } else {
1277 DCHECK_EQ(err, NoDecodeError); 1431 DCHECK_EQ(err, NoDecodeError);
1278 // Nothing else to do in this case. 1432 // Nothing else to do in this case.
1279 } 1433 }
1280 } 1434 }
1281 1435
1282 void SourceBuffer::didStartLoading() { 1436 void SourceBuffer::didStartLoading() {
1283 BLINK_SBLOG << __func__ << " this=" << this; 1437 BLINK_SBLOG << __func__ << " this=" << this;
1284 } 1438 }
1285 1439
1286 void SourceBuffer::didReceiveDataForClient(const char* data, 1440 void SourceBuffer::didReceiveDataForClient(const char* data,
1287 unsigned dataLength) { 1441 unsigned dataLength) {
1288 BLINK_SBLOG << __func__ << " this=" << this << " dataLength=" << dataLength; 1442 BLINK_SBLOG << __func__ << " this=" << this << " dataLength=" << dataLength;
1289 DCHECK(m_updating); 1443 DCHECK(m_updating);
1290 DCHECK(m_loader); 1444 DCHECK(m_loader);
1291 1445
1292 // Section 3.5.6 Stream Append Loop 1446 // Section 3.5.6 Stream Append Loop
1293 // http://w3c.github.io/media-source/#sourcebuffer-stream-append-loop 1447 // http://w3c.github.io/media-source/#sourcebuffer-stream-append-loop
1294 1448
1295 // 10. Run the coded frame eviction algorithm. 1449 // 10. Run the coded frame eviction algorithm.
1296 if (!evictCodedFrames(dataLength)) { 1450 if (!evictCodedFrames(dataLength)) {
1297 // 11. (in appendStreamDone) If the buffer full flag equals true, then run t he append error algorithm with the decode error parameter set to false and abort this algorithm. 1451 // 11. (in appendStreamDone) If the buffer full flag equals true, then run
1452 // the append error algorithm with the decode error parameter set to
1453 // false and abort this algorithm.
1298 appendStreamDone(RunAppendErrorWithNoDecodeError); 1454 appendStreamDone(RunAppendErrorWithNoDecodeError);
1299 return; 1455 return;
1300 } 1456 }
1301 1457
1302 if (!m_webSourceBuffer->append(reinterpret_cast<const unsigned char*>(data), 1458 if (!m_webSourceBuffer->append(reinterpret_cast<const unsigned char*>(data),
1303 dataLength, &m_timestampOffset)) 1459 dataLength, &m_timestampOffset))
1304 appendStreamDone(RunAppendErrorWithDecodeError); 1460 appendStreamDone(RunAppendErrorWithDecodeError);
1305 } 1461 }
1306 1462
1307 void SourceBuffer::didFinishLoading() { 1463 void SourceBuffer::didFinishLoading() {
(...skipping 20 matching lines...) Expand all
1328 visitor->trace(m_removeAsyncPartRunner); 1484 visitor->trace(m_removeAsyncPartRunner);
1329 visitor->trace(m_appendStreamAsyncPartRunner); 1485 visitor->trace(m_appendStreamAsyncPartRunner);
1330 visitor->trace(m_stream); 1486 visitor->trace(m_stream);
1331 visitor->trace(m_audioTracks); 1487 visitor->trace(m_audioTracks);
1332 visitor->trace(m_videoTracks); 1488 visitor->trace(m_videoTracks);
1333 EventTargetWithInlineData::trace(visitor); 1489 EventTargetWithInlineData::trace(visitor);
1334 ActiveDOMObject::trace(visitor); 1490 ActiveDOMObject::trace(visitor);
1335 } 1491 }
1336 1492
1337 } // namespace blink 1493 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698