ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 1 | /* |
| 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 Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #ifndef PC_STREAM_COLLECTION_H_ |
| 12 | #define PC_STREAM_COLLECTION_H_ |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 13 | |
| 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 17 | #include "api/peer_connection_interface.h" |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | // Implementation of StreamCollection. |
| 22 | class StreamCollection : public StreamCollectionInterface { |
| 23 | public: |
| 24 | static rtc::scoped_refptr<StreamCollection> Create() { |
| 25 | rtc::RefCountedObject<StreamCollection>* implementation = |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 26 | new rtc::RefCountedObject<StreamCollection>(); |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 27 | return implementation; |
| 28 | } |
| 29 | |
| 30 | static rtc::scoped_refptr<StreamCollection> Create( |
| 31 | StreamCollection* streams) { |
| 32 | rtc::RefCountedObject<StreamCollection>* implementation = |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 33 | new rtc::RefCountedObject<StreamCollection>(streams); |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 34 | return implementation; |
| 35 | } |
| 36 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 37 | virtual size_t count() { return media_streams_.size(); } |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 38 | |
| 39 | virtual MediaStreamInterface* at(size_t index) { |
| 40 | return media_streams_.at(index); |
| 41 | } |
| 42 | |
Seth Hampson | 13b8bad | 2018-03-13 23:05:28 | [diff] [blame] | 43 | virtual MediaStreamInterface* find(const std::string& id) { |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 44 | for (StreamVector::iterator it = media_streams_.begin(); |
| 45 | it != media_streams_.end(); ++it) { |
Seth Hampson | 13b8bad | 2018-03-13 23:05:28 | [diff] [blame] | 46 | if ((*it)->id().compare(id) == 0) { |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 47 | return (*it); |
| 48 | } |
| 49 | } |
| 50 | return NULL; |
| 51 | } |
| 52 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 53 | virtual MediaStreamTrackInterface* FindAudioTrack(const std::string& id) { |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 54 | 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 Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 63 | virtual MediaStreamTrackInterface* FindVideoTrack(const std::string& id) { |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 64 | 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 Hampson | 13b8bad | 2018-03-13 23:05:28 | [diff] [blame] | 76 | if ((*it)->id().compare(stream->id()) == 0) |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 77 | 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 Hampson | 13b8bad | 2018-03-13 23:05:28 | [diff] [blame] | 85 | if ((*it)->id().compare(remove_stream->id()) == 0) { |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 86 | media_streams_.erase(it); |
| 87 | break; |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | protected: |
| 93 | StreamCollection() {} |
| 94 | explicit StreamCollection(StreamCollection* original) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 95 | : media_streams_(original->media_streams_) {} |
| 96 | typedef std::vector<rtc::scoped_refptr<MediaStreamInterface> > StreamVector; |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 97 | StreamVector media_streams_; |
| 98 | }; |
| 99 | |
| 100 | } // namespace webrtc |
| 101 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 102 | #endif // PC_STREAM_COLLECTION_H_ |