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

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

Issue 1658033002: Add SourceBuffer implementations of Audio/VideoTracks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pass-media-tracks-to-blink
Patch Set: Make A/V track lists plain members in SourceBuffer 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 30 matching lines...) Expand all
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" 45 #include "core/html/track/AudioTrack.h"
46 #include "core/html/track/AudioTrackList.h" 46 #include "core/html/track/AudioTrackList.h"
47 #include "core/html/track/TextTrack.h" 47 #include "core/html/track/TextTrack.h"
48 #include "core/html/track/VideoTrack.h" 48 #include "core/html/track/VideoTrack.h"
49 #include "core/html/track/VideoTrackList.h" 49 #include "core/html/track/VideoTrackList.h"
50 #include "core/streams/Stream.h" 50 #include "core/streams/Stream.h"
51 #include "modules/mediasource/AudioTrackSourceBuffer.h"
51 #include "modules/mediasource/MediaSource.h" 52 #include "modules/mediasource/MediaSource.h"
53 #include "modules/mediasource/VideoTrackSourceBuffer.h"
52 #include "platform/Logging.h" 54 #include "platform/Logging.h"
53 #include "platform/TraceEvent.h" 55 #include "platform/TraceEvent.h"
54 #include "public/platform/WebSourceBuffer.h" 56 #include "public/platform/WebSourceBuffer.h"
55 #include "wtf/MathExtras.h" 57 #include "wtf/MathExtras.h"
56 58
57 #include <limits> 59 #include <limits>
58 #include <sstream> 60 #include <sstream>
59 61
60 using blink::WebSourceBuffer; 62 using blink::WebSourceBuffer;
61 63
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 // 6. If the mode attribute equals "sequence", then set the group start time stamp to new timestamp offset. 227 // 6. If the mode attribute equals "sequence", then set the group start time stamp to new timestamp offset.
226 if (!m_webSourceBuffer->setTimestampOffset(offset)) { 228 if (!m_webSourceBuffer->setTimestampOffset(offset)) {
227 MediaSource::logAndThrowDOMException(exceptionState, InvalidStateError, "The timestamp offset may not be set while the SourceBuffer's append state is 'P ARSING_MEDIA_SEGMENT'."); 229 MediaSource::logAndThrowDOMException(exceptionState, InvalidStateError, "The timestamp offset may not be set while the SourceBuffer's append state is 'P ARSING_MEDIA_SEGMENT'.");
228 return; 230 return;
229 } 231 }
230 232
231 // 7. Update the attribute to new timestamp offset. 233 // 7. Update the attribute to new timestamp offset.
232 m_timestampOffset = offset; 234 m_timestampOffset = offset;
233 } 235 }
234 236
237 AudioTrackList& SourceBuffer::audioTracks()
238 {
239 ASSERT(RuntimeEnabledFeatures::audioVideoTracksEnabled());
240 return *m_audioTracks;
241 }
242
243 VideoTrackList& SourceBuffer::videoTracks()
244 {
245 ASSERT(RuntimeEnabledFeatures::audioVideoTracksEnabled());
246 return *m_videoTracks;
247 }
248
235 double SourceBuffer::appendWindowStart() const 249 double SourceBuffer::appendWindowStart() const
236 { 250 {
237 return m_appendWindowStart; 251 return m_appendWindowStart;
238 } 252 }
239 253
240 void SourceBuffer::setAppendWindowStart(double start, ExceptionState& exceptionS tate) 254 void SourceBuffer::setAppendWindowStart(double start, ExceptionState& exceptionS tate)
241 { 255 {
242 WTF_LOG(Media, "SourceBuffer::setAppendWindowStart %p start=%f", this, start ); 256 WTF_LOG(Media, "SourceBuffer::setAppendWindowStart %p start=%f", this, start );
243 // Section 3.1 appendWindowStart attribute setter steps. 257 // Section 3.1 appendWindowStart attribute setter steps.
244 // https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source. html#widl-SourceBuffer-appendWindowStart 258 // https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source. html#widl-SourceBuffer-appendWindowStart
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 // 6. Set first initialization segment received flag to true. 513 // 6. Set first initialization segment received flag to true.
500 m_firstInitializationSegmentReceived = true; 514 m_firstInitializationSegmentReceived = true;
501 } 515 }
502 516
503 // TODO(servolk): Implement proper MSE init segment received algorithm. 517 // TODO(servolk): Implement proper MSE init segment received algorithm.
504 if (!RuntimeEnabledFeatures::audioVideoTracksEnabled()) { 518 if (!RuntimeEnabledFeatures::audioVideoTracksEnabled()) {
505 m_pendingTracks.clear(); 519 m_pendingTracks.clear();
506 return; 520 return;
507 } 521 }
508 522
523 if (!m_audioTracks)
524 m_audioTracks = AudioTrackList::create(*m_source->mediaElement());
525 if (!m_videoTracks)
526 m_videoTracks = VideoTrackList::create(*m_source->mediaElement());
527
509 for (const auto& trackId : m_audioTrackIds) { 528 for (const auto& trackId : m_audioTrackIds) {
510 m_source->mediaElement()->audioTracks().remove(trackId); 529 m_source->mediaElement()->audioTracks().remove(trackId);
530 audioTracks().remove(trackId);
philipj_slow 2016/03/10 13:12:17 This makes it clear that the order in which the tr
servolk 2016/03/11 02:00:58 see below
511 } 531 }
512 for (const auto& trackId : m_videoTrackIds) { 532 for (const auto& trackId : m_videoTrackIds) {
513 m_source->mediaElement()->videoTracks().remove(trackId); 533 m_source->mediaElement()->videoTracks().remove(trackId);
534 videoTracks().remove(trackId);
514 } 535 }
515 m_audioTrackIds.clear(); 536 m_audioTrackIds.clear();
516 m_videoTrackIds.clear(); 537 m_videoTrackIds.clear();
517 538
518 for (const auto& trackId : newTracks) { 539 for (const auto& trackId : newTracks) {
519 for (const auto& track : m_pendingTracks) { 540 for (const auto& track : m_pendingTracks) {
520 if (track->trackId() == trackId) { 541 if (track->trackId() == trackId) {
521 if (track->type() == WebMediaPlayer::AudioTrack) { 542 if (track->type() == WebMediaPlayer::AudioTrack) {
522 AudioTrack* audioTrack = static_cast<AudioTrack*>(track.get( )); 543 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()); 544 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());
545 audioTracks().add(audioTrack);
philipj_slow 2016/03/10 13:12:17 Order tests needed for adding tracks too.
servolk 2016/03/11 02:00:58 I think we are better off postponing these tests u
524 m_source->mediaElement()->audioTracks().add(audioTrack); 546 m_source->mediaElement()->audioTracks().add(audioTrack);
525 m_audioTrackIds.append(trackId); 547 m_audioTrackIds.append(trackId);
526 } else if (track->type() == WebMediaPlayer::VideoTrack) { 548 } else if (track->type() == WebMediaPlayer::VideoTrack) {
527 VideoTrack* videoTrack = static_cast<VideoTrack*>(track.get( )); 549 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()); 550 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());
551 videoTracks().add(videoTrack);
529 m_source->mediaElement()->videoTracks().add(videoTrack); 552 m_source->mediaElement()->videoTracks().add(videoTrack);
530 m_videoTrackIds.append(trackId); 553 m_videoTrackIds.append(trackId);
531 } 554 }
532 break; 555 break;
533 } 556 }
534 } 557 }
535 } 558 }
536 m_pendingTracks.clear(); 559 m_pendingTracks.clear();
537 } 560 }
538 561
539 WebMediaPlayer::TrackId SourceBuffer::createMediaTrack(WebMediaPlayer::TrackType type, WebString id, WebString kind, WebString label, WebString language) 562 WebMediaPlayer::TrackId SourceBuffer::createMediaTrack(WebMediaPlayer::TrackType type, WebString id, WebString kind, WebString label, WebString language)
540 { 563 {
541 TrackBase* result = nullptr; 564 TrackBase* result = nullptr;
542 switch (type) { 565 switch (type) {
543 case WebMediaPlayer::AudioTrack: 566 case WebMediaPlayer::AudioTrack:
544 result = AudioTrack::create(id, kind, label, language, false); 567 {
545 break; 568 AudioTrack* audioTrack = AudioTrack::create(id, kind, label, languag e, false);
569 if (audioTrack) {
philipj_slow 2016/03/10 13:12:17 It can't be null, can it? On OOM we should have cr
servolk 2016/03/11 02:00:58 Done.
570 new AudioTrackSourceBuffer(*audioTrack, this);
571 result = audioTrack;
572 }
573 WTF_LOG(Media, "SourceBuffer(%p)::createMediaTrack: audioTrack %p tr ackId=%d id=%s label=%s lang=%s", this, audioTrack, audioTrack->trackId(), audio Track->id().utf8().data(), audioTrack->label().utf8().data(), audioTrack->langua ge().utf8().data());
574 break;
575 }
546 case WebMediaPlayer::TextTrack: 576 case WebMediaPlayer::TextTrack:
547 result = TextTrack::create(kind, label, language); 577 result = TextTrack::create(kind, label, language);
548 break; 578 break;
549 case WebMediaPlayer::VideoTrack: 579 case WebMediaPlayer::VideoTrack:
550 result = VideoTrack::create(id, kind, label, language, false); 580 {
551 break; 581 VideoTrack* videoTrack = VideoTrack::create(id, kind, label, languag e, false);
582 if (videoTrack) {
583 new VideoTrackSourceBuffer(*videoTrack, this);
584 result = videoTrack;
585 }
586 WTF_LOG(Media, "SourceBuffer(%p)::createMediaTrack: videoTrack %p tr ackId=%d id=%s label=%s lang=%s", this, videoTrack, videoTrack->trackId(), video Track->id().utf8().data(), videoTrack->label().utf8().data(), videoTrack->langua ge().utf8().data());
587 break;
588 }
552 } 589 }
553 590
554 ASSERT(result); 591 ASSERT(result);
555 m_pendingTracks.append(result); 592 m_pendingTracks.append(result);
556 return result->trackId(); 593 return result->trackId();
557 } 594 }
558 595
559 bool SourceBuffer::hasPendingActivity() const 596 bool SourceBuffer::hasPendingActivity() const
560 { 597 {
561 return m_source; 598 return m_source;
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 visitor->trace(m_source); 967 visitor->trace(m_source);
931 visitor->trace(m_trackDefaults); 968 visitor->trace(m_trackDefaults);
932 visitor->trace(m_asyncEventQueue); 969 visitor->trace(m_asyncEventQueue);
933 visitor->trace(m_appendBufferAsyncPartRunner); 970 visitor->trace(m_appendBufferAsyncPartRunner);
934 visitor->trace(m_removeAsyncPartRunner); 971 visitor->trace(m_removeAsyncPartRunner);
935 visitor->trace(m_appendStreamAsyncPartRunner); 972 visitor->trace(m_appendStreamAsyncPartRunner);
936 visitor->trace(m_stream); 973 visitor->trace(m_stream);
937 visitor->trace(m_pendingTracks); 974 visitor->trace(m_pendingTracks);
938 visitor->trace(m_audioTrackIds); 975 visitor->trace(m_audioTrackIds);
939 visitor->trace(m_videoTrackIds); 976 visitor->trace(m_videoTrackIds);
977 visitor->trace(m_audioTracks);
978 visitor->trace(m_videoTracks);
940 RefCountedGarbageCollectedEventTargetWithInlineData<SourceBuffer>::trace(vis itor); 979 RefCountedGarbageCollectedEventTargetWithInlineData<SourceBuffer>::trace(vis itor);
941 ActiveDOMObject::trace(visitor); 980 ActiveDOMObject::trace(visitor);
942 } 981 }
943 982
944 } // namespace blink 983 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698