xref: /aosp_15_r20/external/webrtc/pc/media_stream.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 
11 // This file contains the implementation of MediaStreamInterface interface.
12 
13 #ifndef PC_MEDIA_STREAM_H_
14 #define PC_MEDIA_STREAM_H_
15 
16 #include <string>
17 
18 #include "api/media_stream_interface.h"
19 #include "api/notifier.h"
20 #include "api/scoped_refptr.h"
21 
22 namespace webrtc {
23 
24 class MediaStream : public Notifier<MediaStreamInterface> {
25  public:
26   static rtc::scoped_refptr<MediaStream> Create(const std::string& id);
27 
id()28   std::string id() const override { return id_; }
29 
30   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;
34   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;
38 
GetAudioTracks()39   AudioTrackVector GetAudioTracks() override { return audio_tracks_; }
GetVideoTracks()40   VideoTrackVector GetVideoTracks() override { return video_tracks_; }
41 
42  protected:
43   explicit MediaStream(const std::string& id);
44 
45  private:
46   template <typename TrackVector, typename Track>
47   bool AddTrack(TrackVector* Tracks, rtc::scoped_refptr<Track> track);
48   template <typename TrackVector>
49   bool RemoveTrack(TrackVector* Tracks,
50                    rtc::scoped_refptr<MediaStreamTrackInterface> track);
51 
52   const std::string id_;
53   AudioTrackVector audio_tracks_;
54   VideoTrackVector video_tracks_;
55 };
56 
57 }  // namespace webrtc
58 
59 #endif  // PC_MEDIA_STREAM_H_
60