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