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