OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "modules/mediasource/WebKitSourceBuffer.h" | 32 #include "modules/mediasource/WebKitSourceBuffer.h" |
33 | 33 |
34 #include "bindings/v8/ExceptionState.h" | |
35 #include "core/dom/ExceptionCode.h" | |
36 #include "core/html/TimeRanges.h" | 34 #include "core/html/TimeRanges.h" |
37 #include "core/platform/graphics/SourceBufferPrivate.h" | 35 #include "core/platform/graphics/SourceBufferPrivate.h" |
38 #include "modules/mediasource/WebKitMediaSource.h" | 36 #include "modules/mediasource/WebKitMediaSource.h" |
39 #include "wtf/Uint8Array.h" | 37 #include "wtf/Uint8Array.h" |
40 | 38 |
41 namespace WebCore { | 39 namespace WebCore { |
42 | 40 |
43 PassRefPtr<WebKitSourceBuffer> WebKitSourceBuffer::create(PassOwnPtr<SourceBuffe
rPrivate> sourceBufferPrivate, PassRefPtr<WebKitMediaSource> source) | 41 PassRefPtr<WebKitSourceBuffer> WebKitSourceBuffer::create(PassOwnPtr<SourceBuffe
rPrivate> sourceBufferPrivate, PassRefPtr<WebKitMediaSource> source) |
44 { | 42 { |
45 return adoptRef(new WebKitSourceBuffer(sourceBufferPrivate, source)); | 43 return adoptRef(new WebKitSourceBuffer(sourceBufferPrivate, source)); |
46 } | 44 } |
47 | 45 |
48 WebKitSourceBuffer::WebKitSourceBuffer(PassOwnPtr<SourceBufferPrivate> sourceBuf
ferPrivate, PassRefPtr<WebKitMediaSource> source) | 46 WebKitSourceBuffer::WebKitSourceBuffer(PassOwnPtr<SourceBufferPrivate> sourceBuf
ferPrivate, PassRefPtr<WebKitMediaSource> source) |
49 : m_private(sourceBufferPrivate) | 47 : m_private(sourceBufferPrivate) |
50 , m_source(source) | 48 , m_source(source) |
51 , m_timestampOffset(0) | 49 , m_timestampOffset(0) |
52 { | 50 { |
53 ASSERT(m_private); | 51 ASSERT(m_private); |
54 ASSERT(m_source); | 52 ASSERT(m_source); |
55 ScriptWrappable::init(this); | 53 ScriptWrappable::init(this); |
56 } | 54 } |
57 | 55 |
58 WebKitSourceBuffer::~WebKitSourceBuffer() | 56 WebKitSourceBuffer::~WebKitSourceBuffer() |
59 { | 57 { |
60 } | 58 } |
61 | 59 |
62 PassRefPtr<TimeRanges> WebKitSourceBuffer::buffered(ExceptionState& es) const | 60 PassRefPtr<TimeRanges> WebKitSourceBuffer::buffered(ExceptionCode& ec) const |
63 { | 61 { |
64 // Section 3.1 buffered attribute steps. | 62 // Section 3.1 buffered attribute steps. |
65 // 1. If this object has been removed from the sourceBuffers attribute of th
e parent media source then throw an | 63 // 1. If this object has been removed from the sourceBuffers attribute of th
e parent media source then throw an |
66 // InvalidStateError exception and abort these steps. | 64 // InvalidStateError exception and abort these steps. |
67 if (isRemoved()) { | 65 if (isRemoved()) { |
68 es.throwDOMException(InvalidStateError); | 66 ec = InvalidStateError; |
69 return 0; | 67 return 0; |
70 } | 68 } |
71 | 69 |
72 // 2. Return a new static normalized TimeRanges object for the media segment
s buffered. | 70 // 2. Return a new static normalized TimeRanges object for the media segment
s buffered. |
73 return m_private->buffered(); | 71 return m_private->buffered(); |
74 } | 72 } |
75 | 73 |
76 double WebKitSourceBuffer::timestampOffset() const | 74 double WebKitSourceBuffer::timestampOffset() const |
77 { | 75 { |
78 return m_timestampOffset; | 76 return m_timestampOffset; |
79 } | 77 } |
80 | 78 |
81 void WebKitSourceBuffer::setTimestampOffset(double offset, ExceptionState& es) | 79 void WebKitSourceBuffer::setTimestampOffset(double offset, ExceptionCode& ec) |
82 { | 80 { |
83 // Section 3.1 timestampOffset attribute setter steps. | 81 // Section 3.1 timestampOffset attribute setter steps. |
84 // 1. If this object has been removed from the sourceBuffers attribute of th
e parent media source then throw an | 82 // 1. If this object has been removed from the sourceBuffers attribute of th
e parent media source then throw an |
85 // InvalidStateError exception and abort these steps. | 83 // InvalidStateError exception and abort these steps. |
86 if (isRemoved()) { | 84 if (isRemoved()) { |
87 es.throwDOMException(InvalidStateError); | 85 ec = InvalidStateError; |
88 return; | 86 return; |
89 } | 87 } |
90 | 88 |
91 // 4. If the readyState attribute of the parent media source is in the "ende
d" state then run the following steps: | 89 // 4. If the readyState attribute of the parent media source is in the "ende
d" state then run the following steps: |
92 // 4.1 Set the readyState attribute of the parent media source to "open" | 90 // 4.1 Set the readyState attribute of the parent media source to "open" |
93 // 4.2 Queue a task to fire a simple event named sourceopen at the parent me
dia source. | 91 // 4.2 Queue a task to fire a simple event named sourceopen at the parent me
dia source. |
94 m_source->openIfInEndedState(); | 92 m_source->openIfInEndedState(); |
95 | 93 |
96 // 5. If this object is waiting for the end of a media segment to be appende
d, then throw an InvalidStateError | 94 // 5. If this object is waiting for the end of a media segment to be appende
d, then throw an InvalidStateError |
97 // and abort these steps. | 95 // and abort these steps. |
98 if (!m_private->setTimestampOffset(offset)) { | 96 if (!m_private->setTimestampOffset(offset)) { |
99 es.throwDOMException(InvalidStateError); | 97 ec = InvalidStateError; |
100 return; | 98 return; |
101 } | 99 } |
102 | 100 |
103 // 6. Update the attribute to the new value. | 101 // 6. Update the attribute to the new value. |
104 m_timestampOffset = offset; | 102 m_timestampOffset = offset; |
105 } | 103 } |
106 | 104 |
107 void WebKitSourceBuffer::append(PassRefPtr<Uint8Array> data, ExceptionState& es) | 105 void WebKitSourceBuffer::append(PassRefPtr<Uint8Array> data, ExceptionCode& ec) |
108 { | 106 { |
109 // SourceBuffer.append() steps from October 1st version of the Media Source
Extensions spec. | 107 // SourceBuffer.append() steps from October 1st version of the Media Source
Extensions spec. |
110 // https://dvcs.w3.org/hg/html-media/raw-file/7bab66368f2c/media-source/medi
a-source.html#dom-append | 108 // https://dvcs.w3.org/hg/html-media/raw-file/7bab66368f2c/media-source/medi
a-source.html#dom-append |
111 | 109 |
112 // 2. If data is null then throw an InvalidAccessError exception and abort t
hese steps. | 110 // 2. If data is null then throw an InvalidAccessError exception and abort t
hese steps. |
113 if (!data) { | 111 if (!data) { |
114 es.throwDOMException(InvalidAccessError); | 112 ec = InvalidAccessError; |
115 return; | 113 return; |
116 } | 114 } |
117 | 115 |
118 // 3. If this object has been removed from the sourceBuffers attribute of me
dia source then throw | 116 // 3. If this object has been removed from the sourceBuffers attribute of me
dia source then throw |
119 // an InvalidStateError exception and abort these steps. | 117 // an InvalidStateError exception and abort these steps. |
120 if (isRemoved()) { | 118 if (isRemoved()) { |
121 es.throwDOMException(InvalidStateError); | 119 ec = InvalidStateError; |
122 return; | 120 return; |
123 } | 121 } |
124 | 122 |
125 // 5. If the readyState attribute of media source is in the "ended" state th
en run the following steps: | 123 // 5. If the readyState attribute of media source is in the "ended" state th
en run the following steps: |
126 // 5.1. Set the readyState attribute of media source to "open" | 124 // 5.1. Set the readyState attribute of media source to "open" |
127 // 5.2. Queue a task to fire a simple event named sourceopen at media source
. | 125 // 5.2. Queue a task to fire a simple event named sourceopen at media source
. |
128 m_source->openIfInEndedState(); | 126 m_source->openIfInEndedState(); |
129 | 127 |
130 // Steps 6 & beyond are handled by the private implementation. | 128 // Steps 6 & beyond are handled by the private implementation. |
131 m_private->append(data->data(), data->length()); | 129 m_private->append(data->data(), data->length()); |
132 } | 130 } |
133 | 131 |
134 void WebKitSourceBuffer::abort(ExceptionState& es) | 132 void WebKitSourceBuffer::abort(ExceptionCode& ec) |
135 { | 133 { |
136 // Section 3.2 abort() method steps. | 134 // Section 3.2 abort() method steps. |
137 // 1. If this object has been removed from the sourceBuffers attribute of th
e parent media source | 135 // 1. If this object has been removed from the sourceBuffers attribute of th
e parent media source |
138 // then throw an InvalidStateError exception and abort these steps. | 136 // then throw an InvalidStateError exception and abort these steps. |
139 // 2. If the readyState attribute of the parent media source is not in the "
open" state | 137 // 2. If the readyState attribute of the parent media source is not in the "
open" state |
140 // then throw an InvalidStateError exception and abort these steps. | 138 // then throw an InvalidStateError exception and abort these steps. |
141 if (isRemoved() || !m_source->isOpen()) { | 139 if (isRemoved() || !m_source->isOpen()) { |
142 es.throwDOMException(InvalidStateError); | 140 ec = InvalidStateError; |
143 return; | 141 return; |
144 } | 142 } |
145 | 143 |
146 // 4. Run the reset parser state algorithm. | 144 // 4. Run the reset parser state algorithm. |
147 m_private->abort(); | 145 m_private->abort(); |
148 } | 146 } |
149 | 147 |
150 void WebKitSourceBuffer::removedFromMediaSource() | 148 void WebKitSourceBuffer::removedFromMediaSource() |
151 { | 149 { |
152 if (isRemoved()) | 150 if (isRemoved()) |
153 return; | 151 return; |
154 | 152 |
155 m_private->removedFromMediaSource(); | 153 m_private->removedFromMediaSource(); |
156 m_source.clear(); | 154 m_source.clear(); |
157 } | 155 } |
158 | 156 |
159 bool WebKitSourceBuffer::isRemoved() const | 157 bool WebKitSourceBuffer::isRemoved() const |
160 { | 158 { |
161 return !m_source; | 159 return !m_source; |
162 } | 160 } |
163 | 161 |
164 } // namespace WebCore | 162 } // namespace WebCore |
OLD | NEW |