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 21 matching lines...) Expand all Loading... |
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" | 39 #include "core/frame/Deprecation.h" |
40 #include "core/frame/UseCounter.h" | 40 #include "core/frame/UseCounter.h" |
41 #include "core/html/HTMLMediaElement.h" | 41 #include "core/html/HTMLMediaElement.h" |
| 42 #include "core/html/track/AudioTrackList.h" |
| 43 #include "core/html/track/VideoTrackList.h" |
42 #include "modules/mediasource/MediaSourceRegistry.h" | 44 #include "modules/mediasource/MediaSourceRegistry.h" |
| 45 #include "modules/mediasource/SourceBufferTrackBaseSupplement.h" |
43 #include "platform/ContentType.h" | 46 #include "platform/ContentType.h" |
44 #include "platform/MIMETypeRegistry.h" | 47 #include "platform/MIMETypeRegistry.h" |
45 #include "platform/RuntimeEnabledFeatures.h" | 48 #include "platform/RuntimeEnabledFeatures.h" |
46 #include "platform/TraceEvent.h" | 49 #include "platform/TraceEvent.h" |
47 #include "public/platform/WebMediaSource.h" | 50 #include "public/platform/WebMediaSource.h" |
48 #include "public/platform/WebSourceBuffer.h" | 51 #include "public/platform/WebSourceBuffer.h" |
49 #include "wtf/PtrUtil.h" | 52 #include "wtf/PtrUtil.h" |
50 #include "wtf/text/CString.h" | 53 #include "wtf/text/CString.h" |
51 #include <memory> | 54 #include <memory> |
52 | 55 |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 | 412 |
410 // 3. Return a single range with a start time of 0 and an end time equal
to the highest end | 413 // 3. Return a single range with a start time of 0 and an end time equal
to the highest end |
411 // time reported by the HTMLMediaElement.buffered attribute. | 414 // time reported by the HTMLMediaElement.buffered attribute. |
412 return TimeRanges::create(0, buffered->end(buffered->length() - 1, ASSER
T_NO_EXCEPTION)); | 415 return TimeRanges::create(0, buffered->end(buffered->length() - 1, ASSER
T_NO_EXCEPTION)); |
413 } | 416 } |
414 | 417 |
415 // 3. Otherwise: Return a single range with a start time of 0 and an end tim
e equal to duration. | 418 // 3. Otherwise: Return a single range with a start time of 0 and an end tim
e equal to duration. |
416 return TimeRanges::create(0, sourceDuration); | 419 return TimeRanges::create(0, sourceDuration); |
417 } | 420 } |
418 | 421 |
| 422 void MediaSource::onTrackChanged(TrackBase* track) |
| 423 { |
| 424 DCHECK(RuntimeEnabledFeatures::audioVideoTracksEnabled()); |
| 425 SourceBuffer* sourceBuffer = SourceBufferTrackBaseSupplement::sourceBuffer(*
track); |
| 426 if (!sourceBuffer) |
| 427 return; |
| 428 |
| 429 DCHECK(m_sourceBuffers->contains(sourceBuffer)); |
| 430 if (track->type() == WebMediaPlayer::AudioTrack) { |
| 431 sourceBuffer->audioTracks().scheduleChangeEvent(); |
| 432 } else if (track->type() == WebMediaPlayer::VideoTrack) { |
| 433 if (static_cast<VideoTrack*>(track)->selected()) |
| 434 sourceBuffer->videoTracks().trackSelected(track->id()); |
| 435 sourceBuffer->videoTracks().scheduleChangeEvent(); |
| 436 } |
| 437 |
| 438 bool isActive = (sourceBuffer->videoTracks().selectedIndex() != -1) || sourc
eBuffer->audioTracks().hasEnabledTrack(); |
| 439 setSourceBufferActive(sourceBuffer, isActive); |
| 440 } |
| 441 |
419 void MediaSource::setDuration(double duration, ExceptionState& exceptionState) | 442 void MediaSource::setDuration(double duration, ExceptionState& exceptionState) |
420 { | 443 { |
421 // 2.1 http://www.w3.org/TR/media-source/#widl-MediaSource-duration | 444 // 2.1 http://www.w3.org/TR/media-source/#widl-MediaSource-duration |
422 // 1. If the value being set is negative or NaN then throw an InvalidAccessE
rror | 445 // 1. If the value being set is negative or NaN then throw an InvalidAccessE
rror |
423 // exception and abort these steps. | 446 // exception and abort these steps. |
424 if (std::isnan(duration)) { | 447 if (std::isnan(duration)) { |
425 logAndThrowDOMException(exceptionState, InvalidAccessError, ExceptionMes
sages::notAFiniteNumber(duration, "duration")); | 448 logAndThrowDOMException(exceptionState, InvalidAccessError, ExceptionMes
sages::notAFiniteNumber(duration, "duration")); |
426 return; | 449 return; |
427 } | 450 } |
428 if (duration < 0.0) { | 451 if (duration < 0.0) { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 | 617 |
595 // 3. Do various steps based on |eosStatus|. | 618 // 3. Do various steps based on |eosStatus|. |
596 m_webMediaSource->markEndOfStream(eosStatus); | 619 m_webMediaSource->markEndOfStream(eosStatus); |
597 } | 620 } |
598 | 621 |
599 bool MediaSource::isOpen() const | 622 bool MediaSource::isOpen() const |
600 { | 623 { |
601 return readyState() == openKeyword(); | 624 return readyState() == openKeyword(); |
602 } | 625 } |
603 | 626 |
604 void MediaSource::setSourceBufferActive(SourceBuffer* sourceBuffer) | 627 void MediaSource::setSourceBufferActive(SourceBuffer* sourceBuffer, bool isActiv
e) |
605 { | 628 { |
606 DCHECK(!m_activeSourceBuffers->contains(sourceBuffer)); | 629 if (!isActive) { |
| 630 DCHECK(m_activeSourceBuffers->contains(sourceBuffer)); |
| 631 m_activeSourceBuffers->remove(sourceBuffer); |
| 632 return; |
| 633 } |
| 634 |
| 635 if (m_activeSourceBuffers->contains(sourceBuffer)) |
| 636 return; |
607 | 637 |
608 // https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.
html#widl-MediaSource-activeSourceBuffers | 638 // https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.
html#widl-MediaSource-activeSourceBuffers |
609 // SourceBuffer objects in SourceBuffer.activeSourceBuffers must appear in | 639 // SourceBuffer objects in SourceBuffer.activeSourceBuffers must appear in |
610 // the same order as they appear in SourceBuffer.sourceBuffers. | 640 // the same order as they appear in SourceBuffer.sourceBuffers. |
611 // SourceBuffer transitions to active are not guaranteed to occur in the | 641 // SourceBuffer transitions to active are not guaranteed to occur in the |
612 // same order as buffers in |m_sourceBuffers|, so this method needs to | 642 // same order as buffers in |m_sourceBuffers|, so this method needs to |
613 // insert |sourceBuffer| into |m_activeSourceBuffers|. | 643 // insert |sourceBuffer| into |m_activeSourceBuffers|. |
614 size_t indexInSourceBuffers = m_sourceBuffers->find(sourceBuffer); | 644 size_t indexInSourceBuffers = m_sourceBuffers->find(sourceBuffer); |
615 DCHECK(indexInSourceBuffers != kNotFound); | 645 DCHECK(indexInSourceBuffers != kNotFound); |
616 | 646 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 | 741 |
712 m_asyncEventQueue->enqueueEvent(event); | 742 m_asyncEventQueue->enqueueEvent(event); |
713 } | 743 } |
714 | 744 |
715 URLRegistry& MediaSource::registry() const | 745 URLRegistry& MediaSource::registry() const |
716 { | 746 { |
717 return MediaSourceRegistry::registry(); | 747 return MediaSourceRegistry::registry(); |
718 } | 748 } |
719 | 749 |
720 } // namespace blink | 750 } // namespace blink |
OLD | NEW |