stream_collection.h 3.0 KB

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