blob: 399e7e3a4450ca34a8df3d0641541bd10915ca68 [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
Mirko Bonadei92ea95e2017-09-15 04:47:3117#include "api/call/audio_sink.h"
18#include "api/notifier.h"
19#include "pc/channel.h"
Steve Anton10542f22019-01-11 17:11:0020#include "rtc_base/critical_section.h"
21#include "rtc_base/message_handler.h"
Tommif888bb52015-12-12 00:37:0122
23namespace rtc {
24struct Message;
25class Thread;
26} // namespace rtc
wu@webrtc.orgb9a088b2014-02-13 23:18:4927
28namespace webrtc {
29
wu@webrtc.orgb9a088b2014-02-13 23:18:4930// This class implements the audio source used by the remote audio track.
Steve Antond3679212018-01-18 01:41:0231// 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 17:17:1233class RemoteAudioSource : public Notifier<AudioSourceInterface>,
34 rtc::MessageHandler {
wu@webrtc.orgb9a088b2014-02-13 23:18:4935 public:
Steve Antond3679212018-01-18 01:41:0236 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:4942
43 // MediaSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:3544 MediaSourceInterface::SourceState state() const override;
tommi6eca7e32015-12-15 12:27:1145 bool remote() const override;
wu@webrtc.orgb9a088b2014-02-13 23:18:4946
47 // AudioSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:3548 void SetVolume(double volume) override;
49 void RegisterAudioObserver(AudioObserver* observer) override;
50 void UnregisterAudioObserver(AudioObserver* observer) override;
wu@webrtc.orgb9a088b2014-02-13 23:18:4951
Steve Antond3679212018-01-18 01:41:0252 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 00:37:0161 void OnData(const AudioSinkInterface::Data& audio);
Taylor Brandstetterba29c6a2016-06-27 23:30:3562 void OnAudioChannelGone();
Tommif888bb52015-12-12 00:37:0163
Steve Anton3b80aac2017-10-19 17:17:1264 void OnMessage(rtc::Message* msg) override;
Tommif888bb52015-12-12 00:37:0165
Steve Antond3679212018-01-18 01:41:0266 rtc::Thread* const main_thread_;
67 rtc::Thread* const worker_thread_;
68 std::list<AudioObserver*> audio_observers_;
Tommif888bb52015-12-12 00:37:0169 rtc::CriticalSection sink_lock_;
70 std::list<AudioTrackSinkInterface*> sinks_;
Tommif888bb52015-12-12 00:37:0171 SourceState state_;
wu@webrtc.orgb9a088b2014-02-13 23:18:4972};
73
74} // namespace webrtc
75
Steve Anton10542f22019-01-11 17:11:0076#endif // PC_REMOTE_AUDIO_SOURCE_H_