Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / mediastream / MediaStreamDescriptor.cpp
blob3e7e71b7d0e26950867ea632d51cdce210055476
1 /*
2 * Copyright (C) 2011 Ericsson AB. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "config.h"
34 #include "platform/mediastream/MediaStreamDescriptor.h"
36 #include "platform/UUID.h"
38 namespace blink {
40 PassRefPtr<MediaStreamDescriptor> MediaStreamDescriptor::create(const MediaStreamSourceVector& audioSources, const MediaStreamSourceVector& videoSources)
42 return adoptRef(new MediaStreamDescriptor(createCanonicalUUIDString(), audioSources, videoSources));
45 PassRefPtr<MediaStreamDescriptor> MediaStreamDescriptor::create(const MediaStreamComponentVector& audioComponents, const MediaStreamComponentVector& videoComponents)
47 return adoptRef(new MediaStreamDescriptor(createCanonicalUUIDString(), audioComponents, videoComponents));
50 PassRefPtr<MediaStreamDescriptor> MediaStreamDescriptor::create(const String& id, const MediaStreamComponentVector& audioComponents, const MediaStreamComponentVector& videoComponents)
52 return adoptRef(new MediaStreamDescriptor(id, audioComponents, videoComponents));
55 void MediaStreamDescriptor::addComponent(PassRefPtr<MediaStreamComponent> component)
57 switch (component->source()->type()) {
58 case MediaStreamSource::TypeAudio:
59 if (m_audioComponents.find(component) == kNotFound)
60 m_audioComponents.append(component);
61 break;
62 case MediaStreamSource::TypeVideo:
63 if (m_videoComponents.find(component) == kNotFound)
64 m_videoComponents.append(component);
65 break;
69 void MediaStreamDescriptor::removeComponent(PassRefPtr<MediaStreamComponent> component)
71 size_t pos = kNotFound;
72 switch (component->source()->type()) {
73 case MediaStreamSource::TypeAudio:
74 pos = m_audioComponents.find(component);
75 if (pos != kNotFound)
76 m_audioComponents.remove(pos);
77 break;
78 case MediaStreamSource::TypeVideo:
79 pos = m_videoComponents.find(component);
80 if (pos != kNotFound)
81 m_videoComponents.remove(pos);
82 break;
86 void MediaStreamDescriptor::addRemoteTrack(MediaStreamComponent* component)
88 if (m_client)
89 m_client->addRemoteTrack(component);
90 else
91 addComponent(component);
94 void MediaStreamDescriptor::removeRemoteTrack(MediaStreamComponent* component)
96 if (m_client)
97 m_client->removeRemoteTrack(component);
98 else
99 removeComponent(component);
102 MediaStreamDescriptor::MediaStreamDescriptor(const String& id, const MediaStreamSourceVector& audioSources, const MediaStreamSourceVector& videoSources)
103 : m_client(0)
104 , m_id(id)
105 , m_active(true)
106 , m_ended(false)
108 ASSERT(m_id.length());
109 for (size_t i = 0; i < audioSources.size(); i++)
110 m_audioComponents.append(MediaStreamComponent::create(audioSources[i]));
112 for (size_t i = 0; i < videoSources.size(); i++)
113 m_videoComponents.append(MediaStreamComponent::create(videoSources[i]));
116 MediaStreamDescriptor::MediaStreamDescriptor(const String& id, const MediaStreamComponentVector& audioComponents, const MediaStreamComponentVector& videoComponents)
117 : m_client(0)
118 , m_id(id)
119 , m_active(true)
120 , m_ended(false)
122 ASSERT(m_id.length());
123 for (MediaStreamComponentVector::const_iterator iter = audioComponents.begin(); iter != audioComponents.end(); ++iter)
124 m_audioComponents.append((*iter));
125 for (MediaStreamComponentVector::const_iterator iter = videoComponents.begin(); iter != videoComponents.end(); ++iter)
126 m_videoComponents.append((*iter));
129 } // namespace blink