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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/mediasource/SourceBuffer.cpp
diff --git a/third_party/WebKit/Source/modules/mediasource/SourceBuffer.cpp b/third_party/WebKit/Source/modules/mediasource/SourceBuffer.cpp
index 487011521a9927f26b3a9bbc7281173505267668..bac2a2fb8aa81f437a7cbb7c675dd7876e48ba39 100644
--- a/third_party/WebKit/Source/modules/mediasource/SourceBuffer.cpp
+++ b/third_party/WebKit/Source/modules/mediasource/SourceBuffer.cpp
@@ -48,7 +48,9 @@
#include "core/html/track/VideoTrack.h"
#include "core/html/track/VideoTrackList.h"
#include "core/streams/Stream.h"
+#include "modules/mediasource/AudioTrackSourceBuffer.h"
#include "modules/mediasource/MediaSource.h"
+#include "modules/mediasource/VideoTrackSourceBuffer.h"
#include "platform/Logging.h"
#include "platform/TraceEvent.h"
#include "public/platform/WebSourceBuffer.h"
@@ -232,6 +234,18 @@ void SourceBuffer::setTimestampOffset(double offset, ExceptionState& exceptionSt
m_timestampOffset = offset;
}
+AudioTrackList& SourceBuffer::audioTracks()
+{
+ ASSERT(RuntimeEnabledFeatures::audioVideoTracksEnabled());
+ return *m_audioTracks;
+}
+
+VideoTrackList& SourceBuffer::videoTracks()
+{
+ ASSERT(RuntimeEnabledFeatures::audioVideoTracksEnabled());
+ return *m_videoTracks;
+}
+
double SourceBuffer::appendWindowStart() const
{
return m_appendWindowStart;
@@ -506,11 +520,18 @@ void SourceBuffer::initializationSegmentReceived(const WebVector<WebMediaPlayer:
return;
}
+ if (!m_audioTracks)
+ m_audioTracks = AudioTrackList::create(*m_source->mediaElement());
+ if (!m_videoTracks)
+ m_videoTracks = VideoTrackList::create(*m_source->mediaElement());
+
for (const auto& trackId : m_audioTrackIds) {
m_source->mediaElement()->audioTracks().remove(trackId);
+ 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
}
for (const auto& trackId : m_videoTrackIds) {
m_source->mediaElement()->videoTracks().remove(trackId);
+ videoTracks().remove(trackId);
}
m_audioTrackIds.clear();
m_videoTrackIds.clear();
@@ -521,11 +542,13 @@ void SourceBuffer::initializationSegmentReceived(const WebVector<WebMediaPlayer:
if (track->type() == WebMediaPlayer::AudioTrack) {
AudioTrack* audioTrack = static_cast<AudioTrack*>(track.get());
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());
+ 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
m_source->mediaElement()->audioTracks().add(audioTrack);
m_audioTrackIds.append(trackId);
} else if (track->type() == WebMediaPlayer::VideoTrack) {
VideoTrack* videoTrack = static_cast<VideoTrack*>(track.get());
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());
+ videoTracks().add(videoTrack);
m_source->mediaElement()->videoTracks().add(videoTrack);
m_videoTrackIds.append(trackId);
}
@@ -541,14 +564,28 @@ WebMediaPlayer::TrackId SourceBuffer::createMediaTrack(WebMediaPlayer::TrackType
TrackBase* result = nullptr;
switch (type) {
case WebMediaPlayer::AudioTrack:
- result = AudioTrack::create(id, kind, label, language, false);
- break;
+ {
+ AudioTrack* audioTrack = AudioTrack::create(id, kind, label, language, false);
+ 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.
+ new AudioTrackSourceBuffer(*audioTrack, this);
+ result = audioTrack;
+ }
+ WTF_LOG(Media, "SourceBuffer(%p)::createMediaTrack: 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());
+ break;
+ }
case WebMediaPlayer::TextTrack:
result = TextTrack::create(kind, label, language);
break;
case WebMediaPlayer::VideoTrack:
- result = VideoTrack::create(id, kind, label, language, false);
- break;
+ {
+ VideoTrack* videoTrack = VideoTrack::create(id, kind, label, language, false);
+ if (videoTrack) {
+ new VideoTrackSourceBuffer(*videoTrack, this);
+ result = videoTrack;
+ }
+ WTF_LOG(Media, "SourceBuffer(%p)::createMediaTrack: 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());
+ break;
+ }
}
ASSERT(result);
@@ -937,6 +974,8 @@ DEFINE_TRACE(SourceBuffer)
visitor->trace(m_pendingTracks);
visitor->trace(m_audioTrackIds);
visitor->trace(m_videoTrackIds);
+ visitor->trace(m_audioTracks);
+ visitor->trace(m_videoTracks);
RefCountedGarbageCollectedEventTargetWithInlineData<SourceBuffer>::trace(visitor);
ActiveDOMObject::trace(visitor);
}

Powered by Google App Engine
This is Rietveld 408576698