Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: third_party/WebKit/Source/modules/mediasource/SourceBuffer.cpp

Issue 1846863002: Remove SourceBuffer media tracks on detach from media element (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blink-sb-tracks6
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 } 480 }
481 481
482 void SourceBuffer::removedFromMediaSource() 482 void SourceBuffer::removedFromMediaSource()
483 { 483 {
484 if (isRemoved()) 484 if (isRemoved())
485 return; 485 return;
486 486
487 WTF_LOG(Media, "SourceBuffer(%p)::removedFromMediaSource", this); 487 WTF_LOG(Media, "SourceBuffer(%p)::removedFromMediaSource", this);
488 abortIfUpdating(); 488 abortIfUpdating();
489 489
490 if (m_source->mediaElement() && RuntimeEnabledFeatures::audioVideoTracksEnab led())
491 removeMediaTracks();
492
490 m_webSourceBuffer->removedFromMediaSource(); 493 m_webSourceBuffer->removedFromMediaSource();
491 m_webSourceBuffer.clear(); 494 m_webSourceBuffer.clear();
492 m_source = nullptr; 495 m_source = nullptr;
493 m_asyncEventQueue = nullptr; 496 m_asyncEventQueue = nullptr;
494 } 497 }
495 498
499 void SourceBuffer::removeMediaTracks()
500 {
501 ASSERT(RuntimeEnabledFeatures::audioVideoTracksEnabled());
502 // Spec: http://w3c.github.io/media-source/#widl-MediaSource-removeSourceBuf fer-void-SourceBuffer-sourceBuffer
503 ASSERT(m_source);
504
505 HTMLMediaElement* mediaElement = m_source->mediaElement();
506 ASSERT(mediaElement);
507 // 3. Let SourceBuffer audioTracks list equal the AudioTrackList object retu rned by sourceBuffer.audioTracks.
508 // 4. If the SourceBuffer audioTracks list is not empty, then run the follow ing steps:
509 // 4.1 Let HTMLMediaElement audioTracks list equal the AudioTrackList object returned by the audioTracks attribute on the HTMLMediaElement.
510 // 4.2 Let the removed enabled audio track flag equal false.
511 bool removedEnabledAudioTrack = false;
512 // 4.3 For each AudioTrack object in the SourceBuffer audioTracks list, run the following steps:
513 while (audioTracks().length() > 0) {
514 AudioTrack* audioTrack = audioTracks().anonymousIndexedGetter(0);
515 // TODO(servolk): 4.3.1 Set the sourceBuffer attribute on the AudioTrack object to null.
wolenetz 2016/03/31 19:06:15 Is this not doable once https://codereview.chromiu
servolk 2016/03/31 22:39:51 Done.
516 // 4.3.2 If the enabled attribute on the AudioTrack object is true, then set the removed enabled audio track flag to true.
517 if (audioTrack->enabled())
518 removedEnabledAudioTrack = true;
519 // 4.3.3 Remove the AudioTrack object from the HTMLMediaElement audioTra cks list.
520 // 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.
521 mediaElement->audioTracks().remove(audioTrack->trackId());
522 // 4.3.5 Remove the AudioTrack object from the SourceBuffer audioTracks list.
523 // 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.
524 audioTracks().remove(audioTrack->trackId());
525 }
526 // 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.
527 if (removedEnabledAudioTrack) {
528 RefPtrWillBeRawPtr<Event> event = Event::create(EventTypeNames::change);
529 event->setTarget(&mediaElement->audioTracks());
530 mediaElement->scheduleEvent(event);
531 }
532
533 // 5. Let SourceBuffer videoTracks list equal the VideoTrackList object retu rned by sourceBuffer.videoTracks.
534 // 6. If the SourceBuffer videoTracks list is not empty, then run the follow ing steps:
535 // 6.1 Let HTMLMediaElement videoTracks list equal the VideoTrackList object returned by the videoTracks attribute on the HTMLMediaElement.
536 // 6.2 Let the removed selected video track flag equal false.
537 bool removedSelectedVideoTrack = false;
538 // 6.3 For each VideoTrack object in the SourceBuffer videoTracks list, run the following steps:
539 while (videoTracks().length() > 0) {
540 VideoTrack* videoTrack = videoTracks().anonymousIndexedGetter(0);
541 // TODO(servolk): 6.3.1 Set the sourceBuffer attribute on the VideoTrack object to null.
wolenetz 2016/03/31 19:06:15 ditto
servolk 2016/03/31 22:39:51 Done.
542 // 6.3.2 If the selected attribute on the VideoTrack object is true, the n set the removed selected video track flag to true.
543 if (videoTrack->selected())
544 removedSelectedVideoTrack = true;
545 // 6.3.3 Remove the VideoTrack object from the HTMLMediaElement videoTra cks list.
546 // 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.
547 mediaElement->videoTracks().remove(videoTrack->trackId());
548 // 6.3.5 Remove the VideoTrack object from the SourceBuffer videoTracks list.
549 // 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.
550 videoTracks().remove(videoTrack->trackId());
551 }
552 // 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.
553 if (removedSelectedVideoTrack) {
554 RefPtrWillBeRawPtr<Event> event = Event::create(EventTypeNames::change);
555 event->setTarget(&mediaElement->videoTracks());
556 mediaElement->scheduleEvent(event);
557 }
558
559 // 7-8. TODO(servolk): Remove text tracks once SourceBuffer has text tracks.
560 }
561
496 template<class T> 562 template<class T>
497 T* findExistingTrackById(const TrackListBase<T>& trackList, const String& id) 563 T* findExistingTrackById(const TrackListBase<T>& trackList, const String& id)
498 { 564 {
499 // According to MSE specification (https://w3c.github.io/media-source/#sourc ebuffer-init-segment-received) step 3.1: 565 // According to MSE specification (https://w3c.github.io/media-source/#sourc ebuffer-init-segment-received) step 3.1:
500 // > 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. 566 // > 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.
501 // I.e. we only need to search by TrackID if there is more than one track, o therwise we can assume that the only 567 // I.e. we only need to search by TrackID if there is more than one track, o therwise we can assume that the only
502 // track of the given type is the same one that we had in previous init segm ents. 568 // track of the given type is the same one that we had in previous init segm ents.
503 if (trackList.length() == 1) 569 if (trackList.length() == 1)
504 return trackList.anonymousIndexedGetter(0); 570 return trackList.anonymousIndexedGetter(0);
505 return trackList.getTrackById(id); 571 return trackList.getTrackById(id);
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 visitor->trace(m_removeAsyncPartRunner); 1024 visitor->trace(m_removeAsyncPartRunner);
959 visitor->trace(m_appendStreamAsyncPartRunner); 1025 visitor->trace(m_appendStreamAsyncPartRunner);
960 visitor->trace(m_stream); 1026 visitor->trace(m_stream);
961 visitor->trace(m_audioTracks); 1027 visitor->trace(m_audioTracks);
962 visitor->trace(m_videoTracks); 1028 visitor->trace(m_videoTracks);
963 RefCountedGarbageCollectedEventTargetWithInlineData<SourceBuffer>::trace(vis itor); 1029 RefCountedGarbageCollectedEventTargetWithInlineData<SourceBuffer>::trace(vis itor);
964 ActiveDOMObject::trace(visitor); 1030 ActiveDOMObject::trace(visitor);
965 } 1031 }
966 1032
967 } // namespace blink 1033 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698