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_H_ 11 #define WEBRTC_CALL_H_ 12 13 #include <string> 14 #include <vector> 15 16 #include "webrtc/common_types.h" 17 #include "webrtc/audio_receive_stream.h" 18 #include "webrtc/audio_send_stream.h" 19 #include "webrtc/audio_state.h" 20 #include "webrtc/base/socket.h" 21 #include "webrtc/video_receive_stream.h" 22 #include "webrtc/video_send_stream.h" 23 24 namespace webrtc { 25 26 class AudioProcessing; 27 28 const char* Version(); 29 30 enum class MediaType { 31 ANY, 32 AUDIO, 33 VIDEO, 34 DATA 35 }; 36 37 class PacketReceiver { 38 public: 39 enum DeliveryStatus { 40 DELIVERY_OK, 41 DELIVERY_UNKNOWN_SSRC, 42 DELIVERY_PACKET_ERROR, 43 }; 44 45 virtual DeliveryStatus DeliverPacket(MediaType media_type, 46 const uint8_t* packet, 47 size_t length, 48 const PacketTime& packet_time) = 0; 49 50 protected: 51 virtual ~PacketReceiver() {} 52 }; 53 54 // Callback interface for reporting when a system overuse is detected. 55 class LoadObserver { 56 public: 57 enum Load { kOveruse, kUnderuse }; 58 59 // Triggered when overuse is detected or when we believe the system can take 60 // more load. 61 virtual void OnLoadUpdate(Load load) = 0; 62 63 protected: 64 virtual ~LoadObserver() {} 65 }; 66 67 // A Call instance can contain several send and/or receive streams. All streams 68 // are assumed to have the same remote endpoint and will share bitrate estimates 69 // etc. 70 class Call { 71 public: 72 struct Config { 73 static const int kDefaultStartBitrateBps; 74 75 // Bitrate config used until valid bitrate estimates are calculated. Also 76 // used to cap total bitrate used. 77 struct BitrateConfig { 78 int min_bitrate_bps = 0; 79 int start_bitrate_bps = kDefaultStartBitrateBps; 80 int max_bitrate_bps = -1; 81 } bitrate_config; 82 83 // AudioState which is possibly shared between multiple calls. 84 // TODO(solenberg): Change this to a shared_ptr once we can use C++11. 85 rtc::scoped_refptr<AudioState> audio_state; 86 87 // Audio Processing Module to be used in this call. 88 // TODO(solenberg): Change this to a shared_ptr once we can use C++11. 89 AudioProcessing* audio_processing = nullptr; 90 }; 91 92 struct Stats { 93 int send_bandwidth_bps = 0; 94 int recv_bandwidth_bps = 0; 95 int64_t pacer_delay_ms = 0; 96 int64_t rtt_ms = -1; 97 }; 98 99 static Call* Create(const Call::Config& config); 100 101 virtual AudioSendStream* CreateAudioSendStream( 102 const AudioSendStream::Config& config) = 0; 103 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0; 104 105 virtual AudioReceiveStream* CreateAudioReceiveStream( 106 const AudioReceiveStream::Config& config) = 0; 107 virtual void DestroyAudioReceiveStream( 108 AudioReceiveStream* receive_stream) = 0; 109 110 virtual VideoSendStream* CreateVideoSendStream( 111 const VideoSendStream::Config& config, 112 const VideoEncoderConfig& encoder_config) = 0; 113 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0; 114 115 virtual VideoReceiveStream* CreateVideoReceiveStream( 116 const VideoReceiveStream::Config& config) = 0; 117 virtual void DestroyVideoReceiveStream( 118 VideoReceiveStream* receive_stream) = 0; 119 120 // All received RTP and RTCP packets for the call should be inserted to this 121 // PacketReceiver. The PacketReceiver pointer is valid as long as the 122 // Call instance exists. 123 virtual PacketReceiver* Receiver() = 0; 124 125 // Returns the call statistics, such as estimated send and receive bandwidth, 126 // pacing delay, etc. 127 virtual Stats GetStats() const = 0; 128 129 // TODO(pbos): Like BitrateConfig above this is currently per-stream instead 130 // of maximum for entire Call. This should be fixed along with the above. 131 // Specifying a start bitrate (>0) will currently reset the current bitrate 132 // estimate. This is due to how the 'x-google-start-bitrate' flag is currently 133 // implemented. 134 virtual void SetBitrateConfig( 135 const Config::BitrateConfig& bitrate_config) = 0; 136 virtual void SignalNetworkState(NetworkState state) = 0; 137 138 virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0; 139 140 virtual ~Call() {} 141 }; 142 143 } // namespace webrtc 144 145 #endif // WEBRTC_CALL_H_ 146