| 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 #include "wtf/text/AtomicStringHash.h" |
| 12 #include "wtf/text/StringHash.h" |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 TrackDefaultList* TrackDefaultList::create() |
| 17 { |
| 18 return new TrackDefaultList(); |
| 19 } |
| 20 |
| 21 TrackDefaultList* TrackDefaultList::create(const HeapVector<Member<TrackDefault>
>& trackDefaults, ExceptionState& exceptionState) |
| 22 { |
| 23 // Per 11 Dec 2014 Editor's Draft |
| 24 // https://w3c.github.io/media-source/#trackdefaultlist |
| 25 // When this method is invoked, the user agent must run the following steps: |
| 26 // 1. If |trackDefaults| contains two or more TrackDefault objects with the |
| 27 // same type and the same byteStreamTrackID, then throw an |
| 28 // InvalidAccessError and abort these steps. |
| 29 // Note: This also applies when byteStreamTrackID contains an empty |
| 30 // string and ensures that there is only one "byteStreamTrackID |
| 31 // independent" default for each TrackDefaultType value. |
| 32 using TypeAndID = std::pair<AtomicString, String>; |
| 33 using TypeAndIDToTrackDefaultMap = HeapHashMap<TypeAndID, Member<TrackDefaul
t>>; |
| 34 TypeAndIDToTrackDefaultMap typeAndIDToTrackDefaultMap; |
| 35 |
| 36 for (const auto& trackDefault : trackDefaults) { |
| 37 TypeAndID key = TypeAndID(trackDefault->type(), trackDefault->byteStream
TrackID()); |
| 38 if (!typeAndIDToTrackDefaultMap.add(key, trackDefault).isNewEntry) { |
| 39 exceptionState.throwDOMException(InvalidAccessError, "Duplicate Trac
kDefault type (" + key.first + ") and byteStreamTrackID (" + key.second + ")"); |
| 40 return nullptr; |
| 41 } |
| 42 } |
| 43 |
| 44 // 2. Store a shallow copy of |trackDefaults| in this new object so the valu
es can |
| 45 // be returned by the accessor methods. |
| 46 // This step is done in constructor initializer. |
| 47 return new TrackDefaultList(trackDefaults); |
| 48 } |
| 49 |
| 50 TrackDefault* TrackDefaultList::item(unsigned index) const |
| 51 { |
| 52 // Per 11 Dec 2014 Editor's Draft |
| 53 // https://w3c.github.io/media-source/#trackdefaultlist |
| 54 // When this method is invoked, the user agent must run the following steps: |
| 55 // 1. If |index| is greater than or equal to the length attribute then |
| 56 // return undefined and abort these steps. |
| 57 if (index >= m_trackDefaults.size()) |
| 58 return 0; |
| 59 |
| 60 // 2. Return the |index|'th TrackDefault object in the list. |
| 61 return m_trackDefaults[index].get(); |
| 62 } |
| 63 |
| 64 TrackDefaultList::TrackDefaultList() |
| 65 { |
| 66 } |
| 67 |
| 68 TrackDefaultList::TrackDefaultList(const HeapVector<Member<TrackDefault>>& track
Defaults) |
| 69 : m_trackDefaults(trackDefaults) |
| 70 { |
| 71 } |
| 72 |
| 73 void TrackDefaultList::trace(Visitor* visitor) |
| 74 { |
| 75 visitor->trace(m_trackDefaults); |
| 76 } |
| 77 |
| 78 } // namespace blink |
| OLD | NEW |