| 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 |
| 11 | #ifndef PC_STREAM_COLLECTION_H_ |
| 12 | #define PC_STREAM_COLLECTION_H_ |
| 13 |
| 14 | #include <string> |
| 15 | #include <utility> |
| 16 | #include <vector> |
| 17 |
| 18 | #include "api/peer_connection_interface.h" |
| 19 |
| 20 | namespace webrtc { |
| 21 |
| 22 | // Implementation of StreamCollection. |
| 23 | class StreamCollection : public StreamCollectionInterface { |
| 24 | public: |
| 25 | static rtc::scoped_refptr<StreamCollection> Create() { |
| 26 | return rtc::make_ref_counted<StreamCollection>(); |
| 27 | } |
| 28 |
| 29 | static rtc::scoped_refptr<StreamCollection> Create( |
| 30 | StreamCollection* streams) { |
| 31 | return rtc::make_ref_counted<StreamCollection>(streams); |
| 32 | } |
| 33 |
| 34 | virtual size_t count() { return media_streams_.size(); } |
| 35 |
| 36 | virtual MediaStreamInterface* at(size_t index) { |
| 37 | return media_streams_.at(index).get(); |
| 38 | } |
| 39 |
| 40 | virtual MediaStreamInterface* find(const std::string& id) { |
| 41 | for (StreamVector::iterator it = media_streams_.begin(); |
| 42 | it != media_streams_.end(); ++it) { |
| 43 | if ((*it)->id().compare(id) == 0) { |
| 44 | return (*it).get(); |
| 45 | } |
| 46 | } |
| 47 | return NULL; |
| 48 | } |
| 49 |
| 50 | virtual MediaStreamTrackInterface* FindAudioTrack(const std::string& id) { |
| 51 | for (size_t i = 0; i < media_streams_.size(); ++i) { |
| 52 | MediaStreamTrackInterface* track = |
| 53 | media_streams_[i]->FindAudioTrack(id).get(); |
| 54 | if (track) { |
| 55 | return track; |
| 56 | } |
| 57 | } |
| 58 | return NULL; |
| 59 | } |
| 60 |
| 61 | virtual MediaStreamTrackInterface* FindVideoTrack(const std::string& id) { |
| 62 | for (size_t i = 0; i < media_streams_.size(); ++i) { |
| 63 | MediaStreamTrackInterface* track = |
| 64 | media_streams_[i]->FindVideoTrack(id).get(); |
| 65 | if (track) { |
| 66 | return track; |
| 67 | } |
| 68 | } |
| 69 | return NULL; |
| 70 | } |
| 71 |
| 72 | void AddStream(rtc::scoped_refptr<MediaStreamInterface> stream) { |
| 73 | for (StreamVector::iterator it = media_streams_.begin(); |
| 74 | it != media_streams_.end(); ++it) { |
| 75 | if ((*it)->id().compare(stream->id()) == 0) |
| 76 | return; |
| 77 | } |
| 78 | media_streams_.push_back(std::move(stream)); |
| 79 | } |
| 80 |
| 81 | void RemoveStream(MediaStreamInterface* remove_stream) { |
| 82 | for (StreamVector::iterator it = media_streams_.begin(); |
| 83 | it != media_streams_.end(); ++it) { |
| 84 | if ((*it)->id().compare(remove_stream->id()) == 0) { |
| 85 | media_streams_.erase(it); |
| 86 | break; |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 |
| 91 | protected: |
| 92 | StreamCollection() {} |
| 93 | explicit StreamCollection(StreamCollection* original) |
| 94 | : media_streams_(original->media_streams_) {} |
| 95 | typedef std::vector<rtc::scoped_refptr<MediaStreamInterface> > StreamVector; |
| 96 | StreamVector media_streams_; |
| 97 | }; |
| 98 |
| 99 | } // namespace webrtc |
| 100 |
| 101 | #endif // PC_STREAM_COLLECTION_H_ |
| 102 |