MediaStream API: Enhance MediaStreamDescriptor add/remove component
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Sep 2013 13:30:10 +0000 (13:30 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Sep 2013 13:30:10 +0000 (13:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=120874

Merge blink https://chromium.googlesource.com/chromium/blink/+/67fcacf13ce922a762d7a1c6fb9e1b8e51e662ea

Patch by Thiago de Barros Lacerda <thiago.lacerda@openbossa.org> on 2013-09-10
Reviewed by Eric Carlson.

No new tests needed.

* Modules/mediastream/MediaStream.cpp:
(WebCore::MediaStream::addTrack):
(WebCore::MediaStream::removeTrack):
(WebCore::MediaStream::addRemoteTrack):
(WebCore::MediaStream::removeRemoteTrack):
* platform/mediastream/MediaStreamDescriptor.h:
(WebCore::MediaStreamDescriptor::addRemoteTrack):
(WebCore::MediaStreamDescriptor::removeRemoteTrack):
(WebCore::MediaStreamDescriptor::addComponent):
(WebCore::MediaStreamDescriptor::removeComponent):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@155434 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/MediaStream.cpp
Source/WebCore/platform/mediastream/MediaStreamDescriptor.h

index fe47b89cc3be9a5a0552a482461c34644771b846..abe09c8ef6cbc4e11f3b14b0a1c1af759c25ecfe 100644 (file)
@@ -1,3 +1,25 @@
+2013-09-10  Thiago de Barros Lacerda  <thiago.lacerda@openbossa.org>
+
+        MediaStream API: Enhance MediaStreamDescriptor add/remove component
+        https://bugs.webkit.org/show_bug.cgi?id=120874
+
+        Merge blink https://chromium.googlesource.com/chromium/blink/+/67fcacf13ce922a762d7a1c6fb9e1b8e51e662ea
+
+        Reviewed by Eric Carlson.
+
+        No new tests needed.
+
+        * Modules/mediastream/MediaStream.cpp:
+        (WebCore::MediaStream::addTrack):
+        (WebCore::MediaStream::removeTrack):
+        (WebCore::MediaStream::addRemoteTrack):
+        (WebCore::MediaStream::removeRemoteTrack):
+        * platform/mediastream/MediaStreamDescriptor.h:
+        (WebCore::MediaStreamDescriptor::addRemoteTrack):
+        (WebCore::MediaStreamDescriptor::removeRemoteTrack):
+        (WebCore::MediaStreamDescriptor::addComponent):
+        (WebCore::MediaStreamDescriptor::removeComponent):
+
 2013-09-10  Andreas Kling  <akling@apple.com>
 
         toFooElement() should use static_cast, not reinterpret_cast.
index d1a60a75da331ede30953d59298cb5d2248a8016..21c8fcdfc6895f9a8e74a426e71d8ea66dd5abfd 100644 (file)
@@ -155,15 +155,14 @@ void MediaStream::addTrack(PassRefPtr<MediaStreamTrack> prpTrack, ExceptionCode&
 
     switch (component->source()->type()) {
     case MediaStreamSource::TypeAudio:
-        m_descriptor->addAudioComponent(component.release());
         m_audioTracks.append(newTrack);
         break;
     case MediaStreamSource::TypeVideo:
-        m_descriptor->addVideoComponent(component.release());
         m_videoTracks.append(newTrack);
         break;
     }
 
+    m_descriptor->addComponent(component.release());
     MediaStreamCenter::instance().didAddMediaStreamTrack(m_descriptor.get(), newTrack->component());
 }
 
@@ -181,24 +180,24 @@ void MediaStream::removeTrack(PassRefPtr<MediaStreamTrack> prpTrack, ExceptionCo
 
     RefPtr<MediaStreamTrack> track = prpTrack;
 
+    size_t pos = notFound;
     switch (track->component()->source()->type()) {
-    case MediaStreamSource::TypeAudio: {
-        size_t pos = m_audioTracks.find(track);
-        if (pos != notFound) {
+    case MediaStreamSource::TypeAudio:
+        pos = m_audioTracks.find(track);
+        if (pos != notFound)
             m_audioTracks.remove(pos);
-            m_descriptor->removeAudioComponent(track->component());
-        }
         break;
-    }
-    case MediaStreamSource::TypeVideo: {
-        size_t pos = m_videoTracks.find(track);
-        if (pos != notFound) {
+    case MediaStreamSource::TypeVideo:
+        pos = m_videoTracks.find(track);
+        if (pos != notFound)
             m_videoTracks.remove(pos);
-            m_descriptor->removeVideoComponent(track->component());
-        }
         break;
     }
-    }
+
+    if (pos == notFound)
+        return;
+
+    m_descriptor->removeComponent(track->component());
 
     if (!m_audioTracks.size() && !m_videoTracks.size())
         m_descriptor->setEnded();
@@ -280,14 +279,13 @@ void MediaStream::addRemoteTrack(MediaStreamComponent* component)
     RefPtr<MediaStreamTrack> track = MediaStreamTrack::create(scriptExecutionContext(), component);
     switch (component->source()->type()) {
     case MediaStreamSource::TypeAudio:
-        m_descriptor->addAudioComponent(component);
         m_audioTracks.append(track);
         break;
     case MediaStreamSource::TypeVideo:
-        m_descriptor->addVideoComponent(component);
         m_videoTracks.append(track);
         break;
     }
+    m_descriptor->addComponent(component);
 
     scheduleDispatchEvent(MediaStreamTrackEvent::create(eventNames().addtrackEvent, false, false, track));
 }
@@ -317,14 +315,7 @@ void MediaStream::removeRemoteTrack(MediaStreamComponent* component)
     if (index == notFound)
         return;
 
-    switch (component->source()->type()) {
-    case MediaStreamSource::TypeAudio:
-        m_descriptor->removeAudioComponent(component);
-        break;
-    case MediaStreamSource::TypeVideo:
-        m_descriptor->removeAudioComponent(component);
-        break;
-    }
+    m_descriptor->removeComponent(component);
 
     RefPtr<MediaStreamTrack> track = (*tracks)[index];
     tracks->remove(index);
index f3b5a7c930f7dd3e8d067cebbeb2a39f20bdf8ac..3a0acba0d7cec8eca2663cc3a7fca46179392fdb 100644 (file)
@@ -74,34 +74,55 @@ public:
 
     unsigned numberOfAudioComponents() const { return m_audioComponents.size(); }
     MediaStreamComponent* audioComponent(unsigned index) const { return m_audioComponents[index].get(); }
-    void addAudioComponent(PassRefPtr<MediaStreamComponent> component) { m_audioComponents.append(component); }
-    void removeAudioComponent(MediaStreamComponent* component)
-    {
-        size_t pos = m_audioComponents.find(component);
-        if (pos != notFound)
-            m_audioComponents.remove(pos);
-    }
 
     void addRemoteTrack(MediaStreamComponent* component)
     {
         if (m_client)
             m_client->addRemoteTrack(component);
+        else
+            addComponent(component);
     }
 
     void removeRemoteTrack(MediaStreamComponent* component)
     {
         if (m_client)
             m_client->removeRemoteTrack(component);
+        else
+            removeComponent(component);
     }
 
     unsigned numberOfVideoComponents() const { return m_videoComponents.size(); }
     MediaStreamComponent* videoComponent(unsigned index) const { return m_videoComponents[index].get(); }
-    void addVideoComponent(PassRefPtr<MediaStreamComponent> component) { m_videoComponents.append(component); }
-    void removeVideoComponent(MediaStreamComponent* component)
+
+    void addComponent(PassRefPtr<MediaStreamComponent> component)
+    {
+        switch (component->source()->type()) {
+        case MediaStreamSource::TypeAudio:
+            if (m_audioComponents.find(component) == notFound)
+                m_audioComponents.append(component);
+            break;
+        case MediaStreamSource::TypeVideo:
+            if (m_videoComponents.find(component) == notFound)
+                m_videoComponents.append(component);
+            break;
+        }
+    }
+
+    void removeComponent(PassRefPtr<MediaStreamComponent> component)
     {
-        size_t pos = m_videoComponents.find(component);
-        if (pos != notFound)
-            m_videoComponents.remove(pos);
+        size_t pos = notFound;
+        switch (component->source()->type()) {
+        case MediaStreamSource::TypeAudio:
+            pos = m_audioComponents.find(component);
+            if (pos != notFound)
+                m_audioComponents.remove(pos);
+            break;
+        case MediaStreamSource::TypeVideo:
+            pos = m_videoComponents.find(component);
+            if (pos != notFound)
+                m_videoComponents.remove(pos);
+            break;
+        }
     }
 
     bool ended() const { return m_ended; }