remote_audio_source.h 2.4 KB

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