blob: 28cd46fc5d77b3fb4b60f0374d21b7d6f6aa5b79 [file] [log] [blame]
ossu7bb87ee2017-01-23 12:56:251/*
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 17:11:0011#ifndef PC_STREAM_COLLECTION_H_
12#define PC_STREAM_COLLECTION_H_
ossu7bb87ee2017-01-23 12:56:2513
14#include <string>
15#include <vector>
16
Steve Anton10542f22019-01-11 17:11:0017#include "api/peer_connection_interface.h"
ossu7bb87ee2017-01-23 12:56:2518
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 13:03:0526 new rtc::RefCountedObject<StreamCollection>();
ossu7bb87ee2017-01-23 12:56:2527 return implementation;
28 }
29
30 static rtc::scoped_refptr<StreamCollection> Create(
31 StreamCollection* streams) {
32 rtc::RefCountedObject<StreamCollection>* implementation =
Yves Gerey665174f2018-06-19 13:03:0533 new rtc::RefCountedObject<StreamCollection>(streams);
ossu7bb87ee2017-01-23 12:56:2534 return implementation;
35 }
36
Yves Gerey665174f2018-06-19 13:03:0537 virtual size_t count() { return media_streams_.size(); }
ossu7bb87ee2017-01-23 12:56:2538
39 virtual MediaStreamInterface* at(size_t index) {
40 return media_streams_.at(index);
41 }
42
Seth Hampson13b8bad2018-03-13 23:05:2843 virtual MediaStreamInterface* find(const std::string& id) {
ossu7bb87ee2017-01-23 12:56:2544 for (StreamVector::iterator it = media_streams_.begin();
45 it != media_streams_.end(); ++it) {
Seth Hampson13b8bad2018-03-13 23:05:2846 if ((*it)->id().compare(id) == 0) {
ossu7bb87ee2017-01-23 12:56:2547 return (*it);
48 }
49 }
50 return NULL;
51 }
52
Yves Gerey665174f2018-06-19 13:03:0553 virtual MediaStreamTrackInterface* FindAudioTrack(const std::string& id) {
ossu7bb87ee2017-01-23 12:56:2554 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 13:03:0563 virtual MediaStreamTrackInterface* FindVideoTrack(const std::string& id) {
ossu7bb87ee2017-01-23 12:56:2564 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 23:05:2876 if ((*it)->id().compare(stream->id()) == 0)
ossu7bb87ee2017-01-23 12:56:2577 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 23:05:2885 if ((*it)->id().compare(remove_stream->id()) == 0) {
ossu7bb87ee2017-01-23 12:56:2586 media_streams_.erase(it);
87 break;
88 }
89 }
90 }
91
92 protected:
93 StreamCollection() {}
94 explicit StreamCollection(StreamCollection* original)
Yves Gerey665174f2018-06-19 13:03:0595 : media_streams_(original->media_streams_) {}
96 typedef std::vector<rtc::scoped_refptr<MediaStreamInterface> > StreamVector;
ossu7bb87ee2017-01-23 12:56:2597 StreamVector media_streams_;
98};
99
100} // namespace webrtc
101
Steve Anton10542f22019-01-11 17:11:00102#endif // PC_STREAM_COLLECTION_H_