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

Side by Side Diff: Source/modules/mediasource/TrackDefaultList.cpp

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

Powered by Google App Engine
This is Rietveld 408576698