blob: 28cd46fc5d77b3fb4b60f0374d21b7d6f6aa5b79 [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
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef PC_STREAM_COLLECTION_H_
12#define PC_STREAM_COLLECTION_H_
ossu7bb87ee2017-01-23 04:56:25 -080013
14#include <string>
15#include <vector>
16
Steve Anton10542f22019-01-11 09:11:00 -080017#include "api/peer_connection_interface.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 =
Yves Gerey665174f2018-06-19 15:03:05 +020026 new rtc::RefCountedObject<StreamCollection>();
ossu7bb87ee2017-01-23 04:56:25 -080027 return implementation;
28 }
29
30 static rtc::scoped_refptr<StreamCollection> Create(
31 StreamCollection* streams) {
32 rtc::RefCountedObject<StreamCollection>* implementation =
Yves Gerey665174f2018-06-19 15:03:05 +020033 new rtc::RefCountedObject<StreamCollection>(streams);
ossu7bb87ee2017-01-23 04:56:25 -080034 return implementation;
35 }
36
Yves Gerey665174f2018-06-19 15:03:05 +020037 virtual size_t count() { return media_streams_.size(); }
ossu7bb87ee2017-01-23 04:56:25 -080038
39 virtual MediaStreamInterface* at(size_t index) {
40 return media_streams_.at(index);
41 }
42
Seth Hampson13b8bad2018-03-13 16:05:28 -070043 virtual MediaStreamInterface* find(const std::string& id) {
ossu7bb87ee2017-01-23 04:56:25 -080044 for (StreamVector::iterator it = media_streams_.begin();
45 it != media_streams_.end(); ++it) {
Seth Hampson13b8bad2018-03-13 16:05:28 -070046 if ((*it)->id().compare(id) == 0) {
ossu7bb87ee2017-01-23 04:56:25 -080047 return (*it);
48 }
49 }
50 return NULL;
51 }
52
Yves Gerey665174f2018-06-19 15:03:05 +020053 virtual MediaStreamTrackInterface* FindAudioTrack(const std::string& id) {
ossu7bb87ee2017-01-23 04:56:25 -080054 for (size_t i = 0; i < media_streams_.size(); ++i) {
55 MediaStreamTrackInterface* track = media_streams_[i]->FindAudioTrack(id);
56 if (track) {
57 return track;
58 }
59 }
60 return NULL;
61 }
62
Yves Gerey665174f2018-06-19 15:03:05 +020063 virtual MediaStreamTrackInterface* FindVideoTrack(const std::string& id) {
ossu7bb87ee2017-01-23 04:56:25 -080064 for (size_t i = 0; i < media_streams_.size(); ++i) {
65 MediaStreamTrackInterface* track = media_streams_[i]->FindVideoTrack(id);
66 if (track) {
67 return track;
68 }
69 }
70 return NULL;
71 }
72
73 void AddStream(MediaStreamInterface* stream) {
74 for (StreamVector::iterator it = media_streams_.begin();
75 it != media_streams_.end(); ++it) {
Seth Hampson13b8bad2018-03-13 16:05:28 -070076 if ((*it)->id().compare(stream->id()) == 0)
ossu7bb87ee2017-01-23 04:56:25 -080077 return;
78 }
79 media_streams_.push_back(stream);
80 }
81
82 void RemoveStream(MediaStreamInterface* remove_stream) {
83 for (StreamVector::iterator it = media_streams_.begin();
84 it != media_streams_.end(); ++it) {
Seth Hampson13b8bad2018-03-13 16:05:28 -070085 if ((*it)->id().compare(remove_stream->id()) == 0) {
ossu7bb87ee2017-01-23 04:56:25 -080086 media_streams_.erase(it);
87 break;
88 }
89 }
90 }
91
92 protected:
93 StreamCollection() {}
94 explicit StreamCollection(StreamCollection* original)
Yves Gerey665174f2018-06-19 15:03:05 +020095 : media_streams_(original->media_streams_) {}
96 typedef std::vector<rtc::scoped_refptr<MediaStreamInterface> > StreamVector;
ossu7bb87ee2017-01-23 04:56:25 -080097 StreamVector media_streams_;
98};
99
100} // namespace webrtc
101
Steve Anton10542f22019-01-11 09:11:00 -0800102#endif // PC_STREAM_COLLECTION_H_