xref: /aosp_15_r20/external/webrtc/pc/media_stream_observer.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2015 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 #ifndef PC_MEDIA_STREAM_OBSERVER_H_
12 #define PC_MEDIA_STREAM_OBSERVER_H_
13 
14 #include <functional>
15 
16 #include "api/media_stream_interface.h"
17 #include "api/scoped_refptr.h"
18 
19 namespace webrtc {
20 
21 // Helper class which will listen for changes to a stream and emit the
22 // corresponding signals.
23 class MediaStreamObserver : public ObserverInterface {
24  public:
25   explicit MediaStreamObserver(
26       MediaStreamInterface* stream,
27       std::function<void(AudioTrackInterface*, MediaStreamInterface*)>
28           audio_track_added_callback,
29       std::function<void(AudioTrackInterface*, MediaStreamInterface*)>
30           audio_track_removed_callback,
31       std::function<void(VideoTrackInterface*, MediaStreamInterface*)>
32           video_track_added_callback,
33       std::function<void(VideoTrackInterface*, MediaStreamInterface*)>
34           video_track_removed_callback);
35   ~MediaStreamObserver() override;
36 
stream()37   const MediaStreamInterface* stream() const { return stream_.get(); }
38 
39   void OnChanged() override;
40 
41  private:
42   rtc::scoped_refptr<MediaStreamInterface> stream_;
43   AudioTrackVector cached_audio_tracks_;
44   VideoTrackVector cached_video_tracks_;
45   const std::function<void(AudioTrackInterface*, MediaStreamInterface*)>
46       audio_track_added_callback_;
47   const std::function<void(AudioTrackInterface*, MediaStreamInterface*)>
48       audio_track_removed_callback_;
49   const std::function<void(VideoTrackInterface*, MediaStreamInterface*)>
50       video_track_added_callback_;
51   const std::function<void(VideoTrackInterface*, MediaStreamInterface*)>
52       video_track_removed_callback_;
53 };
54 
55 }  // namespace webrtc
56 
57 #endif  // PC_MEDIA_STREAM_OBSERVER_H_
58