blob: 9ec09165cff8a94bcfdc6dba582498991b0fd88b [file] [log] [blame]
wu@webrtc.orgb9a088b2014-02-13 23:18:491/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2014 The WebRTC project authors. All Rights Reserved.
wu@webrtc.orgb9a088b2014-02-13 23:18:493 *
kjellanderb24317b2016-02-10 15:54:434 * 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:499 */
10
Steve Anton10542f22019-01-11 17:11:0011#ifndef PC_REMOTE_AUDIO_SOURCE_H_
12#define PC_REMOTE_AUDIO_SOURCE_H_
wu@webrtc.orgb9a088b2014-02-13 23:18:4913
14#include <list>
Tommif888bb52015-12-12 00:37:0115#include <string>
wu@webrtc.orgb9a088b2014-02-13 23:18:4916
Saurav Das749f6602019-12-04 17:31:3617#include "absl/types/optional.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3118#include "api/call/audio_sink.h"
19#include "api/notifier.h"
20#include "pc/channel.h"
Steve Anton10542f22019-01-11 17:11:0021#include "rtc_base/message_handler.h"
Markus Handell6fcd0f82020-07-07 17:08:5322#include "rtc_base/synchronization/mutex.h"
Tommif888bb52015-12-12 00:37:0123
24namespace rtc {
25struct Message;
26class Thread;
27} // namespace rtc
wu@webrtc.orgb9a088b2014-02-13 23:18:4928
29namespace webrtc {
30
wu@webrtc.orgb9a088b2014-02-13 23:18:4931// This class implements the audio source used by the remote audio track.
Steve Antond3679212018-01-18 01:41:0232// 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 17:17:1234class RemoteAudioSource : public Notifier<AudioSourceInterface>,
35 rtc::MessageHandler {
wu@webrtc.orgb9a088b2014-02-13 23:18:4936 public:
Steve Antond3679212018-01-18 01:41:0237 explicit RemoteAudioSource(rtc::Thread* worker_thread);
38
39 // Register and unregister remote audio source with the underlying media
40 // engine.
Saurav Das749f6602019-12-04 17:31:3641 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:4945
46 // MediaSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:3547 MediaSourceInterface::SourceState state() const override;
tommi6eca7e32015-12-15 12:27:1148 bool remote() const override;
wu@webrtc.orgb9a088b2014-02-13 23:18:4949
50 // AudioSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:3551 void SetVolume(double volume) override;
52 void RegisterAudioObserver(AudioObserver* observer) override;
53 void UnregisterAudioObserver(AudioObserver* observer) override;
wu@webrtc.orgb9a088b2014-02-13 23:18:4954
Steve Antond3679212018-01-18 01:41:0255 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 00:37:0164 void OnData(const AudioSinkInterface::Data& audio);
Taylor Brandstetterba29c6a2016-06-27 23:30:3565 void OnAudioChannelGone();
Tommif888bb52015-12-12 00:37:0166
Steve Anton3b80aac2017-10-19 17:17:1267 void OnMessage(rtc::Message* msg) override;
Tommif888bb52015-12-12 00:37:0168
Steve Antond3679212018-01-18 01:41:0269 rtc::Thread* const main_thread_;
70 rtc::Thread* const worker_thread_;
71 std::list<AudioObserver*> audio_observers_;
Markus Handell6fcd0f82020-07-07 17:08:5372 Mutex sink_lock_;
Tommif888bb52015-12-12 00:37:0173 std::list<AudioTrackSinkInterface*> sinks_;
Tommif888bb52015-12-12 00:37:0174 SourceState state_;
wu@webrtc.orgb9a088b2014-02-13 23:18:4975};
76
77} // namespace webrtc
78
Steve Anton10542f22019-01-11 17:11:0079#endif // PC_REMOTE_AUDIO_SOURCE_H_