blob: 4d87331f91dfb28a2fefe1d0190916aa267a73fc [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef PC_REMOTEAUDIOSOURCE_H_
12#define PC_REMOTEAUDIOSOURCE_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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/call/audio_sink.h"
18#include "api/notifier.h"
19#include "pc/channel.h"
20#include "rtc_base/criticalsection.h"
Steve Anton3b80aac2017-10-19 10:17:12 -070021#include "rtc_base/messagehandler.h"
Tommif888bb52015-12-12 01:37:01 +010022
23namespace rtc {
24struct Message;
25class Thread;
26} // namespace rtc
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000027
28namespace webrtc {
29
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000030// This class implements the audio source used by the remote audio track.
Steve Antond3679212018-01-17 17:41:02 -080031// This class works by configuring itself as a sink with the underlying media
32// engine, then when receiving data will fan out to all added sinks.
Steve Anton3b80aac2017-10-19 10:17:12 -070033class RemoteAudioSource : public Notifier<AudioSourceInterface>,
34 rtc::MessageHandler {
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000035 public:
Steve Antond3679212018-01-17 17:41:02 -080036 explicit RemoteAudioSource(rtc::Thread* worker_thread);
37
38 // Register and unregister remote audio source with the underlying media
39 // engine.
40 void Start(cricket::VoiceMediaChannel* media_channel, uint32_t ssrc);
41 void Stop(cricket::VoiceMediaChannel* media_channel, uint32_t ssrc);
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000042
43 // MediaSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000044 MediaSourceInterface::SourceState state() const override;
tommi6eca7e32015-12-15 04:27:11 -080045 bool remote() const override;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000046
47 // AudioSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000048 void SetVolume(double volume) override;
49 void RegisterAudioObserver(AudioObserver* observer) override;
50 void UnregisterAudioObserver(AudioObserver* observer) override;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000051
Steve Antond3679212018-01-17 17:41:02 -080052 void AddSink(AudioTrackSinkInterface* sink) override;
53 void RemoveSink(AudioTrackSinkInterface* sink) override;
54
55 protected:
56 ~RemoteAudioSource() override;
57
58 private:
59 // These are callbacks from the media engine.
60 class AudioDataProxy;
Tommif888bb52015-12-12 01:37:01 +010061 void OnData(const AudioSinkInterface::Data& audio);
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070062 void OnAudioChannelGone();
Tommif888bb52015-12-12 01:37:01 +010063
Steve Anton3b80aac2017-10-19 10:17:12 -070064 void OnMessage(rtc::Message* msg) override;
Tommif888bb52015-12-12 01:37:01 +010065
Steve Antond3679212018-01-17 17:41:02 -080066 rtc::Thread* const main_thread_;
67 rtc::Thread* const worker_thread_;
68 std::list<AudioObserver*> audio_observers_;
Tommif888bb52015-12-12 01:37:01 +010069 rtc::CriticalSection sink_lock_;
70 std::list<AudioTrackSinkInterface*> sinks_;
Tommif888bb52015-12-12 01:37:01 +010071 SourceState state_;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000072};
73
74} // namespace webrtc
75
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020076#endif // PC_REMOTEAUDIOSOURCE_H_