| 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 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "bindings/v8/ExceptionState.h" | 29 #include "bindings/v8/ExceptionState.h" |
| 30 #include "core/dom/ExceptionCode.h" | 30 #include "core/dom/ExceptionCode.h" |
| 31 #include "core/events/Event.h" | 31 #include "core/events/Event.h" |
| 32 #include "modules/mediastream/MediaStreamRegistry.h" | 32 #include "modules/mediastream/MediaStreamRegistry.h" |
| 33 #include "modules/mediastream/MediaStreamTrackEvent.h" | 33 #include "modules/mediastream/MediaStreamTrackEvent.h" |
| 34 #include "platform/mediastream/MediaStreamCenter.h" | 34 #include "platform/mediastream/MediaStreamCenter.h" |
| 35 #include "platform/mediastream/MediaStreamSource.h" | 35 #include "platform/mediastream/MediaStreamSource.h" |
| 36 | 36 |
| 37 namespace WebCore { | 37 namespace WebCore { |
| 38 | 38 |
| 39 DEFINE_GC_INFO(MediaStream); |
| 40 |
| 39 static bool containsSource(MediaStreamSourceVector& sourceVector, MediaStreamSou
rce* source) | 41 static bool containsSource(MediaStreamSourceVector& sourceVector, MediaStreamSou
rce* source) |
| 40 { | 42 { |
| 41 for (size_t i = 0; i < sourceVector.size(); ++i) { | 43 for (size_t i = 0; i < sourceVector.size(); ++i) { |
| 42 if (source->id() == sourceVector[i]->id()) | 44 if (source->id() == sourceVector[i]->id()) |
| 43 return true; | 45 return true; |
| 44 } | 46 } |
| 45 return false; | 47 return false; |
| 46 } | 48 } |
| 47 | 49 |
| 48 static void processTrack(MediaStreamTrack* track, MediaStreamSourceVector& sourc
eVector) | 50 static void processTrack(MediaStreamTrack* track, MediaStreamSourceVector& sourc
eVector) |
| 49 { | 51 { |
| 50 if (track->ended()) | 52 if (track->ended()) |
| 51 return; | 53 return; |
| 52 | 54 |
| 53 MediaStreamSource* source = track->component()->source(); | 55 MediaStreamSource* source = track->component()->source(); |
| 54 if (!containsSource(sourceVector, source)) | 56 if (!containsSource(sourceVector, source)) |
| 55 sourceVector.append(source); | 57 sourceVector.append(source); |
| 56 } | 58 } |
| 57 | 59 |
| 58 static PassRefPtr<MediaStream> createFromSourceVectors(ExecutionContext* context
, const MediaStreamSourceVector& audioSources, const MediaStreamSourceVector& vi
deoSources) | 60 static PassRefPtrWillBeRawPtr<MediaStream> createFromSourceVectors(ExecutionCont
ext* context, const MediaStreamSourceVector& audioSources, const MediaStreamSour
ceVector& videoSources) |
| 59 { | 61 { |
| 60 RefPtr<MediaStreamDescriptor> descriptor = MediaStreamDescriptor::create(aud
ioSources, videoSources); | 62 RefPtr<MediaStreamDescriptor> descriptor = MediaStreamDescriptor::create(aud
ioSources, videoSources); |
| 61 MediaStreamCenter::instance().didCreateMediaStream(descriptor.get()); | 63 MediaStreamCenter::instance().didCreateMediaStream(descriptor.get()); |
| 62 | 64 |
| 63 return MediaStream::create(context, descriptor.release()); | 65 return MediaStream::create(context, descriptor.release()); |
| 64 } | 66 } |
| 65 | 67 |
| 66 PassRefPtr<MediaStream> MediaStream::create(ExecutionContext* context) | 68 PassRefPtrWillBeRawPtr<MediaStream> MediaStream::create(ExecutionContext* contex
t) |
| 67 { | 69 { |
| 68 MediaStreamSourceVector audioSources; | 70 MediaStreamSourceVector audioSources; |
| 69 MediaStreamSourceVector videoSources; | 71 MediaStreamSourceVector videoSources; |
| 70 | 72 |
| 71 return createFromSourceVectors(context, audioSources, videoSources); | 73 return createFromSourceVectors(context, audioSources, videoSources); |
| 72 } | 74 } |
| 73 | 75 |
| 74 PassRefPtr<MediaStream> MediaStream::create(ExecutionContext* context, PassRefPt
r<MediaStream> stream) | 76 PassRefPtrWillBeRawPtr<MediaStream> MediaStream::create(ExecutionContext* contex
t, PassRefPtrWillBeRawPtr<MediaStream> stream) |
| 75 { | 77 { |
| 76 ASSERT(stream); | 78 ASSERT(stream); |
| 77 | 79 |
| 78 MediaStreamSourceVector audioSources; | 80 MediaStreamSourceVector audioSources; |
| 79 MediaStreamSourceVector videoSources; | 81 MediaStreamSourceVector videoSources; |
| 80 | 82 |
| 81 for (size_t i = 0; i < stream->m_audioTracks.size(); ++i) | 83 for (size_t i = 0; i < stream->m_audioTracks.size(); ++i) |
| 82 processTrack(stream->m_audioTracks[i].get(), audioSources); | 84 processTrack(stream->m_audioTracks[i].get(), audioSources); |
| 83 | 85 |
| 84 for (size_t i = 0; i < stream->m_videoTracks.size(); ++i) | 86 for (size_t i = 0; i < stream->m_videoTracks.size(); ++i) |
| 85 processTrack(stream->m_videoTracks[i].get(), videoSources); | 87 processTrack(stream->m_videoTracks[i].get(), videoSources); |
| 86 | 88 |
| 87 return createFromSourceVectors(context, audioSources, videoSources); | 89 return createFromSourceVectors(context, audioSources, videoSources); |
| 88 } | 90 } |
| 89 | 91 |
| 90 PassRefPtr<MediaStream> MediaStream::create(ExecutionContext* context, const Med
iaStreamTrackVector& tracks) | 92 PassRefPtrWillBeRawPtr<MediaStream> MediaStream::create(ExecutionContext* contex
t, const MediaStreamTrackVector& tracks) |
| 91 { | 93 { |
| 92 MediaStreamSourceVector audioSources; | 94 MediaStreamSourceVector audioSources; |
| 93 MediaStreamSourceVector videoSources; | 95 MediaStreamSourceVector videoSources; |
| 94 | 96 |
| 95 for (size_t i = 0; i < tracks.size(); ++i) | 97 for (size_t i = 0; i < tracks.size(); ++i) |
| 96 processTrack(tracks[i].get(), tracks[i]->kind() == "audio" ? audioSource
s : videoSources); | 98 processTrack(tracks[i].get(), tracks[i]->kind() == "audio" ? audioSource
s : videoSources); |
| 97 | 99 |
| 98 return createFromSourceVectors(context, audioSources, videoSources); | 100 return createFromSourceVectors(context, audioSources, videoSources); |
| 99 } | 101 } |
| 100 | 102 |
| 101 PassRefPtr<MediaStream> MediaStream::create(ExecutionContext* context, PassRefPt
r<MediaStreamDescriptor> streamDescriptor) | 103 PassRefPtrWillBeRawPtr<MediaStream> MediaStream::create(ExecutionContext* contex
t, PassRefPtr<MediaStreamDescriptor> streamDescriptor) |
| 102 { | 104 { |
| 103 return adoptRef(new MediaStream(context, streamDescriptor)); | 105 return adoptRefCountedWillBeRefCountedGarbageCollected(new MediaStream(conte
xt, streamDescriptor)); |
| 104 } | 106 } |
| 105 | 107 |
| 106 MediaStream::MediaStream(ExecutionContext* context, PassRefPtr<MediaStreamDescri
ptor> streamDescriptor) | 108 MediaStream::MediaStream(ExecutionContext* context, PassRefPtr<MediaStreamDescri
ptor> streamDescriptor) |
| 107 : ContextLifecycleObserver(context) | 109 : ContextLifecycleObserver(context) |
| 108 , m_stopped(false) | 110 , m_stopped(false) |
| 109 , m_descriptor(streamDescriptor) | 111 , m_descriptor(streamDescriptor) |
| 110 , m_scheduledEventTimer(this, &MediaStream::scheduledEventTimerFired) | 112 , m_scheduledEventTimer(this, &MediaStream::scheduledEventTimerFired) |
| 111 { | 113 { |
| 112 ScriptWrappable::init(this); | 114 ScriptWrappable::init(this); |
| 113 m_descriptor->setClient(this); | 115 m_descriptor->setClient(this); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 126 MediaStream::~MediaStream() | 128 MediaStream::~MediaStream() |
| 127 { | 129 { |
| 128 m_descriptor->setClient(0); | 130 m_descriptor->setClient(0); |
| 129 } | 131 } |
| 130 | 132 |
| 131 bool MediaStream::ended() const | 133 bool MediaStream::ended() const |
| 132 { | 134 { |
| 133 return m_stopped || m_descriptor->ended(); | 135 return m_stopped || m_descriptor->ended(); |
| 134 } | 136 } |
| 135 | 137 |
| 136 void MediaStream::addTrack(PassRefPtr<MediaStreamTrack> prpTrack, ExceptionState
& exceptionState) | 138 void MediaStream::addTrack(PassRefPtrWillBeRawPtr<MediaStreamTrack> prpTrack, Ex
ceptionState& exceptionState) |
| 137 { | 139 { |
| 138 if (ended()) { | 140 if (ended()) { |
| 139 exceptionState.throwDOMException(InvalidStateError, "The MediaStream is
finished."); | 141 exceptionState.throwDOMException(InvalidStateError, "The MediaStream is
finished."); |
| 140 return; | 142 return; |
| 141 } | 143 } |
| 142 | 144 |
| 143 if (!prpTrack) { | 145 if (!prpTrack) { |
| 144 exceptionState.throwDOMException(TypeMismatchError, "The MediaStreamTrac
k provided is invalid."); | 146 exceptionState.throwDOMException(TypeMismatchError, "The MediaStreamTrac
k provided is invalid."); |
| 145 return; | 147 return; |
| 146 } | 148 } |
| 147 | 149 |
| 148 RefPtr<MediaStreamTrack> track = prpTrack; | 150 RefPtrWillBeRawPtr<MediaStreamTrack> track = prpTrack; |
| 149 | 151 |
| 150 if (getTrackById(track->id())) | 152 if (getTrackById(track->id())) |
| 151 return; | 153 return; |
| 152 | 154 |
| 153 RefPtr<MediaStreamComponent> component = MediaStreamComponent::create(m_desc
riptor.get(), track->component()->source()); | 155 RefPtr<MediaStreamComponent> component = MediaStreamComponent::create(m_desc
riptor.get(), track->component()->source()); |
| 154 RefPtr<MediaStreamTrack> newTrack = MediaStreamTrack::create(executionContex
t(), component.get()); | 156 RefPtrWillBeRawPtr<MediaStreamTrack> newTrack = MediaStreamTrack::create(exe
cutionContext(), component.get()); |
| 155 | 157 |
| 156 switch (component->source()->type()) { | 158 switch (component->source()->type()) { |
| 157 case MediaStreamSource::TypeAudio: | 159 case MediaStreamSource::TypeAudio: |
| 158 m_audioTracks.append(newTrack); | 160 m_audioTracks.append(newTrack); |
| 159 break; | 161 break; |
| 160 case MediaStreamSource::TypeVideo: | 162 case MediaStreamSource::TypeVideo: |
| 161 m_videoTracks.append(newTrack); | 163 m_videoTracks.append(newTrack); |
| 162 break; | 164 break; |
| 163 } | 165 } |
| 164 | 166 |
| 165 m_descriptor->addComponent(component.release()); | 167 m_descriptor->addComponent(component.release()); |
| 166 | 168 |
| 167 MediaStreamCenter::instance().didAddMediaStreamTrack(m_descriptor.get(), new
Track->component()); | 169 MediaStreamCenter::instance().didAddMediaStreamTrack(m_descriptor.get(), new
Track->component()); |
| 168 } | 170 } |
| 169 | 171 |
| 170 void MediaStream::removeTrack(PassRefPtr<MediaStreamTrack> prpTrack, ExceptionSt
ate& exceptionState) | 172 void MediaStream::removeTrack(PassRefPtrWillBeRawPtr<MediaStreamTrack> prpTrack,
ExceptionState& exceptionState) |
| 171 { | 173 { |
| 172 if (ended()) { | 174 if (ended()) { |
| 173 exceptionState.throwDOMException(InvalidStateError, "The MediaStream is
finished."); | 175 exceptionState.throwDOMException(InvalidStateError, "The MediaStream is
finished."); |
| 174 return; | 176 return; |
| 175 } | 177 } |
| 176 | 178 |
| 177 if (!prpTrack) { | 179 if (!prpTrack) { |
| 178 exceptionState.throwDOMException(TypeMismatchError, "The MediaStreamTrac
k provided is invalid."); | 180 exceptionState.throwDOMException(TypeMismatchError, "The MediaStreamTrac
k provided is invalid."); |
| 179 return; | 181 return; |
| 180 } | 182 } |
| 181 | 183 |
| 182 RefPtr<MediaStreamTrack> track = prpTrack; | 184 RefPtrWillBeRawPtr<MediaStreamTrack> track = prpTrack; |
| 183 | 185 |
| 184 size_t pos = kNotFound; | 186 size_t pos = kNotFound; |
| 185 switch (track->component()->source()->type()) { | 187 switch (track->component()->source()->type()) { |
| 186 case MediaStreamSource::TypeAudio: | 188 case MediaStreamSource::TypeAudio: |
| 187 pos = m_audioTracks.find(track); | 189 pos = m_audioTracks.find(track); |
| 188 if (pos != kNotFound) | 190 if (pos != kNotFound) |
| 189 m_audioTracks.remove(pos); | 191 m_audioTracks.remove(pos); |
| 190 break; | 192 break; |
| 191 case MediaStreamSource::TypeVideo: | 193 case MediaStreamSource::TypeVideo: |
| 192 pos = m_videoTracks.find(track); | 194 pos = m_videoTracks.find(track); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } | 272 } |
| 271 | 273 |
| 272 void MediaStream::addRemoteTrack(MediaStreamComponent* component) | 274 void MediaStream::addRemoteTrack(MediaStreamComponent* component) |
| 273 { | 275 { |
| 274 ASSERT(component && !component->stream()); | 276 ASSERT(component && !component->stream()); |
| 275 if (ended()) | 277 if (ended()) |
| 276 return; | 278 return; |
| 277 | 279 |
| 278 component->setStream(descriptor()); | 280 component->setStream(descriptor()); |
| 279 | 281 |
| 280 RefPtr<MediaStreamTrack> track = MediaStreamTrack::create(executionContext()
, component); | 282 RefPtrWillBeRawPtr<MediaStreamTrack> track = MediaStreamTrack::create(execut
ionContext(), component); |
| 281 switch (component->source()->type()) { | 283 switch (component->source()->type()) { |
| 282 case MediaStreamSource::TypeAudio: | 284 case MediaStreamSource::TypeAudio: |
| 283 m_audioTracks.append(track); | 285 m_audioTracks.append(track); |
| 284 break; | 286 break; |
| 285 case MediaStreamSource::TypeVideo: | 287 case MediaStreamSource::TypeVideo: |
| 286 m_videoTracks.append(track); | 288 m_videoTracks.append(track); |
| 287 break; | 289 break; |
| 288 } | 290 } |
| 289 m_descriptor->addComponent(component); | 291 m_descriptor->addComponent(component); |
| 290 | 292 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 311 if ((*tracks)[i]->component() == component) { | 313 if ((*tracks)[i]->component() == component) { |
| 312 index = i; | 314 index = i; |
| 313 break; | 315 break; |
| 314 } | 316 } |
| 315 } | 317 } |
| 316 if (index == kNotFound) | 318 if (index == kNotFound) |
| 317 return; | 319 return; |
| 318 | 320 |
| 319 m_descriptor->removeComponent(component); | 321 m_descriptor->removeComponent(component); |
| 320 | 322 |
| 321 RefPtr<MediaStreamTrack> track = (*tracks)[index]; | 323 RefPtrWillBeRawPtr<MediaStreamTrack> track = (*tracks)[index]; |
| 322 tracks->remove(index); | 324 tracks->remove(index); |
| 323 scheduleDispatchEvent(MediaStreamTrackEvent::create(EventTypeNames::removetr
ack, false, false, track)); | 325 scheduleDispatchEvent(MediaStreamTrackEvent::create(EventTypeNames::removetr
ack, false, false, track)); |
| 324 } | 326 } |
| 325 | 327 |
| 326 void MediaStream::scheduleDispatchEvent(PassRefPtr<Event> event) | 328 void MediaStream::scheduleDispatchEvent(PassRefPtr<Event> event) |
| 327 { | 329 { |
| 328 m_scheduledEvents.append(event); | 330 m_scheduledEvents.append(event); |
| 329 | 331 |
| 330 if (!m_scheduledEventTimer.isActive()) | 332 if (!m_scheduledEventTimer.isActive()) |
| 331 m_scheduledEventTimer.startOneShot(0); | 333 m_scheduledEventTimer.startOneShot(0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 345 | 347 |
| 346 events.clear(); | 348 events.clear(); |
| 347 } | 349 } |
| 348 | 350 |
| 349 URLRegistry& MediaStream::registry() const | 351 URLRegistry& MediaStream::registry() const |
| 350 { | 352 { |
| 351 return MediaStreamRegistry::registry(); | 353 return MediaStreamRegistry::registry(); |
| 352 } | 354 } |
| 353 | 355 |
| 354 } // namespace WebCore | 356 } // namespace WebCore |
| OLD | NEW |