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

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

Issue 1659653002: Pass MSE media track info from ChunkDemuxer to blink::SourceBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@use-media-tracks-in-media
Patch Set: CR feedback2 Created 4 years, 9 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 24 matching lines...) Expand all
35 #include "core/dom/DOMArrayBuffer.h" 35 #include "core/dom/DOMArrayBuffer.h"
36 #include "core/dom/DOMArrayBufferView.h" 36 #include "core/dom/DOMArrayBufferView.h"
37 #include "core/dom/ExceptionCode.h" 37 #include "core/dom/ExceptionCode.h"
38 #include "core/dom/ExecutionContext.h" 38 #include "core/dom/ExecutionContext.h"
39 #include "core/events/Event.h" 39 #include "core/events/Event.h"
40 #include "core/events/GenericEventQueue.h" 40 #include "core/events/GenericEventQueue.h"
41 #include "core/fileapi/FileReaderLoader.h" 41 #include "core/fileapi/FileReaderLoader.h"
42 #include "core/html/HTMLMediaElement.h" 42 #include "core/html/HTMLMediaElement.h"
43 #include "core/html/MediaError.h" 43 #include "core/html/MediaError.h"
44 #include "core/html/TimeRanges.h" 44 #include "core/html/TimeRanges.h"
45 #include "core/html/track/AudioTrack.h"
46 #include "core/html/track/AudioTrackList.h"
47 #include "core/html/track/TextTrack.h"
48 #include "core/html/track/VideoTrack.h"
49 #include "core/html/track/VideoTrackList.h"
45 #include "core/streams/Stream.h" 50 #include "core/streams/Stream.h"
46 #include "modules/mediasource/MediaSource.h" 51 #include "modules/mediasource/MediaSource.h"
47 #include "platform/Logging.h" 52 #include "platform/Logging.h"
48 #include "platform/TraceEvent.h" 53 #include "platform/TraceEvent.h"
49 #include "public/platform/WebSourceBuffer.h" 54 #include "public/platform/WebSourceBuffer.h"
50 #include "wtf/MathExtras.h" 55 #include "wtf/MathExtras.h"
51 56
52 #include <limits> 57 #include <limits>
53 #include <sstream> 58 #include <sstream>
54 59
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 468
464 WTF_LOG(Media, "SourceBuffer(%p)::removedFromMediaSource", this); 469 WTF_LOG(Media, "SourceBuffer(%p)::removedFromMediaSource", this);
465 abortIfUpdating(); 470 abortIfUpdating();
466 471
467 m_webSourceBuffer->removedFromMediaSource(); 472 m_webSourceBuffer->removedFromMediaSource();
468 m_webSourceBuffer.clear(); 473 m_webSourceBuffer.clear();
469 m_source = nullptr; 474 m_source = nullptr;
470 m_asyncEventQueue = nullptr; 475 m_asyncEventQueue = nullptr;
471 } 476 }
472 477
473 void SourceBuffer::initializationSegmentReceived() 478 void SourceBuffer::initializationSegmentReceived(const WebVector<WebMediaPlayer: :TrackId>& newTracks)
474 { 479 {
475 WTF_LOG(Media, "SourceBuffer::initializationSegmentReceived %p", this); 480 WTF_LOG(Media, "SourceBuffer::initializationSegmentReceived %p tracks=%zu", this, newTracks.size());
476 ASSERT(m_source); 481 ASSERT(m_source);
482 ASSERT(m_source->mediaElement());
477 ASSERT(m_updating); 483 ASSERT(m_updating);
484 ASSERT(newTracks.size() == m_pendingTracks.size());
478 485
479 // https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source. html#sourcebuffer-init-segment-received 486 // https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source. html#sourcebuffer-init-segment-received
480 // FIXME: Make steps 1-7 synchronous with this call. 487 // FIXME: Make steps 1-7 synchronous with this call.
481 // FIXME: Augment the interface to this method to implement compliant steps 4-7 here. 488 // FIXME: Augment the interface to this method to implement compliant steps 4-7 here.
482 // Step 3 (if the first initialization segment received flag is true) is 489 // Step 3 (if the first initialization segment received flag is true) is
483 // implemented by caller. 490 // implemented by caller.
484 491
485 if (!m_firstInitializationSegmentReceived) { 492 if (!m_firstInitializationSegmentReceived) {
486 // 5. If active track flag equals true, then run the following steps: 493 // 5. If active track flag equals true, then run the following steps:
487 // 5.1. Add this SourceBuffer to activeSourceBuffers. 494 // 5.1. Add this SourceBuffer to activeSourceBuffers.
488 // 5.2. Queue a task to fire a simple event named addsourcebuffer at 495 // 5.2. Queue a task to fire a simple event named addsourcebuffer at
489 // activesourcebuffers. 496 // activesourcebuffers.
490 m_source->setSourceBufferActive(this); 497 m_source->setSourceBufferActive(this);
491 498
492 // 6. Set first initialization segment received flag to true. 499 // 6. Set first initialization segment received flag to true.
493 m_firstInitializationSegmentReceived = true; 500 m_firstInitializationSegmentReceived = true;
494 } 501 }
502
503 // TODO(servolk): Implement proper MSE init segment received algorithm.
504 if (!RuntimeEnabledFeatures::audioVideoTracksEnabled()) {
505 m_pendingTracks.clear();
506 return;
507 }
508
509 for (const auto& trackId : m_audioTrackIds) {
510 m_source->mediaElement()->audioTracks().remove(trackId);
philipj_slow 2016/03/24 05:56:00 Can't this end up adding and removing the same tra
servolk 2016/03/29 01:26:33 initializationSegmentReceived is definitely going
511 }
512 for (const auto& trackId : m_videoTrackIds) {
513 m_source->mediaElement()->videoTracks().remove(trackId);
514 }
515 m_audioTrackIds.clear();
516 m_videoTrackIds.clear();
517
518 for (const auto& trackId : newTracks) {
519 for (const auto& track : m_pendingTracks) {
520 if (track->trackId() == trackId) {
521 if (track->type() == WebMediaPlayer::AudioTrack) {
522 AudioTrack* audioTrack = static_cast<AudioTrack*>(track.get( ));
523 WTF_LOG(Media, "Tracks (sb=%p): adding audioTrack %p trackId =%d id=%s label=%s lang=%s", this, audioTrack, audioTrack->trackId(), audioTrack ->id().utf8().data(), audioTrack->label().utf8().data(), audioTrack->language(). utf8().data());
524 m_source->mediaElement()->audioTracks().add(audioTrack);
525 m_audioTrackIds.append(trackId);
526 } else if (track->type() == WebMediaPlayer::VideoTrack) {
527 VideoTrack* videoTrack = static_cast<VideoTrack*>(track.get( ));
528 WTF_LOG(Media, "Tracks (sb=%p): adding videoTrack %p trackId =%d id=%s label=%s lang=%s", this, videoTrack, videoTrack->trackId(), videoTrack ->id().utf8().data(), videoTrack->label().utf8().data(), videoTrack->language(). utf8().data());
529 m_source->mediaElement()->videoTracks().add(videoTrack);
530 m_videoTrackIds.append(trackId);
531 }
532 break;
533 }
534 }
535 }
536 m_pendingTracks.clear();
537 }
538
539 WebMediaPlayer::TrackId SourceBuffer::createMediaTrack(WebMediaPlayer::TrackType type, WebString id, WebString kind, WebString label, WebString language)
540 {
541 TrackBase* result = nullptr;
542 switch (type) {
543 case WebMediaPlayer::AudioTrack:
544 result = AudioTrack::create(id, kind, label, language, false);
545 break;
546 case WebMediaPlayer::TextTrack:
547 result = TextTrack::create(kind, label, language);
548 break;
549 case WebMediaPlayer::VideoTrack:
550 result = VideoTrack::create(id, kind, label, language, false);
551 break;
552 }
553
554 ASSERT(result);
555 m_pendingTracks.append(result);
philipj_slow 2016/03/24 05:56:00 These only end up used in initializationSegmentRec
servolk 2016/03/29 01:26:33 Yes, the same functionality can be achieved in a s
556 return result->trackId();
495 } 557 }
496 558
497 bool SourceBuffer::hasPendingActivity() const 559 bool SourceBuffer::hasPendingActivity() const
498 { 560 {
499 return m_source; 561 return m_source;
500 } 562 }
501 563
502 void SourceBuffer::suspend() 564 void SourceBuffer::suspend()
503 { 565 {
504 m_appendBufferAsyncPartRunner->suspend(); 566 m_appendBufferAsyncPartRunner->suspend();
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 927
866 DEFINE_TRACE(SourceBuffer) 928 DEFINE_TRACE(SourceBuffer)
867 { 929 {
868 visitor->trace(m_source); 930 visitor->trace(m_source);
869 visitor->trace(m_trackDefaults); 931 visitor->trace(m_trackDefaults);
870 visitor->trace(m_asyncEventQueue); 932 visitor->trace(m_asyncEventQueue);
871 visitor->trace(m_appendBufferAsyncPartRunner); 933 visitor->trace(m_appendBufferAsyncPartRunner);
872 visitor->trace(m_removeAsyncPartRunner); 934 visitor->trace(m_removeAsyncPartRunner);
873 visitor->trace(m_appendStreamAsyncPartRunner); 935 visitor->trace(m_appendStreamAsyncPartRunner);
874 visitor->trace(m_stream); 936 visitor->trace(m_stream);
937 visitor->trace(m_pendingTracks);
938 visitor->trace(m_audioTrackIds);
939 visitor->trace(m_videoTrackIds);
875 RefCountedGarbageCollectedEventTargetWithInlineData<SourceBuffer>::trace(vis itor); 940 RefCountedGarbageCollectedEventTargetWithInlineData<SourceBuffer>::trace(vis itor);
876 ActiveDOMObject::trace(visitor); 941 ActiveDOMObject::trace(visitor);
877 } 942 }
878 943
879 } // namespace blink 944 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698