wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2014 The WebRTC project authors. All Rights Reserved. |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 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. |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #ifndef PC_REMOTE_AUDIO_SOURCE_H_ |
| 12 | #define PC_REMOTE_AUDIO_SOURCE_H_ |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 13 | |
| 14 | #include <list> |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 15 | #include <string> |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 16 | |
Saurav Das | 749f660 | 2019-12-04 17:31:36 | [diff] [blame] | 17 | #include "absl/types/optional.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 18 | #include "api/call/audio_sink.h" |
| 19 | #include "api/notifier.h" |
| 20 | #include "pc/channel.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 21 | #include "rtc_base/message_handler.h" |
Markus Handell | 6fcd0f8 | 2020-07-07 17:08:53 | [diff] [blame] | 22 | #include "rtc_base/synchronization/mutex.h" |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 23 | |
| 24 | namespace rtc { |
| 25 | struct Message; |
| 26 | class Thread; |
| 27 | } // namespace rtc |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 28 | |
| 29 | namespace webrtc { |
| 30 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 31 | // This class implements the audio source used by the remote audio track. |
Steve Anton | d367921 | 2018-01-18 01:41:02 | [diff] [blame] | 32 | // This class works by configuring itself as a sink with the underlying media |
| 33 | // engine, then when receiving data will fan out to all added sinks. |
Steve Anton | 3b80aac | 2017-10-19 17:17:12 | [diff] [blame] | 34 | class RemoteAudioSource : public Notifier<AudioSourceInterface>, |
| 35 | rtc::MessageHandler { |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 36 | public: |
Steve Anton | d367921 | 2018-01-18 01:41:02 | [diff] [blame] | 37 | explicit RemoteAudioSource(rtc::Thread* worker_thread); |
| 38 | |
| 39 | // Register and unregister remote audio source with the underlying media |
| 40 | // engine. |
Saurav Das | 749f660 | 2019-12-04 17:31:36 | [diff] [blame] | 41 | void Start(cricket::VoiceMediaChannel* media_channel, |
| 42 | absl::optional<uint32_t> ssrc); |
| 43 | void Stop(cricket::VoiceMediaChannel* media_channel, |
| 44 | absl::optional<uint32_t> ssrc); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 45 | |
| 46 | // MediaSourceInterface implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 47 | MediaSourceInterface::SourceState state() const override; |
tommi | 6eca7e3 | 2015-12-15 12:27:11 | [diff] [blame] | 48 | bool remote() const override; |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 49 | |
| 50 | // AudioSourceInterface implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 51 | void SetVolume(double volume) override; |
| 52 | void RegisterAudioObserver(AudioObserver* observer) override; |
| 53 | void UnregisterAudioObserver(AudioObserver* observer) override; |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 54 | |
Steve Anton | d367921 | 2018-01-18 01:41:02 | [diff] [blame] | 55 | void AddSink(AudioTrackSinkInterface* sink) override; |
| 56 | void RemoveSink(AudioTrackSinkInterface* sink) override; |
| 57 | |
| 58 | protected: |
| 59 | ~RemoteAudioSource() override; |
| 60 | |
| 61 | private: |
| 62 | // These are callbacks from the media engine. |
| 63 | class AudioDataProxy; |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 64 | void OnData(const AudioSinkInterface::Data& audio); |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 65 | void OnAudioChannelGone(); |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 66 | |
Steve Anton | 3b80aac | 2017-10-19 17:17:12 | [diff] [blame] | 67 | void OnMessage(rtc::Message* msg) override; |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 68 | |
Steve Anton | d367921 | 2018-01-18 01:41:02 | [diff] [blame] | 69 | rtc::Thread* const main_thread_; |
| 70 | rtc::Thread* const worker_thread_; |
| 71 | std::list<AudioObserver*> audio_observers_; |
Markus Handell | 6fcd0f8 | 2020-07-07 17:08:53 | [diff] [blame] | 72 | Mutex sink_lock_; |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 73 | std::list<AudioTrackSinkInterface*> sinks_; |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 74 | SourceState state_; |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | } // namespace webrtc |
| 78 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 79 | #endif // PC_REMOTE_AUDIO_SOURCE_H_ |