Chromium Code Reviews| 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 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 11 matching lines...) Expand all Loading... | |
| 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 "MediaStreamTrack.h" | 27 #include "MediaStreamTrack.h" |
| 28 | 28 |
| 29 #if ENABLE(MEDIA_STREAM) | 29 #if ENABLE(MEDIA_STREAM) |
| 30 | 30 |
| 31 #include "Event.h" | 31 #include "Event.h" |
| 32 #include "MediaStream.h" | |
| 32 #include "MediaStreamCenter.h" | 33 #include "MediaStreamCenter.h" |
| 33 #include "MediaStreamComponent.h" | 34 #include "MediaStreamComponent.h" |
| 34 | 35 |
| 35 namespace WebCore { | 36 namespace WebCore { |
| 36 | 37 |
| 37 PassRefPtr<MediaStreamTrack> MediaStreamTrack::create(ScriptExecutionContext* co ntext, MediaStreamComponent* component) | 38 PassRefPtr<MediaStreamTrack> MediaStreamTrack::create(ScriptExecutionContext* co ntext, MediaStreamComponent* component, MediaStream* stream) |
| 38 { | 39 { |
| 39 RefPtr<MediaStreamTrack> track = adoptRef(new MediaStreamTrack(context, comp onent)); | 40 RefPtr<MediaStreamTrack> track = adoptRef(new MediaStreamTrack(context, comp onent, stream)); |
| 40 track->suspendIfNeeded(); | 41 track->suspendIfNeeded(); |
| 41 return track.release(); | 42 return track.release(); |
| 42 } | 43 } |
| 43 | 44 |
| 44 MediaStreamTrack::MediaStreamTrack(ScriptExecutionContext* context, MediaStreamC omponent* component) | 45 MediaStreamTrack::MediaStreamTrack(ScriptExecutionContext* context, MediaStreamC omponent* component, MediaStream* stream) |
| 45 : ActiveDOMObject(context) | 46 : ActiveDOMObject(context) |
| 46 , m_stopped(false) | 47 , m_stopped(false) |
| 47 , m_component(component) | 48 , m_component(component) |
| 49 , m_stream(stream) | |
| 48 { | 50 { |
| 49 m_component->source()->addObserver(this); | 51 m_component->source()->addObserver(this); |
| 50 } | 52 } |
| 51 | 53 |
| 52 MediaStreamTrack::~MediaStreamTrack() | 54 MediaStreamTrack::~MediaStreamTrack() |
| 53 { | 55 { |
| 54 m_component->source()->removeObserver(this); | 56 m_component->source()->removeObserver(this); |
| 55 } | 57 } |
| 56 | 58 |
| 57 String MediaStreamTrack::kind() const | 59 String MediaStreamTrack::kind() const |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 | 116 |
| 115 ASSERT_NOT_REACHED(); | 117 ASSERT_NOT_REACHED(); |
| 116 return String(); | 118 return String(); |
| 117 } | 119 } |
| 118 | 120 |
| 119 bool MediaStreamTrack::ended() const | 121 bool MediaStreamTrack::ended() const |
| 120 { | 122 { |
| 121 return m_stopped || (m_component->source()->readyState() == MediaStreamSourc e::ReadyStateEnded); | 123 return m_stopped || (m_component->source()->readyState() == MediaStreamSourc e::ReadyStateEnded); |
| 122 } | 124 } |
| 123 | 125 |
| 124 void MediaStreamTrack::sourceChangedState() | 126 void MediaStreamTrack::sourceChangedState() |
|
abarth-chromium
2013/04/08 16:58:41
Who calls this function? Maybe it would be easier
Li Yin
2013/04/09 06:34:07
It is a callback from MediaStreamSource::setReadyS
| |
| 125 { | 127 { |
| 126 if (m_stopped) | 128 if (m_stopped) |
| 127 return; | 129 return; |
| 128 | 130 |
| 129 switch (m_component->source()->readyState()) { | 131 switch (m_component->source()->readyState()) { |
| 130 case MediaStreamSource::ReadyStateLive: | 132 case MediaStreamSource::ReadyStateLive: |
| 131 dispatchEvent(Event::create(eventNames().unmuteEvent, false, false)); | 133 dispatchEvent(Event::create(eventNames().unmuteEvent, false, false)); |
| 132 break; | 134 break; |
| 133 case MediaStreamSource::ReadyStateMuted: | 135 case MediaStreamSource::ReadyStateMuted: |
| 134 dispatchEvent(Event::create(eventNames().muteEvent, false, false)); | 136 dispatchEvent(Event::create(eventNames().muteEvent, false, false)); |
| 135 break; | 137 break; |
| 136 case MediaStreamSource::ReadyStateEnded: | 138 case MediaStreamSource::ReadyStateEnded: |
| 137 dispatchEvent(Event::create(eventNames().endedEvent, false, false)); | 139 dispatchEvent(Event::create(eventNames().endedEvent, false, false)); |
| 140 if (m_stream) | |
| 141 m_stream->trackEndedNotification(); | |
| 138 break; | 142 break; |
| 139 } | 143 } |
| 140 } | 144 } |
| 141 | 145 |
| 142 MediaStreamComponent* MediaStreamTrack::component() | 146 MediaStreamComponent* MediaStreamTrack::component() |
| 143 { | 147 { |
| 144 return m_component.get(); | 148 return m_component.get(); |
| 145 } | 149 } |
| 146 | 150 |
| 147 void MediaStreamTrack::stop() | 151 void MediaStreamTrack::stop() |
| 148 { | 152 { |
| 149 m_stopped = true; | 153 m_stopped = true; |
| 154 if (m_stream) | |
| 155 m_stream->trackEndedNotification(); | |
|
Tommy Widenflycht
2013/04/08 14:01:07
This is a bit overkill because when stop() is call
abarth-chromium
2013/04/08 16:58:41
Yeah.
| |
| 150 } | 156 } |
| 151 | 157 |
| 152 const AtomicString& MediaStreamTrack::interfaceName() const | 158 const AtomicString& MediaStreamTrack::interfaceName() const |
| 153 { | 159 { |
| 154 return eventNames().interfaceForMediaStreamTrack; | 160 return eventNames().interfaceForMediaStreamTrack; |
| 155 } | 161 } |
| 156 | 162 |
| 157 ScriptExecutionContext* MediaStreamTrack::scriptExecutionContext() const | 163 ScriptExecutionContext* MediaStreamTrack::scriptExecutionContext() const |
| 158 { | 164 { |
| 159 return ActiveDOMObject::scriptExecutionContext(); | 165 return ActiveDOMObject::scriptExecutionContext(); |
| 160 } | 166 } |
| 161 | 167 |
| 162 EventTargetData* MediaStreamTrack::eventTargetData() | 168 EventTargetData* MediaStreamTrack::eventTargetData() |
| 163 { | 169 { |
| 164 return &m_eventTargetData; | 170 return &m_eventTargetData; |
| 165 } | 171 } |
| 166 | 172 |
| 167 EventTargetData* MediaStreamTrack::ensureEventTargetData() | 173 EventTargetData* MediaStreamTrack::ensureEventTargetData() |
| 168 { | 174 { |
| 169 return &m_eventTargetData; | 175 return &m_eventTargetData; |
| 170 } | 176 } |
| 171 | 177 |
| 172 } // namespace WebCore | 178 } // namespace WebCore |
| 173 | 179 |
| 174 #endif // ENABLE(MEDIA_STREAM) | 180 #endif // ENABLE(MEDIA_STREAM) |
| OLD | NEW |