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 466 matching lines...) Loading... |
477 } | 477 } |
478 | 478 |
479 void SourceBuffer::removedFromMediaSource() | 479 void SourceBuffer::removedFromMediaSource() |
480 { | 480 { |
481 if (isRemoved()) | 481 if (isRemoved()) |
482 return; | 482 return; |
483 | 483 |
484 WTF_LOG(Media, "SourceBuffer(%p)::removedFromMediaSource", this); | 484 WTF_LOG(Media, "SourceBuffer(%p)::removedFromMediaSource", this); |
485 abortIfUpdating(); | 485 abortIfUpdating(); |
486 | 486 |
| 487 if (RuntimeEnabledFeatures::audioVideoTracksEnabled()) { |
| 488 ASSERT(m_source); |
| 489 if (m_source->mediaElement()->audioTracks().length() > 0 |
| 490 || m_source->mediaElement()->videoTracks().length() > 0) { |
| 491 removeMediaTracks(); |
| 492 } |
| 493 } |
| 494 |
487 m_webSourceBuffer->removedFromMediaSource(); | 495 m_webSourceBuffer->removedFromMediaSource(); |
488 m_webSourceBuffer.clear(); | 496 m_webSourceBuffer.clear(); |
489 m_source = nullptr; | 497 m_source = nullptr; |
490 m_asyncEventQueue = nullptr; | 498 m_asyncEventQueue = nullptr; |
491 } | 499 } |
492 | 500 |
| 501 void SourceBuffer::removeMediaTracks() |
| 502 { |
| 503 ASSERT(RuntimeEnabledFeatures::audioVideoTracksEnabled()); |
| 504 // Spec: http://w3c.github.io/media-source/#widl-MediaSource-removeSourceBuf
fer-void-SourceBuffer-sourceBuffer |
| 505 ASSERT(m_source); |
| 506 |
| 507 HTMLMediaElement* mediaElement = m_source->mediaElement(); |
| 508 ASSERT(mediaElement); |
| 509 // 3. Let SourceBuffer audioTracks list equal the AudioTrackList object retu
rned by sourceBuffer.audioTracks. |
| 510 // 4. If the SourceBuffer audioTracks list is not empty, then run the follow
ing steps: |
| 511 // 4.1 Let HTMLMediaElement audioTracks list equal the AudioTrackList object
returned by the audioTracks attribute on the HTMLMediaElement. |
| 512 // 4.2 Let the removed enabled audio track flag equal false. |
| 513 bool removedEnabledAudioTrack = false; |
| 514 // 4.3 For each AudioTrack object in the SourceBuffer audioTracks list, run
the following steps: |
| 515 while (audioTracks().length() > 0) { |
| 516 AudioTrack* audioTrack = audioTracks().anonymousIndexedGetter(0); |
| 517 // 4.3.1 Set the sourceBuffer attribute on the AudioTrack object to null
. |
| 518 SourceBufferTrackBaseSupplement::setSourceBuffer(*audioTrack, nullptr); |
| 519 // 4.3.2 If the enabled attribute on the AudioTrack object is true, then
set the removed enabled audio track flag to true. |
| 520 if (audioTrack->enabled()) |
| 521 removedEnabledAudioTrack = true; |
| 522 // 4.3.3 Remove the AudioTrack object from the HTMLMediaElement audioTra
cks list. |
| 523 // 4.3.4 Queue a task to fire a trusted event named removetrack, that do
es not bubble and is not cancelable, and that uses the TrackEvent interface, at
the HTMLMediaElement audioTracks list. |
| 524 mediaElement->audioTracks().remove(audioTrack->trackId()); |
| 525 // 4.3.5 Remove the AudioTrack object from the SourceBuffer audioTracks
list. |
| 526 // 4.3.6 Queue a task to fire a trusted event named removetrack, that do
es not bubble and is not cancelable, and that uses the TrackEvent interface, at
the SourceBuffer audioTracks list. |
| 527 audioTracks().remove(audioTrack->trackId()); |
| 528 } |
| 529 // 4.4 If the removed enabled audio track flag equals true, then queue a tas
k to fire a simple event named change at the HTMLMediaElement audioTracks list. |
| 530 if (removedEnabledAudioTrack) { |
| 531 Event* event = Event::create(EventTypeNames::change); |
| 532 event->setTarget(&mediaElement->audioTracks()); |
| 533 mediaElement->scheduleEvent(event); |
| 534 } |
| 535 |
| 536 // 5. Let SourceBuffer videoTracks list equal the VideoTrackList object retu
rned by sourceBuffer.videoTracks. |
| 537 // 6. If the SourceBuffer videoTracks list is not empty, then run the follow
ing steps: |
| 538 // 6.1 Let HTMLMediaElement videoTracks list equal the VideoTrackList object
returned by the videoTracks attribute on the HTMLMediaElement. |
| 539 // 6.2 Let the removed selected video track flag equal false. |
| 540 bool removedSelectedVideoTrack = false; |
| 541 // 6.3 For each VideoTrack object in the SourceBuffer videoTracks list, run
the following steps: |
| 542 while (videoTracks().length() > 0) { |
| 543 VideoTrack* videoTrack = videoTracks().anonymousIndexedGetter(0); |
| 544 // 6.3.1 Set the sourceBuffer attribute on the VideoTrack object to null
. |
| 545 SourceBufferTrackBaseSupplement::setSourceBuffer(*videoTrack, nullptr); |
| 546 // 6.3.2 If the selected attribute on the VideoTrack object is true, the
n set the removed selected video track flag to true. |
| 547 if (videoTrack->selected()) |
| 548 removedSelectedVideoTrack = true; |
| 549 // 6.3.3 Remove the VideoTrack object from the HTMLMediaElement videoTra
cks list. |
| 550 // 6.3.4 Queue a task to fire a trusted event named removetrack, that do
es not bubble and is not cancelable, and that uses the TrackEvent interface, at
the HTMLMediaElement videoTracks list. |
| 551 mediaElement->videoTracks().remove(videoTrack->trackId()); |
| 552 // 6.3.5 Remove the VideoTrack object from the SourceBuffer videoTracks
list. |
| 553 // 6.3.6 Queue a task to fire a trusted event named removetrack, that do
es not bubble and is not cancelable, and that uses the TrackEvent interface, at
the SourceBuffer videoTracks list. |
| 554 videoTracks().remove(videoTrack->trackId()); |
| 555 } |
| 556 // 6.4 If the removed selected video track flag equals true, then queue a ta
sk to fire a simple event named change at the HTMLMediaElement videoTracks list. |
| 557 if (removedSelectedVideoTrack) { |
| 558 Event* event = Event::create(EventTypeNames::change); |
| 559 event->setTarget(&mediaElement->videoTracks()); |
| 560 mediaElement->scheduleEvent(event); |
| 561 } |
| 562 |
| 563 // 7-8. TODO(servolk): Remove text tracks once SourceBuffer has text tracks. |
| 564 } |
| 565 |
493 template<class T> | 566 template<class T> |
494 T* findExistingTrackById(const TrackListBase<T>& trackList, const String& id) | 567 T* findExistingTrackById(const TrackListBase<T>& trackList, const String& id) |
495 { | 568 { |
496 // According to MSE specification (https://w3c.github.io/media-source/#sourc
ebuffer-init-segment-received) step 3.1: | 569 // According to MSE specification (https://w3c.github.io/media-source/#sourc
ebuffer-init-segment-received) step 3.1: |
497 // > 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. | 570 // > 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. |
498 // I.e. we only need to search by TrackID if there is more than one track, o
therwise we can assume that the only | 571 // I.e. we only need to search by TrackID if there is more than one track, o
therwise we can assume that the only |
499 // track of the given type is the same one that we had in previous init segm
ents. | 572 // track of the given type is the same one that we had in previous init segm
ents. |
500 if (trackList.length() == 1) | 573 if (trackList.length() == 1) |
501 return trackList.anonymousIndexedGetter(0); | 574 return trackList.anonymousIndexedGetter(0); |
502 return trackList.getTrackById(id); | 575 return trackList.getTrackById(id); |
(...skipping 447 matching lines...) Loading... |
950 visitor->trace(m_removeAsyncPartRunner); | 1023 visitor->trace(m_removeAsyncPartRunner); |
951 visitor->trace(m_appendStreamAsyncPartRunner); | 1024 visitor->trace(m_appendStreamAsyncPartRunner); |
952 visitor->trace(m_stream); | 1025 visitor->trace(m_stream); |
953 visitor->trace(m_audioTracks); | 1026 visitor->trace(m_audioTracks); |
954 visitor->trace(m_videoTracks); | 1027 visitor->trace(m_videoTracks); |
955 EventTargetWithInlineData::trace(visitor); | 1028 EventTargetWithInlineData::trace(visitor); |
956 ActiveDOMObject::trace(visitor); | 1029 ActiveDOMObject::trace(visitor); |
957 } | 1030 } |
958 | 1031 |
959 } // namespace blink | 1032 } // namespace blink |
OLD | NEW |