ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 | #ifndef WEBRTC_CALL_CALL_H_ |
| 11 | #define WEBRTC_CALL_CALL_H_ |
| 12 | |
| 13 | #include <string> |
| 14 | #include <vector> |
| 15 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 16 | #include "webrtc/base/networkroute.h" |
| 17 | #include "webrtc/base/platform_file.h" |
| 18 | #include "webrtc/base/socket.h" |
| 19 | #include "webrtc/call/audio_receive_stream.h" |
| 20 | #include "webrtc/call/audio_send_stream.h" |
| 21 | #include "webrtc/call/audio_state.h" |
brandtr | 7250b39 | 2016-12-19 01:13:46 -0800 | [diff] [blame] | 22 | #include "webrtc/call/flexfec_receive_stream.h" |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 23 | #include "webrtc/common_types.h" |
| 24 | #include "webrtc/video_receive_stream.h" |
| 25 | #include "webrtc/video_send_stream.h" |
| 26 | |
| 27 | namespace webrtc { |
| 28 | |
| 29 | class AudioProcessing; |
| 30 | class RtcEventLog; |
| 31 | |
| 32 | const char* Version(); |
| 33 | |
| 34 | enum class MediaType { |
| 35 | ANY, |
| 36 | AUDIO, |
| 37 | VIDEO, |
| 38 | DATA |
| 39 | }; |
| 40 | |
| 41 | class PacketReceiver { |
| 42 | public: |
| 43 | enum DeliveryStatus { |
| 44 | DELIVERY_OK, |
| 45 | DELIVERY_UNKNOWN_SSRC, |
| 46 | DELIVERY_PACKET_ERROR, |
| 47 | }; |
| 48 | |
| 49 | virtual DeliveryStatus DeliverPacket(MediaType media_type, |
| 50 | const uint8_t* packet, |
| 51 | size_t length, |
| 52 | const PacketTime& packet_time) = 0; |
| 53 | |
| 54 | protected: |
| 55 | virtual ~PacketReceiver() {} |
| 56 | }; |
| 57 | |
| 58 | // A Call instance can contain several send and/or receive streams. All streams |
| 59 | // are assumed to have the same remote endpoint and will share bitrate estimates |
| 60 | // etc. |
| 61 | class Call { |
| 62 | public: |
| 63 | struct Config { |
| 64 | explicit Config(RtcEventLog* event_log) : event_log(event_log) { |
| 65 | RTC_DCHECK(event_log); |
| 66 | } |
| 67 | |
| 68 | static const int kDefaultStartBitrateBps; |
| 69 | |
| 70 | // Bitrate config used until valid bitrate estimates are calculated. Also |
| 71 | // used to cap total bitrate used. |
| 72 | struct BitrateConfig { |
| 73 | int min_bitrate_bps = 0; |
| 74 | int start_bitrate_bps = kDefaultStartBitrateBps; |
| 75 | int max_bitrate_bps = -1; |
| 76 | } bitrate_config; |
| 77 | |
| 78 | // AudioState which is possibly shared between multiple calls. |
| 79 | // TODO(solenberg): Change this to a shared_ptr once we can use C++11. |
| 80 | rtc::scoped_refptr<AudioState> audio_state; |
| 81 | |
| 82 | // Audio Processing Module to be used in this call. |
| 83 | // TODO(solenberg): Change this to a shared_ptr once we can use C++11. |
| 84 | AudioProcessing* audio_processing = nullptr; |
| 85 | |
| 86 | // RtcEventLog to use for this call. Required. |
| 87 | // Use webrtc::RtcEventLog::CreateNull() for a null implementation. |
| 88 | RtcEventLog* event_log = nullptr; |
| 89 | }; |
| 90 | |
| 91 | struct Stats { |
| 92 | std::string ToString(int64_t time_ms) const; |
| 93 | |
| 94 | int send_bandwidth_bps = 0; // Estimated available send bandwidth. |
| 95 | int max_padding_bitrate_bps = 0; // Cumulative configured max padding. |
| 96 | int recv_bandwidth_bps = 0; // Estimated available receive bandwidth. |
| 97 | int64_t pacer_delay_ms = 0; |
| 98 | int64_t rtt_ms = -1; |
| 99 | }; |
| 100 | |
| 101 | static Call* Create(const Call::Config& config); |
| 102 | |
| 103 | virtual AudioSendStream* CreateAudioSendStream( |
| 104 | const AudioSendStream::Config& config) = 0; |
| 105 | virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0; |
| 106 | |
| 107 | virtual AudioReceiveStream* CreateAudioReceiveStream( |
| 108 | const AudioReceiveStream::Config& config) = 0; |
| 109 | virtual void DestroyAudioReceiveStream( |
| 110 | AudioReceiveStream* receive_stream) = 0; |
| 111 | |
| 112 | virtual VideoSendStream* CreateVideoSendStream( |
| 113 | VideoSendStream::Config config, |
| 114 | VideoEncoderConfig encoder_config) = 0; |
| 115 | virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0; |
| 116 | |
| 117 | virtual VideoReceiveStream* CreateVideoReceiveStream( |
| 118 | VideoReceiveStream::Config configuration) = 0; |
| 119 | virtual void DestroyVideoReceiveStream( |
| 120 | VideoReceiveStream* receive_stream) = 0; |
| 121 | |
brandtr | fb45c6c | 2017-01-27 06:47:55 -0800 | [diff] [blame^] | 122 | // In order for a created VideoReceiveStream to be aware that it is |
| 123 | // protected by a FlexfecReceiveStream, the latter should be created before |
| 124 | // the former. |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 125 | virtual FlexfecReceiveStream* CreateFlexfecReceiveStream( |
brandtr | 446fcb6 | 2016-12-08 04:14:24 -0800 | [diff] [blame] | 126 | const FlexfecReceiveStream::Config& config) = 0; |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 127 | virtual void DestroyFlexfecReceiveStream( |
| 128 | FlexfecReceiveStream* receive_stream) = 0; |
| 129 | |
| 130 | // All received RTP and RTCP packets for the call should be inserted to this |
| 131 | // PacketReceiver. The PacketReceiver pointer is valid as long as the |
| 132 | // Call instance exists. |
| 133 | virtual PacketReceiver* Receiver() = 0; |
| 134 | |
| 135 | // Returns the call statistics, such as estimated send and receive bandwidth, |
| 136 | // pacing delay, etc. |
| 137 | virtual Stats GetStats() const = 0; |
| 138 | |
| 139 | // TODO(pbos): Like BitrateConfig above this is currently per-stream instead |
| 140 | // of maximum for entire Call. This should be fixed along with the above. |
| 141 | // Specifying a start bitrate (>0) will currently reset the current bitrate |
| 142 | // estimate. This is due to how the 'x-google-start-bitrate' flag is currently |
| 143 | // implemented. |
| 144 | virtual void SetBitrateConfig( |
| 145 | const Config::BitrateConfig& bitrate_config) = 0; |
| 146 | |
| 147 | // TODO(skvlad): When the unbundled case with multiple streams for the same |
| 148 | // media type going over different networks is supported, track the state |
| 149 | // for each stream separately. Right now it's global per media type. |
| 150 | virtual void SignalChannelNetworkState(MediaType media, |
| 151 | NetworkState state) = 0; |
| 152 | |
| 153 | virtual void OnTransportOverheadChanged( |
| 154 | MediaType media, |
| 155 | int transport_overhead_per_packet) = 0; |
| 156 | |
| 157 | virtual void OnNetworkRouteChanged( |
| 158 | const std::string& transport_name, |
| 159 | const rtc::NetworkRoute& network_route) = 0; |
| 160 | |
| 161 | virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0; |
| 162 | |
| 163 | virtual ~Call() {} |
| 164 | }; |
| 165 | |
| 166 | } // namespace webrtc |
| 167 | |
| 168 | #endif // WEBRTC_CALL_CALL_H_ |