• 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 CALL_AUDIO_RECEIVE_STREAM_H_
12 #define CALL_AUDIO_RECEIVE_STREAM_H_
13 
14 #include <map>
15 #include <memory>
16 #include <string>
17 #include <vector>
18 
19 #include "absl/types/optional.h"
20 #include "api/audio_codecs/audio_decoder_factory.h"
21 #include "api/call/transport.h"
22 #include "api/crypto/crypto_options.h"
23 #include "api/crypto/frame_decryptor_interface.h"
24 #include "api/frame_transformer_interface.h"
25 #include "api/rtp_parameters.h"
26 #include "api/scoped_refptr.h"
27 #include "api/transport/rtp/rtp_source.h"
28 #include "call/rtp_config.h"
29 
30 namespace webrtc {
31 class AudioSinkInterface;
32 
33 class AudioReceiveStream {
34  public:
35   struct Stats {
36     Stats();
37     ~Stats();
38     uint32_t remote_ssrc = 0;
39     int64_t payload_bytes_rcvd = 0;
40     int64_t header_and_padding_bytes_rcvd = 0;
41     uint32_t packets_rcvd = 0;
42     uint64_t fec_packets_received = 0;
43     uint64_t fec_packets_discarded = 0;
44     uint32_t packets_lost = 0;
45     std::string codec_name;
46     absl::optional<int> codec_payload_type;
47     uint32_t jitter_ms = 0;
48     uint32_t jitter_buffer_ms = 0;
49     uint32_t jitter_buffer_preferred_ms = 0;
50     uint32_t delay_estimate_ms = 0;
51     int32_t audio_level = -1;
52     // Stats below correspond to similarly-named fields in the WebRTC stats
53     // spec. https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
54     double total_output_energy = 0.0;
55     uint64_t total_samples_received = 0;
56     double total_output_duration = 0.0;
57     uint64_t concealed_samples = 0;
58     uint64_t silent_concealed_samples = 0;
59     uint64_t concealment_events = 0;
60     double jitter_buffer_delay_seconds = 0.0;
61     uint64_t jitter_buffer_emitted_count = 0;
62     double jitter_buffer_target_delay_seconds = 0.0;
63     uint64_t inserted_samples_for_deceleration = 0;
64     uint64_t removed_samples_for_acceleration = 0;
65     // Stats below DO NOT correspond directly to anything in the WebRTC stats
66     float expand_rate = 0.0f;
67     float speech_expand_rate = 0.0f;
68     float secondary_decoded_rate = 0.0f;
69     float secondary_discarded_rate = 0.0f;
70     float accelerate_rate = 0.0f;
71     float preemptive_expand_rate = 0.0f;
72     uint64_t delayed_packet_outage_samples = 0;
73     int32_t decoding_calls_to_silence_generator = 0;
74     int32_t decoding_calls_to_neteq = 0;
75     int32_t decoding_normal = 0;
76     // TODO(alexnarest): Consider decoding_neteq_plc for consistency
77     int32_t decoding_plc = 0;
78     int32_t decoding_codec_plc = 0;
79     int32_t decoding_cng = 0;
80     int32_t decoding_plc_cng = 0;
81     int32_t decoding_muted_output = 0;
82     int64_t capture_start_ntp_time_ms = 0;
83     // The timestamp at which the last packet was received, i.e. the time of the
84     // local clock when it was received - not the RTP timestamp of that packet.
85     // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp
86     absl::optional<int64_t> last_packet_received_timestamp_ms;
87     uint64_t jitter_buffer_flushes = 0;
88     double relative_packet_arrival_delay_seconds = 0.0;
89     int32_t interruption_count = 0;
90     int32_t total_interruption_duration_ms = 0;
91     // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-estimatedplayouttimestamp
92     absl::optional<int64_t> estimated_playout_ntp_timestamp_ms;
93   };
94 
95   struct Config {
96     Config();
97     ~Config();
98 
99     std::string ToString() const;
100 
101     // Receive-stream specific RTP settings.
102     struct Rtp {
103       Rtp();
104       ~Rtp();
105 
106       std::string ToString() const;
107 
108       // Synchronization source (stream identifier) to be received.
109       uint32_t remote_ssrc = 0;
110 
111       // Sender SSRC used for sending RTCP (such as receiver reports).
112       uint32_t local_ssrc = 0;
113 
114       // Enable feedback for send side bandwidth estimation.
115       // See
116       // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions
117       // for details.
118       bool transport_cc = false;
119 
120       // See NackConfig for description.
121       NackConfig nack;
122 
123       // RTP header extensions used for the received stream.
124       std::vector<RtpExtension> extensions;
125     } rtp;
126 
127     Transport* rtcp_send_transport = nullptr;
128 
129     // NetEq settings.
130     size_t jitter_buffer_max_packets = 200;
131     bool jitter_buffer_fast_accelerate = false;
132     int jitter_buffer_min_delay_ms = 0;
133     bool jitter_buffer_enable_rtx_handling = false;
134 
135     // Identifier for an A/V synchronization group. Empty string to disable.
136     // TODO(pbos): Synchronize streams in a sync group, not just one video
137     // stream to one audio stream. Tracked by issue webrtc:4762.
138     std::string sync_group;
139 
140     // Decoder specifications for every payload type that we can receive.
141     std::map<int, SdpAudioFormat> decoder_map;
142 
143     rtc::scoped_refptr<AudioDecoderFactory> decoder_factory;
144 
145     absl::optional<AudioCodecPairId> codec_pair_id;
146 
147     // Per PeerConnection crypto options.
148     webrtc::CryptoOptions crypto_options;
149 
150     // An optional custom frame decryptor that allows the entire frame to be
151     // decrypted in whatever way the caller choses. This is not required by
152     // default.
153     rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor;
154 
155     // An optional frame transformer used by insertable streams to transform
156     // encoded frames.
157     rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer;
158   };
159 
160   // Reconfigure the stream according to the Configuration.
161   virtual void Reconfigure(const Config& config) = 0;
162 
163   // Starts stream activity.
164   // When a stream is active, it can receive, process and deliver packets.
165   virtual void Start() = 0;
166   // Stops stream activity.
167   // When a stream is stopped, it can't receive, process or deliver packets.
168   virtual void Stop() = 0;
169 
170   virtual Stats GetStats() const = 0;
171 
172   // Sets an audio sink that receives unmixed audio from the receive stream.
173   // Ownership of the sink is managed by the caller.
174   // Only one sink can be set and passing a null sink clears an existing one.
175   // NOTE: Audio must still somehow be pulled through AudioTransport for audio
176   // to stream through this sink. In practice, this happens if mixed audio
177   // is being pulled+rendered and/or if audio is being pulled for the purposes
178   // of feeding to the AEC.
179   virtual void SetSink(AudioSinkInterface* sink) = 0;
180 
181   // Sets playback gain of the stream, applied when mixing, and thus after it
182   // is potentially forwarded to any attached AudioSinkInterface implementation.
183   virtual void SetGain(float gain) = 0;
184 
185   // Sets a base minimum for the playout delay. Base minimum delay sets lower
186   // bound on minimum delay value determining lower bound on playout delay.
187   //
188   // Returns true if value was successfully set, false overwise.
189   virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0;
190 
191   // Returns current value of base minimum delay in milliseconds.
192   virtual int GetBaseMinimumPlayoutDelayMs() const = 0;
193 
194   virtual std::vector<RtpSource> GetSources() const = 0;
195 
196  protected:
~AudioReceiveStream()197   virtual ~AudioReceiveStream() {}
198 };
199 }  // namespace webrtc
200 
201 #endif  // CALL_AUDIO_RECEIVE_STREAM_H_
202