blob: d35fb04ed51cb993a52df4b182d2b66b7093e74b [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 Anton3b80aac2017-10-19 10:17:12 -070031class RemoteAudioSource : public Notifier<AudioSourceInterface>,
32 rtc::MessageHandler {
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000033 public:
34 // Creates an instance of RemoteAudioSource.
Tommif888bb52015-12-12 01:37:01 +010035 static rtc::scoped_refptr<RemoteAudioSource> Create(
36 uint32_t ssrc,
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070037 cricket::VoiceChannel* channel);
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000038
39 // MediaSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000040 MediaSourceInterface::SourceState state() const override;
tommi6eca7e32015-12-15 04:27:11 -080041 bool remote() const override;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000042
tommi6eca7e32015-12-15 04:27:11 -080043 void AddSink(AudioTrackSinkInterface* sink) override;
44 void RemoveSink(AudioTrackSinkInterface* sink) override;
Tommif888bb52015-12-12 01:37:01 +010045
46 protected:
47 RemoteAudioSource();
48 ~RemoteAudioSource() override;
49
50 // Post construction initialize where we can do things like save a reference
51 // to ourselves (need to be fully constructed).
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070052 void Initialize(uint32_t ssrc, cricket::VoiceChannel* channel);
Tommif888bb52015-12-12 01:37:01 +010053
54 private:
55 typedef std::list<AudioObserver*> AudioObserverList;
56
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000057 // AudioSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000058 void SetVolume(double volume) override;
59 void RegisterAudioObserver(AudioObserver* observer) override;
60 void UnregisterAudioObserver(AudioObserver* observer) override;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000061
Tommif888bb52015-12-12 01:37:01 +010062 class Sink;
63 void OnData(const AudioSinkInterface::Data& audio);
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070064 void OnAudioChannelGone();
Tommif888bb52015-12-12 01:37:01 +010065
Steve Anton3b80aac2017-10-19 10:17:12 -070066 void OnMessage(rtc::Message* msg) override;
Tommif888bb52015-12-12 01:37:01 +010067
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000068 AudioObserverList audio_observers_;
Tommif888bb52015-12-12 01:37:01 +010069 rtc::CriticalSection sink_lock_;
70 std::list<AudioTrackSinkInterface*> sinks_;
71 rtc::Thread* const main_thread_;
72 SourceState state_;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000073};
74
75} // namespace webrtc
76
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020077#endif // PC_REMOTEAUDIOSOURCE_H_