blob: abb55f62a768442eb0c8935499fe4f8c241df7b2 [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
tkchin3784b4a2016-06-24 19:31:47 -070017#include "webrtc/api/mediastreaminterface.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010018#include "webrtc/api/notifier.h"
kjellander@webrtc.org7ffeab52016-02-26 22:46:09 +010019#include "webrtc/audio_sink.h"
Tommif888bb52015-12-12 01:37:01 +010020#include "webrtc/base/criticalsection.h"
21
22namespace rtc {
23struct Message;
24class Thread;
25} // namespace rtc
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000026
27namespace webrtc {
28
tkchin3784b4a2016-06-24 19:31:47 -070029class AudioProviderInterface;
30
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000031// This class implements the audio source used by the remote audio track.
32class RemoteAudioSource : public Notifier<AudioSourceInterface> {
33 public:
34 // Creates an instance of RemoteAudioSource.
Tommif888bb52015-12-12 01:37:01 +010035 static rtc::scoped_refptr<RemoteAudioSource> Create(
36 uint32_t ssrc,
tkchin3784b4a2016-06-24 19:31:47 -070037 AudioProviderInterface* provider);
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).
tkchin3784b4a2016-06-24 19:31:47 -070052 void Initialize(uint32_t ssrc, AudioProviderInterface* provider);
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);
tkchin3784b4a2016-06-24 19:31:47 -070064 void OnAudioProviderGone();
Tommif888bb52015-12-12 01:37:01 +010065
66 class MessageHandler;
67 void OnMessage(rtc::Message* msg);
68
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000069 AudioObserverList audio_observers_;
Tommif888bb52015-12-12 01:37:01 +010070 rtc::CriticalSection sink_lock_;
71 std::list<AudioTrackSinkInterface*> sinks_;
72 rtc::Thread* const main_thread_;
73 SourceState state_;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000074};
75
76} // namespace webrtc
77
Henrik Kjellander15583c12016-02-10 10:53:12 +010078#endif // WEBRTC_API_REMOTEAUDIOSOURCE_H_