blob: eadbccacc74d2ae8fb0e43873752a3a8da909efa [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(
Steve Anton60776752018-01-10 11:51:34 -080036 rtc::Thread* worker_thread,
37 cricket::VoiceMediaChannel* media_channel,
38 uint32_t ssrc);
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000039
40 // MediaSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000041 MediaSourceInterface::SourceState state() const override;
tommi6eca7e32015-12-15 04:27:11 -080042 bool remote() const override;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000043
tommi6eca7e32015-12-15 04:27:11 -080044 void AddSink(AudioTrackSinkInterface* sink) override;
45 void RemoveSink(AudioTrackSinkInterface* sink) override;
Tommif888bb52015-12-12 01:37:01 +010046
47 protected:
48 RemoteAudioSource();
49 ~RemoteAudioSource() override;
50
51 // Post construction initialize where we can do things like save a reference
52 // to ourselves (need to be fully constructed).
Steve Anton60776752018-01-10 11:51:34 -080053 void Initialize(rtc::Thread* worker_thread,
54 cricket::VoiceMediaChannel* media_channel,
55 uint32_t ssrc);
Tommif888bb52015-12-12 01:37:01 +010056
57 private:
58 typedef std::list<AudioObserver*> AudioObserverList;
59
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000060 // AudioSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000061 void SetVolume(double volume) override;
62 void RegisterAudioObserver(AudioObserver* observer) override;
63 void UnregisterAudioObserver(AudioObserver* observer) override;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000064
Tommif888bb52015-12-12 01:37:01 +010065 class Sink;
66 void OnData(const AudioSinkInterface::Data& audio);
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070067 void OnAudioChannelGone();
Tommif888bb52015-12-12 01:37:01 +010068
Steve Anton3b80aac2017-10-19 10:17:12 -070069 void OnMessage(rtc::Message* msg) override;
Tommif888bb52015-12-12 01:37:01 +010070
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000071 AudioObserverList audio_observers_;
Tommif888bb52015-12-12 01:37:01 +010072 rtc::CriticalSection sink_lock_;
73 std::list<AudioTrackSinkInterface*> sinks_;
74 rtc::Thread* const main_thread_;
75 SourceState state_;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000076};
77
78} // namespace webrtc
79
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020080#endif // PC_REMOTEAUDIOSOURCE_H_