blob: c033cf6f35f07d74438304feac4a003ea1a725e6 [file] [log] [blame]
ossu7bb87ee2017-01-23 04:56:25 -08001/*
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
11// This file contains the implementation of MediaStreamInterface interface.
12
Steve Anton10542f22019-01-11 09:11:00 -080013#ifndef PC_MEDIA_STREAM_H_
14#define PC_MEDIA_STREAM_H_
ossu7bb87ee2017-01-23 04:56:25 -080015
16#include <string>
ossu7bb87ee2017-01-23 04:56:25 -080017
Steve Anton10542f22019-01-11 09:11:00 -080018#include "api/media_stream_interface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/notifier.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010020#include "api/scoped_refptr.h"
ossu7bb87ee2017-01-23 04:56:25 -080021
22namespace webrtc {
23
24class MediaStream : public Notifier<MediaStreamInterface> {
25 public:
Seth Hampsona859c1a2018-03-30 17:09:43 -070026 static rtc::scoped_refptr<MediaStream> Create(const std::string& id);
ossu7bb87ee2017-01-23 04:56:25 -080027
Seth Hampson845e8782018-03-02 11:34:10 -080028 std::string id() const override { return id_; }
ossu7bb87ee2017-01-23 04:56:25 -080029
Harald Alvestrand2f7ad282022-04-21 11:35:43 +000030 bool AddTrack(rtc::scoped_refptr<AudioTrackInterface> track) override;
31 bool AddTrack(rtc::scoped_refptr<VideoTrackInterface> track) override;
32 bool RemoveTrack(rtc::scoped_refptr<AudioTrackInterface> track) override;
33 bool RemoveTrack(rtc::scoped_refptr<VideoTrackInterface> track) override;
Yves Gerey665174f2018-06-19 15:03:05 +020034 rtc::scoped_refptr<AudioTrackInterface> FindAudioTrack(
35 const std::string& track_id) override;
36 rtc::scoped_refptr<VideoTrackInterface> FindVideoTrack(
37 const std::string& track_id) override;
ossu7bb87ee2017-01-23 04:56:25 -080038
39 AudioTrackVector GetAudioTracks() override { return audio_tracks_; }
40 VideoTrackVector GetVideoTracks() override { return video_tracks_; }
41
42 protected:
Seth Hampsona859c1a2018-03-30 17:09:43 -070043 explicit MediaStream(const std::string& id);
ossu7bb87ee2017-01-23 04:56:25 -080044
45 private:
46 template <typename TrackVector, typename Track>
Niels Möllere7cc8832022-01-04 15:20:03 +010047 bool AddTrack(TrackVector* Tracks, rtc::scoped_refptr<Track> track);
ossu7bb87ee2017-01-23 04:56:25 -080048 template <typename TrackVector>
Harald Alvestrand2f7ad282022-04-21 11:35:43 +000049 bool RemoveTrack(TrackVector* Tracks,
50 rtc::scoped_refptr<MediaStreamTrackInterface> track);
ossu7bb87ee2017-01-23 04:56:25 -080051
Tomas Gunnarssonfc83cdc2020-09-10 13:04:50 +020052 const std::string id_;
ossu7bb87ee2017-01-23 04:56:25 -080053 AudioTrackVector audio_tracks_;
54 VideoTrackVector video_tracks_;
55};
56
57} // namespace webrtc
58
Steve Anton10542f22019-01-11 09:11:00 -080059#endif // PC_MEDIA_STREAM_H_