webrtc_m130/call/audio_send_stream.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

197 lines
6.6 KiB
C
Raw Normal View History

/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef CALL_AUDIO_SEND_STREAM_H_
#define CALL_AUDIO_SEND_STREAM_H_
#include <memory>
#include <string>
#include <vector>
#include "absl/types/optional.h"
#include "api/audio_codecs/audio_codec_pair_id.h"
#include "api/audio_codecs/audio_encoder.h"
#include "api/audio_codecs/audio_encoder_factory.h"
#include "api/audio_codecs/audio_format.h"
#include "api/call/transport.h"
#include "api/crypto/crypto_options.h"
#include "api/crypto/frame_encryptor_interface.h"
#include "api/frame_transformer_interface.h"
#include "api/rtp_parameters.h"
#include "api/scoped_refptr.h"
#include "call/audio_sender.h"
#include "call/rtp_config.h"
#include "modules/audio_processing/include/audio_processing_statistics.h"
#include "modules/rtp_rtcp/include/report_block_data.h"
namespace webrtc {
class AudioSendStream : public AudioSender {
public:
struct Stats {
Stats();
~Stats();
// TODO(solenberg): Harmonize naming and defaults with receive stream stats.
uint32_t local_ssrc = 0;
int64_t payload_bytes_sent = 0;
int64_t header_and_padding_bytes_sent = 0;
// https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedbytessent
uint64_t retransmitted_bytes_sent = 0;
int32_t packets_sent = 0;
// https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-retransmittedpacketssent
uint64_t retransmitted_packets_sent = 0;
int32_t packets_lost = -1;
float fraction_lost = -1.0f;
std::string codec_name;
absl::optional<int> codec_payload_type;
int32_t jitter_ms = -1;
int64_t rtt_ms = -1;
[getStats] Implement "media-source" audio levels, fixing Chrome bug. Implements RTCAudioSourceStats members: - audioLevel - totalAudioEnergy - totalSamplesDuration In this CL description these are collectively referred to as the audio levels. The audio levels are removed from sending "track" stats (in Chrome, these are now reported as undefined instead of 0). Background: For sending tracks, audio levels were always reported as 0 in Chrome (https://crbug.com/736403), while audio levels were correctly reported for receiving tracks. This problem affected the standard getStats() but not the legacy getStats(), blocking some people from migrating. This was likely not a problem in native third_party/webrtc code because the delivery of audio frames from device to send-stream uses a different code path outside of chromium. A recent PR (https://github.com/w3c/webrtc-stats/pull/451) moved the send-side audio levels to the RTCAudioSourceStats, while keeping the receive-side audio levels on the "track" stats. This allows an implementation to report the audio levels even if samples are not sent onto the network (such as if an ICE connection has not been established yet), reflecting some of the current implementation. Changes: 1. Audio levels are added to RTCAudioSourceStats. Send-side audio "track" stats are left undefined. Receive-side audio "track" stats are not changed in this CL and continue to work. 2. Audio level computation is moved from the AudioState and AudioTransportImpl to the AudioSendStream. This is because a) the AudioTransportImpl::RecordedDataIsAvailable() code path is not exercised in chromium, and b) audio levels should, per-spec, not be calculated on a per-call basis, for which the AudioState is defined. 3. The audio level computation is now performed in AudioSendStream::SendAudioData(), a code path used by both native and chromium code. 4. Comments are added to document behavior of existing code, such as AudioLevel and AudioSendStream::SendAudioData(). Note: In this CL, just like before this CL, audio level is only calculated after an AudioSendStream has been created. This means that before an O/A negotiation, audio levels are unavailable. According to spec, if we have an audio source, we should have audio levels. An immediate solution to this would have been to calculate the audio level at pc/rtp_sender.cc. The problem is that the LocalAudioSinkAdapter::OnData() code path, while exercised in chromium, is not exercised in native code. The issue of calculating audio levels on a per-source bases rather than on a per-send stream basis is left to https://crbug.com/webrtc/10771, an existing "media-source" bug. This CL can be verified manually in Chrome at: https://codepen.io/anon/pen/vqRGyq Bug: chromium:736403, webrtc:10771 Change-Id: I8036cd9984f3b187c3177470a8c0d6670a201a5a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/143789 Reviewed-by: Oskar Sundbom <ossu@webrtc.org> Reviewed-by: Stefan Holmer <stefan@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/master@{#28480}
2019-07-03 17:11:10 +02:00
int16_t audio_level = 0;
// See description of "totalAudioEnergy" in the WebRTC stats spec:
// https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
double total_input_energy = 0.0;
double total_input_duration = 0.0;
bool typing_noise_detected = false;
ANAStats ana_statistics;
AudioProcessingStats apm_statistics;
int64_t target_bitrate_bps = 0;
// A snapshot of Report Blocks with additional data of interest to
// statistics. Within this list, the sender-source SSRC pair is unique and
// per-pair the ReportBlockData represents the latest Report Block that was
// received for that pair.
std::vector<ReportBlockData> report_block_datas;
};
struct Config {
Config() = delete;
explicit Config(Transport* send_transport);
~Config();
std::string ToString() const;
// Send-stream specific RTP settings.
struct Rtp {
Rtp();
~Rtp();
std::string ToString() const;
// Sender SSRC.
uint32_t ssrc = 0;
// The value to send in the RID RTP header extension if the extension is
// included in the list of extensions.
std::string rid;
// The value to send in the MID RTP header extension if the extension is
// included in the list of extensions.
std::string mid;
// Corresponds to the SDP attribute extmap-allow-mixed.
bool extmap_allow_mixed = false;
// RTP header extensions used for the sent stream.
std::vector<RtpExtension> extensions;
// RTCP CNAME, see RFC 3550.
std::string c_name;
} rtp;
// Time interval between RTCP report for audio
int rtcp_report_interval_ms = 5000;
// Transport for outgoing packets. The transport is expected to exist for
// the entire life of the AudioSendStream and is owned by the API client.
Transport* send_transport = nullptr;
// Bitrate limits used for variable audio bitrate streams. Set both to -1 to
// disable audio bitrate adaptation.
// Note: This is still an experimental feature and not ready for real usage.
int min_bitrate_bps = -1;
int max_bitrate_bps = -1;
double bitrate_priority = 1.0;
bool has_dscp = false;
// Defines whether to turn on audio network adaptor, and defines its config
// string.
absl::optional<std::string> audio_network_adaptor_config;
struct SendCodecSpec {
SendCodecSpec(int payload_type, const SdpAudioFormat& format);
~SendCodecSpec();
std::string ToString() const;
bool operator==(const SendCodecSpec& rhs) const;
bool operator!=(const SendCodecSpec& rhs) const {
return !(*this == rhs);
}
int payload_type;
SdpAudioFormat format;
bool nack_enabled = false;
bool transport_cc_enabled = false;
absl::optional<int> cng_payload_type;
absl::optional<int> red_payload_type;
// If unset, use the encoder's default target bitrate.
absl::optional<int> target_bitrate_bps;
};
absl::optional<SendCodecSpec> send_codec_spec;
rtc::scoped_refptr<AudioEncoderFactory> encoder_factory;
absl::optional<AudioCodecPairId> codec_pair_id;
// Track ID as specified during track creation.
std::string track_id;
// Per PeerConnection crypto options.
webrtc::CryptoOptions crypto_options;
// An optional custom frame encryptor that allows the entire frame to be
// encryptor in whatever way the caller choses. This is not required by
// default.
rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor;
// An optional frame transformer used by insertable streams to transform
// encoded frames.
rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer;
};
virtual ~AudioSendStream() = default;
virtual const webrtc::AudioSendStream::Config& GetConfig() const = 0;
// Reconfigure the stream according to the Configuration.
virtual void Reconfigure(const Config& config) = 0;
// Starts stream activity.
// When a stream is active, it can receive, process and deliver packets.
virtual void Start() = 0;
// Stops stream activity.
// When a stream is stopped, it can't receive, process or deliver packets.
virtual void Stop() = 0;
// TODO(solenberg): Make payload_type a config property instead.
virtual bool SendTelephoneEvent(int payload_type,
int payload_frequency,
int event,
int duration_ms) = 0;
virtual void SetMuted(bool muted) = 0;
virtual Stats GetStats() const = 0;
virtual Stats GetStats(bool has_remote_tracks) const = 0;
};
} // namespace webrtc
#endif // CALL_AUDIO_SEND_STREAM_H_