blob: 1414e39c644333f958965f880e38b947769b6cd5 [file] [log] [blame]
solenbergc7a8b082015-10-16 14:35:07 -07001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef AUDIO_AUDIO_SEND_STREAM_H_
12#define AUDIO_AUDIO_SEND_STREAM_H_
solenbergc7a8b082015-10-16 14:35:07 -070013
kwibergfffa42b2016-02-23 10:46:32 -080014#include <memory>
elad.alond12a8e12017-03-23 11:04:48 -070015#include <vector>
kwibergfffa42b2016-02-23 10:46:32 -080016
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "audio/time_interval.h"
18#include "call/audio_send_stream.h"
19#include "call/audio_state.h"
20#include "call/bitrate_allocator.h"
21#include "modules/rtp_rtcp/include/rtp_rtcp.h"
22#include "rtc_base/constructormagic.h"
23#include "rtc_base/thread_checker.h"
24#include "voice_engine/transport_feedback_packet_loss_tracker.h"
solenbergc7a8b082015-10-16 14:35:07 -070025
26namespace webrtc {
solenberg3a941542015-11-16 07:34:50 -080027class VoiceEngine;
tereliuse035e2d2016-09-21 06:51:47 -070028class RtcEventLog;
stefan7de8d642017-02-07 07:14:08 -080029class RtcpBandwidthObserver;
michaelt9332b7d2016-11-30 07:51:13 -080030class RtcpRttStats;
nisseb8f9a322017-03-27 05:36:15 -070031class RtpTransportControllerSendInterface;
solenberg3a941542015-11-16 07:34:50 -080032
solenberg13725082015-11-25 08:16:52 -080033namespace voe {
34class ChannelProxy;
35} // namespace voe
solenbergc7a8b082015-10-16 14:35:07 -070036
solenberg13725082015-11-25 08:16:52 -080037namespace internal {
mflodman86cc6ff2016-07-26 04:44:06 -070038class AudioSendStream final : public webrtc::AudioSendStream,
elad.alond12a8e12017-03-23 11:04:48 -070039 public webrtc::BitrateAllocatorObserver,
40 public webrtc::PacketFeedbackObserver {
solenbergc7a8b082015-10-16 14:35:07 -070041 public:
solenberg85a04962015-10-27 03:35:21 -070042 AudioSendStream(const webrtc::AudioSendStream::Config& config,
Stefan Holmerb86d4e42015-12-07 10:26:18 +010043 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
perkj26091b12016-09-01 01:17:40 -070044 rtc::TaskQueue* worker_queue,
nisseb8f9a322017-03-27 05:36:15 -070045 RtpTransportControllerSendInterface* transport,
tereliuse035e2d2016-09-21 06:51:47 -070046 BitrateAllocator* bitrate_allocator,
michaelt9332b7d2016-11-30 07:51:13 -080047 RtcEventLog* event_log,
ossuc3d4b482017-05-23 06:07:11 -070048 RtcpRttStats* rtcp_rtt_stats,
49 const rtc::Optional<RtpState>& suspended_rtp_state);
solenbergc7a8b082015-10-16 14:35:07 -070050 ~AudioSendStream() override;
51
pbos1ba8d392016-05-01 20:18:34 -070052 // webrtc::AudioSendStream implementation.
eladalonabbc4302017-07-26 02:09:44 -070053 const webrtc::AudioSendStream::Config& GetConfig() const override;
ossu20a4b3f2017-04-27 02:08:52 -070054 void Reconfigure(const webrtc::AudioSendStream::Config& config) override;
solenbergc7a8b082015-10-16 14:35:07 -070055 void Start() override;
56 void Stop() override;
solenbergffbbcac2016-11-17 05:25:37 -080057 bool SendTelephoneEvent(int payload_type, int payload_frequency, int event,
solenberg8842c3e2016-03-11 03:06:41 -080058 int duration_ms) override;
solenberg94218532016-06-16 10:53:22 -070059 void SetMuted(bool muted) override;
solenbergc7a8b082015-10-16 14:35:07 -070060 webrtc::AudioSendStream::Stats GetStats() const override;
Ivo Creusen56d46092017-11-24 17:29:59 +010061 webrtc::AudioSendStream::Stats GetStats(
62 bool has_remote_tracks) const override;
solenbergc7a8b082015-10-16 14:35:07 -070063
pbos1ba8d392016-05-01 20:18:34 -070064 void SignalNetworkState(NetworkState state);
65 bool DeliverRtcp(const uint8_t* packet, size_t length);
mflodman86cc6ff2016-07-26 04:44:06 -070066
67 // Implements BitrateAllocatorObserver.
68 uint32_t OnBitrateUpdated(uint32_t bitrate_bps,
69 uint8_t fraction_loss,
minyue78b4d562016-11-30 04:47:39 -080070 int64_t rtt,
minyue93e45222017-05-18 14:32:41 -070071 int64_t bwe_period_ms) override;
mflodman86cc6ff2016-07-26 04:44:06 -070072
elad.alond12a8e12017-03-23 11:04:48 -070073 // From PacketFeedbackObserver.
74 void OnPacketAdded(uint32_t ssrc, uint16_t seq_num) override;
75 void OnPacketFeedbackVector(
76 const std::vector<PacketFeedback>& packet_feedback_vector) override;
77
michaelt79e05882016-11-08 02:50:09 -080078 void SetTransportOverhead(int transport_overhead_per_packet);
solenbergc7a8b082015-10-16 14:35:07 -070079
ossuc3d4b482017-05-23 06:07:11 -070080 RtpState GetRtpState() const;
sazac58f8c02017-07-19 00:39:19 -070081 const TimeInterval& GetActiveLifetime() const;
ossuc3d4b482017-05-23 06:07:11 -070082
solenbergc7a8b082015-10-16 14:35:07 -070083 private:
sazac58f8c02017-07-19 00:39:19 -070084 class TimedTransport;
85
solenberg3a941542015-11-16 07:34:50 -080086 VoiceEngine* voice_engine() const;
87
ossu20a4b3f2017-04-27 02:08:52 -070088 // These are all static to make it less likely that (the old) config_ is
89 // accessed unintentionally.
90 static void ConfigureStream(AudioSendStream* stream,
91 const Config& new_config,
92 bool first_time);
93 static bool SetupSendCodec(AudioSendStream* stream, const Config& new_config);
94 static bool ReconfigureSendCodec(AudioSendStream* stream,
95 const Config& new_config);
96 static void ReconfigureANA(AudioSendStream* stream, const Config& new_config);
97 static void ReconfigureCNG(AudioSendStream* stream, const Config& new_config);
98 static void ReconfigureBitrateObserver(AudioSendStream* stream,
99 const Config& new_config);
100
101 void ConfigureBitrateObserver(int min_bitrate_bps, int max_bitrate_bps);
102 void RemoveBitrateObserver();
minyue7a973442016-10-20 03:27:12 -0700103
ossu3b9ff382017-04-27 08:03:42 -0700104 void RegisterCngPayloadType(int payload_type, int clockrate_hz);
105
elad.alond12a8e12017-03-23 11:04:48 -0700106 rtc::ThreadChecker worker_thread_checker_;
107 rtc::ThreadChecker pacer_thread_checker_;
perkj26091b12016-09-01 01:17:40 -0700108 rtc::TaskQueue* worker_queue_;
ossu20a4b3f2017-04-27 02:08:52 -0700109 webrtc::AudioSendStream::Config config_;
solenberg566ef242015-11-06 15:34:49 -0800110 rtc::scoped_refptr<webrtc::AudioState> audio_state_;
kwibergfffa42b2016-02-23 10:46:32 -0800111 std::unique_ptr<voe::ChannelProxy> channel_proxy_;
ossu20a4b3f2017-04-27 02:08:52 -0700112 RtcEventLog* const event_log_;
solenberg85a04962015-10-27 03:35:21 -0700113
mflodman86cc6ff2016-07-26 04:44:06 -0700114 BitrateAllocator* const bitrate_allocator_;
nisseb8f9a322017-03-27 05:36:15 -0700115 RtpTransportControllerSendInterface* const transport_;
mflodman86cc6ff2016-07-26 04:44:06 -0700116
elad.alond12a8e12017-03-23 11:04:48 -0700117 rtc::CriticalSection packet_loss_tracker_cs_;
118 TransportFeedbackPacketLossTracker packet_loss_tracker_
danilchapa37de392017-09-09 04:17:22 -0700119 RTC_GUARDED_BY(&packet_loss_tracker_cs_);
elad.alond12a8e12017-03-23 11:04:48 -0700120
ossuc3d4b482017-05-23 06:07:11 -0700121 RtpRtcp* rtp_rtcp_module_;
122 rtc::Optional<RtpState> const suspended_rtp_state_;
123
sazac58f8c02017-07-19 00:39:19 -0700124 std::unique_ptr<TimedTransport> timed_send_transport_adapter_;
125 TimeInterval active_lifetime_;
126
Alex Narestcedd3512017-12-07 20:54:55 +0100127 // RFC 5285: Each distinct extension MUST have a unique ID. The value 0 is
128 // reserved for padding and MUST NOT be used as a local identifier.
129 // So it should be safe to use 0 here to indicate "not configured".
130 struct ExtensionIds {
131 int audio_level = 0;
132 int transport_sequence_number = 0;
133 };
134 static ExtensionIds FindExtensionIds(
135 const std::vector<RtpExtension>& extensions);
136
solenberg85a04962015-10-27 03:35:21 -0700137 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioSendStream);
solenbergc7a8b082015-10-16 14:35:07 -0700138};
139} // namespace internal
140} // namespace webrtc
141
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200142#endif // AUDIO_AUDIO_SEND_STREAM_H_