blob: 3759d6fbc3148a09499d1a9fa25b615e49dd6eb5 [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
Mirko Bonadei92ea95e2017-09-15 04:47:3111#ifndef PC_REMOTEAUDIOSOURCE_H_
12#define PC_REMOTEAUDIOSOURCE_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"
20#include "rtc_base/criticalsection.h"
Tommif888bb52015-12-12 00:37:0121
22namespace rtc {
23struct Message;
24class Thread;
25} // namespace rtc
wu@webrtc.orgb9a088b2014-02-13 23:18:4926
27namespace webrtc {
28
wu@webrtc.orgb9a088b2014-02-13 23:18:4929// This class implements the audio source used by the remote audio track.
30class RemoteAudioSource : public Notifier<AudioSourceInterface> {
31 public:
32 // Creates an instance of RemoteAudioSource.
Tommif888bb52015-12-12 00:37:0133 static rtc::scoped_refptr<RemoteAudioSource> Create(
34 uint32_t ssrc,
Taylor Brandstetterba29c6a2016-06-27 23:30:3535 cricket::VoiceChannel* channel);
wu@webrtc.orgb9a088b2014-02-13 23:18:4936
37 // MediaSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:3538 MediaSourceInterface::SourceState state() const override;
tommi6eca7e32015-12-15 12:27:1139 bool remote() const override;
wu@webrtc.orgb9a088b2014-02-13 23:18:4940
tommi6eca7e32015-12-15 12:27:1141 void AddSink(AudioTrackSinkInterface* sink) override;
42 void RemoveSink(AudioTrackSinkInterface* sink) override;
Tommif888bb52015-12-12 00:37:0143
44 protected:
45 RemoteAudioSource();
46 ~RemoteAudioSource() override;
47
48 // Post construction initialize where we can do things like save a reference
49 // to ourselves (need to be fully constructed).
Taylor Brandstetterba29c6a2016-06-27 23:30:3550 void Initialize(uint32_t ssrc, cricket::VoiceChannel* channel);
Tommif888bb52015-12-12 00:37:0151
52 private:
53 typedef std::list<AudioObserver*> AudioObserverList;
54
wu@webrtc.orgb9a088b2014-02-13 23:18:4955 // AudioSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:3556 void SetVolume(double volume) override;
57 void RegisterAudioObserver(AudioObserver* observer) override;
58 void UnregisterAudioObserver(AudioObserver* observer) override;
wu@webrtc.orgb9a088b2014-02-13 23:18:4959
Tommif888bb52015-12-12 00:37:0160 class Sink;
61 void OnData(const AudioSinkInterface::Data& audio);
Taylor Brandstetterba29c6a2016-06-27 23:30:3562 void OnAudioChannelGone();
Tommif888bb52015-12-12 00:37:0163
64 class MessageHandler;
65 void OnMessage(rtc::Message* msg);
66
wu@webrtc.orgb9a088b2014-02-13 23:18:4967 AudioObserverList audio_observers_;
Tommif888bb52015-12-12 00:37:0168 rtc::CriticalSection sink_lock_;
69 std::list<AudioTrackSinkInterface*> sinks_;
70 rtc::Thread* const main_thread_;
71 SourceState state_;
wu@webrtc.orgb9a088b2014-02-13 23:18:4972};
73
74} // namespace webrtc
75
Mirko Bonadei92ea95e2017-09-15 04:47:3176#endif // PC_REMOTEAUDIOSOURCE_H_