Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 1 | /* |
kjellander | 95ed4e6 | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2014 The WebRTC project authors. All Rights Reserved. |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 3 | * |
kjellander | 95ed4e6 | 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. |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 9 | */ |
| 10 | |
ossu | 25e4ac7 | 2017-01-23 12:56:25 | [diff] [blame] | 11 | #ifndef WEBRTC_PC_REMOTEAUDIOSOURCE_H_ |
| 12 | #define WEBRTC_PC_REMOTEAUDIOSOURCE_H_ |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 13 | |
| 14 | #include <list> |
| 15 | #include <string> |
| 16 | |
kjellander | cf82062 | 2016-08-31 14:33:05 | [diff] [blame] | 17 | #include "webrtc/api/call/audio_sink.h" |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 18 | #include "webrtc/api/notifier.h" |
Taylor Brandstetter | bc1f6bd | 2016-06-27 23:30:35 | [diff] [blame] | 19 | #include "webrtc/pc/channel.h" |
Edward Lemur | 76de83e | 2017-07-06 17:44:34 | [diff] [blame] | 20 | #include "webrtc/rtc_base/criticalsection.h" |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 21 | |
| 22 | namespace rtc { |
| 23 | struct Message; |
| 24 | class Thread; |
| 25 | } // namespace rtc |
| 26 | |
| 27 | namespace webrtc { |
| 28 | |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [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. |
| 33 | static rtc::scoped_refptr<RemoteAudioSource> Create( |
| 34 | uint32_t ssrc, |
Taylor Brandstetter | bc1f6bd | 2016-06-27 23:30:35 | [diff] [blame] | 35 | cricket::VoiceChannel* channel); |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 36 | |
| 37 | // MediaSourceInterface implementation. |
| 38 | MediaSourceInterface::SourceState state() const override; |
| 39 | bool remote() const override; |
| 40 | |
| 41 | void AddSink(AudioTrackSinkInterface* sink) override; |
| 42 | void RemoveSink(AudioTrackSinkInterface* sink) override; |
| 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 | bc1f6bd | 2016-06-27 23:30:35 | [diff] [blame] | 50 | void Initialize(uint32_t ssrc, cricket::VoiceChannel* channel); |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | typedef std::list<AudioObserver*> AudioObserverList; |
| 54 | |
| 55 | // AudioSourceInterface implementation. |
| 56 | void SetVolume(double volume) override; |
| 57 | void RegisterAudioObserver(AudioObserver* observer) override; |
| 58 | void UnregisterAudioObserver(AudioObserver* observer) override; |
| 59 | |
| 60 | class Sink; |
| 61 | void OnData(const AudioSinkInterface::Data& audio); |
Taylor Brandstetter | bc1f6bd | 2016-06-27 23:30:35 | [diff] [blame] | 62 | void OnAudioChannelGone(); |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 63 | |
| 64 | class MessageHandler; |
| 65 | void OnMessage(rtc::Message* msg); |
| 66 | |
| 67 | AudioObserverList audio_observers_; |
| 68 | rtc::CriticalSection sink_lock_; |
| 69 | std::list<AudioTrackSinkInterface*> sinks_; |
| 70 | rtc::Thread* const main_thread_; |
| 71 | SourceState state_; |
| 72 | }; |
| 73 | |
| 74 | } // namespace webrtc |
| 75 | |
ossu | 25e4ac7 | 2017-01-23 12:56:25 | [diff] [blame] | 76 | #endif // WEBRTC_PC_REMOTEAUDIOSOURCE_H_ |