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

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

Issue 14876007: Add Blink side support for SourceBuffer.appendWindowStart & SourceBuffer.appendWindowEnd. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 7 years, 4 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 23 matching lines...) Expand all
34 #include "bindings/v8/ExceptionState.h" 34 #include "bindings/v8/ExceptionState.h"
35 #include "core/dom/Event.h" 35 #include "core/dom/Event.h"
36 #include "core/dom/ExceptionCode.h" 36 #include "core/dom/ExceptionCode.h"
37 #include "core/dom/GenericEventQueue.h" 37 #include "core/dom/GenericEventQueue.h"
38 #include "core/html/TimeRanges.h" 38 #include "core/html/TimeRanges.h"
39 #include "core/platform/Logging.h" 39 #include "core/platform/Logging.h"
40 #include "core/platform/graphics/SourceBufferPrivate.h" 40 #include "core/platform/graphics/SourceBufferPrivate.h"
41 #include "modules/mediasource/MediaSource.h" 41 #include "modules/mediasource/MediaSource.h"
42 #include "wtf/ArrayBuffer.h" 42 #include "wtf/ArrayBuffer.h"
43 #include "wtf/ArrayBufferView.h" 43 #include "wtf/ArrayBufferView.h"
44 #include "wtf/MathExtras.h"
45
46 #include <limits>
44 47
45 namespace WebCore { 48 namespace WebCore {
46 49
47 PassRefPtr<SourceBuffer> SourceBuffer::create(PassOwnPtr<SourceBufferPrivate> so urceBufferPrivate, MediaSource* source, GenericEventQueue* asyncEventQueue) 50 PassRefPtr<SourceBuffer> SourceBuffer::create(PassOwnPtr<SourceBufferPrivate> so urceBufferPrivate, MediaSource* source, GenericEventQueue* asyncEventQueue)
48 { 51 {
49 RefPtr<SourceBuffer> sourceBuffer(adoptRef(new SourceBuffer(sourceBufferPriv ate, source, asyncEventQueue))); 52 RefPtr<SourceBuffer> sourceBuffer(adoptRef(new SourceBuffer(sourceBufferPriv ate, source, asyncEventQueue)));
50 sourceBuffer->suspendIfNeeded(); 53 sourceBuffer->suspendIfNeeded();
51 return sourceBuffer.release(); 54 return sourceBuffer.release();
52 } 55 }
53 56
54 SourceBuffer::SourceBuffer(PassOwnPtr<SourceBufferPrivate> sourceBufferPrivate, MediaSource* source, GenericEventQueue* asyncEventQueue) 57 SourceBuffer::SourceBuffer(PassOwnPtr<SourceBufferPrivate> sourceBufferPrivate, MediaSource* source, GenericEventQueue* asyncEventQueue)
55 : ActiveDOMObject(source->scriptExecutionContext()) 58 : ActiveDOMObject(source->scriptExecutionContext())
56 , m_private(sourceBufferPrivate) 59 , m_private(sourceBufferPrivate)
57 , m_source(source) 60 , m_source(source)
58 , m_asyncEventQueue(asyncEventQueue) 61 , m_asyncEventQueue(asyncEventQueue)
59 , m_updating(false) 62 , m_updating(false)
60 , m_timestampOffset(0) 63 , m_timestampOffset(0)
61 , m_appendBufferTimer(this, &SourceBuffer::appendBufferTimerFired) 64 , m_appendBufferTimer(this, &SourceBuffer::appendBufferTimerFired)
65 , m_appendWindowStart(0)
66 , m_appendWindowEnd(std::numeric_limits<double>::infinity())
62 { 67 {
63 ASSERT(m_private); 68 ASSERT(m_private);
64 ASSERT(m_source); 69 ASSERT(m_source);
65 ScriptWrappable::init(this); 70 ScriptWrappable::init(this);
66 } 71 }
67 72
68 SourceBuffer::~SourceBuffer() 73 SourceBuffer::~SourceBuffer()
69 { 74 {
70 ASSERT(isRemoved()); 75 ASSERT(isRemoved());
71 } 76 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // and abort these steps. 119 // and abort these steps.
115 if (!m_private->setTimestampOffset(offset)) { 120 if (!m_private->setTimestampOffset(offset)) {
116 es.throwDOMException(InvalidStateError); 121 es.throwDOMException(InvalidStateError);
117 return; 122 return;
118 } 123 }
119 124
120 // 6. Update the attribute to the new value. 125 // 6. Update the attribute to the new value.
121 m_timestampOffset = offset; 126 m_timestampOffset = offset;
122 } 127 }
123 128
129 double SourceBuffer::appendWindowStart() const
130 {
131 return m_appendWindowStart;
132 }
133
134 void SourceBuffer::setAppendWindowStart(double start, ExceptionState& es)
135 {
136 // Enforce throwing an exception on restricted double values.
137 if (std::isnan(start)
138 || start == std::numeric_limits<double>::infinity()
139 || start == -std::numeric_limits<double>::infinity()) {
140 es.throwDOMException(TypeMismatchError);
141 return;
142 }
143
144 // Section 3.1 appendWindowStart attribute setter steps.
145 // 1. If this object has been removed from the sourceBuffers attribute of th e parent media source then throw an
146 // InvalidStateError exception and abort these steps.
147 // 2. If the updating attribute equals true, then throw an InvalidStateError exception and abort these steps.
148 if (isRemoved() || m_updating) {
149 es.throwDOMException(InvalidStateError);
150 return;
151 }
152
153 // 3. If the new value is less than 0 or greater than or equal to appendWind owEnd then throw an InvalidAccessError
154 // exception and abort these steps.
155 if (start < 0 || start >= m_appendWindowEnd) {
156 es.throwDOMException(InvalidAccessError);
157 return;
158 }
159
160 m_private->setAppendWindowStart(start);
161
162 // 4. Update the attribute to the new value.
163 m_appendWindowStart = start;
164 }
165
166 double SourceBuffer::appendWindowEnd() const
167 {
168 return m_appendWindowEnd;
169 }
170
171 void SourceBuffer::setAppendWindowEnd(double end, ExceptionState& es)
172 {
173 // Section 3.1 appendWindowEnd attribute setter steps.
174 // 1. If this object has been removed from the sourceBuffers attribute of th e parent media source then throw an
175 // InvalidStateError exception and abort these steps.
176 // 2. If the updating attribute equals true, then throw an InvalidStateError exception and abort these steps.
177 if (isRemoved() || m_updating) {
178 es.throwDOMException(InvalidStateError);
179 return;
180 }
181
182 // 3. If the new value equals NaN, then throw an InvalidAccessError and abor t these steps.
183 // 4. If the new value is less than or equal to appendWindowStart then throw an InvalidAccessError
184 // exception and abort these steps.
185 if (std::isnan(end) || end <= m_appendWindowStart) {
186 es.throwDOMException(InvalidAccessError);
187 return;
188 }
189
190 m_private->setAppendWindowEnd(end);
191
192 // 5. Update the attribute to the new value.
193 m_appendWindowEnd = end;
194 }
195
124 void SourceBuffer::appendBuffer(PassRefPtr<ArrayBuffer> data, ExceptionState& es ) 196 void SourceBuffer::appendBuffer(PassRefPtr<ArrayBuffer> data, ExceptionState& es )
125 { 197 {
126 // Section 3.2 appendBuffer() 198 // Section 3.2 appendBuffer()
127 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data 199 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data
128 // 1. If data is null then throw an InvalidAccessError exception and abort t hese steps. 200 // 1. If data is null then throw an InvalidAccessError exception and abort t hese steps.
129 if (!data) { 201 if (!data) {
130 es.throwDOMException(InvalidAccessError); 202 es.throwDOMException(InvalidAccessError);
131 return; 203 return;
132 } 204 }
133 205
(...skipping 25 matching lines...) Expand all
159 es.throwDOMException(InvalidStateError); 231 es.throwDOMException(InvalidStateError);
160 return; 232 return;
161 } 233 }
162 234
163 // 3. If the sourceBuffer.updating attribute equals true, then run the follo wing steps: ... 235 // 3. If the sourceBuffer.updating attribute equals true, then run the follo wing steps: ...
164 abortIfUpdating(); 236 abortIfUpdating();
165 237
166 // 4. Run the reset parser state algorithm. 238 // 4. Run the reset parser state algorithm.
167 m_private->abort(); 239 m_private->abort();
168 240
169 // FIXME(229408) Add steps 5-6 update appendWindowStart & appendWindowEnd. 241 // 5. Set appendWindowStart to 0.
242 setAppendWindowStart(0, es);
243
244 // 6. Set appendWindowEnd to positive Infinity.
245 setAppendWindowEnd(std::numeric_limits<double>::infinity(), es);
170 } 246 }
171 247
172 248
173 void SourceBuffer::abortIfUpdating() 249 void SourceBuffer::abortIfUpdating()
174 { 250 {
175 // Section 3.2 abort() method step 3 substeps. 251 // Section 3.2 abort() method step 3 substeps.
176 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-abort-void 252 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-abort-void
177 253
178 if (!m_updating) 254 if (!m_updating)
179 return; 255 return;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 m_pendingAppendData.clear(); 377 m_pendingAppendData.clear();
302 378
303 // 4. Queue a task to fire a simple event named update at this SourceBuffer object. 379 // 4. Queue a task to fire a simple event named update at this SourceBuffer object.
304 scheduleEvent(eventNames().updateEvent); 380 scheduleEvent(eventNames().updateEvent);
305 381
306 // 5. Queue a task to fire a simple event named updateend at this SourceBuff er object. 382 // 5. Queue a task to fire a simple event named updateend at this SourceBuff er object.
307 scheduleEvent(eventNames().updateendEvent); 383 scheduleEvent(eventNames().updateendEvent);
308 } 384 }
309 385
310 } // namespace WebCore 386 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698