• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2014 The WebRTC project authors. All Rights Reserved.
3  *
4  *  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.
9  */
10 
11 #ifndef PC_REMOTE_AUDIO_SOURCE_H_
12 #define PC_REMOTE_AUDIO_SOURCE_H_
13 
14 #include <list>
15 #include <string>
16 
17 #include "absl/types/optional.h"
18 #include "api/call/audio_sink.h"
19 #include "api/notifier.h"
20 #include "pc/channel.h"
21 #include "rtc_base/message_handler.h"
22 #include "rtc_base/synchronization/mutex.h"
23 
24 namespace rtc {
25 struct Message;
26 class Thread;
27 }  // namespace rtc
28 
29 namespace webrtc {
30 
31 // This class implements the audio source used by the remote audio track.
32 // This class works by configuring itself as a sink with the underlying media
33 // engine, then when receiving data will fan out to all added sinks.
34 class RemoteAudioSource : public Notifier<AudioSourceInterface>,
35                           rtc::MessageHandler {
36  public:
37   explicit RemoteAudioSource(rtc::Thread* worker_thread);
38 
39   // Register and unregister remote audio source with the underlying media
40   // engine.
41   void Start(cricket::VoiceMediaChannel* media_channel,
42              absl::optional<uint32_t> ssrc);
43   void Stop(cricket::VoiceMediaChannel* media_channel,
44             absl::optional<uint32_t> ssrc);
45 
46   // MediaSourceInterface implementation.
47   MediaSourceInterface::SourceState state() const override;
48   bool remote() const override;
49 
50   // AudioSourceInterface implementation.
51   void SetVolume(double volume) override;
52   void RegisterAudioObserver(AudioObserver* observer) override;
53   void UnregisterAudioObserver(AudioObserver* observer) override;
54 
55   void AddSink(AudioTrackSinkInterface* sink) override;
56   void RemoveSink(AudioTrackSinkInterface* sink) override;
57 
58  protected:
59   ~RemoteAudioSource() override;
60 
61  private:
62   // These are callbacks from the media engine.
63   class AudioDataProxy;
64   void OnData(const AudioSinkInterface::Data& audio);
65   void OnAudioChannelGone();
66 
67   void OnMessage(rtc::Message* msg) override;
68 
69   rtc::Thread* const main_thread_;
70   rtc::Thread* const worker_thread_;
71   std::list<AudioObserver*> audio_observers_;
72   Mutex sink_lock_;
73   std::list<AudioTrackSinkInterface*> sinks_;
74   SourceState state_;
75 };
76 
77 }  // namespace webrtc
78 
79 #endif  // PC_REMOTE_AUDIO_SOURCE_H_
80