blob: 20e5d90cdd077fc7eaca4d1b468a0e6e6794db0f [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
Henrik Kjellander15583c12016-02-10 10:53:12 +010011#ifndef WEBRTC_API_REMOTEAUDIOSOURCE_H_
12#define WEBRTC_API_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
Henrik Kjellander15583c12016-02-10 10:53:12 +010017#include "webrtc/api/mediastreaminterface.h"
18#include "webrtc/api/notifier.h"
Tommif888bb52015-12-12 01:37:01 +010019#include "webrtc/audio/audio_sink.h"
20#include "webrtc/base/criticalsection.h"
kjellandera96e2d72016-02-04 23:52:28 -080021#include "webrtc/media/base/audiorenderer.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
Tommif888bb52015-12-12 01:37:01 +010030class AudioProviderInterface;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000031
32// This class implements the audio source used by the remote audio track.
33class RemoteAudioSource : public Notifier<AudioSourceInterface> {
34 public:
35 // Creates an instance of RemoteAudioSource.
Tommif888bb52015-12-12 01:37:01 +010036 static rtc::scoped_refptr<RemoteAudioSource> Create(
37 uint32_t ssrc,
38 AudioProviderInterface* provider);
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).
53 void Initialize(uint32_t ssrc, AudioProviderInterface* provider);
54
55 private:
56 typedef std::list<AudioObserver*> AudioObserverList;
57
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000058 // AudioSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000059 void SetVolume(double volume) override;
60 void RegisterAudioObserver(AudioObserver* observer) override;
61 void UnregisterAudioObserver(AudioObserver* observer) override;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000062
Tommif888bb52015-12-12 01:37:01 +010063 class Sink;
64 void OnData(const AudioSinkInterface::Data& audio);
65 void OnAudioProviderGone();
66
67 class MessageHandler;
68 void OnMessage(rtc::Message* msg);
69
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000070 AudioObserverList audio_observers_;
Tommif888bb52015-12-12 01:37:01 +010071 rtc::CriticalSection sink_lock_;
72 std::list<AudioTrackSinkInterface*> sinks_;
73 rtc::Thread* const main_thread_;
74 SourceState state_;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000075};
76
77} // namespace webrtc
78
Henrik Kjellander15583c12016-02-10 10:53:12 +010079#endif // WEBRTC_API_REMOTEAUDIOSOURCE_H_