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 16 matching lines...) Expand all Loading... |
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" | 34 #include "bindings/v8/ExceptionState.h" |
35 #include "core/dom/ExceptionCode.h" | 35 #include "core/dom/ExceptionCode.h" |
36 #include "core/html/TimeRanges.h" | 36 #include "core/html/TimeRanges.h" |
37 #include "core/platform/graphics/SourceBufferPrivate.h" | |
38 #include "modules/mediasource/WebKitMediaSource.h" | 37 #include "modules/mediasource/WebKitMediaSource.h" |
39 #include "platform/TraceEvent.h" | 38 #include "platform/TraceEvent.h" |
| 39 #include "public/platform/WebSourceBuffer.h" |
40 #include "wtf/Uint8Array.h" | 40 #include "wtf/Uint8Array.h" |
41 | 41 |
| 42 using blink::WebSourceBuffer; |
| 43 |
42 namespace WebCore { | 44 namespace WebCore { |
43 | 45 |
44 PassRefPtr<WebKitSourceBuffer> WebKitSourceBuffer::create(PassOwnPtr<SourceBuffe
rPrivate> sourceBufferPrivate, PassRefPtr<WebKitMediaSource> source) | 46 PassRefPtr<WebKitSourceBuffer> WebKitSourceBuffer::create(PassOwnPtr<WebSourceBu
ffer> webSourceBuffer, PassRefPtr<WebKitMediaSource> source) |
45 { | 47 { |
46 return adoptRef(new WebKitSourceBuffer(sourceBufferPrivate, source)); | 48 return adoptRef(new WebKitSourceBuffer(webSourceBuffer, source)); |
47 } | 49 } |
48 | 50 |
49 WebKitSourceBuffer::WebKitSourceBuffer(PassOwnPtr<SourceBufferPrivate> sourceBuf
ferPrivate, PassRefPtr<WebKitMediaSource> source) | 51 WebKitSourceBuffer::WebKitSourceBuffer(PassOwnPtr<WebSourceBuffer> webSourceBuff
er, PassRefPtr<WebKitMediaSource> source) |
50 : m_private(sourceBufferPrivate) | 52 : m_webSourceBuffer(webSourceBuffer) |
51 , m_source(source) | 53 , m_source(source) |
52 , m_timestampOffset(0) | 54 , m_timestampOffset(0) |
53 { | 55 { |
54 ASSERT(m_private); | 56 ASSERT(m_webSourceBuffer); |
55 ASSERT(m_source); | 57 ASSERT(m_source); |
56 ScriptWrappable::init(this); | 58 ScriptWrappable::init(this); |
57 } | 59 } |
58 | 60 |
59 WebKitSourceBuffer::~WebKitSourceBuffer() | 61 WebKitSourceBuffer::~WebKitSourceBuffer() |
60 { | 62 { |
61 } | 63 } |
62 | 64 |
63 PassRefPtr<TimeRanges> WebKitSourceBuffer::buffered(ExceptionState& es) const | 65 PassRefPtr<TimeRanges> WebKitSourceBuffer::buffered(ExceptionState& es) const |
64 { | 66 { |
65 // Section 3.1 buffered attribute steps. | 67 // Section 3.1 buffered attribute steps. |
66 // 1. If this object has been removed from the sourceBuffers attribute of th
e parent media source then throw an | 68 // 1. If this object has been removed from the sourceBuffers attribute of th
e parent media source then throw an |
67 // InvalidStateError exception and abort these steps. | 69 // InvalidStateError exception and abort these steps. |
68 if (isRemoved()) { | 70 if (isRemoved()) { |
69 es.throwUninformativeAndGenericDOMException(InvalidStateError); | 71 es.throwUninformativeAndGenericDOMException(InvalidStateError); |
70 return 0; | 72 return 0; |
71 } | 73 } |
72 | 74 |
73 // 2. Return a new static normalized TimeRanges object for the media segment
s buffered. | 75 // 2. Return a new static normalized TimeRanges object for the media segment
s buffered. |
74 return m_private->buffered(); | 76 return TimeRanges::create(m_webSourceBuffer->buffered()); |
75 } | 77 } |
76 | 78 |
77 double WebKitSourceBuffer::timestampOffset() const | 79 double WebKitSourceBuffer::timestampOffset() const |
78 { | 80 { |
79 return m_timestampOffset; | 81 return m_timestampOffset; |
80 } | 82 } |
81 | 83 |
82 void WebKitSourceBuffer::setTimestampOffset(double offset, ExceptionState& es) | 84 void WebKitSourceBuffer::setTimestampOffset(double offset, ExceptionState& es) |
83 { | 85 { |
84 // Section 3.1 timestampOffset attribute setter steps. | 86 // Section 3.1 timestampOffset attribute setter steps. |
85 // 1. If this object has been removed from the sourceBuffers attribute of th
e parent media source then throw an | 87 // 1. If this object has been removed from the sourceBuffers attribute of th
e parent media source then throw an |
86 // InvalidStateError exception and abort these steps. | 88 // InvalidStateError exception and abort these steps. |
87 if (isRemoved()) { | 89 if (isRemoved()) { |
88 es.throwUninformativeAndGenericDOMException(InvalidStateError); | 90 es.throwUninformativeAndGenericDOMException(InvalidStateError); |
89 return; | 91 return; |
90 } | 92 } |
91 | 93 |
92 // 4. If the readyState attribute of the parent media source is in the "ende
d" state then run the following steps: | 94 // 4. If the readyState attribute of the parent media source is in the "ende
d" state then run the following steps: |
93 // 4.1 Set the readyState attribute of the parent media source to "open" | 95 // 4.1 Set the readyState attribute of the parent media source to "open" |
94 // 4.2 Queue a task to fire a simple event named sourceopen at the parent me
dia source. | 96 // 4.2 Queue a task to fire a simple event named sourceopen at the parent me
dia source. |
95 m_source->openIfInEndedState(); | 97 m_source->openIfInEndedState(); |
96 | 98 |
97 // 5. If this object is waiting for the end of a media segment to be appende
d, then throw an InvalidStateError | 99 // 5. If this object is waiting for the end of a media segment to be appende
d, then throw an InvalidStateError |
98 // and abort these steps. | 100 // and abort these steps. |
99 if (!m_private->setTimestampOffset(offset)) { | 101 if (!m_webSourceBuffer->setTimestampOffset(offset)) { |
100 es.throwUninformativeAndGenericDOMException(InvalidStateError); | 102 es.throwUninformativeAndGenericDOMException(InvalidStateError); |
101 return; | 103 return; |
102 } | 104 } |
103 | 105 |
104 // 6. Update the attribute to the new value. | 106 // 6. Update the attribute to the new value. |
105 m_timestampOffset = offset; | 107 m_timestampOffset = offset; |
106 } | 108 } |
107 | 109 |
108 void WebKitSourceBuffer::append(PassRefPtr<Uint8Array> data, ExceptionState& es) | 110 void WebKitSourceBuffer::append(PassRefPtr<Uint8Array> data, ExceptionState& es) |
109 { | 111 { |
(...skipping 13 matching lines...) Expand all Loading... |
123 if (isRemoved()) { | 125 if (isRemoved()) { |
124 es.throwUninformativeAndGenericDOMException(InvalidStateError); | 126 es.throwUninformativeAndGenericDOMException(InvalidStateError); |
125 return; | 127 return; |
126 } | 128 } |
127 | 129 |
128 // 5. If the readyState attribute of media source is in the "ended" state th
en run the following steps: | 130 // 5. If the readyState attribute of media source is in the "ended" state th
en run the following steps: |
129 // 5.1. Set the readyState attribute of media source to "open" | 131 // 5.1. Set the readyState attribute of media source to "open" |
130 // 5.2. Queue a task to fire a simple event named sourceopen at media source
. | 132 // 5.2. Queue a task to fire a simple event named sourceopen at media source
. |
131 m_source->openIfInEndedState(); | 133 m_source->openIfInEndedState(); |
132 | 134 |
133 // Steps 6 & beyond are handled by the private implementation. | 135 // Steps 6 & beyond are handled by m_webSourceBuffer. |
134 m_private->append(data->data(), data->length()); | 136 m_webSourceBuffer->append(data->data(), data->length()); |
135 } | 137 } |
136 | 138 |
137 void WebKitSourceBuffer::abort(ExceptionState& es) | 139 void WebKitSourceBuffer::abort(ExceptionState& es) |
138 { | 140 { |
139 // Section 3.2 abort() method steps. | 141 // Section 3.2 abort() method steps. |
140 // 1. If this object has been removed from the sourceBuffers attribute of th
e parent media source | 142 // 1. If this object has been removed from the sourceBuffers attribute of th
e parent media source |
141 // then throw an InvalidStateError exception and abort these steps. | 143 // then throw an InvalidStateError exception and abort these steps. |
142 // 2. If the readyState attribute of the parent media source is not in the "
open" state | 144 // 2. If the readyState attribute of the parent media source is not in the "
open" state |
143 // then throw an InvalidStateError exception and abort these steps. | 145 // then throw an InvalidStateError exception and abort these steps. |
144 if (isRemoved() || !m_source->isOpen()) { | 146 if (isRemoved() || !m_source->isOpen()) { |
145 es.throwUninformativeAndGenericDOMException(InvalidStateError); | 147 es.throwUninformativeAndGenericDOMException(InvalidStateError); |
146 return; | 148 return; |
147 } | 149 } |
148 | 150 |
149 // 4. Run the reset parser state algorithm. | 151 // 4. Run the reset parser state algorithm. |
150 m_private->abort(); | 152 m_webSourceBuffer->abort(); |
151 } | 153 } |
152 | 154 |
153 void WebKitSourceBuffer::removedFromMediaSource() | 155 void WebKitSourceBuffer::removedFromMediaSource() |
154 { | 156 { |
155 if (isRemoved()) | 157 if (isRemoved()) |
156 return; | 158 return; |
157 | 159 |
158 m_private->removedFromMediaSource(); | 160 m_webSourceBuffer->removedFromMediaSource(); |
159 m_source.clear(); | 161 m_source.clear(); |
160 } | 162 } |
161 | 163 |
162 bool WebKitSourceBuffer::isRemoved() const | 164 bool WebKitSourceBuffer::isRemoved() const |
163 { | 165 { |
164 return !m_source; | 166 return !m_source; |
165 } | 167 } |
166 | 168 |
167 } // namespace WebCore | 169 } // namespace WebCore |
OLD | NEW |