blob: 15dc75b5116bccea5aba7789da5b2ede233e8019 [file] [log] [blame]
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2014 The WebRTC project authors. All Rights Reserved.
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.orgb9a088b2014-02-13 23:18:49 +00009 */
10
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef PC_REMOTE_AUDIO_SOURCE_H_
12#define PC_REMOTE_AUDIO_SOURCE_H_
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000013
14#include <list>
Tommif888bb52015-12-12 01:37:01 +010015#include <string>
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000016
Saurav Das749f6602019-12-04 09:31:36 -080017#include "absl/types/optional.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "api/call/audio_sink.h"
19#include "api/notifier.h"
20#include "pc/channel.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "rtc_base/critical_section.h"
22#include "rtc_base/message_handler.h"
Tommif888bb52015-12-12 01:37:01 +010023
24namespace rtc {
25struct Message;
26class Thread;
27} // namespace rtc
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000028
29namespace webrtc {
30
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000031// This class implements the audio source used by the remote audio track.
Steve Antond3679212018-01-17 17:41:02 -080032// 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 Anton3b80aac2017-10-19 10:17:12 -070034class RemoteAudioSource : public Notifier<AudioSourceInterface>,
35 rtc::MessageHandler {
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000036 public:
Steve Antond3679212018-01-17 17:41:02 -080037 explicit RemoteAudioSource(rtc::Thread* worker_thread);
38
39 // Register and unregister remote audio source with the underlying media
40 // engine.
Saurav Das749f6602019-12-04 09:31:36 -080041 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.orgb9a088b2014-02-13 23:18:49 +000045
46 // MediaSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000047 MediaSourceInterface::SourceState state() const override;
tommi6eca7e32015-12-15 04:27:11 -080048 bool remote() const override;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000049
50 // AudioSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000051 void SetVolume(double volume) override;
52 void RegisterAudioObserver(AudioObserver* observer) override;
53 void UnregisterAudioObserver(AudioObserver* observer) override;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000054
Steve Antond3679212018-01-17 17:41:02 -080055 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;
Tommif888bb52015-12-12 01:37:01 +010064 void OnData(const AudioSinkInterface::Data& audio);
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070065 void OnAudioChannelGone();
Tommif888bb52015-12-12 01:37:01 +010066
Steve Anton3b80aac2017-10-19 10:17:12 -070067 void OnMessage(rtc::Message* msg) override;
Tommif888bb52015-12-12 01:37:01 +010068
Steve Antond3679212018-01-17 17:41:02 -080069 rtc::Thread* const main_thread_;
70 rtc::Thread* const worker_thread_;
71 std::list<AudioObserver*> audio_observers_;
Tommif888bb52015-12-12 01:37:01 +010072 rtc::CriticalSection sink_lock_;
73 std::list<AudioTrackSinkInterface*> sinks_;
Tommif888bb52015-12-12 01:37:01 +010074 SourceState state_;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000075};
76
77} // namespace webrtc
78
Steve Anton10542f22019-01-11 09:11:00 -080079#endif // PC_REMOTE_AUDIO_SOURCE_H_