OLD | NEW |
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 18 matching lines...) Expand all Loading... |
29 */ | 29 */ |
30 | 30 |
31 #include "modules/mediasource/MediaSource.h" | 31 #include "modules/mediasource/MediaSource.h" |
32 | 32 |
33 #include "bindings/core/v8/ExceptionMessages.h" | 33 #include "bindings/core/v8/ExceptionMessages.h" |
34 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
35 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 35 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
36 #include "core/dom/ExceptionCode.h" | 36 #include "core/dom/ExceptionCode.h" |
37 #include "core/events/Event.h" | 37 #include "core/events/Event.h" |
38 #include "core/events/GenericEventQueue.h" | 38 #include "core/events/GenericEventQueue.h" |
| 39 #include "core/frame/Deprecation.h" |
| 40 #include "core/frame/UseCounter.h" |
39 #include "core/html/HTMLMediaElement.h" | 41 #include "core/html/HTMLMediaElement.h" |
40 #include "modules/mediasource/MediaSourceRegistry.h" | 42 #include "modules/mediasource/MediaSourceRegistry.h" |
41 #include "platform/ContentType.h" | 43 #include "platform/ContentType.h" |
42 #include "platform/Logging.h" | 44 #include "platform/Logging.h" |
43 #include "platform/MIMETypeRegistry.h" | 45 #include "platform/MIMETypeRegistry.h" |
44 #include "platform/RuntimeEnabledFeatures.h" | 46 #include "platform/RuntimeEnabledFeatures.h" |
45 #include "platform/TraceEvent.h" | 47 #include "platform/TraceEvent.h" |
46 #include "public/platform/WebMediaSource.h" | 48 #include "public/platform/WebMediaSource.h" |
47 #include "public/platform/WebSourceBuffer.h" | 49 #include "public/platform/WebSourceBuffer.h" |
48 #include "wtf/PtrUtil.h" | 50 #include "wtf/PtrUtil.h" |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 | 421 |
420 // 2. If the readyState attribute is not "open" then throw an InvalidStateEr
ror | 422 // 2. If the readyState attribute is not "open" then throw an InvalidStateEr
ror |
421 // exception and abort these steps. | 423 // exception and abort these steps. |
422 // 3. If the updating attribute equals true on any SourceBuffer in sourceBuf
fers, | 424 // 3. If the updating attribute equals true on any SourceBuffer in sourceBuf
fers, |
423 // then throw an InvalidStateError exception and abort these steps. | 425 // then throw an InvalidStateError exception and abort these steps. |
424 if (throwExceptionIfClosedOrUpdating(isOpen(), isUpdating(), exceptionState)
) | 426 if (throwExceptionIfClosedOrUpdating(isOpen(), isUpdating(), exceptionState)
) |
425 return; | 427 return; |
426 | 428 |
427 // 4. Run the duration change algorithm with new duration set to the value b
eing | 429 // 4. Run the duration change algorithm with new duration set to the value b
eing |
428 // assigned to this attribute. | 430 // assigned to this attribute. |
429 durationChangeAlgorithm(duration); | 431 durationChangeAlgorithm(duration, exceptionState); |
430 } | 432 } |
431 | 433 |
432 void MediaSource::durationChangeAlgorithm(double newDuration) | 434 void MediaSource::durationChangeAlgorithm(double newDuration, ExceptionState& ex
ceptionState) |
433 { | 435 { |
434 // Section 2.6.4 Duration change | 436 // http://w3c.github.io/media-source/#duration-change-algorithm |
435 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou
rce.html#duration-change-algorithm | |
436 // 1. If the current value of duration is equal to new duration, then return
. | 437 // 1. If the current value of duration is equal to new duration, then return
. |
437 if (newDuration == duration()) | 438 if (newDuration == duration()) |
438 return; | 439 return; |
439 | 440 |
440 // 2. Set old duration to the current value of duration. | 441 // 2. If new duration is less than the highest starting presentation |
| 442 // timestamp of any buffered coded frames for all SourceBuffer objects in |
| 443 // sourceBuffers, then throw an InvalidStateError exception and abort these |
| 444 // steps. Note: duration reductions that would truncate currently buffered |
| 445 // media are disallowed. When truncation is necessary, use remove() to |
| 446 // reduce the buffered range before updating duration. |
| 447 double highestBufferedPresentationTimestamp = 0; |
| 448 for (size_t i = 0; i < m_sourceBuffers->length(); ++i) { |
| 449 highestBufferedPresentationTimestamp = std::max(highestBufferedPresentat
ionTimestamp, m_sourceBuffers->item(i)->highestPresentationTimestamp()); |
| 450 } |
| 451 |
| 452 if (newDuration < highestBufferedPresentationTimestamp) { |
| 453 if (RuntimeEnabledFeatures::mediaSourceNewAbortAndDurationEnabled()) { |
| 454 logAndThrowDOMException(exceptionState, InvalidStateError, "Setting
duration below highest presentation timestamp of any buffered coded frames is di
sallowed. Instead, first do asynchronous remove(newDuration, oldDuration) on all
sourceBuffers, where newDuration < oldDuration."); |
| 455 return; |
| 456 } |
| 457 |
| 458 Deprecation::countDeprecation(m_attachedElement->document(), UseCounter:
:MediaSourceDurationTruncatingBuffered); |
| 459 // See also deprecated remove(new duration, old duration) behavior below
. |
| 460 } |
| 461 |
| 462 // 3. Set old duration to the current value of duration. |
441 double oldDuration = duration(); | 463 double oldDuration = duration(); |
| 464 DCHECK_LE(highestBufferedPresentationTimestamp, std::isnan(oldDuration) ? 0
: oldDuration); |
442 | 465 |
| 466 // 4. Update duration to new duration. |
443 bool requestSeek = m_attachedElement->currentTime() > newDuration; | 467 bool requestSeek = m_attachedElement->currentTime() > newDuration; |
444 | |
445 // 3. Update duration to new duration. | |
446 m_webMediaSource->setDuration(newDuration); | 468 m_webMediaSource->setDuration(newDuration); |
447 | 469 |
448 // 4. If the new duration is less than old duration, then call remove(new du
ration, old duration) on all all objects in sourceBuffers. | 470 if (!RuntimeEnabledFeatures::mediaSourceNewAbortAndDurationEnabled() && newD
uration < oldDuration) { |
449 if (newDuration < oldDuration) { | 471 // Deprecated behavior: if the new duration is less than old duration, |
| 472 // then call remove(new duration, old duration) on all all objects in |
| 473 // sourceBuffers. |
450 for (size_t i = 0; i < m_sourceBuffers->length(); ++i) | 474 for (size_t i = 0; i < m_sourceBuffers->length(); ++i) |
451 m_sourceBuffers->item(i)->remove(newDuration, oldDuration, ASSERT_NO
_EXCEPTION); | 475 m_sourceBuffers->item(i)->remove(newDuration, oldDuration, ASSERT_NO
_EXCEPTION); |
452 } | 476 } |
453 | 477 |
454 // 5. If a user agent is unable to partially render audio frames or text cue
s that start before and end after the duration, then run the following steps: | 478 // 5. If a user agent is unable to partially render audio frames or text cue
s that start before and end after the duration, then run the following steps: |
455 // NOTE: Currently we assume that the media engine is able to render partial
frames/cues. If a media | 479 // NOTE: Currently we assume that the media engine is able to render partial
frames/cues. If a media |
456 // engine gets added that doesn't support this, then we'll need to add logic
to handle the substeps. | 480 // engine gets added that doesn't support this, then we'll need to add logic
to handle the substeps. |
457 | 481 |
458 // 6. Update the media controller duration to new duration and run the HTMLM
ediaElement duration change algorithm. | 482 // 6. Update the media controller duration to new duration and run the HTMLM
ediaElement duration change algorithm. |
459 m_attachedElement->durationChanged(newDuration, requestSeek); | 483 m_attachedElement->durationChanged(newDuration, requestSeek); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 | 696 |
673 m_asyncEventQueue->enqueueEvent(event); | 697 m_asyncEventQueue->enqueueEvent(event); |
674 } | 698 } |
675 | 699 |
676 URLRegistry& MediaSource::registry() const | 700 URLRegistry& MediaSource::registry() const |
677 { | 701 { |
678 return MediaSourceRegistry::registry(); | 702 return MediaSourceRegistry::registry(); |
679 } | 703 } |
680 | 704 |
681 } // namespace blink | 705 } // namespace blink |
OLD | NEW |