| 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 19 matching lines...) Expand all Loading... |
| 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/html/HTMLMediaElement.h" | 39 #include "core/html/HTMLMediaElement.h" |
| 40 #include "core/html/TimeRanges.h" | |
| 41 #include "modules/mediasource/MediaSourceRegistry.h" | 40 #include "modules/mediasource/MediaSourceRegistry.h" |
| 42 #include "platform/ContentType.h" | 41 #include "platform/ContentType.h" |
| 43 #include "platform/Logging.h" | 42 #include "platform/Logging.h" |
| 44 #include "platform/MIMETypeRegistry.h" | 43 #include "platform/MIMETypeRegistry.h" |
| 45 #include "platform/RuntimeEnabledFeatures.h" | 44 #include "platform/RuntimeEnabledFeatures.h" |
| 46 #include "platform/TraceEvent.h" | 45 #include "platform/TraceEvent.h" |
| 47 #include "public/platform/WebMediaSource.h" | 46 #include "public/platform/WebMediaSource.h" |
| 48 #include "public/platform/WebSourceBuffer.h" | 47 #include "public/platform/WebSourceBuffer.h" |
| 49 #include "wtf/PtrUtil.h" | 48 #include "wtf/PtrUtil.h" |
| 50 #include "wtf/text/CString.h" | 49 #include "wtf/text/CString.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 96 } |
| 98 | 97 |
| 99 MediaSource::MediaSource(ExecutionContext* context) | 98 MediaSource::MediaSource(ExecutionContext* context) |
| 100 : ActiveScriptWrappable(this) | 99 : ActiveScriptWrappable(this) |
| 101 , ActiveDOMObject(context) | 100 , ActiveDOMObject(context) |
| 102 , m_readyState(closedKeyword()) | 101 , m_readyState(closedKeyword()) |
| 103 , m_asyncEventQueue(GenericEventQueue::create(this)) | 102 , m_asyncEventQueue(GenericEventQueue::create(this)) |
| 104 , m_attachedElement(nullptr) | 103 , m_attachedElement(nullptr) |
| 105 , m_sourceBuffers(SourceBufferList::create(getExecutionContext(), m_asyncEve
ntQueue.get())) | 104 , m_sourceBuffers(SourceBufferList::create(getExecutionContext(), m_asyncEve
ntQueue.get())) |
| 106 , m_activeSourceBuffers(SourceBufferList::create(getExecutionContext(), m_as
yncEventQueue.get())) | 105 , m_activeSourceBuffers(SourceBufferList::create(getExecutionContext(), m_as
yncEventQueue.get())) |
| 106 , m_liveSeekableRange(TimeRanges::create()) |
| 107 , m_isAddedToRegistry(false) | 107 , m_isAddedToRegistry(false) |
| 108 { | 108 { |
| 109 MSLOG << __FUNCTION__ << " this=" << this; | 109 MSLOG << __FUNCTION__ << " this=" << this; |
| 110 } | 110 } |
| 111 | 111 |
| 112 MediaSource::~MediaSource() | 112 MediaSource::~MediaSource() |
| 113 { | 113 { |
| 114 MSLOG << __FUNCTION__ << " this=" << this; | 114 MSLOG << __FUNCTION__ << " this=" << this; |
| 115 DCHECK(isClosed()); | 115 DCHECK(isClosed()); |
| 116 } | 116 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 { | 276 { |
| 277 return ActiveDOMObject::getExecutionContext(); | 277 return ActiveDOMObject::getExecutionContext(); |
| 278 } | 278 } |
| 279 | 279 |
| 280 DEFINE_TRACE(MediaSource) | 280 DEFINE_TRACE(MediaSource) |
| 281 { | 281 { |
| 282 visitor->trace(m_asyncEventQueue); | 282 visitor->trace(m_asyncEventQueue); |
| 283 visitor->trace(m_attachedElement); | 283 visitor->trace(m_attachedElement); |
| 284 visitor->trace(m_sourceBuffers); | 284 visitor->trace(m_sourceBuffers); |
| 285 visitor->trace(m_activeSourceBuffers); | 285 visitor->trace(m_activeSourceBuffers); |
| 286 visitor->trace(m_liveSeekableRange); |
| 286 EventTargetWithInlineData::trace(visitor); | 287 EventTargetWithInlineData::trace(visitor); |
| 287 ActiveDOMObject::trace(visitor); | 288 ActiveDOMObject::trace(visitor); |
| 288 } | 289 } |
| 289 | 290 |
| 290 void MediaSource::setWebMediaSourceAndOpen(std::unique_ptr<WebMediaSource> webMe
diaSource) | 291 void MediaSource::setWebMediaSourceAndOpen(std::unique_ptr<WebMediaSource> webMe
diaSource) |
| 291 { | 292 { |
| 292 TRACE_EVENT_ASYNC_END0("media", "MediaSource::attachToElement", this); | 293 TRACE_EVENT_ASYNC_END0("media", "MediaSource::attachToElement", this); |
| 293 DCHECK(webMediaSource); | 294 DCHECK(webMediaSource); |
| 294 DCHECK(!m_webMediaSource); | 295 DCHECK(!m_webMediaSource); |
| 295 DCHECK(m_attachedElement); | 296 DCHECK(m_attachedElement); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 // 5.4 Replace the ranges in intersection ranges with the new intersecti
on ranges. | 357 // 5.4 Replace the ranges in intersection ranges with the new intersecti
on ranges. |
| 357 intersectionRanges->intersectWith(sourceRanges); | 358 intersectionRanges->intersectWith(sourceRanges); |
| 358 } | 359 } |
| 359 | 360 |
| 360 return intersectionRanges; | 361 return intersectionRanges; |
| 361 } | 362 } |
| 362 | 363 |
| 363 TimeRanges* MediaSource::seekable() const | 364 TimeRanges* MediaSource::seekable() const |
| 364 { | 365 { |
| 365 // Implements MediaSource algorithm for HTMLMediaElement.seekable. | 366 // Implements MediaSource algorithm for HTMLMediaElement.seekable. |
| 366 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou
rce.html#htmlmediaelement-extensions | 367 // http://w3c.github.io/media-source/#htmlmediaelement-extensions |
| 367 | 368 |
| 368 double sourceDuration = duration(); | 369 double sourceDuration = duration(); |
| 369 // If duration equals NaN: Return an empty TimeRanges object. | 370 // If duration equals NaN: Return an empty TimeRanges object. |
| 370 if (std::isnan(sourceDuration)) | 371 if (std::isnan(sourceDuration)) |
| 371 return TimeRanges::create(); | 372 return TimeRanges::create(); |
| 372 | 373 |
| 373 // If duration equals positive Infinity: | 374 // If duration equals positive Infinity: |
| 374 if (sourceDuration == std::numeric_limits<double>::infinity()) { | 375 if (sourceDuration == std::numeric_limits<double>::infinity()) { |
| 375 TimeRanges* buffered = m_attachedElement->buffered(); | 376 TimeRanges* buffered = m_attachedElement->buffered(); |
| 376 | 377 |
| 377 // 1. If the HTMLMediaElement.buffered attribute returns an empty TimeRa
nges object, then | 378 // 1. If live seekable range is not empty: |
| 378 // return an empty TimeRanges object and abort these steps. | 379 if (m_liveSeekableRange->length() != 0) { |
| 380 // 1.1. Let union ranges be the union of live seekable range and the |
| 381 // HTMLMediaElement.buffered attribute. |
| 382 // 1.2. Return a single range with a start time equal to the |
| 383 // earliest start time in union ranges and an end time equal to |
| 384 // the highest end time in union ranges and abort these steps. |
| 385 if (buffered->length() == 0) { |
| 386 return TimeRanges::create(m_liveSeekableRange->start(0, ASSERT_N
O_EXCEPTION), m_liveSeekableRange->end(0, ASSERT_NO_EXCEPTION)); |
| 387 } |
| 388 |
| 389 return TimeRanges::create(std::min(m_liveSeekableRange->start(0, ASS
ERT_NO_EXCEPTION), buffered->start(0, ASSERT_NO_EXCEPTION)), |
| 390 std::max(m_liveSeekableRange->end(0, ASSERT_NO_EXCEPTION), buffe
red->end(buffered->length() - 1, ASSERT_NO_EXCEPTION))); |
| 391 } |
| 392 // 2. If the HTMLMediaElement.buffered attribute returns an empty TimeRa
nges object, then |
| 393 // return an empty TimeRanges object and abort these steps. |
| 379 if (buffered->length() == 0) | 394 if (buffered->length() == 0) |
| 380 return TimeRanges::create(); | 395 return TimeRanges::create(); |
| 381 | 396 |
| 382 // 2. Return a single range with a start time of 0 and an end time equal
to the highest end | 397 // 3. Return a single range with a start time of 0 and an end time equal
to the highest end |
| 383 // time reported by the HTMLMediaElement.buffered attribute. | 398 // time reported by the HTMLMediaElement.buffered attribute. |
| 384 return TimeRanges::create(0, buffered->end(buffered->length() - 1, ASSER
T_NO_EXCEPTION)); | 399 return TimeRanges::create(0, buffered->end(buffered->length() - 1, ASSER
T_NO_EXCEPTION)); |
| 385 } | 400 } |
| 386 | 401 |
| 387 // 3. Otherwise: Return a single range with a start time of 0 and an end tim
e equal to duration. | 402 // 3. Otherwise: Return a single range with a start time of 0 and an end tim
e equal to duration. |
| 388 return TimeRanges::create(0, sourceDuration); | 403 return TimeRanges::create(0, sourceDuration); |
| 389 } | 404 } |
| 390 | 405 |
| 391 void MediaSource::setDuration(double duration, ExceptionState& exceptionState) | 406 void MediaSource::setDuration(double duration, ExceptionState& exceptionState) |
| 392 { | 407 { |
| 393 // 2.1 http://www.w3.org/TR/media-source/#widl-MediaSource-duration | 408 // 2.1 http://www.w3.org/TR/media-source/#widl-MediaSource-duration |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 } else { | 490 } else { |
| 476 NOTREACHED(); // IDL enforcement should prevent this case. | 491 NOTREACHED(); // IDL enforcement should prevent this case. |
| 477 } | 492 } |
| 478 } | 493 } |
| 479 | 494 |
| 480 void MediaSource::endOfStream(ExceptionState& exceptionState) | 495 void MediaSource::endOfStream(ExceptionState& exceptionState) |
| 481 { | 496 { |
| 482 endOfStreamInternal(WebMediaSource::EndOfStreamStatusNoError, exceptionState
); | 497 endOfStreamInternal(WebMediaSource::EndOfStreamStatusNoError, exceptionState
); |
| 483 } | 498 } |
| 484 | 499 |
| 500 void MediaSource::setLiveSeekableRange(double start, double end, ExceptionState&
exceptionState) |
| 501 { |
| 502 // http://w3c.github.io/media-source/#widl-MediaSource-setLiveSeekableRange-
void-double-start-double-end |
| 503 // 1. If the readyState attribute is not "open" then throw an |
| 504 // InvalidStateError exception and abort these steps. |
| 505 // 2. If the updating attribute equals true on any SourceBuffer in |
| 506 // SourceBuffers, then throw an InvalidStateError exception and abort |
| 507 // these steps. |
| 508 if (throwExceptionIfClosedOrUpdating(isOpen(), isUpdating(), exceptionState)
) |
| 509 return; |
| 510 |
| 511 // 3. If start is negative or greater than end, then throw a TypeError |
| 512 // exception and abort these steps. |
| 513 if (start < 0 || start > end) { |
| 514 exceptionState.throwTypeError(ExceptionMessages::indexOutsideRange("star
t value", start, 0.0, ExceptionMessages::InclusiveBound, end, ExceptionMessages:
:InclusiveBound)); |
| 515 return; |
| 516 } |
| 517 |
| 518 // 4. Set live seekable range to be a new normalized TimeRanges object |
| 519 // containing a single range whose start position is start and end |
| 520 // position is end. |
| 521 m_liveSeekableRange = TimeRanges::create(start, end); |
| 522 } |
| 523 |
| 524 void MediaSource::clearLiveSeekableRange(ExceptionState& exceptionState) |
| 525 { |
| 526 // http://w3c.github.io/media-source/#widl-MediaSource-clearLiveSeekableRang
e-void |
| 527 // 1. If the readyState attribute is not "open" then throw an |
| 528 // InvalidStateError exception and abort these steps. |
| 529 // 2. If the updating attribute equals true on any SourceBuffer in |
| 530 // SourceBuffers, then throw an InvalidStateError exception and abort |
| 531 // these steps. |
| 532 if (throwExceptionIfClosedOrUpdating(isOpen(), isUpdating(), exceptionState)
) |
| 533 return; |
| 534 |
| 535 // 3. If live seekable range contains a range, then set live seekable range |
| 536 // to be a new empty TimeRanges object. |
| 537 if (m_liveSeekableRange->length() != 0) |
| 538 m_liveSeekableRange = TimeRanges::create(); |
| 539 } |
| 540 |
| 485 void MediaSource::endOfStreamInternal(const WebMediaSource::EndOfStreamStatus eo
sStatus, ExceptionState& exceptionState) | 541 void MediaSource::endOfStreamInternal(const WebMediaSource::EndOfStreamStatus eo
sStatus, ExceptionState& exceptionState) |
| 486 { | 542 { |
| 487 // 2.2 http://www.w3.org/TR/media-source/#widl-MediaSource-endOfStream-void-
EndOfStreamError-error | 543 // 2.2 http://www.w3.org/TR/media-source/#widl-MediaSource-endOfStream-void-
EndOfStreamError-error |
| 488 // 1. If the readyState attribute is not in the "open" state then throw an | 544 // 1. If the readyState attribute is not in the "open" state then throw an |
| 489 // InvalidStateError exception and abort these steps. | 545 // InvalidStateError exception and abort these steps. |
| 490 // 2. If the updating attribute equals true on any SourceBuffer in sourceBuf
fers, then throw an | 546 // 2. If the updating attribute equals true on any SourceBuffer in sourceBuf
fers, then throw an |
| 491 // InvalidStateError exception and abort these steps. | 547 // InvalidStateError exception and abort these steps. |
| 492 if (throwExceptionIfClosedOrUpdating(isOpen(), isUpdating(), exceptionState)
) | 548 if (throwExceptionIfClosedOrUpdating(isOpen(), isUpdating(), exceptionState)
) |
| 493 return; | 549 return; |
| 494 | 550 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 | 672 |
| 617 m_asyncEventQueue->enqueueEvent(event); | 673 m_asyncEventQueue->enqueueEvent(event); |
| 618 } | 674 } |
| 619 | 675 |
| 620 URLRegistry& MediaSource::registry() const | 676 URLRegistry& MediaSource::registry() const |
| 621 { | 677 { |
| 622 return MediaSourceRegistry::registry(); | 678 return MediaSourceRegistry::registry(); |
| 623 } | 679 } |
| 624 | 680 |
| 625 } // namespace blink | 681 } // namespace blink |
| OLD | NEW |