Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(511)

Side by Side Diff: Source/modules/mediastream/MediaStreamTrack.cpp

Issue 173363002: Move mediastream module to oilpan transition types (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2011 Ericsson AB. All rights reserved. 3 * Copyright (C) 2011 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 12 matching lines...) Expand all
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/MediaStreamTrack.h" 27 #include "modules/mediastream/MediaStreamTrack.h"
28 28
29 #include "bindings/v8/ExceptionMessages.h" 29 #include "bindings/v8/ExceptionMessages.h"
30 #include "core/dom/ExceptionCode.h" 30 #include "core/dom/ExceptionCode.h"
31 #include "core/dom/ExecutionContext.h" 31 #include "core/dom/ExecutionContext.h"
32 #include "core/events/Event.h" 32 #include "core/events/Event.h"
33 #include "modules/mediastream/MediaStream.h"
33 #include "modules/mediastream/MediaStreamTrackSourcesCallback.h" 34 #include "modules/mediastream/MediaStreamTrackSourcesCallback.h"
34 #include "modules/mediastream/MediaStreamTrackSourcesRequestImpl.h" 35 #include "modules/mediastream/MediaStreamTrackSourcesRequestImpl.h"
35 #include "platform/mediastream/MediaStreamCenter.h" 36 #include "platform/mediastream/MediaStreamCenter.h"
36 #include "platform/mediastream/MediaStreamComponent.h" 37 #include "platform/mediastream/MediaStreamComponent.h"
37 #include "public/platform/WebSourceInfo.h" 38 #include "public/platform/WebSourceInfo.h"
38 39
39 namespace WebCore { 40 namespace WebCore {
40 41
41 PassRefPtr<MediaStreamTrack> MediaStreamTrack::create(ExecutionContext* context, MediaStreamComponent* component) 42 PassRefPtrWillBeRawPtr<MediaStreamTrack> MediaStreamTrack::create(ExecutionConte xt* context, MediaStreamComponent* component)
42 { 43 {
43 RefPtr<MediaStreamTrack> track = adoptRef(new MediaStreamTrack(context, comp onent)); 44 RefPtrWillBeRawPtr<MediaStreamTrack> track = adoptRefWillBeRefCountedGarbage Collected(new MediaStreamTrack(context, component));
44 track->suspendIfNeeded(); 45 track->suspendIfNeeded();
45 return track.release(); 46 return track.release();
46 } 47 }
47 48
48 MediaStreamTrack::MediaStreamTrack(ExecutionContext* context, MediaStreamCompone nt* component) 49 MediaStreamTrack::MediaStreamTrack(ExecutionContext* context, MediaStreamCompone nt* component)
49 : ActiveDOMObject(context) 50 : ActiveDOMObject(context)
50 , m_readyState(MediaStreamSource::ReadyStateLive) 51 , m_readyState(MediaStreamSource::ReadyStateLive)
51 , m_isIteratingObservers(false) 52 , m_isIteratingRegisteredMediaStreams(false)
52 , m_stopped(false) 53 , m_stopped(false)
53 , m_component(component) 54 , m_component(component)
54 { 55 {
55 ScriptWrappable::init(this); 56 ScriptWrappable::init(this);
56 m_component->source()->addObserver(this); 57 m_component->source()->addObserver(this);
57 } 58 }
58 59
59 MediaStreamTrack::~MediaStreamTrack() 60 MediaStreamTrack::~MediaStreamTrack()
60 { 61 {
61 m_component->source()->removeObserver(this); 62 m_component->source()->removeObserver(this);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 case MediaStreamSource::ReadyStateEnded: 117 case MediaStreamSource::ReadyStateEnded:
117 return "ended"; 118 return "ended";
118 } 119 }
119 120
120 ASSERT_NOT_REACHED(); 121 ASSERT_NOT_REACHED();
121 return String(); 122 return String();
122 } 123 }
123 124
124 void MediaStreamTrack::getSources(ExecutionContext* context, PassOwnPtr<MediaStr eamTrackSourcesCallback> callback, ExceptionState& exceptionState) 125 void MediaStreamTrack::getSources(ExecutionContext* context, PassOwnPtr<MediaStr eamTrackSourcesCallback> callback, ExceptionState& exceptionState)
125 { 126 {
126 RefPtr<MediaStreamTrackSourcesRequest> request = MediaStreamTrackSourcesRequ estImpl::create(context->securityOrigin()->toString(), callback); 127 RefPtrWillBeRawPtr<MediaStreamTrackSourcesRequest> request = MediaStreamTrac kSourcesRequestImpl::create(context->securityOrigin()->toString(), callback);
127 if (!MediaStreamCenter::instance().getMediaStreamTrackSources(request.releas e())) 128 if (!MediaStreamCenter::instance().getMediaStreamTrackSources(request.releas e()))
128 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::f ailedToExecute("getSources", "MediaStreamTrack", "Functionality not implemented yet")); 129 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::f ailedToExecute("getSources", "MediaStreamTrack", "Functionality not implemented yet"));
129 } 130 }
130 131
131 void MediaStreamTrack::stopTrack(ExceptionState& exceptionState) 132 void MediaStreamTrack::stopTrack(ExceptionState& exceptionState)
132 { 133 {
133 if (ended()) 134 if (ended())
134 return; 135 return;
135 136
136 m_readyState = MediaStreamSource::ReadyStateEnded; 137 m_readyState = MediaStreamSource::ReadyStateEnded;
137 MediaStreamCenter::instance().didStopMediaStreamTrack(component()); 138 MediaStreamCenter::instance().didStopMediaStreamTrack(component());
138 dispatchEvent(Event::create(EventTypeNames::ended)); 139 dispatchEvent(Event::create(EventTypeNames::ended));
139 propagateTrackEnded(); 140 propagateTrackEnded();
140 } 141 }
141 142
142 PassRefPtr<MediaStreamTrack> MediaStreamTrack::clone(ExecutionContext* context) 143 PassRefPtrWillBeRawPtr<MediaStreamTrack> MediaStreamTrack::clone(ExecutionContex t* context)
143 { 144 {
144 RefPtr<MediaStreamComponent> clonedComponent = MediaStreamComponent::create( component()->source()); 145 RefPtr<MediaStreamComponent> clonedComponent = MediaStreamComponent::create( component()->source());
145 RefPtr<MediaStreamTrack> clonedTrack = MediaStreamTrack::create(context, clo nedComponent.get()); 146 RefPtrWillBeRawPtr<MediaStreamTrack> clonedTrack = MediaStreamTrack::create( context, clonedComponent.get());
146 MediaStreamCenter::instance().didCreateMediaStreamTrack(clonedComponent.get( )); 147 MediaStreamCenter::instance().didCreateMediaStreamTrack(clonedComponent.get( ));
147 return clonedTrack.release(); 148 return clonedTrack.release();
148 } 149 }
149 150
150 bool MediaStreamTrack::ended() const 151 bool MediaStreamTrack::ended() const
151 { 152 {
152 return m_stopped || (m_readyState == MediaStreamSource::ReadyStateEnded); 153 return m_stopped || (m_readyState == MediaStreamSource::ReadyStateEnded);
153 } 154 }
154 155
155 void MediaStreamTrack::sourceChangedState() 156 void MediaStreamTrack::sourceChangedState()
(...skipping 11 matching lines...) Expand all
167 break; 168 break;
168 case MediaStreamSource::ReadyStateEnded: 169 case MediaStreamSource::ReadyStateEnded:
169 dispatchEvent(Event::create(EventTypeNames::ended)); 170 dispatchEvent(Event::create(EventTypeNames::ended));
170 propagateTrackEnded(); 171 propagateTrackEnded();
171 break; 172 break;
172 } 173 }
173 } 174 }
174 175
175 void MediaStreamTrack::propagateTrackEnded() 176 void MediaStreamTrack::propagateTrackEnded()
176 { 177 {
177 RELEASE_ASSERT(!m_isIteratingObservers); 178 RELEASE_ASSERT(!m_isIteratingRegisteredMediaStreams);
178 m_isIteratingObservers = true; 179 m_isIteratingRegisteredMediaStreams = true;
179 for (Vector<Observer*>::iterator iter = m_observers.begin(); iter != m_obser vers.end(); ++iter) 180 for (WillBeHeapHashSet<RawPtrWillBeWeakMember<MediaStream> >::iterator iter = m_registeredMediaStreams.begin(); iter != m_registeredMediaStreams.end(); ++it er)
180 (*iter)->trackEnded(); 181 (*iter)->trackEnded();
181 m_isIteratingObservers = false; 182 m_isIteratingRegisteredMediaStreams = false;
182 } 183 }
183 184
184 MediaStreamComponent* MediaStreamTrack::component() 185 MediaStreamComponent* MediaStreamTrack::component()
185 { 186 {
186 return m_component.get(); 187 return m_component.get();
187 } 188 }
188 189
189 void MediaStreamTrack::stop() 190 void MediaStreamTrack::stop()
190 { 191 {
191 m_stopped = true; 192 m_stopped = true;
192 } 193 }
193 194
194 PassOwnPtr<AudioSourceProvider> MediaStreamTrack::createWebAudioSource() 195 PassOwnPtr<AudioSourceProvider> MediaStreamTrack::createWebAudioSource()
195 { 196 {
196 return MediaStreamCenter::instance().createWebAudioSourceFromMediaStreamTrac k(component()); 197 return MediaStreamCenter::instance().createWebAudioSourceFromMediaStreamTrac k(component());
197 } 198 }
198 199
199 void MediaStreamTrack::addObserver(MediaStreamTrack::Observer* observer) 200 void MediaStreamTrack::registerMediaStream(MediaStream* mediaStream)
200 { 201 {
201 RELEASE_ASSERT(!m_isIteratingObservers); 202 RELEASE_ASSERT(!m_isIteratingRegisteredMediaStreams);
202 m_observers.append(observer); 203 RELEASE_ASSERT(!m_registeredMediaStreams.contains(mediaStream));
204 m_registeredMediaStreams.add(mediaStream);
203 } 205 }
204 206
205 void MediaStreamTrack::removeObserver(MediaStreamTrack::Observer* observer) 207 void MediaStreamTrack::unregisterMediaStream(MediaStream* mediaStream)
206 { 208 {
207 RELEASE_ASSERT(!m_isIteratingObservers); 209 RELEASE_ASSERT(!m_isIteratingRegisteredMediaStreams);
208 size_t pos = m_observers.find(observer); 210 WillBeHeapHashSet<RawPtrWillBeWeakMember<MediaStream> >::iterator iter = m_r egisteredMediaStreams.find(mediaStream);
209 RELEASE_ASSERT(pos != kNotFound); 211 RELEASE_ASSERT(iter != m_registeredMediaStreams.end());
210 m_observers.remove(pos); 212 m_registeredMediaStreams.remove(iter);
211 } 213 }
212 214
213 const AtomicString& MediaStreamTrack::interfaceName() const 215 const AtomicString& MediaStreamTrack::interfaceName() const
214 { 216 {
215 return EventTargetNames::MediaStreamTrack; 217 return EventTargetNames::MediaStreamTrack;
216 } 218 }
217 219
218 ExecutionContext* MediaStreamTrack::executionContext() const 220 ExecutionContext* MediaStreamTrack::executionContext() const
219 { 221 {
220 return ActiveDOMObject::executionContext(); 222 return ActiveDOMObject::executionContext();
221 } 223 }
222 224
225 void MediaStreamTrack::trace(Visitor* visitor)
226 {
227 visitor->trace(m_registeredMediaStreams);
228 }
229
223 } // namespace WebCore 230 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698