| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2011, 2012 Ericsson AB. All rights reserved. | 3 * Copyright (C) 2011, 2012 Ericsson AB. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 13 * | 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 17 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
| 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
| 21 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "modules/mediastream/MediaStream.h" | 27 #include "modules/mediastream/MediaStream.h" |
| 28 | 28 |
| 29 #include "bindings/core/v8/ExceptionState.h" | 29 #include "bindings/core/v8/ExceptionState.h" |
| 30 #include "bindings/core/v8/ScriptValue.h" |
| 31 #include "bindings/modules/v8/V8MediaStream.h" |
| 32 #include "core/dom/DOMURL.h" |
| 30 #include "core/dom/ExceptionCode.h" | 33 #include "core/dom/ExceptionCode.h" |
| 31 #include "modules/mediastream/MediaStreamRegistry.h" | 34 #include "modules/mediastream/MediaStreamRegistry.h" |
| 32 #include "modules/mediastream/MediaStreamTrackEvent.h" | 35 #include "modules/mediastream/MediaStreamTrackEvent.h" |
| 33 #include "platform/mediastream/MediaStreamCenter.h" | 36 #include "platform/mediastream/MediaStreamCenter.h" |
| 34 #include "platform/mediastream/MediaStreamSource.h" | 37 #include "platform/mediastream/MediaStreamSource.h" |
| 35 | 38 |
| 36 namespace blink { | 39 namespace blink { |
| 37 | 40 |
| 38 static bool containsSource(MediaStreamTrackVector& trackVector, MediaStreamSourc
e* source) | 41 static bool containsSource(MediaStreamTrackVector& trackVector, MediaStreamSourc
e* source) |
| 39 { | 42 { |
| 40 for (size_t i = 0; i < trackVector.size(); ++i) { | 43 for (size_t i = 0; i < trackVector.size(); ++i) { |
| 41 if (source->id() == trackVector[i]->component()->source()->id()) | 44 if (source->id() == trackVector[i]->component()->source()->id()) |
| 42 return true; | 45 return true; |
| 43 } | 46 } |
| 44 return false; | 47 return false; |
| 45 } | 48 } |
| 46 | 49 |
| 47 static void processTrack(MediaStreamTrack* track, MediaStreamTrackVector& trackV
ector) | 50 static void processTrack(MediaStreamTrack* track, MediaStreamTrackVector& trackV
ector) |
| 48 { | 51 { |
| 49 if (track->ended()) | 52 if (track->ended()) |
| 50 return; | 53 return; |
| 51 | 54 |
| 52 MediaStreamSource* source = track->component()->source(); | 55 MediaStreamSource* source = track->component()->source(); |
| 53 if (!containsSource(trackVector, source)) | 56 if (!containsSource(trackVector, source)) |
| 54 trackVector.append(track); | 57 trackVector.append(track); |
| 55 } | 58 } |
| 56 | 59 |
| 60 static MediaProvider* MediaProviderConverter(const ScriptValue& value) |
| 61 { |
| 62 v8::Handle<v8::Value> v8Value(value.v8Value()); |
| 63 MediaStream* stream = V8MediaStream::toNativeWithTypeCheck(value.isolate(),
v8Value); |
| 64 if (!stream) |
| 65 return nullptr; |
| 66 return stream; |
| 67 } |
| 68 |
| 57 MediaStream* MediaStream::create(ExecutionContext* context) | 69 MediaStream* MediaStream::create(ExecutionContext* context) |
| 58 { | 70 { |
| 59 MediaStreamTrackVector audioTracks; | 71 MediaStreamTrackVector audioTracks; |
| 60 MediaStreamTrackVector videoTracks; | 72 MediaStreamTrackVector videoTracks; |
| 61 | 73 |
| 62 return adoptRefCountedGarbageCollectedWillBeNoop(new MediaStream(context, au
dioTracks, videoTracks)); | 74 return adoptRefCountedGarbageCollectedWillBeNoop(new MediaStream(context, au
dioTracks, videoTracks)); |
| 63 } | 75 } |
| 64 | 76 |
| 65 MediaStream* MediaStream::create(ExecutionContext* context, MediaStream* stream) | 77 MediaStream* MediaStream::create(ExecutionContext* context, MediaStream* stream) |
| 66 { | 78 { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 88 | 100 |
| 89 return adoptRefCountedGarbageCollectedWillBeNoop(new MediaStream(context, au
dioTracks, videoTracks)); | 101 return adoptRefCountedGarbageCollectedWillBeNoop(new MediaStream(context, au
dioTracks, videoTracks)); |
| 90 } | 102 } |
| 91 | 103 |
| 92 MediaStream* MediaStream::create(ExecutionContext* context, PassRefPtr<MediaStre
amDescriptor> streamDescriptor) | 104 MediaStream* MediaStream::create(ExecutionContext* context, PassRefPtr<MediaStre
amDescriptor> streamDescriptor) |
| 93 { | 105 { |
| 94 return adoptRefCountedGarbageCollectedWillBeNoop(new MediaStream(context, st
reamDescriptor)); | 106 return adoptRefCountedGarbageCollectedWillBeNoop(new MediaStream(context, st
reamDescriptor)); |
| 95 } | 107 } |
| 96 | 108 |
| 97 MediaStream::MediaStream(ExecutionContext* context, PassRefPtr<MediaStreamDescri
ptor> streamDescriptor) | 109 MediaStream::MediaStream(ExecutionContext* context, PassRefPtr<MediaStreamDescri
ptor> streamDescriptor) |
| 98 : ContextLifecycleObserver(context) | 110 : MediaProvider(EventTargetNames::MediaStream, bind<const ScriptValue&>(Medi
aProviderConverter)) |
| 111 , ContextLifecycleObserver(context) |
| 99 , m_stopped(false) | 112 , m_stopped(false) |
| 100 , m_descriptor(streamDescriptor) | 113 , m_descriptor(streamDescriptor) |
| 101 , m_scheduledEventTimer(this, &MediaStream::scheduledEventTimerFired) | 114 , m_scheduledEventTimer(this, &MediaStream::scheduledEventTimerFired) |
| 102 { | 115 { |
| 103 ScriptWrappable::init(this); | 116 ScriptWrappable::init(this); |
| 104 m_descriptor->setClient(this); | 117 m_descriptor->setClient(this); |
| 105 | 118 |
| 106 size_t numberOfAudioTracks = m_descriptor->numberOfAudioComponents(); | 119 size_t numberOfAudioTracks = m_descriptor->numberOfAudioComponents(); |
| 107 m_audioTracks.reserveCapacity(numberOfAudioTracks); | 120 m_audioTracks.reserveCapacity(numberOfAudioTracks); |
| 108 for (size_t i = 0; i < numberOfAudioTracks; i++) { | 121 for (size_t i = 0; i < numberOfAudioTracks; i++) { |
| 109 MediaStreamTrack* newTrack = MediaStreamTrack::create(context, m_descrip
tor->audioComponent(i)); | 122 MediaStreamTrack* newTrack = MediaStreamTrack::create(context, m_descrip
tor->audioComponent(i)); |
| 110 newTrack->registerMediaStream(this); | 123 newTrack->registerMediaStream(this); |
| 111 m_audioTracks.append(newTrack); | 124 m_audioTracks.append(newTrack); |
| 112 } | 125 } |
| 113 | 126 |
| 114 size_t numberOfVideoTracks = m_descriptor->numberOfVideoComponents(); | 127 size_t numberOfVideoTracks = m_descriptor->numberOfVideoComponents(); |
| 115 m_videoTracks.reserveCapacity(numberOfVideoTracks); | 128 m_videoTracks.reserveCapacity(numberOfVideoTracks); |
| 116 for (size_t i = 0; i < numberOfVideoTracks; i++) { | 129 for (size_t i = 0; i < numberOfVideoTracks; i++) { |
| 117 MediaStreamTrack* newTrack = MediaStreamTrack::create(context, m_descrip
tor->videoComponent(i)); | 130 MediaStreamTrack* newTrack = MediaStreamTrack::create(context, m_descrip
tor->videoComponent(i)); |
| 118 newTrack->registerMediaStream(this); | 131 newTrack->registerMediaStream(this); |
| 119 m_videoTracks.append(newTrack); | 132 m_videoTracks.append(newTrack); |
| 120 } | 133 } |
| 121 } | 134 } |
| 122 | 135 |
| 123 MediaStream::MediaStream(ExecutionContext* context, const MediaStreamTrackVector
& audioTracks, const MediaStreamTrackVector& videoTracks) | 136 MediaStream::MediaStream(ExecutionContext* context, const MediaStreamTrackVector
& audioTracks, const MediaStreamTrackVector& videoTracks) |
| 124 : ContextLifecycleObserver(context) | 137 : MediaProvider(EventTargetNames::MediaStream, bind<const ScriptValue&>(Medi
aProviderConverter)) |
| 138 , ContextLifecycleObserver(context) |
| 125 , m_stopped(false) | 139 , m_stopped(false) |
| 126 , m_scheduledEventTimer(this, &MediaStream::scheduledEventTimerFired) | 140 , m_scheduledEventTimer(this, &MediaStream::scheduledEventTimerFired) |
| 127 { | 141 { |
| 128 ScriptWrappable::init(this); | 142 ScriptWrappable::init(this); |
| 129 | 143 |
| 130 MediaStreamComponentVector audioComponents; | 144 MediaStreamComponentVector audioComponents; |
| 131 MediaStreamComponentVector videoComponents; | 145 MediaStreamComponentVector videoComponents; |
| 132 | 146 |
| 133 MediaStreamTrackVector::const_iterator iter; | 147 MediaStreamTrackVector::const_iterator iter; |
| 134 for (iter = audioTracks.begin(); iter != audioTracks.end(); ++iter) { | 148 for (iter = audioTracks.begin(); iter != audioTracks.end(); ++iter) { |
| 135 (*iter)->registerMediaStream(this); | 149 (*iter)->registerMediaStream(this); |
| 136 audioComponents.append((*iter)->component()); | 150 audioComponents.append((*iter)->component()); |
| 137 } | 151 } |
| 138 for (iter = videoTracks.begin(); iter != videoTracks.end(); ++iter) { | 152 for (iter = videoTracks.begin(); iter != videoTracks.end(); ++iter) { |
| 139 (*iter)->registerMediaStream(this); | 153 (*iter)->registerMediaStream(this); |
| 140 videoComponents.append((*iter)->component()); | 154 videoComponents.append((*iter)->component()); |
| 141 } | 155 } |
| 142 | 156 |
| 143 m_descriptor = MediaStreamDescriptor::create(audioComponents, videoComponent
s); | 157 m_descriptor = MediaStreamDescriptor::create(audioComponents, videoComponent
s); |
| 144 m_descriptor->setClient(this); | 158 m_descriptor->setClient(this); |
| 145 MediaStreamCenter::instance().didCreateMediaStream(m_descriptor.get()); | 159 MediaStreamCenter::instance().didCreateMediaStream(m_descriptor.get()); |
| 146 | 160 |
| 147 m_audioTracks = audioTracks; | 161 m_audioTracks = audioTracks; |
| 148 m_videoTracks = videoTracks; | 162 m_videoTracks = videoTracks; |
| 149 } | 163 } |
| 150 | 164 |
| 151 MediaStream::~MediaStream() | 165 MediaStream::~MediaStream() |
| 152 { | 166 { |
| 167 if (!m_objectUrl.isEmpty()) |
| 168 DOMURL::revokeObjectURL(executionContext(), m_objectUrl); |
| 153 m_descriptor->setClient(0); | 169 m_descriptor->setClient(0); |
| 154 } | 170 } |
| 155 | 171 |
| 156 bool MediaStream::ended() const | 172 bool MediaStream::ended() const |
| 157 { | 173 { |
| 158 return m_stopped || m_descriptor->ended(); | 174 return m_stopped || m_descriptor->ended(); |
| 159 } | 175 } |
| 160 | 176 |
| 161 MediaStreamTrackVector MediaStream::getTracks() | 177 MediaStreamTrackVector MediaStream::getTracks() |
| 162 { | 178 { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 dispatchEvent((*it).release()); | 399 dispatchEvent((*it).release()); |
| 384 | 400 |
| 385 events.clear(); | 401 events.clear(); |
| 386 } | 402 } |
| 387 | 403 |
| 388 URLRegistry& MediaStream::registry() const | 404 URLRegistry& MediaStream::registry() const |
| 389 { | 405 { |
| 390 return MediaStreamRegistry::registry(); | 406 return MediaStreamRegistry::registry(); |
| 391 } | 407 } |
| 392 | 408 |
| 409 const String& MediaStream::getObjectUrl() |
| 410 { |
| 411 if (m_objectUrl.isEmpty()) |
| 412 m_objectUrl = m_objectUrl = DOMURL::createPublicURL(executionContext(),
this); |
| 413 return m_objectUrl; |
| 414 } |
| 415 |
| 393 void MediaStream::trace(Visitor* visitor) | 416 void MediaStream::trace(Visitor* visitor) |
| 394 { | 417 { |
| 395 visitor->trace(m_audioTracks); | 418 visitor->trace(m_audioTracks); |
| 396 visitor->trace(m_videoTracks); | 419 visitor->trace(m_videoTracks); |
| 397 visitor->trace(m_scheduledEvents); | 420 visitor->trace(m_scheduledEvents); |
| 398 EventTargetWithInlineData::trace(visitor); | 421 EventTargetWithInlineData::trace(visitor); |
| 399 } | 422 } |
| 400 | 423 |
| 401 } // namespace blink | 424 } // namespace blink |
| OLD | NEW |