| OLD | NEW |
| 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 Loading... |
| 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) |
| 64 , m_appendWindowStart(0) |
| 65 , m_appendWindowEnd(std::numeric_limits<double>::infinity()) |
| 61 , m_appendBufferTimer(this, &SourceBuffer::appendBufferTimerFired) | 66 , m_appendBufferTimer(this, &SourceBuffer::appendBufferTimerFired) |
| 62 , m_removeTimer(this, &SourceBuffer::removeTimerFired) | 67 , m_removeTimer(this, &SourceBuffer::removeTimerFired) |
| 63 , m_pendingRemoveStart(-1) | 68 , m_pendingRemoveStart(-1) |
| 64 , m_pendingRemoveEnd(-1) | 69 , m_pendingRemoveEnd(-1) |
| 65 { | 70 { |
| 66 ASSERT(m_private); | 71 ASSERT(m_private); |
| 67 ASSERT(m_source); | 72 ASSERT(m_source); |
| 68 ScriptWrappable::init(this); | 73 ScriptWrappable::init(this); |
| 69 } | 74 } |
| 70 | 75 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // FIXME: Add step 6 text when mode attribute is implemented. | 120 // FIXME: Add step 6 text when mode attribute is implemented. |
| 116 if (!m_private->setTimestampOffset(offset)) { | 121 if (!m_private->setTimestampOffset(offset)) { |
| 117 es.throwDOMException(InvalidStateError); | 122 es.throwDOMException(InvalidStateError); |
| 118 return; | 123 return; |
| 119 } | 124 } |
| 120 | 125 |
| 121 // 7. Update the attribute to new timestamp offset. | 126 // 7. Update the attribute to new timestamp offset. |
| 122 m_timestampOffset = offset; | 127 m_timestampOffset = offset; |
| 123 } | 128 } |
| 124 | 129 |
| 130 double SourceBuffer::appendWindowStart() const |
| 131 { |
| 132 return m_appendWindowStart; |
| 133 } |
| 134 |
| 135 void SourceBuffer::setAppendWindowStart(double start, ExceptionState& es) |
| 136 { |
| 137 // Enforce throwing an exception on restricted double values. |
| 138 if (std::isnan(start) |
| 139 || start == std::numeric_limits<double>::infinity() |
| 140 || start == -std::numeric_limits<double>::infinity()) { |
| 141 es.throwDOMException(TypeMismatchError); |
| 142 return; |
| 143 } |
| 144 |
| 145 // Section 3.1 appendWindowStart attribute setter steps. |
| 146 // 1. If this object has been removed from the sourceBuffers attribute of th
e parent media source then throw an |
| 147 // InvalidStateError exception and abort these steps. |
| 148 // 2. If the updating attribute equals true, then throw an InvalidStateError
exception and abort these steps. |
| 149 if (isRemoved() || m_updating) { |
| 150 es.throwDOMException(InvalidStateError); |
| 151 return; |
| 152 } |
| 153 |
| 154 // 3. If the new value is less than 0 or greater than or equal to appendWind
owEnd then throw an InvalidAccessError |
| 155 // exception and abort these steps. |
| 156 if (start < 0 || start >= m_appendWindowEnd) { |
| 157 es.throwDOMException(InvalidAccessError); |
| 158 return; |
| 159 } |
| 160 |
| 161 m_private->setAppendWindowStart(start); |
| 162 |
| 163 // 4. Update the attribute to the new value. |
| 164 m_appendWindowStart = start; |
| 165 } |
| 166 |
| 167 double SourceBuffer::appendWindowEnd() const |
| 168 { |
| 169 return m_appendWindowEnd; |
| 170 } |
| 171 |
| 172 void SourceBuffer::setAppendWindowEnd(double end, ExceptionState& es) |
| 173 { |
| 174 // Section 3.1 appendWindowEnd attribute setter steps. |
| 175 // 1. If this object has been removed from the sourceBuffers attribute of th
e parent media source then throw an |
| 176 // InvalidStateError exception and abort these steps. |
| 177 // 2. If the updating attribute equals true, then throw an InvalidStateError
exception and abort these steps. |
| 178 if (isRemoved() || m_updating) { |
| 179 es.throwDOMException(InvalidStateError); |
| 180 return; |
| 181 } |
| 182 |
| 183 // 3. If the new value equals NaN, then throw an InvalidAccessError and abor
t these steps. |
| 184 // 4. If the new value is less than or equal to appendWindowStart then throw
an InvalidAccessError |
| 185 // exception and abort these steps. |
| 186 if (std::isnan(end) || end <= m_appendWindowStart) { |
| 187 es.throwDOMException(InvalidAccessError); |
| 188 return; |
| 189 } |
| 190 |
| 191 m_private->setAppendWindowEnd(end); |
| 192 |
| 193 // 5. Update the attribute to the new value. |
| 194 m_appendWindowEnd = end; |
| 195 } |
| 196 |
| 125 void SourceBuffer::appendBuffer(PassRefPtr<ArrayBuffer> data, ExceptionState& es
) | 197 void SourceBuffer::appendBuffer(PassRefPtr<ArrayBuffer> data, ExceptionState& es
) |
| 126 { | 198 { |
| 127 // Section 3.2 appendBuffer() | 199 // Section 3.2 appendBuffer() |
| 128 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou
rce.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data | 200 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou
rce.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data |
| 129 // 1. If data is null then throw an InvalidAccessError exception and abort t
hese steps. | 201 // 1. If data is null then throw an InvalidAccessError exception and abort t
hese steps. |
| 130 if (!data) { | 202 if (!data) { |
| 131 es.throwDOMException(InvalidAccessError); | 203 es.throwDOMException(InvalidAccessError); |
| 132 return; | 204 return; |
| 133 } | 205 } |
| 134 | 206 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 160 es.throwDOMException(InvalidStateError); | 232 es.throwDOMException(InvalidStateError); |
| 161 return; | 233 return; |
| 162 } | 234 } |
| 163 | 235 |
| 164 // 3. If the sourceBuffer.updating attribute equals true, then run the follo
wing steps: ... | 236 // 3. If the sourceBuffer.updating attribute equals true, then run the follo
wing steps: ... |
| 165 abortIfUpdating(); | 237 abortIfUpdating(); |
| 166 | 238 |
| 167 // 4. Run the reset parser state algorithm. | 239 // 4. Run the reset parser state algorithm. |
| 168 m_private->abort(); | 240 m_private->abort(); |
| 169 | 241 |
| 170 // FIXME(229408) Add steps 5-6 update appendWindowStart & appendWindowEnd. | 242 // 5. Set appendWindowStart to 0. |
| 243 setAppendWindowStart(0, es); |
| 244 |
| 245 // 6. Set appendWindowEnd to positive Infinity. |
| 246 setAppendWindowEnd(std::numeric_limits<double>::infinity(), es); |
| 171 } | 247 } |
| 172 | 248 |
| 173 void SourceBuffer::remove(double start, double end, ExceptionState& es) | 249 void SourceBuffer::remove(double start, double end, ExceptionState& es) |
| 174 { | 250 { |
| 175 // Section 3.2 remove() method steps. | 251 // Section 3.2 remove() method steps. |
| 176 // 1. If start is negative or greater than duration, then throw an InvalidAc
cessError exception and abort these steps. | 252 // 1. If start is negative or greater than duration, then throw an InvalidAc
cessError exception and abort these steps. |
| 177 // 2. If end is less than or equal to start, then throw an InvalidAccessErro
r exception and abort these steps. | 253 // 2. If end is less than or equal to start, then throw an InvalidAccessErro
r exception and abort these steps. |
| 178 if (start < 0 || (m_source && (std::isnan(m_source->duration()) || start > m
_source->duration())) || end <= start) { | 254 if (start < 0 || (m_source && (std::isnan(m_source->duration()) || start > m
_source->duration())) || end <= start) { |
| 179 es.throwDOMException(InvalidAccessError); | 255 es.throwDOMException(InvalidAccessError); |
| 180 return; | 256 return; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 m_pendingRemoveEnd = -1; | 443 m_pendingRemoveEnd = -1; |
| 368 | 444 |
| 369 // 11. Queue a task to fire a simple event named update at this SourceBuffer
object. | 445 // 11. Queue a task to fire a simple event named update at this SourceBuffer
object. |
| 370 scheduleEvent(eventNames().updateEvent); | 446 scheduleEvent(eventNames().updateEvent); |
| 371 | 447 |
| 372 // 12. Queue a task to fire a simple event named updateend at this SourceBuf
fer object. | 448 // 12. Queue a task to fire a simple event named updateend at this SourceBuf
fer object. |
| 373 scheduleEvent(eventNames().updateendEvent); | 449 scheduleEvent(eventNames().updateendEvent); |
| 374 } | 450 } |
| 375 | 451 |
| 376 } // namespace WebCore | 452 } // namespace WebCore |
| OLD | NEW |