blob: 19ddca991f911271de64de3b5ec30f420257c56a [file] [log] [blame]
ossu7bb87ee2017-01-23 04:56:25 -08001/*
2 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef PC_STREAMCOLLECTION_H_
12#define PC_STREAMCOLLECTION_H_
ossu7bb87ee2017-01-23 04:56:25 -080013
14#include <string>
15#include <vector>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/peerconnectioninterface.h"
ossu7bb87ee2017-01-23 04:56:25 -080018
19namespace webrtc {
20
21// Implementation of StreamCollection.
22class StreamCollection : public StreamCollectionInterface {
23 public:
24 static rtc::scoped_refptr<StreamCollection> Create() {
25 rtc::RefCountedObject<StreamCollection>* implementation =
26 new rtc::RefCountedObject<StreamCollection>();
27 return implementation;
28 }
29
30 static rtc::scoped_refptr<StreamCollection> Create(
31 StreamCollection* streams) {
32 rtc::RefCountedObject<StreamCollection>* implementation =
33 new rtc::RefCountedObject<StreamCollection>(streams);
34 return implementation;
35 }
36
37 virtual size_t count() {
38 return media_streams_.size();
39 }
40
41 virtual MediaStreamInterface* at(size_t index) {
42 return media_streams_.at(index);
43 }
44
45 virtual MediaStreamInterface* find(const std::string& label) {
46 for (StreamVector::iterator it = media_streams_.begin();
47 it != media_streams_.end(); ++it) {
48 if ((*it)->label().compare(label) == 0) {
49 return (*it);
50 }
51 }
52 return NULL;
53 }
54
55 virtual MediaStreamTrackInterface* FindAudioTrack(
56 const std::string& id) {
57 for (size_t i = 0; i < media_streams_.size(); ++i) {
58 MediaStreamTrackInterface* track = media_streams_[i]->FindAudioTrack(id);
59 if (track) {
60 return track;
61 }
62 }
63 return NULL;
64 }
65
66 virtual MediaStreamTrackInterface* FindVideoTrack(
67 const std::string& id) {
68 for (size_t i = 0; i < media_streams_.size(); ++i) {
69 MediaStreamTrackInterface* track = media_streams_[i]->FindVideoTrack(id);
70 if (track) {
71 return track;
72 }
73 }
74 return NULL;
75 }
76
77 void AddStream(MediaStreamInterface* stream) {
78 for (StreamVector::iterator it = media_streams_.begin();
79 it != media_streams_.end(); ++it) {
80 if ((*it)->label().compare(stream->label()) == 0)
81 return;
82 }
83 media_streams_.push_back(stream);
84 }
85
86 void RemoveStream(MediaStreamInterface* remove_stream) {
87 for (StreamVector::iterator it = media_streams_.begin();
88 it != media_streams_.end(); ++it) {
89 if ((*it)->label().compare(remove_stream->label()) == 0) {
90 media_streams_.erase(it);
91 break;
92 }
93 }
94 }
95
96 protected:
97 StreamCollection() {}
98 explicit StreamCollection(StreamCollection* original)
99 : media_streams_(original->media_streams_) {
100 }
101 typedef std::vector<rtc::scoped_refptr<MediaStreamInterface> >
102 StreamVector;
103 StreamVector media_streams_;
104};
105
106} // namespace webrtc
107
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200108#endif // PC_STREAMCOLLECTION_H_