1*d9f75844SAndroid Build Coastguard Worker /* 2*d9f75844SAndroid Build Coastguard Worker * Copyright 2014 The WebRTC project authors. All Rights Reserved. 3*d9f75844SAndroid Build Coastguard Worker * 4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license 5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source 6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found 7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may 8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree. 9*d9f75844SAndroid Build Coastguard Worker */ 10*d9f75844SAndroid Build Coastguard Worker 11*d9f75844SAndroid Build Coastguard Worker #ifndef PC_REMOTE_AUDIO_SOURCE_H_ 12*d9f75844SAndroid Build Coastguard Worker #define PC_REMOTE_AUDIO_SOURCE_H_ 13*d9f75844SAndroid Build Coastguard Worker 14*d9f75844SAndroid Build Coastguard Worker #include <stdint.h> 15*d9f75844SAndroid Build Coastguard Worker 16*d9f75844SAndroid Build Coastguard Worker #include <list> 17*d9f75844SAndroid Build Coastguard Worker #include <string> 18*d9f75844SAndroid Build Coastguard Worker 19*d9f75844SAndroid Build Coastguard Worker #include "absl/types/optional.h" 20*d9f75844SAndroid Build Coastguard Worker #include "api/call/audio_sink.h" 21*d9f75844SAndroid Build Coastguard Worker #include "api/media_stream_interface.h" 22*d9f75844SAndroid Build Coastguard Worker #include "api/notifier.h" 23*d9f75844SAndroid Build Coastguard Worker #include "api/task_queue/task_queue_base.h" 24*d9f75844SAndroid Build Coastguard Worker #include "media/base/media_channel.h" 25*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/synchronization/mutex.h" 26*d9f75844SAndroid Build Coastguard Worker 27*d9f75844SAndroid Build Coastguard Worker namespace webrtc { 28*d9f75844SAndroid Build Coastguard Worker 29*d9f75844SAndroid Build Coastguard Worker // This class implements the audio source used by the remote audio track. 30*d9f75844SAndroid Build Coastguard Worker // This class works by configuring itself as a sink with the underlying media 31*d9f75844SAndroid Build Coastguard Worker // engine, then when receiving data will fan out to all added sinks. 32*d9f75844SAndroid Build Coastguard Worker class RemoteAudioSource : public Notifier<AudioSourceInterface> { 33*d9f75844SAndroid Build Coastguard Worker public: 34*d9f75844SAndroid Build Coastguard Worker // In Unified Plan, receivers map to m= sections and their tracks and sources 35*d9f75844SAndroid Build Coastguard Worker // survive SSRCs being reconfigured. The life cycle of the remote audio source 36*d9f75844SAndroid Build Coastguard Worker // is associated with the life cycle of the m= section, and thus even if an 37*d9f75844SAndroid Build Coastguard Worker // audio channel is destroyed the RemoteAudioSource should kSurvive. 38*d9f75844SAndroid Build Coastguard Worker // 39*d9f75844SAndroid Build Coastguard Worker // In Plan B however, remote audio sources map 1:1 with an SSRCs and if an 40*d9f75844SAndroid Build Coastguard Worker // audio channel is destroyed, the RemoteAudioSource should kEnd. 41*d9f75844SAndroid Build Coastguard Worker enum class OnAudioChannelGoneAction { 42*d9f75844SAndroid Build Coastguard Worker kSurvive, 43*d9f75844SAndroid Build Coastguard Worker kEnd, 44*d9f75844SAndroid Build Coastguard Worker }; 45*d9f75844SAndroid Build Coastguard Worker 46*d9f75844SAndroid Build Coastguard Worker explicit RemoteAudioSource( 47*d9f75844SAndroid Build Coastguard Worker TaskQueueBase* worker_thread, 48*d9f75844SAndroid Build Coastguard Worker OnAudioChannelGoneAction on_audio_channel_gone_action); 49*d9f75844SAndroid Build Coastguard Worker 50*d9f75844SAndroid Build Coastguard Worker // Register and unregister remote audio source with the underlying media 51*d9f75844SAndroid Build Coastguard Worker // engine. 52*d9f75844SAndroid Build Coastguard Worker void Start(cricket::VoiceMediaChannel* media_channel, 53*d9f75844SAndroid Build Coastguard Worker absl::optional<uint32_t> ssrc); 54*d9f75844SAndroid Build Coastguard Worker void Stop(cricket::VoiceMediaChannel* media_channel, 55*d9f75844SAndroid Build Coastguard Worker absl::optional<uint32_t> ssrc); 56*d9f75844SAndroid Build Coastguard Worker void SetState(SourceState new_state); 57*d9f75844SAndroid Build Coastguard Worker 58*d9f75844SAndroid Build Coastguard Worker // MediaSourceInterface implementation. 59*d9f75844SAndroid Build Coastguard Worker MediaSourceInterface::SourceState state() const override; 60*d9f75844SAndroid Build Coastguard Worker bool remote() const override; 61*d9f75844SAndroid Build Coastguard Worker 62*d9f75844SAndroid Build Coastguard Worker // AudioSourceInterface implementation. 63*d9f75844SAndroid Build Coastguard Worker void SetVolume(double volume) override; 64*d9f75844SAndroid Build Coastguard Worker void RegisterAudioObserver(AudioObserver* observer) override; 65*d9f75844SAndroid Build Coastguard Worker void UnregisterAudioObserver(AudioObserver* observer) override; 66*d9f75844SAndroid Build Coastguard Worker 67*d9f75844SAndroid Build Coastguard Worker void AddSink(AudioTrackSinkInterface* sink) override; 68*d9f75844SAndroid Build Coastguard Worker void RemoveSink(AudioTrackSinkInterface* sink) override; 69*d9f75844SAndroid Build Coastguard Worker 70*d9f75844SAndroid Build Coastguard Worker protected: 71*d9f75844SAndroid Build Coastguard Worker ~RemoteAudioSource() override; 72*d9f75844SAndroid Build Coastguard Worker 73*d9f75844SAndroid Build Coastguard Worker private: 74*d9f75844SAndroid Build Coastguard Worker // These are callbacks from the media engine. 75*d9f75844SAndroid Build Coastguard Worker class AudioDataProxy; 76*d9f75844SAndroid Build Coastguard Worker 77*d9f75844SAndroid Build Coastguard Worker void OnData(const AudioSinkInterface::Data& audio); 78*d9f75844SAndroid Build Coastguard Worker void OnAudioChannelGone(); 79*d9f75844SAndroid Build Coastguard Worker 80*d9f75844SAndroid Build Coastguard Worker TaskQueueBase* const main_thread_; 81*d9f75844SAndroid Build Coastguard Worker TaskQueueBase* const worker_thread_; 82*d9f75844SAndroid Build Coastguard Worker const OnAudioChannelGoneAction on_audio_channel_gone_action_; 83*d9f75844SAndroid Build Coastguard Worker std::list<AudioObserver*> audio_observers_; 84*d9f75844SAndroid Build Coastguard Worker Mutex sink_lock_; 85*d9f75844SAndroid Build Coastguard Worker std::list<AudioTrackSinkInterface*> sinks_; 86*d9f75844SAndroid Build Coastguard Worker SourceState state_; 87*d9f75844SAndroid Build Coastguard Worker }; 88*d9f75844SAndroid Build Coastguard Worker 89*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc 90*d9f75844SAndroid Build Coastguard Worker 91*d9f75844SAndroid Build Coastguard Worker #endif // PC_REMOTE_AUDIO_SOURCE_H_ 92