blob: 2eae073272eb1f993cfbc5f388aeaba9ce1fdcce [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
Harald Alvestrand5761e7b2021-01-29 14:45:0814#include <stdint.h>
15
wu@webrtc.orgb9a088b2014-02-13 23:18:4916#include <list>
Tommif888bb52015-12-12 00:37:0117#include <string>
wu@webrtc.orgb9a088b2014-02-13 23:18:4918
Saurav Das749f6602019-12-04 17:31:3619#include "absl/types/optional.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3120#include "api/call/audio_sink.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0821#include "api/media_stream_interface.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3122#include "api/notifier.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0823#include "media/base/media_channel.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3124#include "pc/channel.h"
Steve Anton10542f22019-01-11 17:11:0025#include "rtc_base/message_handler.h"
Markus Handell6fcd0f82020-07-07 17:08:5326#include "rtc_base/synchronization/mutex.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0827#include "rtc_base/thread.h"
28#include "rtc_base/thread_message.h"
Tommif888bb52015-12-12 00:37:0129
30namespace rtc {
31struct Message;
32class Thread;
33} // namespace rtc
wu@webrtc.orgb9a088b2014-02-13 23:18:4934
35namespace webrtc {
36
wu@webrtc.orgb9a088b2014-02-13 23:18:4937// This class implements the audio source used by the remote audio track.
Steve Antond3679212018-01-18 01:41:0238// This class works by configuring itself as a sink with the underlying media
39// engine, then when receiving data will fan out to all added sinks.
Steve Anton3b80aac2017-10-19 17:17:1240class RemoteAudioSource : public Notifier<AudioSourceInterface>,
41 rtc::MessageHandler {
wu@webrtc.orgb9a088b2014-02-13 23:18:4942 public:
Henrik Boströmc335b0e2021-04-08 05:25:3843 // In Unified Plan, receivers map to m= sections and their tracks and sources
44 // survive SSRCs being reconfigured. The life cycle of the remote audio source
45 // is associated with the life cycle of the m= section, and thus even if an
46 // audio channel is destroyed the RemoteAudioSource should kSurvive.
47 //
48 // In Plan B however, remote audio sources map 1:1 with an SSRCs and if an
49 // audio channel is destroyed, the RemoteAudioSource should kEnd.
50 enum class OnAudioChannelGoneAction {
51 kSurvive,
52 kEnd,
53 };
54
55 explicit RemoteAudioSource(
56 rtc::Thread* worker_thread,
57 OnAudioChannelGoneAction on_audio_channel_gone_action);
Steve Antond3679212018-01-18 01:41:0258
59 // Register and unregister remote audio source with the underlying media
60 // engine.
Saurav Das749f6602019-12-04 17:31:3661 void Start(cricket::VoiceMediaChannel* media_channel,
62 absl::optional<uint32_t> ssrc);
63 void Stop(cricket::VoiceMediaChannel* media_channel,
64 absl::optional<uint32_t> ssrc);
Henrik Boströmc335b0e2021-04-08 05:25:3865 void SetState(SourceState new_state);
wu@webrtc.orgb9a088b2014-02-13 23:18:4966
67 // MediaSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:3568 MediaSourceInterface::SourceState state() const override;
tommi6eca7e32015-12-15 12:27:1169 bool remote() const override;
wu@webrtc.orgb9a088b2014-02-13 23:18:4970
71 // AudioSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:3572 void SetVolume(double volume) override;
73 void RegisterAudioObserver(AudioObserver* observer) override;
74 void UnregisterAudioObserver(AudioObserver* observer) override;
wu@webrtc.orgb9a088b2014-02-13 23:18:4975
Steve Antond3679212018-01-18 01:41:0276 void AddSink(AudioTrackSinkInterface* sink) override;
77 void RemoveSink(AudioTrackSinkInterface* sink) override;
78
79 protected:
80 ~RemoteAudioSource() override;
81
82 private:
83 // These are callbacks from the media engine.
84 class AudioDataProxy;
Harald Alvestrand5761e7b2021-01-29 14:45:0885
Tommif888bb52015-12-12 00:37:0186 void OnData(const AudioSinkInterface::Data& audio);
Taylor Brandstetterba29c6a2016-06-27 23:30:3587 void OnAudioChannelGone();
Tommif888bb52015-12-12 00:37:0188
Steve Anton3b80aac2017-10-19 17:17:1289 void OnMessage(rtc::Message* msg) override;
Tommif888bb52015-12-12 00:37:0190
Steve Antond3679212018-01-18 01:41:0291 rtc::Thread* const main_thread_;
92 rtc::Thread* const worker_thread_;
Henrik Boströmc335b0e2021-04-08 05:25:3893 const OnAudioChannelGoneAction on_audio_channel_gone_action_;
Steve Antond3679212018-01-18 01:41:0294 std::list<AudioObserver*> audio_observers_;
Markus Handell6fcd0f82020-07-07 17:08:5395 Mutex sink_lock_;
Tommif888bb52015-12-12 00:37:0196 std::list<AudioTrackSinkInterface*> sinks_;
Tommif888bb52015-12-12 00:37:0197 SourceState state_;
wu@webrtc.orgb9a088b2014-02-13 23:18:4998};
99
100} // namespace webrtc
101
Steve Anton10542f22019-01-11 17:11:00102#endif // PC_REMOTE_AUDIO_SOURCE_H_