blob: a46dc3b16f59e60e9d942730877b898331c0ea7b [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;
61
pbos1ba8d392016-05-01 20:18:34 -070062 void SignalNetworkState(NetworkState state);
63 bool DeliverRtcp(const uint8_t* packet, size_t length);
mflodman86cc6ff2016-07-26 04:44:06 -070064
65 // Implements BitrateAllocatorObserver.
66 uint32_t OnBitrateUpdated(uint32_t bitrate_bps,
67 uint8_t fraction_loss,
minyue78b4d562016-11-30 04:47:39 -080068 int64_t rtt,
minyue93e45222017-05-18 14:32:41 -070069 int64_t bwe_period_ms) override;
mflodman86cc6ff2016-07-26 04:44:06 -070070
elad.alond12a8e12017-03-23 11:04:48 -070071 // From PacketFeedbackObserver.
72 void OnPacketAdded(uint32_t ssrc, uint16_t seq_num) override;
73 void OnPacketFeedbackVector(
74 const std::vector<PacketFeedback>& packet_feedback_vector) override;
75
michaelt79e05882016-11-08 02:50:09 -080076 void SetTransportOverhead(int transport_overhead_per_packet);
solenbergc7a8b082015-10-16 14:35:07 -070077
ossuc3d4b482017-05-23 06:07:11 -070078 RtpState GetRtpState() const;
sazac58f8c02017-07-19 00:39:19 -070079 const TimeInterval& GetActiveLifetime() const;
ossuc3d4b482017-05-23 06:07:11 -070080
solenbergc7a8b082015-10-16 14:35:07 -070081 private:
sazac58f8c02017-07-19 00:39:19 -070082 class TimedTransport;
83
solenberg3a941542015-11-16 07:34:50 -080084 VoiceEngine* voice_engine() const;
85
ossu20a4b3f2017-04-27 02:08:52 -070086 // These are all static to make it less likely that (the old) config_ is
87 // accessed unintentionally.
88 static void ConfigureStream(AudioSendStream* stream,
89 const Config& new_config,
90 bool first_time);
91 static bool SetupSendCodec(AudioSendStream* stream, const Config& new_config);
92 static bool ReconfigureSendCodec(AudioSendStream* stream,
93 const Config& new_config);
94 static void ReconfigureANA(AudioSendStream* stream, const Config& new_config);
95 static void ReconfigureCNG(AudioSendStream* stream, const Config& new_config);
96 static void ReconfigureBitrateObserver(AudioSendStream* stream,
97 const Config& new_config);
98
99 void ConfigureBitrateObserver(int min_bitrate_bps, int max_bitrate_bps);
100 void RemoveBitrateObserver();
minyue7a973442016-10-20 03:27:12 -0700101
ossu3b9ff382017-04-27 08:03:42 -0700102 void RegisterCngPayloadType(int payload_type, int clockrate_hz);
103
elad.alond12a8e12017-03-23 11:04:48 -0700104 rtc::ThreadChecker worker_thread_checker_;
105 rtc::ThreadChecker pacer_thread_checker_;
perkj26091b12016-09-01 01:17:40 -0700106 rtc::TaskQueue* worker_queue_;
ossu20a4b3f2017-04-27 02:08:52 -0700107 webrtc::AudioSendStream::Config config_;
solenberg566ef242015-11-06 15:34:49 -0800108 rtc::scoped_refptr<webrtc::AudioState> audio_state_;
kwibergfffa42b2016-02-23 10:46:32 -0800109 std::unique_ptr<voe::ChannelProxy> channel_proxy_;
ossu20a4b3f2017-04-27 02:08:52 -0700110 RtcEventLog* const event_log_;
solenberg85a04962015-10-27 03:35:21 -0700111
mflodman86cc6ff2016-07-26 04:44:06 -0700112 BitrateAllocator* const bitrate_allocator_;
nisseb8f9a322017-03-27 05:36:15 -0700113 RtpTransportControllerSendInterface* const transport_;
stefan7de8d642017-02-07 07:14:08 -0800114 std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_;
mflodman86cc6ff2016-07-26 04:44:06 -0700115
elad.alond12a8e12017-03-23 11:04:48 -0700116 rtc::CriticalSection packet_loss_tracker_cs_;
117 TransportFeedbackPacketLossTracker packet_loss_tracker_
danilchapa37de392017-09-09 04:17:22 -0700118 RTC_GUARDED_BY(&packet_loss_tracker_cs_);
elad.alond12a8e12017-03-23 11:04:48 -0700119
ossuc3d4b482017-05-23 06:07:11 -0700120 RtpRtcp* rtp_rtcp_module_;
121 rtc::Optional<RtpState> const suspended_rtp_state_;
122
sazac58f8c02017-07-19 00:39:19 -0700123 std::unique_ptr<TimedTransport> timed_send_transport_adapter_;
124 TimeInterval active_lifetime_;
125
solenberg85a04962015-10-27 03:35:21 -0700126 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioSendStream);
solenbergc7a8b082015-10-16 14:35:07 -0700127};
128} // namespace internal
129} // namespace webrtc
130
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200131#endif // AUDIO_AUDIO_SEND_STREAM_H_