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
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
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.
34 #include "platform/mediastream/MediaStreamDescriptor.h"
36 #include "platform/UUID.h"
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
);
62 case MediaStreamSource::TypeVideo
:
63 if (m_videoComponents
.find(component
) == kNotFound
)
64 m_videoComponents
.append(component
);
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
);
76 m_audioComponents
.remove(pos
);
78 case MediaStreamSource::TypeVideo
:
79 pos
= m_videoComponents
.find(component
);
81 m_videoComponents
.remove(pos
);
86 void MediaStreamDescriptor::addRemoteTrack(MediaStreamComponent
* component
)
89 m_client
->addRemoteTrack(component
);
91 addComponent(component
);
94 void MediaStreamDescriptor::removeRemoteTrack(MediaStreamComponent
* component
)
97 m_client
->removeRemoteTrack(component
);
99 removeComponent(component
);
102 MediaStreamDescriptor::MediaStreamDescriptor(const String
& id
, const MediaStreamSourceVector
& audioSources
, const MediaStreamSourceVector
& videoSources
)
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
)
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
));