blob: 8f062c3a7bb72578ffef7623c45eee83faf67f33 [file] [log] [blame]
Erik Språng09708512018-03-14 15:16:50 +01001/*
2 * Copyright (c) 2018 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_DEGRADED_CALL_H_
12#define CALL_DEGRADED_CALL_H_
13
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <stddef.h>
15#include <stdint.h>
Erik Språng09708512018-03-14 15:16:50 +010016#include <memory>
17
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020018#include "absl/types/optional.h"
Erik Språng09708512018-03-14 15:16:50 +010019#include "api/call/transport.h"
Yves Gerey3e707812018-11-28 16:47:49 +010020#include "api/fec_controller.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "api/media_types.h"
Yves Gerey3e707812018-11-28 16:47:49 +010022#include "api/rtp_headers.h"
Artem Titov3229d652018-08-17 13:00:54 +020023#include "api/test/simulated_network.h"
Yves Gerey3e707812018-11-28 16:47:49 +010024#include "api/video_codecs/video_encoder_config.h"
25#include "call/audio_receive_stream.h"
26#include "call/audio_send_stream.h"
Erik Språng09708512018-03-14 15:16:50 +010027#include "call/call.h"
28#include "call/fake_network_pipe.h"
Yves Gerey3e707812018-11-28 16:47:49 +010029#include "call/flexfec_receive_stream.h"
30#include "call/packet_receiver.h"
31#include "call/rtp_transport_controller_send_interface.h"
Artem Titov3229d652018-08-17 13:00:54 +020032#include "call/simulated_network.h"
Yves Gerey3e707812018-11-28 16:47:49 +010033#include "call/video_receive_stream.h"
34#include "call/video_send_stream.h"
Erik Språng09708512018-03-14 15:16:50 +010035#include "modules/utility/include/process_thread.h"
Steve Anton10542f22019-01-11 09:11:00 -080036#include "rtc_base/bitrate_allocation_strategy.h"
37#include "rtc_base/copy_on_write_buffer.h"
Yves Gerey3e707812018-11-28 16:47:49 +010038#include "rtc_base/network/sent_packet.h"
Erik Språng09708512018-03-14 15:16:50 +010039#include "system_wrappers/include/clock.h"
40
41namespace webrtc {
42
43class DegradedCall : public Call, private Transport, private PacketReceiver {
44 public:
Artem Titov3229d652018-08-17 13:00:54 +020045 explicit DegradedCall(
46 std::unique_ptr<Call> call,
Artem Titov75e36472018-10-08 12:28:56 +020047 absl::optional<BuiltInNetworkBehaviorConfig> send_config,
48 absl::optional<BuiltInNetworkBehaviorConfig> receive_config);
Erik Språng09708512018-03-14 15:16:50 +010049 ~DegradedCall() override;
50
51 // Implements Call.
52 AudioSendStream* CreateAudioSendStream(
53 const AudioSendStream::Config& config) override;
54 void DestroyAudioSendStream(AudioSendStream* send_stream) override;
55
56 AudioReceiveStream* CreateAudioReceiveStream(
57 const AudioReceiveStream::Config& config) override;
58 void DestroyAudioReceiveStream(AudioReceiveStream* receive_stream) override;
59
60 VideoSendStream* CreateVideoSendStream(
61 VideoSendStream::Config config,
62 VideoEncoderConfig encoder_config) override;
63 VideoSendStream* CreateVideoSendStream(
64 VideoSendStream::Config config,
65 VideoEncoderConfig encoder_config,
66 std::unique_ptr<FecController> fec_controller) override;
67 void DestroyVideoSendStream(VideoSendStream* send_stream) override;
68
69 VideoReceiveStream* CreateVideoReceiveStream(
70 VideoReceiveStream::Config configuration) override;
71 void DestroyVideoReceiveStream(VideoReceiveStream* receive_stream) override;
72
73 FlexfecReceiveStream* CreateFlexfecReceiveStream(
74 const FlexfecReceiveStream::Config& config) override;
75 void DestroyFlexfecReceiveStream(
76 FlexfecReceiveStream* receive_stream) override;
77
78 PacketReceiver* Receiver() override;
79
80 RtpTransportControllerSendInterface* GetTransportControllerSend() override;
81
82 Stats GetStats() const override;
83
84 void SetBitrateAllocationStrategy(
85 std::unique_ptr<rtc::BitrateAllocationStrategy>
86 bitrate_allocation_strategy) override;
87
88 void SignalChannelNetworkState(MediaType media, NetworkState state) override;
Stefan Holmer64be7fa2018-10-04 15:21:55 +020089 void OnAudioTransportOverheadChanged(
90 int transport_overhead_per_packet) override;
Erik Språng09708512018-03-14 15:16:50 +010091 void OnSentPacket(const rtc::SentPacket& sent_packet) override;
92
93 protected:
94 // Implements Transport.
95 bool SendRtp(const uint8_t* packet,
96 size_t length,
97 const PacketOptions& options) override;
98
99 bool SendRtcp(const uint8_t* packet, size_t length) override;
100
101 // Implements PacketReceiver.
102 DeliveryStatus DeliverPacket(MediaType media_type,
103 rtc::CopyOnWriteBuffer packet,
Niels Möller70082872018-08-07 11:03:12 +0200104 int64_t packet_time_us) override;
Erik Språng09708512018-03-14 15:16:50 +0100105
106 private:
107 Clock* const clock_;
108 const std::unique_ptr<Call> call_;
109
Piotr (Peter) Slatalacc8e8bb2018-11-15 08:26:19 -0800110 void MediaTransportChange(MediaTransportInterface* media_transport) override;
Artem Titov75e36472018-10-08 12:28:56 +0200111 const absl::optional<BuiltInNetworkBehaviorConfig> send_config_;
Erik Språng09708512018-03-14 15:16:50 +0100112 const std::unique_ptr<ProcessThread> send_process_thread_;
Artem Titov3229d652018-08-17 13:00:54 +0200113 SimulatedNetwork* send_simulated_network_;
Erik Språng09708512018-03-14 15:16:50 +0100114 std::unique_ptr<FakeNetworkPipe> send_pipe_;
115 size_t num_send_streams_;
116
Artem Titov75e36472018-10-08 12:28:56 +0200117 const absl::optional<BuiltInNetworkBehaviorConfig> receive_config_;
Artem Titov3229d652018-08-17 13:00:54 +0200118 SimulatedNetwork* receive_simulated_network_;
Erik Språng09708512018-03-14 15:16:50 +0100119 std::unique_ptr<FakeNetworkPipe> receive_pipe_;
120};
121
122} // namespace webrtc
123
124#endif // CALL_DEGRADED_CALL_H_