blob: bedad832025bfcaac3eca98a6f6d9d1f54973e84 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Henrik Kjellander15583c12016-02-10 10:53:12 +010011#ifndef WEBRTC_API_STREAMCOLLECTION_H_
12#define WEBRTC_API_STREAMCOLLECTION_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
14#include <string>
15#include <vector>
16
Henrik Kjellander15583c12016-02-10 10:53:12 +010017#include "webrtc/api/peerconnectioninterface.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018
19namespace webrtc {
20
21// Implementation of StreamCollection.
22class StreamCollection : public StreamCollectionInterface {
23 public:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000024 static rtc::scoped_refptr<StreamCollection> Create() {
25 rtc::RefCountedObject<StreamCollection>* implementation =
26 new rtc::RefCountedObject<StreamCollection>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027 return implementation;
28 }
29
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000030 static rtc::scoped_refptr<StreamCollection> Create(
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031 StreamCollection* streams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000032 rtc::RefCountedObject<StreamCollection>* implementation =
33 new rtc::RefCountedObject<StreamCollection>(streams);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034 return implementation;
35 }
36
37 virtual size_t count() {
38 return media_streams_.size();
39 }
40
41 virtual MediaStreamInterface* at(size_t index) {
42 return media_streams_.at(index);
43 }
44
45 virtual MediaStreamInterface* find(const std::string& label) {
46 for (StreamVector::iterator it = media_streams_.begin();
47 it != media_streams_.end(); ++it) {
48 if ((*it)->label().compare(label) == 0) {
49 return (*it);
50 }
51 }
52 return NULL;
53 }
54
55 virtual MediaStreamTrackInterface* FindAudioTrack(
56 const std::string& id) {
57 for (size_t i = 0; i < media_streams_.size(); ++i) {
58 MediaStreamTrackInterface* track = media_streams_[i]->FindAudioTrack(id);
59 if (track) {
60 return track;
61 }
62 }
63 return NULL;
64 }
65
66 virtual MediaStreamTrackInterface* FindVideoTrack(
67 const std::string& id) {
68 for (size_t i = 0; i < media_streams_.size(); ++i) {
69 MediaStreamTrackInterface* track = media_streams_[i]->FindVideoTrack(id);
70 if (track) {
71 return track;
72 }
73 }
74 return NULL;
75 }
76
77 void AddStream(MediaStreamInterface* stream) {
78 for (StreamVector::iterator it = media_streams_.begin();
79 it != media_streams_.end(); ++it) {
80 if ((*it)->label().compare(stream->label()) == 0)
81 return;
82 }
83 media_streams_.push_back(stream);
84 }
85
86 void RemoveStream(MediaStreamInterface* remove_stream) {
87 for (StreamVector::iterator it = media_streams_.begin();
88 it != media_streams_.end(); ++it) {
89 if ((*it)->label().compare(remove_stream->label()) == 0) {
90 media_streams_.erase(it);
91 break;
92 }
93 }
94 }
95
96 protected:
97 StreamCollection() {}
98 explicit StreamCollection(StreamCollection* original)
99 : media_streams_(original->media_streams_) {
100 }
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000101 typedef std::vector<rtc::scoped_refptr<MediaStreamInterface> >
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102 StreamVector;
103 StreamVector media_streams_;
104};
105
106} // namespace webrtc
107
Henrik Kjellander15583c12016-02-10 10:53:12 +0100108#endif // WEBRTC_API_STREAMCOLLECTION_H_