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