audio_receive_stream.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (c) 2015 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 AUDIO_AUDIO_RECEIVE_STREAM_H_
  11. #define AUDIO_AUDIO_RECEIVE_STREAM_H_
  12. #include <memory>
  13. #include <vector>
  14. #include "api/audio/audio_mixer.h"
  15. #include "api/neteq/neteq_factory.h"
  16. #include "api/rtp_headers.h"
  17. #include "audio/audio_state.h"
  18. #include "call/audio_receive_stream.h"
  19. #include "call/syncable.h"
  20. #include "modules/rtp_rtcp/source/source_tracker.h"
  21. #include "rtc_base/thread_checker.h"
  22. #include "system_wrappers/include/clock.h"
  23. namespace webrtc {
  24. class PacketRouter;
  25. class ProcessThread;
  26. class RtcEventLog;
  27. class RtpPacketReceived;
  28. class RtpStreamReceiverControllerInterface;
  29. class RtpStreamReceiverInterface;
  30. namespace voe {
  31. class ChannelReceiveInterface;
  32. } // namespace voe
  33. namespace internal {
  34. class AudioSendStream;
  35. class AudioReceiveStream final : public webrtc::AudioReceiveStream,
  36. public AudioMixer::Source,
  37. public Syncable {
  38. public:
  39. AudioReceiveStream(Clock* clock,
  40. RtpStreamReceiverControllerInterface* receiver_controller,
  41. PacketRouter* packet_router,
  42. ProcessThread* module_process_thread,
  43. NetEqFactory* neteq_factory,
  44. const webrtc::AudioReceiveStream::Config& config,
  45. const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
  46. webrtc::RtcEventLog* event_log);
  47. // For unit tests, which need to supply a mock channel receive.
  48. AudioReceiveStream(
  49. Clock* clock,
  50. RtpStreamReceiverControllerInterface* receiver_controller,
  51. PacketRouter* packet_router,
  52. const webrtc::AudioReceiveStream::Config& config,
  53. const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
  54. webrtc::RtcEventLog* event_log,
  55. std::unique_ptr<voe::ChannelReceiveInterface> channel_receive);
  56. AudioReceiveStream() = delete;
  57. AudioReceiveStream(const AudioReceiveStream&) = delete;
  58. AudioReceiveStream& operator=(const AudioReceiveStream&) = delete;
  59. ~AudioReceiveStream() override;
  60. // webrtc::AudioReceiveStream implementation.
  61. void Reconfigure(const webrtc::AudioReceiveStream::Config& config) override;
  62. void Start() override;
  63. void Stop() override;
  64. webrtc::AudioReceiveStream::Stats GetStats(
  65. bool get_and_clear_legacy_stats) const override;
  66. void SetSink(AudioSinkInterface* sink) override;
  67. void SetGain(float gain) override;
  68. bool SetBaseMinimumPlayoutDelayMs(int delay_ms) override;
  69. int GetBaseMinimumPlayoutDelayMs() const override;
  70. std::vector<webrtc::RtpSource> GetSources() const override;
  71. // AudioMixer::Source
  72. AudioFrameInfo GetAudioFrameWithInfo(int sample_rate_hz,
  73. AudioFrame* audio_frame) override;
  74. int Ssrc() const override;
  75. int PreferredSampleRate() const override;
  76. // Syncable
  77. uint32_t id() const override;
  78. absl::optional<Syncable::Info> GetInfo() const override;
  79. bool GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
  80. int64_t* time_ms) const override;
  81. void SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
  82. int64_t time_ms) override;
  83. bool SetMinimumPlayoutDelay(int delay_ms) override;
  84. void AssociateSendStream(AudioSendStream* send_stream);
  85. void DeliverRtcp(const uint8_t* packet, size_t length);
  86. const webrtc::AudioReceiveStream::Config& config() const;
  87. const AudioSendStream* GetAssociatedSendStreamForTesting() const;
  88. private:
  89. static void ConfigureStream(AudioReceiveStream* stream,
  90. const Config& new_config,
  91. bool first_time);
  92. AudioState* audio_state() const;
  93. rtc::ThreadChecker worker_thread_checker_;
  94. rtc::ThreadChecker module_process_thread_checker_;
  95. webrtc::AudioReceiveStream::Config config_;
  96. rtc::scoped_refptr<webrtc::AudioState> audio_state_;
  97. const std::unique_ptr<voe::ChannelReceiveInterface> channel_receive_;
  98. SourceTracker source_tracker_;
  99. AudioSendStream* associated_send_stream_ = nullptr;
  100. bool playing_ RTC_GUARDED_BY(worker_thread_checker_) = false;
  101. std::unique_ptr<RtpStreamReceiverInterface> rtp_stream_receiver_;
  102. };
  103. } // namespace internal
  104. } // namespace webrtc
  105. #endif // AUDIO_AUDIO_RECEIVE_STREAM_H_