Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 | |
| 7 #include "modules/mediasource/TrackDefaultList.h" | |
| 8 | |
| 9 #include "bindings/core/v8/ExceptionState.h" | |
| 10 #include "core/dom/ExceptionCode.h" | |
| 11 | |
| 12 namespace blink { | |
| 13 | |
| 14 TrackDefaultList* TrackDefaultList::create(const HeapVector<Member<TrackDefault> >& trackDefaults, ExceptionState& exceptionState) | |
| 15 { | |
| 16 // Per 11 Dec 2014 Editor's Draft | |
| 17 // https://w3c.github.io/media-source/#trackdefaultlist | |
| 18 // When this method is invoked, the user agent must run the following steps: | |
| 19 // 1. If |trackDefaults| contains two or more TrackDefault objects with the | |
| 20 // same type and the same byteStreamTrackID, then throw an | |
| 21 // InvalidAccessError and abort these steps. | |
| 22 // Note: This also applies when byteStreamTrackID contains an empty | |
| 23 // string and ensures that there is only one "byteStreamTrackID | |
| 24 // independent" default for each TrackDefaultType value. | |
| 25 TypeAndIDToTrackDefaultMap typeAndIDToTrackDefaultMap; | |
|
sof
2014/12/12 09:37:00
How about inverting this and create the empty obje
wolenetz
2014/12/12 19:18:31
Haha :). Yeah, I noticed there was an extra copy o
philipj_slow
2014/12/12 20:25:21
typeAndIDToTrackDefaultMap ought to be possible to
wolenetz
2014/12/12 21:48:05
Done.
| |
| 26 for (const auto& trackDefault : trackDefaults) { | |
| 27 TypeAndID key = TypeAndID(trackDefault->type(), trackDefault->byteStream TrackID()); | |
| 28 if (!typeAndIDToTrackDefaultMap.add(key, trackDefault).isNewEntry) { | |
| 29 exceptionState.throwDOMException(InvalidAccessError, "Duplicate Trac kDefault type (" + key.first + ") and byteStreamTrackID (" + key.second + ")"); | |
| 30 return nullptr; | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 // 2. Store a shallow copy of |trackDefaults| in this new object so the valu es can | |
| 35 // be returned by the accessor methods. | |
| 36 // This step is done in constructor initializer. | |
| 37 return new TrackDefaultList(trackDefaults, typeAndIDToTrackDefaultMap); | |
| 38 } | |
| 39 | |
| 40 TrackDefault* TrackDefaultList::item(unsigned index) const | |
| 41 { | |
| 42 // Per 11 Dec 2014 Editor's Draft | |
| 43 // https://w3c.github.io/media-source/#trackdefaultlist | |
| 44 // When this method is invoked, the user agent must run the following steps: | |
| 45 // 1. If |index| is greater than or equal to the length attribute then | |
| 46 // return undefined and abort these steps. | |
| 47 if (index >= m_trackDefaults.size()) | |
| 48 return 0; | |
| 49 | |
| 50 // 2. Return the |index|'th TrackDefault object in the list. | |
| 51 return m_trackDefaults[index].get(); | |
| 52 } | |
| 53 | |
| 54 TrackDefaultList::TrackDefaultList(const HeapVector<Member<TrackDefault>>& track Defaults, const TypeAndIDToTrackDefaultMap& typeAndIDToTrackDefaultMap) | |
| 55 : m_trackDefaults(trackDefaults) | |
| 56 , m_typeAndIDToTrackDefaultMap(typeAndIDToTrackDefaultMap) | |
| 57 { | |
| 58 } | |
| 59 | |
| 60 void TrackDefaultList::trace(Visitor* visitor) | |
| 61 { | |
| 62 visitor->trace(m_trackDefaults); | |
| 63 visitor->trace(m_typeAndIDToTrackDefaultMap); | |
| 64 } | |
| 65 | |
| 66 } // namespace blink | |
| OLD | NEW |