Source/WebCore/ChangeLog

 12013-09-09 Thiago de Barros Lacerda <thiago.lacerda@openbossa.org>
 2
 3 MediaStream API: Enhance MediaStreamDescriptor add/remove component
 4 https://bugs.webkit.org/show_bug.cgi?id=120874
 5
 6 Merged from blink patch
 7 https://chromium.googlesource.com/chromium/blink/+/67fcacf13ce922a762d7a1c6fb9e1b8e51e662ea
 8
 9 Reviewed by NOBODY (OOPS!).
 10
 11 No new tests needed.
 12
 13 * Modules/mediastream/MediaStream.cpp:
 14 (WebCore::MediaStream::addTrack):
 15 (WebCore::MediaStream::removeTrack):
 16 (WebCore::MediaStream::addRemoteTrack):
 17 (WebCore::MediaStream::removeRemoteTrack):
 18 * platform/mediastream/MediaStreamDescriptor.h:
 19 (WebCore::MediaStreamDescriptor::addComponent):
 20 (WebCore::MediaStreamDescriptor::removeComponent):
 21
1222013-09-09 Hugo Parente Lima <hugo.lima@openbossa.org>
223
324 Preparing WebCore to receive Nix Port

Source/WebCore/Modules/mediastream/MediaStream.cpp

@@void MediaStream::addTrack(PassRefPtr<MediaStreamTrack> prpTrack, ExceptionCode&
155155
156156 switch (component->source()->type()) {
157157 case MediaStreamSource::TypeAudio:
158  m_descriptor->addAudioComponent(component.release());
159158 m_audioTracks.append(newTrack);
160159 break;
161160 case MediaStreamSource::TypeVideo:
162  m_descriptor->addVideoComponent(component.release());
163161 m_videoTracks.append(newTrack);
164162 break;
165163 }
166164
 165 m_descriptor->addComponent(component.release());
167166 MediaStreamCenter::instance().didAddMediaStreamTrack(m_descriptor.get(), newTrack->component());
168167}
169168

@@void MediaStream::removeTrack(PassRefPtr<MediaStreamTrack> prpTrack , ExceptionC
181180
182181 RefPtr<MediaStreamTrack> track = prpTrack;
183182
 183 size_t pos = notFound;
184184 switch (track->component()->source()->type()) {
185  case MediaStreamSource::TypeAudio: {
186  size_t pos = m_audioTracks.find(track);
187  if (pos != notFound) {
 185 case MediaStreamSource::TypeAudio:
 186 pos = m_audioTracks.find(track);
 187 if (pos != notFound)
188188 m_audioTracks.remove(pos);
189  m_descriptor->removeAudioComponent(track->component());
190  }
191189 break;
192  }
193  case MediaStreamSource::TypeVideo: {
194  size_t pos = m_videoTracks.find(track);
195  if (pos != notFound) {
 190 case MediaStreamSource::TypeVideo:
 191 pos = m_videoTracks.find(track);
 192 if (pos != notFound)
196193 m_videoTracks.remove(pos);
197  m_descriptor->removeVideoComponent(track->component());
198  }
199194 break;
200195 }
201  }
 196
 197 if (pos != notFound)
 198 m_descriptor->removeComponent(track->component());
202199
203200 if (!m_audioTracks.size() && !m_videoTracks.size())
204201 m_descriptor->setEnded();

@@void MediaStream::addRemoteTrack(MediaStreamComponent* component)
286283 m_videoTracks.append(track);
287284 break;
288285 }
 286 m_descriptor->addComponent(component);
289287
290288 scheduleDispatchEvent(MediaStreamTrackEvent::create(eventNames().addtrackEvent, false, false, track));
291289}

@@void MediaStream::removeRemoteTrack(MediaStreamComponent* component)
315313 if (index == notFound)
316314 return;
317315
 316 m_descriptor->removeComponent(component);
 317
318318 RefPtr<MediaStreamTrack> track = (*tracks)[index];
319319 tracks->remove(index);
320320 scheduleDispatchEvent(MediaStreamTrackEvent::create(eventNames().removetrackEvent, false, false, track));

Source/WebCore/platform/mediastream/MediaStreamDescriptor.h

@@public:
7474
7575 unsigned numberOfAudioComponents() const { return m_audioComponents.size(); }
7676 MediaStreamComponent* audioComponent(unsigned index) const { return m_audioComponents[index].get(); }
77  void addAudioComponent(PassRefPtr<MediaStreamComponent> component) { m_audioComponents.append(component); }
78  void removeAudioComponent(MediaStreamComponent* component)
79  {
80  size_t pos = m_audioComponents.find(component);
81  if (pos != notFound)
82  m_audioComponents.remove(pos);
83  }
8477
8578 unsigned numberOfVideoComponents() const { return m_videoComponents.size(); }
8679 MediaStreamComponent* videoComponent(unsigned index) const { return m_videoComponents[index].get(); }
87  void addVideoComponent(PassRefPtr<MediaStreamComponent> component) { m_videoComponents.append(component); }
88  void removeVideoComponent(MediaStreamComponent* component)
 80
 81 void addComponent(PassRefPtr<MediaStreamComponent> component)
 82 {
 83 switch (component->source()->type()) {
 84 case MediaStreamSource::TypeAudio:
 85 if (m_audioComponents.find(component) == notFound)
 86 m_audioComponents.append(component);
 87 break;
 88 case MediaStreamSource::TypeVideo:
 89 if (m_videoComponents.find(component) == notFound)
 90 m_videoComponents.append(component);
 91 break;
 92 }
 93 }
 94
 95 void removeComponent(PassRefPtr<MediaStreamComponent> component)
8996 {
90  size_t pos = m_videoComponents.find(component);
91  if (pos != notFound)
92  m_videoComponents.remove(pos);
 97 size_t pos = notFound;
 98 switch (component->source()->type()) {
 99 case MediaStreamSource::TypeAudio:
 100 pos = m_audioComponents.find(component);
 101 if (pos != notFound)
 102 m_audioComponents.remove(pos);
 103 break;
 104 case MediaStreamSource::TypeVideo:
 105 pos = m_videoComponents.find(component);
 106 if (pos != notFound)
 107 m_videoComponents.remove(pos);
 108 break;
 109 }
93110 }
94111
95112 bool ended() const { return m_ended; }