blob: ed85947bf5b16a87b336e93e9d792b2067e09413 [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>
Niels Möllere7cc8832022-01-04 15:20:03 +010015#include <utility>
ossu7bb87ee2017-01-23 04:56:25 -080016#include <vector>
17
Steve Anton10542f22019-01-11 09:11:00 -080018#include "api/peer_connection_interface.h"
ossu7bb87ee2017-01-23 04:56:25 -080019
20namespace webrtc {
21
22// Implementation of StreamCollection.
23class StreamCollection : public StreamCollectionInterface {
24 public:
25 static rtc::scoped_refptr<StreamCollection> Create() {
Tommi87f70902021-04-27 14:43:08 +020026 return rtc::make_ref_counted<StreamCollection>();
ossu7bb87ee2017-01-23 04:56:25 -080027 }
28
29 static rtc::scoped_refptr<StreamCollection> Create(
30 StreamCollection* streams) {
Tommi87f70902021-04-27 14:43:08 +020031 return rtc::make_ref_counted<StreamCollection>(streams);
ossu7bb87ee2017-01-23 04:56:25 -080032 }
33
Yves Gerey665174f2018-06-19 15:03:05 +020034 virtual size_t count() { return media_streams_.size(); }
ossu7bb87ee2017-01-23 04:56:25 -080035
36 virtual MediaStreamInterface* at(size_t index) {
37 return media_streams_.at(index);
38 }
39
Seth Hampson13b8bad2018-03-13 16:05:28 -070040 virtual MediaStreamInterface* find(const std::string& id) {
ossu7bb87ee2017-01-23 04:56:25 -080041 for (StreamVector::iterator it = media_streams_.begin();
42 it != media_streams_.end(); ++it) {
Seth Hampson13b8bad2018-03-13 16:05:28 -070043 if ((*it)->id().compare(id) == 0) {
ossu7bb87ee2017-01-23 04:56:25 -080044 return (*it);
45 }
46 }
47 return NULL;
48 }
49
Yves Gerey665174f2018-06-19 15:03:05 +020050 virtual MediaStreamTrackInterface* FindAudioTrack(const std::string& id) {
ossu7bb87ee2017-01-23 04:56:25 -080051 for (size_t i = 0; i < media_streams_.size(); ++i) {
52 MediaStreamTrackInterface* track = media_streams_[i]->FindAudioTrack(id);
53 if (track) {
54 return track;
55 }
56 }
57 return NULL;
58 }
59
Yves Gerey665174f2018-06-19 15:03:05 +020060 virtual MediaStreamTrackInterface* FindVideoTrack(const std::string& id) {
ossu7bb87ee2017-01-23 04:56:25 -080061 for (size_t i = 0; i < media_streams_.size(); ++i) {
62 MediaStreamTrackInterface* track = media_streams_[i]->FindVideoTrack(id);
63 if (track) {
64 return track;
65 }
66 }
67 return NULL;
68 }
69
Niels Möllere7cc8832022-01-04 15:20:03 +010070 void AddStream(rtc::scoped_refptr<MediaStreamInterface> stream) {
ossu7bb87ee2017-01-23 04:56:25 -080071 for (StreamVector::iterator it = media_streams_.begin();
72 it != media_streams_.end(); ++it) {
Seth Hampson13b8bad2018-03-13 16:05:28 -070073 if ((*it)->id().compare(stream->id()) == 0)
ossu7bb87ee2017-01-23 04:56:25 -080074 return;
75 }
Niels Möllere7cc8832022-01-04 15:20:03 +010076 media_streams_.push_back(std::move(stream));
ossu7bb87ee2017-01-23 04:56:25 -080077 }
78
79 void RemoveStream(MediaStreamInterface* remove_stream) {
80 for (StreamVector::iterator it = media_streams_.begin();
81 it != media_streams_.end(); ++it) {
Seth Hampson13b8bad2018-03-13 16:05:28 -070082 if ((*it)->id().compare(remove_stream->id()) == 0) {
ossu7bb87ee2017-01-23 04:56:25 -080083 media_streams_.erase(it);
84 break;
85 }
86 }
87 }
88
89 protected:
90 StreamCollection() {}
91 explicit StreamCollection(StreamCollection* original)
Yves Gerey665174f2018-06-19 15:03:05 +020092 : media_streams_(original->media_streams_) {}
93 typedef std::vector<rtc::scoped_refptr<MediaStreamInterface> > StreamVector;
ossu7bb87ee2017-01-23 04:56:25 -080094 StreamVector media_streams_;
95};
96
97} // namespace webrtc
98
Steve Anton10542f22019-01-11 09:11:00 -080099#endif // PC_STREAM_COLLECTION_H_