audio_receive_stream.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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/constructor_magic.h"
  22. #include "rtc_base/thread_checker.h"
  23. #include "system_wrappers/include/clock.h"
  24. namespace webrtc {
  25. class PacketRouter;
  26. class ProcessThread;
  27. class RtcEventLog;
  28. class RtpPacketReceived;
  29. class RtpStreamReceiverControllerInterface;
  30. class RtpStreamReceiverInterface;
  31. namespace voe {
  32. class ChannelReceiveInterface;
  33. } // namespace voe
  34. namespace internal {
  35. class AudioSendStream;
  36. class AudioReceiveStream final : public webrtc::AudioReceiveStream,
  37. public AudioMixer::Source,
  38. public Syncable {
  39. public:
  40. AudioReceiveStream(Clock* clock,
  41. RtpStreamReceiverControllerInterface* receiver_controller,
  42. PacketRouter* packet_router,
  43. ProcessThread* module_process_thread,
  44. NetEqFactory* neteq_factory,
  45. const webrtc::AudioReceiveStream::Config& config,
  46. const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
  47. webrtc::RtcEventLog* event_log);
  48. // For unit tests, which need to supply a mock channel receive.
  49. AudioReceiveStream(
  50. Clock* clock,
  51. RtpStreamReceiverControllerInterface* receiver_controller,
  52. PacketRouter* packet_router,
  53. const webrtc::AudioReceiveStream::Config& config,
  54. const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
  55. webrtc::RtcEventLog* event_log,
  56. std::unique_ptr<voe::ChannelReceiveInterface> channel_receive);
  57. ~AudioReceiveStream() override;
  58. // webrtc::AudioReceiveStream implementation.
  59. void Reconfigure(const webrtc::AudioReceiveStream::Config& config) override;
  60. void Start() override;
  61. void Stop() override;
  62. webrtc::AudioReceiveStream::Stats GetStats() const override;
  63. void SetSink(AudioSinkInterface* sink) override;
  64. void SetGain(float gain) override;
  65. bool SetBaseMinimumPlayoutDelayMs(int delay_ms) override;
  66. int GetBaseMinimumPlayoutDelayMs() const override;
  67. std::vector<webrtc::RtpSource> GetSources() const override;
  68. // TODO(nisse): We don't formally implement RtpPacketSinkInterface, and this
  69. // method shouldn't be needed. But it's currently used by the
  70. // AudioReceiveStreamTest.ReceiveRtpPacket unittest. Figure out if that test
  71. // shuld be refactored or deleted, and then delete this method.
  72. void OnRtpPacket(const RtpPacketReceived& packet);
  73. // AudioMixer::Source
  74. AudioFrameInfo GetAudioFrameWithInfo(int sample_rate_hz,
  75. AudioFrame* audio_frame) override;
  76. int Ssrc() const override;
  77. int PreferredSampleRate() const override;
  78. // Syncable
  79. uint32_t id() const override;
  80. absl::optional<Syncable::Info> GetInfo() const override;
  81. bool GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
  82. int64_t* time_ms) const override;
  83. void SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
  84. int64_t time_ms) override;
  85. void SetMinimumPlayoutDelay(int delay_ms) override;
  86. void AssociateSendStream(AudioSendStream* send_stream);
  87. void DeliverRtcp(const uint8_t* packet, size_t length);
  88. const webrtc::AudioReceiveStream::Config& config() const;
  89. const AudioSendStream* GetAssociatedSendStreamForTesting() const;
  90. private:
  91. static void ConfigureStream(AudioReceiveStream* stream,
  92. const Config& new_config,
  93. bool first_time);
  94. AudioState* audio_state() const;
  95. rtc::ThreadChecker worker_thread_checker_;
  96. rtc::ThreadChecker module_process_thread_checker_;
  97. webrtc::AudioReceiveStream::Config config_;
  98. rtc::scoped_refptr<webrtc::AudioState> audio_state_;
  99. const std::unique_ptr<voe::ChannelReceiveInterface> channel_receive_;
  100. SourceTracker source_tracker_;
  101. AudioSendStream* associated_send_stream_ = nullptr;
  102. bool playing_ RTC_GUARDED_BY(worker_thread_checker_) = false;
  103. std::unique_ptr<RtpStreamReceiverInterface> rtp_stream_receiver_;
  104. RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioReceiveStream);
  105. };
  106. } // namespace internal
  107. } // namespace webrtc
  108. #endif // AUDIO_AUDIO_RECEIVE_STREAM_H_