Chromium Code Reviews| Index: third_party/WebKit/Source/modules/mediasource/SourceBufferTrackBaseSupplement.cpp |
| diff --git a/third_party/WebKit/Source/modules/mediasource/SourceBufferTrackBaseSupplement.cpp b/third_party/WebKit/Source/modules/mediasource/SourceBufferTrackBaseSupplement.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5718c2aa91df32a4c96b006fa0be657c736ca556 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/mediasource/SourceBufferTrackBaseSupplement.cpp |
| @@ -0,0 +1,53 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "modules/mediasource/SourceBufferTrackBaseSupplement.h" |
| + |
| +#include "core/html/track/TrackBase.h" |
| +#include "modules/mediasource/SourceBuffer.h" |
| + |
| +namespace blink { |
| + |
| +static const char* SupplementName = "SourceBufferTrackBaseSupplement"; |
| + |
| +SourceBufferTrackBaseSupplement::SourceBufferTrackBaseSupplement(TrackBase& trackBase) |
| +{ |
| + provideTo(trackBase, SupplementName, this); |
| +} |
| + |
| +// static |
| +SourceBufferTrackBaseSupplement& SourceBufferTrackBaseSupplement::from(TrackBase& track) |
| +{ |
| + SourceBufferTrackBaseSupplement* supplement = static_cast<SourceBufferTrackBaseSupplement*>(Supplement<TrackBase>::from(track, SupplementName)); |
| + if (!supplement) { |
| + supplement = new SourceBufferTrackBaseSupplement(track); |
| + } |
| + return *supplement; |
| +} |
| + |
| +// static |
| +SourceBuffer* SourceBufferTrackBaseSupplement::sourceBuffer(TrackBase& track) |
| +{ |
| + // We could use SourceBufferTrackBaseSupplement::from(track).m_sourceBuffer here, but the 'from' method always creates a new supplement if an |
| + // existing one is not found, so using 'from' here would result in supplement being created even for tracks that never have non-null .sourceBuffer |
| + // property (i.e. tracks created by HTMLMediaElement and not SourceBuffer). |
| + SourceBufferTrackBaseSupplement* supplement = static_cast<SourceBufferTrackBaseSupplement*>(Supplement<TrackBase>::from(track, SupplementName)); |
|
philipj_slow
2016/04/07 08:59:35
You're only doing this in one place, but CSSSelect
servolk
2016/04/07 17:03:55
Ah, ok, thanks for pointing that out. If just wasn
|
| + if (supplement) |
| + return supplement->m_sourceBuffer; |
| + return nullptr; |
| +} |
| + |
| +void SourceBufferTrackBaseSupplement::setSourceBuffer(SourceBuffer* sourceBuffer) |
| +{ |
| + m_sourceBuffer = sourceBuffer; |
| +} |
| + |
| +DEFINE_TRACE(SourceBufferTrackBaseSupplement) |
| +{ |
| + visitor->trace(m_sourceBuffer); |
| + Supplement<TrackBase>::trace(visitor); |
| +} |
| + |
| +} // namespace blink |
| + |