blob: 83bbd20994add968df6479b56183c7da2c46fd26 [file] [log] [blame]
Taylor Brandstettercf846ad2015-12-10 23:52:021/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
Taylor Brandstettercf846ad2015-12-10 23:52:023 *
kjellanderb24317b2016-02-10 15:54:434 * 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.
Taylor Brandstettercf846ad2015-12-10 23:52:029 */
10
Steve Anton10542f22019-01-11 17:11:0011#ifndef PC_MEDIA_STREAM_OBSERVER_H_
12#define PC_MEDIA_STREAM_OBSERVER_H_
Taylor Brandstettercf846ad2015-12-10 23:52:0213
Mirko Bonadei9ff450d2021-08-02 08:56:3314#include <functional>
15
Steve Anton10542f22019-01-11 17:11:0016#include "api/media_stream_interface.h"
Mirko Bonadeid9708072019-01-25 19:26:4817#include "api/scoped_refptr.h"
deadbeefeb459812015-12-16 03:24:4318
19namespace webrtc {
20
21// Helper class which will listen for changes to a stream and emit the
22// corresponding signals.
23class MediaStreamObserver : public ObserverInterface {
24 public:
Mirko Bonadei9ff450d2021-08-02 08:56:3325 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);
Mirko Bonadei2ffed6d2018-07-20 09:09:3235 ~MediaStreamObserver() override;
deadbeefeb459812015-12-16 03:24:4336
Niels Möllerafb246b2022-04-20 12:26:5037 const MediaStreamInterface* stream() const { return stream_.get(); }
deadbeefeb459812015-12-16 03:24:4338
39 void OnChanged() override;
40
deadbeefeb459812015-12-16 03:24:4341 private:
42 rtc::scoped_refptr<MediaStreamInterface> stream_;
43 AudioTrackVector cached_audio_tracks_;
44 VideoTrackVector cached_video_tracks_;
Mirko Bonadei9ff450d2021-08-02 08:56:3345 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_;
deadbeefeb459812015-12-16 03:24:4353};
54
55} // namespace webrtc
56
Steve Anton10542f22019-01-11 17:11:0057#endif // PC_MEDIA_STREAM_OBSERVER_H_