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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef PC_REMOTEAUDIOSOURCE_H_ |
| 12 | #define PC_REMOTEAUDIOSOURCE_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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [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" |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 21 | |
| 22 | namespace rtc { |
| 23 | struct Message; |
| 24 | class Thread; |
| 25 | } // namespace rtc |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 29 | // This class implements the audio source used by the remote audio track. |
| 30 | class RemoteAudioSource : public Notifier<AudioSourceInterface> { |
| 31 | public: |
| 32 | // Creates an instance of RemoteAudioSource. |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 33 | static rtc::scoped_refptr<RemoteAudioSource> Create( |
| 34 | uint32_t ssrc, |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 35 | cricket::VoiceChannel* channel); |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 36 | |
| 37 | // MediaSourceInterface implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 38 | MediaSourceInterface::SourceState state() const override; |
tommi | 6eca7e3 | 2015-12-15 12:27:11 | [diff] [blame] | 39 | bool remote() const override; |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 40 | |
tommi | 6eca7e3 | 2015-12-15 12:27:11 | [diff] [blame] | 41 | void AddSink(AudioTrackSinkInterface* sink) override; |
| 42 | void RemoveSink(AudioTrackSinkInterface* sink) override; |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 43 | |
| 44 | protected: |
| 45 | RemoteAudioSource(); |
| 46 | ~RemoteAudioSource() override; |
| 47 | |
| 48 | // Post construction initialize where we can do things like save a reference |
| 49 | // to ourselves (need to be fully constructed). |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 50 | void Initialize(uint32_t ssrc, cricket::VoiceChannel* channel); |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | typedef std::list<AudioObserver*> AudioObserverList; |
| 54 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 55 | // AudioSourceInterface implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 56 | void SetVolume(double volume) override; |
| 57 | void RegisterAudioObserver(AudioObserver* observer) override; |
| 58 | void UnregisterAudioObserver(AudioObserver* observer) override; |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 59 | |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 60 | class Sink; |
| 61 | void OnData(const AudioSinkInterface::Data& audio); |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 62 | void OnAudioChannelGone(); |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 63 | |
| 64 | class MessageHandler; |
| 65 | void OnMessage(rtc::Message* msg); |
| 66 | |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 67 | AudioObserverList audio_observers_; |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 68 | rtc::CriticalSection sink_lock_; |
| 69 | std::list<AudioTrackSinkInterface*> sinks_; |
| 70 | rtc::Thread* const main_thread_; |
| 71 | SourceState state_; |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | } // namespace webrtc |
| 75 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 76 | #endif // PC_REMOTEAUDIOSOURCE_H_ |