• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 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_CHANNEL_RECEIVE_H_
12 #define AUDIO_CHANNEL_RECEIVE_H_
13 
14 #include <map>
15 #include <memory>
16 #include <utility>
17 #include <vector>
18 
19 #include "absl/types/optional.h"
20 #include "api/audio/audio_mixer.h"
21 #include "api/audio_codecs/audio_decoder_factory.h"
22 #include "api/call/audio_sink.h"
23 #include "api/call/transport.h"
24 #include "api/crypto/crypto_options.h"
25 #include "api/frame_transformer_interface.h"
26 #include "api/neteq/neteq_factory.h"
27 #include "api/transport/rtp/rtp_source.h"
28 #include "call/rtp_packet_sink_interface.h"
29 #include "call/syncable.h"
30 #include "modules/audio_coding/include/audio_coding_module_typedefs.h"
31 #include "modules/rtp_rtcp/source/source_tracker.h"
32 #include "system_wrappers/include/clock.h"
33 
34 // TODO(solenberg, nisse): This file contains a few NOLINT marks, to silence
35 // warnings about use of unsigned short.
36 // These need cleanup, in a separate cl.
37 
38 namespace rtc {
39 class TimestampWrapAroundHandler;
40 }
41 
42 namespace webrtc {
43 
44 class AudioDeviceModule;
45 class FrameDecryptorInterface;
46 class PacketRouter;
47 class RateLimiter;
48 class ReceiveStatistics;
49 class RtcEventLog;
50 class RtpPacketReceived;
51 class RtpRtcp;
52 
53 struct CallReceiveStatistics {
54   int cumulativeLost;
55   unsigned int jitterSamples;
56   int64_t payload_bytes_rcvd = 0;
57   int64_t header_and_padding_bytes_rcvd = 0;
58   int packetsReceived;
59   uint32_t nacks_sent = 0;
60   // The capture NTP time (in local timebase) of the first played out audio
61   // frame.
62   int64_t capture_start_ntp_time_ms_;
63   // The timestamp at which the last packet was received, i.e. the time of the
64   // local clock when it was received - not the RTP timestamp of that packet.
65   // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp
66   absl::optional<int64_t> last_packet_received_timestamp_ms;
67   // Remote outbound stats derived by the received RTCP sender reports.
68   // Note that the timestamps below correspond to the time elapsed since the
69   // Unix epoch.
70   // https://w3c.github.io/webrtc-stats/#remoteoutboundrtpstats-dict*
71   absl::optional<int64_t> last_sender_report_timestamp_ms;
72   absl::optional<int64_t> last_sender_report_remote_timestamp_ms;
73   uint32_t sender_reports_packets_sent = 0;
74   uint64_t sender_reports_bytes_sent = 0;
75   uint64_t sender_reports_reports_count = 0;
76   absl::optional<TimeDelta> round_trip_time;
77   TimeDelta total_round_trip_time = TimeDelta::Zero();
78   int round_trip_time_measurements;
79 };
80 
81 namespace voe {
82 
83 class ChannelSendInterface;
84 
85 // Interface class needed for AudioReceiveStreamInterface tests that use a
86 // MockChannelReceive.
87 
88 class ChannelReceiveInterface : public RtpPacketSinkInterface {
89  public:
90   virtual ~ChannelReceiveInterface() = default;
91 
92   virtual void SetSink(AudioSinkInterface* sink) = 0;
93 
94   virtual void SetReceiveCodecs(
95       const std::map<int, SdpAudioFormat>& codecs) = 0;
96 
97   virtual void StartPlayout() = 0;
98   virtual void StopPlayout() = 0;
99 
100   // Payload type and format of last received RTP packet, if any.
101   virtual absl::optional<std::pair<int, SdpAudioFormat>> GetReceiveCodec()
102       const = 0;
103 
104   virtual void ReceivedRTCPPacket(const uint8_t* data, size_t length) = 0;
105 
106   virtual void SetChannelOutputVolumeScaling(float scaling) = 0;
107   virtual int GetSpeechOutputLevelFullRange() const = 0;
108   // See description of "totalAudioEnergy" in the WebRTC stats spec:
109   // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
110   virtual double GetTotalOutputEnergy() const = 0;
111   virtual double GetTotalOutputDuration() const = 0;
112 
113   // Stats.
114   virtual NetworkStatistics GetNetworkStatistics(
115       bool get_and_clear_legacy_stats) const = 0;
116   virtual AudioDecodingCallStats GetDecodingCallStatistics() const = 0;
117 
118   // Audio+Video Sync.
119   virtual uint32_t GetDelayEstimate() const = 0;
120   virtual bool SetMinimumPlayoutDelay(int delay_ms) = 0;
121   virtual bool GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
122                                       int64_t* time_ms) const = 0;
123   virtual void SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
124                                                  int64_t time_ms) = 0;
125   virtual absl::optional<int64_t> GetCurrentEstimatedPlayoutNtpTimestampMs(
126       int64_t now_ms) const = 0;
127 
128   // Audio quality.
129   // Base minimum delay sets lower bound on minimum delay value which
130   // determines minimum delay until audio playout.
131   virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0;
132   virtual int GetBaseMinimumPlayoutDelayMs() const = 0;
133 
134   // Produces the transport-related timestamps; current_delay_ms is left unset.
135   virtual absl::optional<Syncable::Info> GetSyncInfo() const = 0;
136 
137   virtual void RegisterReceiverCongestionControlObjects(
138       PacketRouter* packet_router) = 0;
139   virtual void ResetReceiverCongestionControlObjects() = 0;
140 
141   virtual CallReceiveStatistics GetRTCPStatistics() const = 0;
142   virtual void SetNACKStatus(bool enable, int max_packets) = 0;
143   virtual void SetNonSenderRttMeasurement(bool enabled) = 0;
144 
145   virtual AudioMixer::Source::AudioFrameInfo GetAudioFrameWithInfo(
146       int sample_rate_hz,
147       AudioFrame* audio_frame) = 0;
148 
149   virtual int PreferredSampleRate() const = 0;
150 
151   // Sets the source tracker to notify about "delivered" packets when output is
152   // muted.
153   virtual void SetSourceTracker(SourceTracker* source_tracker) = 0;
154 
155   // Associate to a send channel.
156   // Used for obtaining RTT for a receive-only channel.
157   virtual void SetAssociatedSendChannel(
158       const ChannelSendInterface* channel) = 0;
159 
160   // Sets a frame transformer between the depacketizer and the decoder, to
161   // transform the received frames before decoding them.
162   virtual void SetDepacketizerToDecoderFrameTransformer(
163       rtc::scoped_refptr<webrtc::FrameTransformerInterface>
164           frame_transformer) = 0;
165 
166   virtual void SetFrameDecryptor(
167       rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor) = 0;
168 
169   virtual void OnLocalSsrcChange(uint32_t local_ssrc) = 0;
170   virtual uint32_t GetLocalSsrc() const = 0;
171 };
172 
173 std::unique_ptr<ChannelReceiveInterface> CreateChannelReceive(
174     Clock* clock,
175     NetEqFactory* neteq_factory,
176     AudioDeviceModule* audio_device_module,
177     Transport* rtcp_send_transport,
178     RtcEventLog* rtc_event_log,
179     uint32_t local_ssrc,
180     uint32_t remote_ssrc,
181     size_t jitter_buffer_max_packets,
182     bool jitter_buffer_fast_playout,
183     int jitter_buffer_min_delay_ms,
184     bool enable_non_sender_rtt,
185     rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
186     absl::optional<AudioCodecPairId> codec_pair_id,
187     rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor,
188     const webrtc::CryptoOptions& crypto_options,
189     rtc::scoped_refptr<FrameTransformerInterface> frame_transformer);
190 
191 }  // namespace voe
192 }  // namespace webrtc
193 
194 #endif  // AUDIO_CHANNEL_RECEIVE_H_
195