Thanks to visit codestin.com
Credit goes to webrtc.googlesource.com

blob: 648dff28ec985d2269ada30f84c731e1d6235810 [file] [log] [blame]
ossu7bb87ee2017-01-23 12:56:251/*
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
Steve Anton10542f22019-01-11 17:11:0011#ifndef PC_STREAM_COLLECTION_H_
12#define PC_STREAM_COLLECTION_H_
ossu7bb87ee2017-01-23 12:56:2513
Philipp Hancke59927372025-08-01 16:43:3214#include <cstddef>
ossu7bb87ee2017-01-23 12:56:2515#include <string>
Niels Möllere7cc8832022-01-04 14:20:0316#include <utility>
ossu7bb87ee2017-01-23 12:56:2517#include <vector>
18
Philipp Hancke59927372025-08-01 16:43:3219#include "api/make_ref_counted.h"
20#include "api/media_stream_interface.h"
Steve Anton10542f22019-01-11 17:11:0021#include "api/peer_connection_interface.h"
Philipp Hancke59927372025-08-01 16:43:3222#include "api/scoped_refptr.h"
ossu7bb87ee2017-01-23 12:56:2523
24namespace webrtc {
25
26// Implementation of StreamCollection.
27class StreamCollection : public StreamCollectionInterface {
28 public:
Evan Shrubsolee6a1f702025-04-15 14:55:4229 static scoped_refptr<StreamCollection> Create() {
30 return make_ref_counted<StreamCollection>();
ossu7bb87ee2017-01-23 12:56:2531 }
32
Evan Shrubsolee6a1f702025-04-15 14:55:4233 static scoped_refptr<StreamCollection> Create(StreamCollection* streams) {
34 return make_ref_counted<StreamCollection>(streams);
ossu7bb87ee2017-01-23 12:56:2535 }
36
Yves Gerey665174f2018-06-19 13:03:0537 virtual size_t count() { return media_streams_.size(); }
ossu7bb87ee2017-01-23 12:56:2538
39 virtual MediaStreamInterface* at(size_t index) {
Niels Möllerafb246b2022-04-20 12:26:5040 return media_streams_.at(index).get();
ossu7bb87ee2017-01-23 12:56:2541 }
42
Seth Hampson13b8bad2018-03-13 23:05:2843 virtual MediaStreamInterface* find(const std::string& id) {
ossu7bb87ee2017-01-23 12:56:2544 for (StreamVector::iterator it = media_streams_.begin();
45 it != media_streams_.end(); ++it) {
Seth Hampson13b8bad2018-03-13 23:05:2846 if ((*it)->id().compare(id) == 0) {
Niels Möllerafb246b2022-04-20 12:26:5047 return (*it).get();
ossu7bb87ee2017-01-23 12:56:2548 }
49 }
50 return NULL;
51 }
52
Yves Gerey665174f2018-06-19 13:03:0553 virtual MediaStreamTrackInterface* FindAudioTrack(const std::string& id) {
ossu7bb87ee2017-01-23 12:56:2554 for (size_t i = 0; i < media_streams_.size(); ++i) {
Niels Möllerafb246b2022-04-20 12:26:5055 MediaStreamTrackInterface* track =
56 media_streams_[i]->FindAudioTrack(id).get();
ossu7bb87ee2017-01-23 12:56:2557 if (track) {
58 return track;
59 }
60 }
61 return NULL;
62 }
63
Yves Gerey665174f2018-06-19 13:03:0564 virtual MediaStreamTrackInterface* FindVideoTrack(const std::string& id) {
ossu7bb87ee2017-01-23 12:56:2565 for (size_t i = 0; i < media_streams_.size(); ++i) {
Niels Möllerafb246b2022-04-20 12:26:5066 MediaStreamTrackInterface* track =
67 media_streams_[i]->FindVideoTrack(id).get();
ossu7bb87ee2017-01-23 12:56:2568 if (track) {
69 return track;
70 }
71 }
72 return NULL;
73 }
74
Evan Shrubsolee6a1f702025-04-15 14:55:4275 void AddStream(scoped_refptr<MediaStreamInterface> stream) {
ossu7bb87ee2017-01-23 12:56:2576 for (StreamVector::iterator it = media_streams_.begin();
77 it != media_streams_.end(); ++it) {
Seth Hampson13b8bad2018-03-13 23:05:2878 if ((*it)->id().compare(stream->id()) == 0)
ossu7bb87ee2017-01-23 12:56:2579 return;
80 }
Niels Möllere7cc8832022-01-04 14:20:0381 media_streams_.push_back(std::move(stream));
ossu7bb87ee2017-01-23 12:56:2582 }
83
84 void RemoveStream(MediaStreamInterface* remove_stream) {
85 for (StreamVector::iterator it = media_streams_.begin();
86 it != media_streams_.end(); ++it) {
Seth Hampson13b8bad2018-03-13 23:05:2887 if ((*it)->id().compare(remove_stream->id()) == 0) {
ossu7bb87ee2017-01-23 12:56:2588 media_streams_.erase(it);
89 break;
90 }
91 }
92 }
93
94 protected:
95 StreamCollection() {}
96 explicit StreamCollection(StreamCollection* original)
Yves Gerey665174f2018-06-19 13:03:0597 : media_streams_(original->media_streams_) {}
Evan Shrubsolee6a1f702025-04-15 14:55:4298 typedef std::vector<scoped_refptr<MediaStreamInterface> > StreamVector;
ossu7bb87ee2017-01-23 12:56:2599 StreamVector media_streams_;
100};
101
102} // namespace webrtc
103
Steve Anton10542f22019-01-11 17:11:00104#endif // PC_STREAM_COLLECTION_H_