Chromium Code Reviews| 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 "core/html/TimeRanges.h" | 42 #include "core/html/TimeRanges.h" |
| 41 #include "modules/mediasource/MediaSourceRegistry.h" | 43 #include "modules/mediasource/MediaSourceRegistry.h" |
| 42 #include "platform/ContentType.h" | 44 #include "platform/ContentType.h" |
| 43 #include "platform/Logging.h" | 45 #include "platform/Logging.h" |
| 44 #include "platform/MIMETypeRegistry.h" | 46 #include "platform/MIMETypeRegistry.h" |
| 45 #include "platform/RuntimeEnabledFeatures.h" | 47 #include "platform/RuntimeEnabledFeatures.h" |
| 46 #include "platform/TraceEvent.h" | 48 #include "platform/TraceEvent.h" |
| 47 #include "public/platform/WebMediaSource.h" | 49 #include "public/platform/WebMediaSource.h" |
| 48 #include "public/platform/WebSourceBuffer.h" | 50 #include "public/platform/WebSourceBuffer.h" |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 | 406 |
| 405 // 2. If the readyState attribute is not "open" then throw an InvalidStateEr ror | 407 // 2. If the readyState attribute is not "open" then throw an InvalidStateEr ror |
| 406 // exception and abort these steps. | 408 // exception and abort these steps. |
| 407 // 3. If the updating attribute equals true on any SourceBuffer in sourceBuf fers, | 409 // 3. If the updating attribute equals true on any SourceBuffer in sourceBuf fers, |
| 408 // then throw an InvalidStateError exception and abort these steps. | 410 // then throw an InvalidStateError exception and abort these steps. |
| 409 if (throwExceptionIfClosedOrUpdating(isOpen(), isUpdating(), exceptionState) ) | 411 if (throwExceptionIfClosedOrUpdating(isOpen(), isUpdating(), exceptionState) ) |
| 410 return; | 412 return; |
| 411 | 413 |
| 412 // 4. Run the duration change algorithm with new duration set to the value b eing | 414 // 4. Run the duration change algorithm with new duration set to the value b eing |
| 413 // assigned to this attribute. | 415 // assigned to this attribute. |
| 414 durationChangeAlgorithm(duration); | 416 durationChangeAlgorithm(duration, exceptionState); |
| 415 } | 417 } |
| 416 | 418 |
| 417 void MediaSource::durationChangeAlgorithm(double newDuration) | 419 void MediaSource::durationChangeAlgorithm(double newDuration, ExceptionState& ex ceptionState) |
| 418 { | 420 { |
| 419 // Section 2.6.4 Duration change | 421 // http://w3c.github.io/media-source/#duration-change-algorithm |
| 420 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#duration-change-algorithm | |
| 421 // 1. If the current value of duration is equal to new duration, then return . | 422 // 1. If the current value of duration is equal to new duration, then return . |
| 422 if (newDuration == duration()) | 423 if (newDuration == duration()) |
| 423 return; | 424 return; |
| 424 | 425 |
| 425 // 2. Set old duration to the current value of duration. | 426 // 2. If new duration is less than the highest starting presentation |
| 427 // timestamp of any buffered coded frames for all SourceBuffer objects in | |
| 428 // sourceBuffers, then throw an InvalidStateError exception and abort these | |
| 429 // steps. Note: duration reductions that would truncate currently buffered | |
| 430 // media are disallowed. When truncation is necessary, use remove() to | |
| 431 // reduce the buffered range before updating duration. | |
| 432 double highestBufferedPresentationTimestamp = 0; | |
| 433 for (size_t i = 0; i < m_sourceBuffers->length(); ++i) { | |
| 434 highestBufferedPresentationTimestamp = std::max(highestBufferedPresentat ionTimestamp, m_sourceBuffers->item(i)->highestPresentationTimestamp()); | |
| 435 } | |
| 436 | |
| 437 if (newDuration < highestBufferedPresentationTimestamp) { | |
| 438 if (RuntimeEnabledFeatures::mediaSourceNewAbortAndDurationEnabled()) { | |
| 439 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."); | |
| 440 return; | |
| 441 } | |
| 442 | |
| 443 Deprecation::countDeprecation(m_attachedElement->document(), UseCounter: :MediaSourceDurationTruncatingBuffered); | |
| 444 // See also deprecated remove(new duration, old duration) behavior below . | |
|
chcunningham
2016/06/29 21:19:24
given that they aren't related, this is maybe more
wolenetz
2016/06/30 01:35:49
They are tightly related. This is referring to lin
| |
| 445 } | |
| 446 | |
| 447 // 3. Set old duration to the current value of duration. | |
| 426 double oldDuration = duration(); | 448 double oldDuration = duration(); |
| 449 DCHECK_LE(highestBufferedPresentationTimestamp, oldDuration); | |
| 427 | 450 |
| 451 // 4. Update duration to new duration. | |
| 428 bool requestSeek = m_attachedElement->currentTime() > newDuration; | 452 bool requestSeek = m_attachedElement->currentTime() > newDuration; |
| 429 | |
| 430 // 3. Update duration to new duration. | |
| 431 m_webMediaSource->setDuration(newDuration); | 453 m_webMediaSource->setDuration(newDuration); |
| 432 | 454 |
| 433 // 4. If the new duration is less than old duration, then call remove(new du ration, old duration) on all all objects in sourceBuffers. | 455 if (!RuntimeEnabledFeatures::mediaSourceNewAbortAndDurationEnabled() && newD uration < oldDuration) { |
|
chcunningham
2016/06/29 21:19:24
Maybe you can save some cycles and only run this r
wolenetz
2016/06/30 01:35:49
There are events and an async period of time when
| |
| 434 if (newDuration < oldDuration) { | 456 // Deprecated behavior: if the new duration is less than old duration, |
| 457 // then call remove(new duration, old duration) on all all objects in | |
| 458 // sourceBuffers. | |
| 435 for (size_t i = 0; i < m_sourceBuffers->length(); ++i) | 459 for (size_t i = 0; i < m_sourceBuffers->length(); ++i) |
| 436 m_sourceBuffers->item(i)->remove(newDuration, oldDuration, ASSERT_NO _EXCEPTION); | 460 m_sourceBuffers->item(i)->remove(newDuration, oldDuration, ASSERT_NO _EXCEPTION); |
| 437 } | 461 } |
| 438 | 462 |
| 439 // 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: | 463 // 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: |
| 440 // NOTE: Currently we assume that the media engine is able to render partial frames/cues. If a media | 464 // NOTE: Currently we assume that the media engine is able to render partial frames/cues. If a media |
| 441 // engine gets added that doesn't support this, then we'll need to add logic to handle the substeps. | 465 // engine gets added that doesn't support this, then we'll need to add logic to handle the substeps. |
| 442 | 466 |
| 443 // 6. Update the media controller duration to new duration and run the HTMLM ediaElement duration change algorithm. | 467 // 6. Update the media controller duration to new duration and run the HTMLM ediaElement duration change algorithm. |
| 444 m_attachedElement->durationChanged(newDuration, requestSeek); | 468 m_attachedElement->durationChanged(newDuration, requestSeek); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 616 | 640 |
| 617 m_asyncEventQueue->enqueueEvent(event); | 641 m_asyncEventQueue->enqueueEvent(event); |
| 618 } | 642 } |
| 619 | 643 |
| 620 URLRegistry& MediaSource::registry() const | 644 URLRegistry& MediaSource::registry() const |
| 621 { | 645 { |
| 622 return MediaSourceRegistry::registry(); | 646 return MediaSourceRegistry::registry(); |
| 623 } | 647 } |
| 624 | 648 |
| 625 } // namespace blink | 649 } // namespace blink |
| OLD | NEW |