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