| 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 | rtc::RefCountedObject<StreamCollection>* implementation = |
| 26 | new rtc::RefCountedObject<StreamCollection>(); |
| 27 | return implementation; |
| 28 | } |
| 29 |
| 30 | static rtc::scoped_refptr<StreamCollection> Create( |
| 31 | StreamCollection* streams) { |
| 32 | rtc::RefCountedObject<StreamCollection>* implementation = |
| 33 | new rtc::RefCountedObject<StreamCollection>(streams); |
| 34 | return implementation; |
| 35 | } |
| 36 |
| 37 | virtual size_t count() { return media_streams_.size(); } |
| 38 |
| 39 | virtual MediaStreamInterface* at(size_t index) { |
| 40 | return media_streams_.at(index); |
| 41 | } |
| 42 |
| 43 | virtual MediaStreamInterface* find(const std::string& id) { |
| 44 | for (StreamVector::iterator it = media_streams_.begin(); |
| 45 | it != media_streams_.end(); ++it) { |
| 46 | if ((*it)->id().compare(id) == 0) { |
| 47 | return (*it); |
| 48 | } |
| 49 | } |
| 50 | return NULL; |
| 51 | } |
| 52 |
| 53 | virtual MediaStreamTrackInterface* FindAudioTrack(const std::string& id) { |
| 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 |
| 63 | virtual MediaStreamTrackInterface* FindVideoTrack(const std::string& id) { |
| 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) { |
| 76 | if ((*it)->id().compare(stream->id()) == 0) |
| 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) { |
| 85 | if ((*it)->id().compare(remove_stream->id()) == 0) { |
| 86 | media_streams_.erase(it); |
| 87 | break; |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 |
| 92 | protected: |
| 93 | StreamCollection() {} |
| 94 | explicit StreamCollection(StreamCollection* original) |
| 95 | : media_streams_(original->media_streams_) {} |
| 96 | typedef std::vector<rtc::scoped_refptr<MediaStreamInterface> > StreamVector; |
| 97 | StreamVector media_streams_; |
| 98 | }; |
| 99 |
| 100 | } // namespace webrtc |
| 101 |
| 102 | #endif // PC_STREAM_COLLECTION_H_ |
| 103 |