blob: 4cc68f8047fd85167b27370371d09b191a0cfb95 [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/notifier.h"
kjellander@webrtc.org7ffeab52016-02-26 22:46:09 +010018#include "webrtc/audio_sink.h"
Tommif888bb52015-12-12 01:37:01 +010019#include "webrtc/base/criticalsection.h"
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070020#include "webrtc/pc/channel.h"
Tommif888bb52015-12-12 01:37:01 +010021
22namespace rtc {
23struct Message;
24class Thread;
25} // namespace rtc
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000026
27namespace webrtc {
28
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000029// 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 01:37:01 +010033 static rtc::scoped_refptr<RemoteAudioSource> Create(
34 uint32_t ssrc,
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070035 cricket::VoiceChannel* channel);
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000036
37 // MediaSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000038 MediaSourceInterface::SourceState state() const override;
tommi6eca7e32015-12-15 04:27:11 -080039 bool remote() const override;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000040
tommi6eca7e32015-12-15 04:27:11 -080041 void AddSink(AudioTrackSinkInterface* sink) override;
42 void RemoveSink(AudioTrackSinkInterface* sink) override;
Tommif888bb52015-12-12 01:37:01 +010043
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 16:30:35 -070050 void Initialize(uint32_t ssrc, cricket::VoiceChannel* channel);
Tommif888bb52015-12-12 01:37:01 +010051
52 private:
53 typedef std::list<AudioObserver*> AudioObserverList;
54
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000055 // AudioSourceInterface implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000056 void SetVolume(double volume) override;
57 void RegisterAudioObserver(AudioObserver* observer) override;
58 void UnregisterAudioObserver(AudioObserver* observer) override;
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000059
Tommif888bb52015-12-12 01:37:01 +010060 class Sink;
61 void OnData(const AudioSinkInterface::Data& audio);
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070062 void OnAudioChannelGone();
Tommif888bb52015-12-12 01:37:01 +010063
64 class MessageHandler;
65 void OnMessage(rtc::Message* msg);
66
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +000067 AudioObserverList audio_observers_;
Tommif888bb52015-12-12 01:37:01 +010068 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:49 +000072};
73
74} // namespace webrtc
75
Henrik Kjellander15583c12016-02-10 10:53:12 +010076#endif // WEBRTC_API_REMOTEAUDIOSOURCE_H_