tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

audio_receive_stream.h (9186B)


      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 <cstddef>
     15 #include <cstdint>
     16 #include <map>
     17 #include <optional>
     18 #include <string>
     19 
     20 #include "api/audio/audio_mixer.h"
     21 #include "api/audio_codecs/audio_codec_pair_id.h"
     22 #include "api/audio_codecs/audio_decoder_factory.h"
     23 #include "api/audio_codecs/audio_format.h"
     24 #include "api/call/transport.h"
     25 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
     26 #include "api/crypto/crypto_options.h"
     27 #include "api/crypto/frame_decryptor_interface.h"
     28 #include "api/frame_transformer_interface.h"
     29 #include "api/rtp_headers.h"
     30 #include "api/scoped_refptr.h"
     31 #include "api/units/time_delta.h"
     32 #include "api/units/timestamp.h"
     33 #include "call/receive_stream.h"
     34 #include "call/rtp_config.h"
     35 
     36 namespace webrtc {
     37 class AudioSinkInterface;
     38 
     39 class AudioReceiveStreamInterface : public MediaReceiveStreamInterface {
     40 public:
     41  struct Stats {
     42    Stats();
     43    ~Stats();
     44    uint32_t remote_ssrc = 0;
     45    int64_t payload_bytes_received = 0;
     46    int64_t header_and_padding_bytes_received = 0;
     47    uint32_t packets_received = 0;
     48    // https://w3c.github.io/webrtc-stats/#dom-rtcreceivedrtpstreamstats-packetsreceivedwithect1
     49    int64_t packets_received_with_ect1 = 0;
     50    // https://w3c.github.io/webrtc-stats/#dom-rtcreceivedrtpstreamstats-packetsreceivedwithce
     51    int64_t packets_received_with_ce = 0;
     52    uint64_t fec_packets_received = 0;
     53    uint64_t fec_packets_discarded = 0;
     54    int32_t packets_lost = 0;
     55    uint64_t packets_discarded = 0;
     56    uint32_t nacks_sent = 0;
     57    std::string codec_name;
     58    std::optional<int> codec_payload_type;
     59    uint32_t jitter_ms = 0;
     60    uint32_t jitter_buffer_ms = 0;
     61    uint32_t jitter_buffer_preferred_ms = 0;
     62    uint32_t delay_estimate_ms = 0;
     63    int32_t audio_level = -1;
     64    // Stats below correspond to similarly-named fields in the WebRTC stats
     65    // spec. https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats
     66    double total_output_energy = 0.0;
     67    uint64_t total_samples_received = 0;
     68    double total_output_duration = 0.0;
     69    uint64_t concealed_samples = 0;
     70    uint64_t silent_concealed_samples = 0;
     71    uint64_t concealment_events = 0;
     72    double jitter_buffer_delay_seconds = 0.0;
     73    uint64_t jitter_buffer_emitted_count = 0;
     74    double jitter_buffer_target_delay_seconds = 0.0;
     75    double jitter_buffer_minimum_delay_seconds = 0.0;
     76    uint64_t inserted_samples_for_deceleration = 0;
     77    uint64_t removed_samples_for_acceleration = 0;
     78    double total_processing_delay_seconds = 0.0;
     79    // Stats below DO NOT correspond directly to anything in the WebRTC stats
     80    float expand_rate = 0.0f;
     81    float speech_expand_rate = 0.0f;
     82    float secondary_decoded_rate = 0.0f;
     83    float secondary_discarded_rate = 0.0f;
     84    float accelerate_rate = 0.0f;
     85    float preemptive_expand_rate = 0.0f;
     86    uint64_t delayed_packet_outage_samples = 0;
     87    int32_t decoding_calls_to_silence_generator = 0;
     88    int32_t decoding_calls_to_neteq = 0;
     89    int32_t decoding_normal = 0;
     90    // TODO(alexnarest): Consider decoding_neteq_plc for consistency
     91    int32_t decoding_plc = 0;
     92    int32_t decoding_codec_plc = 0;
     93    int32_t decoding_cng = 0;
     94    int32_t decoding_plc_cng = 0;
     95    int32_t decoding_muted_output = 0;
     96    int64_t capture_start_ntp_time_ms = 0;
     97    // The timestamp at which the last packet was received, i.e. the time of the
     98    // local clock when it was received - not the RTP timestamp of that packet.
     99    // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp
    100    std::optional<Timestamp> last_packet_received;
    101    uint64_t jitter_buffer_flushes = 0;
    102    double relative_packet_arrival_delay_seconds = 0.0;
    103    int32_t interruption_count = 0;
    104    int32_t total_interruption_duration_ms = 0;
    105    // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-estimatedplayouttimestamp
    106    std::optional<int64_t> estimated_playout_ntp_timestamp_ms;
    107    // Remote outbound stats derived by the received RTCP sender reports.
    108    // https://w3c.github.io/webrtc-stats/#remoteoutboundrtpstats-dict*
    109    std::optional<Timestamp> last_sender_report_timestamp;
    110    // TODO: bugs.webrtc.org/370535296 - Remove the utc timestamp when linked
    111    // issue is fixed.
    112    std::optional<Timestamp> last_sender_report_utc_timestamp;
    113    std::optional<Timestamp> last_sender_report_remote_utc_timestamp;
    114    uint64_t sender_reports_packets_sent = 0;
    115    uint64_t sender_reports_bytes_sent = 0;
    116    uint64_t sender_reports_reports_count = 0;
    117    std::optional<TimeDelta> round_trip_time;
    118    TimeDelta total_round_trip_time = TimeDelta::Zero();
    119    int round_trip_time_measurements = 0;
    120  };
    121 
    122  struct Config {
    123    Config();
    124    ~Config();
    125 
    126    std::string ToString() const;
    127 
    128    // Receive-stream specific RTP settings.
    129    struct Rtp : public ReceiveStreamRtpConfig {
    130      Rtp();
    131      ~Rtp();
    132 
    133      std::string ToString() const;
    134 
    135      // See NackConfig for description.
    136      NackConfig nack;
    137      RtcpMode rtcp_mode = RtcpMode::kCompound;
    138 
    139      RtcpEventObserver* rtcp_event_observer = nullptr;
    140    } rtp;
    141 
    142    // Receive-side RTT.
    143    bool enable_non_sender_rtt = false;
    144 
    145    Transport* rtcp_send_transport = nullptr;
    146 
    147    // NetEq settings.
    148    size_t jitter_buffer_max_packets = 200;
    149    bool jitter_buffer_fast_accelerate = false;
    150    int jitter_buffer_min_delay_ms = 0;
    151 
    152    // Identifier for an A/V synchronization group. Empty string to disable.
    153    // TODO(pbos): Synchronize streams in a sync group, not just one video
    154    // stream to one audio stream. Tracked by issue webrtc:4762.
    155    std::string sync_group;
    156 
    157    // Decoder specifications for every payload type that we can receive.
    158    std::map<int, SdpAudioFormat> decoder_map;
    159 
    160    scoped_refptr<AudioDecoderFactory> decoder_factory;
    161 
    162    std::optional<AudioCodecPairId> codec_pair_id;
    163 
    164    // Per PeerConnection crypto options.
    165    webrtc::CryptoOptions crypto_options;
    166 
    167    // An optional custom frame decryptor that allows the entire frame to be
    168    // decrypted in whatever way the caller choses. This is not required by
    169    // default.
    170    // TODO(tommi): Remove this member variable from the struct. It's not
    171    // a part of the AudioReceiveStreamInterface state but rather a pass through
    172    // variable.
    173    scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor;
    174 
    175    // An optional frame transformer used by insertable streams to transform
    176    // encoded frames.
    177    // TODO(tommi): Remove this member variable from the struct. It's not
    178    // a part of the AudioReceiveStreamInterface state but rather a pass through
    179    // variable.
    180    scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer;
    181  };
    182 
    183  // Methods that support reconfiguring the stream post initialization.
    184  virtual void SetDecoderMap(std::map<int, SdpAudioFormat> decoder_map) = 0;
    185  virtual void SetNackHistory(int history_ms) = 0;
    186  virtual void SetNonSenderRttMeasurement(bool enabled) = 0;
    187 
    188  // Returns true if the stream has been started.
    189  virtual bool IsRunning() const = 0;
    190 
    191  virtual Stats GetStats(bool get_and_clear_legacy_stats) const = 0;
    192  Stats GetStats() { return GetStats(/*get_and_clear_legacy_stats=*/true); }
    193 
    194  // Sets an audio sink that receives unmixed audio from the receive stream.
    195  // Ownership of the sink is managed by the caller.
    196  // Only one sink can be set and passing a null sink clears an existing one.
    197  // NOTE: Audio must still somehow be pulled through AudioTransport for audio
    198  // to stream through this sink. In practice, this happens if mixed audio
    199  // is being pulled+rendered and/or if audio is being pulled for the purposes
    200  // of feeding to the AEC.
    201  virtual void SetSink(AudioSinkInterface* sink) = 0;
    202 
    203  // Sets playback gain of the stream, applied when mixing, and thus after it
    204  // is potentially forwarded to any attached AudioSinkInterface implementation.
    205  virtual void SetGain(float gain) = 0;
    206 
    207  // Sets a base minimum for the playout delay. Base minimum delay sets lower
    208  // bound on minimum delay value determining lower bound on playout delay.
    209  //
    210  // Returns true if value was successfully set, false overwise.
    211  virtual bool SetBaseMinimumPlayoutDelayMs(int delay_ms) = 0;
    212 
    213  // Returns current value of base minimum delay in milliseconds.
    214  virtual int GetBaseMinimumPlayoutDelayMs() const = 0;
    215 
    216  // Synchronization source (stream identifier) to be received.
    217  // This member will not change mid-stream and can be assumed to be const
    218  // post initialization.
    219  virtual uint32_t remote_ssrc() const = 0;
    220 
    221  // Get the object suitable to inject into the AudioMixer
    222  // (normally "this").
    223  virtual AudioMixer::Source* source() = 0;
    224 
    225 protected:
    226  virtual ~AudioReceiveStreamInterface() {}
    227 };
    228 
    229 }  // namespace webrtc
    230 
    231 #endif  // CALL_AUDIO_RECEIVE_STREAM_H_