blob: e55ade799eddd756a59cbfede980bc1b4d23d7d0 [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +00001/*
2 * Copyright (c) 2012 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 WEBRTC_VIDEO_ENGINE_VIE_CHANNEL_H_
12#define WEBRTC_VIDEO_ENGINE_VIE_CHANNEL_H_
13
14#include <list>
15
pwestin@webrtc.org065b64d2013-04-02 20:37:14 +000016#include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
17#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
18#include "webrtc/modules/video_coding/main/interface/video_coding_defines.h"
andresp@webrtc.orgf8ec08e2014-07-08 14:32:58 +000019#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
pwestin@webrtc.org065b64d2013-04-02 20:37:14 +000020#include "webrtc/system_wrappers/interface/scoped_ptr.h"
21#include "webrtc/system_wrappers/interface/tick_util.h"
22#include "webrtc/typedefs.h"
23#include "webrtc/video_engine/include/vie_network.h"
24#include "webrtc/video_engine/include/vie_rtp_rtcp.h"
25#include "webrtc/video_engine/vie_defines.h"
pwestin@webrtc.org065b64d2013-04-02 20:37:14 +000026#include "webrtc/video_engine/vie_frame_provider_base.h"
27#include "webrtc/video_engine/vie_receiver.h"
28#include "webrtc/video_engine/vie_sender.h"
29#include "webrtc/video_engine/vie_sync_module.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000030
31namespace webrtc {
32
fischman@webrtc.org0329e592013-02-19 22:09:36 +000033class CallStatsObserver;
mflodman@webrtc.org78696d32012-11-26 12:40:15 +000034class ChannelStatsObserver;
andresp@webrtc.orgac6d9192013-05-13 10:50:50 +000035class Config;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000036class CriticalSectionWrapper;
sprang@webrtc.org2e98d452013-11-26 11:41:59 +000037class EncodedImageCallback;
pbos@webrtc.org63301bd2013-10-21 10:34:43 +000038class I420FrameCallback;
pwestin@webrtc.org5e87b5f2012-11-13 21:12:39 +000039class PacedSender;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000040class ProcessThread;
asapersson@webrtc.orgc4af4cf2013-11-20 12:46:11 +000041class RtcpRttStats;
andresp@webrtc.orgac6d9192013-05-13 10:50:50 +000042class RtpRtcp;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000043class ThreadWrapper;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000044class ViEDecoderObserver;
45class ViEEffectFilter;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000046class ViERTCPObserver;
47class ViERTPObserver;
andresp@webrtc.orgac6d9192013-05-13 10:50:50 +000048class VideoCodingModule;
49class VideoDecoder;
50class VideoRenderCallback;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000051class VoEVideoSync;
52
53class ViEChannel
54 : public VCMFrameTypeCallback,
55 public VCMReceiveCallback,
56 public VCMReceiveStatisticsCallback,
fischman@webrtc.orgecfef192013-10-23 23:59:45 +000057 public VCMDecoderTimingCallback,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000058 public VCMPacketRequestCallback,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000059 public RtcpFeedback,
60 public RtpFeedback,
61 public ViEFrameProviderBase {
62 public:
mflodman@webrtc.org78696d32012-11-26 12:40:15 +000063 friend class ChannelStatsObserver;
64
pbos@webrtc.org67879bc2013-04-09 13:41:51 +000065 ViEChannel(int32_t channel_id,
66 int32_t engine_id,
67 uint32_t number_of_cores,
andresp@webrtc.orgac6d9192013-05-13 10:50:50 +000068 const Config& config,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000069 ProcessThread& module_process_thread,
70 RtcpIntraFrameObserver* intra_frame_observer,
71 RtcpBandwidthObserver* bandwidth_observer,
72 RemoteBitrateEstimator* remote_bitrate_estimator,
asapersson@webrtc.orgc4af4cf2013-11-20 12:46:11 +000073 RtcpRttStats* rtt_stats,
pwestin@webrtc.org5e87b5f2012-11-13 21:12:39 +000074 PacedSender* paced_sender,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000075 RtpRtcp* default_rtp_rtcp,
76 bool sender);
77 ~ViEChannel();
78
pbos@webrtc.org67879bc2013-04-09 13:41:51 +000079 int32_t Init();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000080
81 // Sets the encoder to use for the channel. |new_stream| indicates the encoder
82 // type has changed and we should start a new RTP stream.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +000083 int32_t SetSendCodec(const VideoCodec& video_codec, bool new_stream = true);
84 int32_t SetReceiveCodec(const VideoCodec& video_codec);
85 int32_t GetReceiveCodec(VideoCodec* video_codec);
86 int32_t RegisterCodecObserver(ViEDecoderObserver* observer);
pbos@webrtc.org208a6482013-04-09 00:34:42 +000087 // Registers an external decoder. |buffered_rendering| means that the decoder
88 // will render frames after decoding according to the render timestamp
89 // provided by the video coding module. |render_delay| indicates the time
90 // needed to decode and render a frame.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +000091 int32_t RegisterExternalDecoder(const uint8_t pl_type,
92 VideoDecoder* decoder,
93 bool buffered_rendering,
94 int32_t render_delay);
95 int32_t DeRegisterExternalDecoder(const uint8_t pl_type);
96 int32_t ReceiveCodecStatistics(uint32_t* num_key_frames,
97 uint32_t* num_delta_frames);
98 uint32_t DiscardedPackets() const;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000099
mflodman@webrtc.orgf314c802012-12-14 14:02:10 +0000100 // Returns the estimated delay in milliseconds.
101 int ReceiveDelay() const;
102
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000103 // Only affects calls to SetReceiveCodec done after this call.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000104 int32_t WaitForKeyFrame(bool wait);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000105
106 // If enabled, a key frame request will be sent as soon as there are lost
107 // packets. If |only_key_frames| are set, requests are only sent for loss in
108 // key frames.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000109 int32_t SetSignalPacketLossStatus(bool enable, bool only_key_frames);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000110
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000111 int32_t SetRTCPMode(const RTCPMethod rtcp_mode);
112 int32_t GetRTCPMode(RTCPMethod* rtcp_mode);
113 int32_t SetNACKStatus(const bool enable);
114 int32_t SetFECStatus(const bool enable,
115 const unsigned char payload_typeRED,
116 const unsigned char payload_typeFEC);
117 int32_t SetHybridNACKFECStatus(const bool enable,
118 const unsigned char payload_typeRED,
119 const unsigned char payload_typeFEC);
mikhal@webrtc.org9d6fcb32013-02-15 23:22:18 +0000120 int SetSenderBufferingMode(int target_delay_ms);
121 int SetReceiverBufferingMode(int target_delay_ms);
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000122 int32_t SetKeyFrameRequestMethod(const KeyFrameRequestMethod method);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000123 bool EnableRemb(bool enable);
124 int SetSendTimestampOffsetStatus(bool enable, int id);
125 int SetReceiveTimestampOffsetStatus(bool enable, int id);
solenberg@webrtc.org453f9c02013-05-20 12:00:23 +0000126 int SetSendAbsoluteSendTimeStatus(bool enable, int id);
127 int SetReceiveAbsoluteSendTimeStatus(bool enable, int id);
solenberg@webrtc.orgf40e9b62013-05-27 16:02:56 +0000128 bool GetReceiveAbsoluteSendTimeStatus() const;
asapersson@webrtc.org3dc7ff32013-11-21 08:57:04 +0000129 void SetRtcpXrRrtrStatus(bool enable);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000130 void SetTransmissionSmoothingStatus(bool enable);
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000131 int32_t EnableTMMBR(const bool enable);
132 int32_t EnableKeyFrameRequestCallback(const bool enable);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000133
134 // Sets SSRC for outgoing stream.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000135 int32_t SetSSRC(const uint32_t SSRC,
136 const StreamType usage,
137 const unsigned char simulcast_idx);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000138
mflodman@webrtc.orgb6d9cfc2012-10-25 11:30:29 +0000139 // Gets SSRC for outgoing stream number |idx|.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000140 int32_t GetLocalSSRC(uint8_t idx, unsigned int* ssrc);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000141
142 // Gets SSRC for the incoming stream.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000143 int32_t GetRemoteSSRC(uint32_t* ssrc);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000144
145 // Gets the CSRC for the incoming stream.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000146 int32_t GetRemoteCSRC(uint32_t CSRCs[kRtpCsrcSize]);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000147
mflodman@webrtc.org7bc7e022013-04-12 14:55:46 +0000148 int SetRtxSendPayloadType(int payload_type);
stefan@webrtc.org6845de72014-06-11 13:41:36 +0000149 // Only has an effect once RTX is enabled.
150 void SetPadWithRedundantPayloads(bool enable);
mflodman@webrtc.org7bc7e022013-04-12 14:55:46 +0000151 void SetRtxReceivePayloadType(int payload_type);
152
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000153 // Sets the starting sequence number, must be called before StartSend.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000154 int32_t SetStartSequenceNumber(uint16_t sequence_number);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000155
pbos@webrtc.org2fd91bd2014-07-07 13:06:48 +0000156 void SetRtpStateForSsrc(uint32_t ssrc, const RtpState& rtp_state);
157 RtpState GetRtpStateForSsrc(uint32_t ssrc);
158
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000159 // Sets the CName for the outgoing stream on the channel.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000160 int32_t SetRTCPCName(const char rtcp_cname[]);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000161
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000162 // Gets the CName of the incoming stream.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000163 int32_t GetRemoteRTCPCName(char rtcp_cname[]);
164 int32_t RegisterRtpObserver(ViERTPObserver* observer);
165 int32_t RegisterRtcpObserver(ViERTCPObserver* observer);
166 int32_t SendApplicationDefinedRTCPPacket(
167 const uint8_t sub_type,
168 uint32_t name,
169 const uint8_t* data,
170 uint16_t data_length_in_bytes);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000171
172 // Returns statistics reported by the remote client in an RTCP packet.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000173 int32_t GetSendRtcpStatistics(uint16_t* fraction_lost,
174 uint32_t* cumulative_lost,
175 uint32_t* extended_max,
176 uint32_t* jitter_samples,
177 int32_t* rtt_ms);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000178
sprang@webrtc.org9b30fd32013-12-05 09:48:44 +0000179 // Called on receipt of RTCP report block from remote side.
180 void RegisterSendChannelRtcpStatisticsCallback(
181 RtcpStatisticsCallback* callback);
182
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000183 // Returns our localy created statistics of the received RTP stream.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000184 int32_t GetReceivedRtcpStatistics(uint16_t* fraction_lost,
185 uint32_t* cumulative_lost,
186 uint32_t* extended_max,
187 uint32_t* jitter_samples,
188 int32_t* rtt_ms);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000189
sprang@webrtc.org4f1f5fa2013-12-19 13:26:02 +0000190 // Called on generation of RTCP stats
191 void RegisterReceiveChannelRtcpStatisticsCallback(
192 RtcpStatisticsCallback* callback);
193
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000194 // Gets sent/received packets statistics.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000195 int32_t GetRtpStatistics(uint32_t* bytes_sent,
196 uint32_t* packets_sent,
197 uint32_t* bytes_received,
198 uint32_t* packets_received) const;
sprang@webrtc.orgb1139812013-12-05 14:29:02 +0000199
200 // Called on update of RTP statistics.
201 void RegisterSendChannelRtpStatisticsCallback(
202 StreamDataCountersCallback* callback);
203
sprang@webrtc.org7d99cd42014-01-23 10:00:39 +0000204 // Called on update of RTP statistics.
205 void RegisterReceiveChannelRtpStatisticsCallback(
206 StreamDataCountersCallback* callback);
207
asapersson@webrtc.org4a155602014-02-19 11:59:02 +0000208 void GetRtcpPacketTypeCounters(RtcpPacketTypeCounter* packets_sent,
209 RtcpPacketTypeCounter* packets_received) const;
210
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000211 void GetBandwidthUsage(uint32_t* total_bitrate_sent,
212 uint32_t* video_bitrate_sent,
213 uint32_t* fec_bitrate_sent,
214 uint32_t* nackBitrateSent) const;
stefan@webrtc.org55b0f2e2014-07-11 13:44:02 +0000215 // TODO(holmer): Deprecated. We should use the SendSideDelayObserver instead
216 // to avoid deadlocks.
stefan@webrtc.orgee234be2013-12-05 14:05:07 +0000217 bool GetSendSideDelay(int* avg_send_delay, int* max_send_delay) const;
stefan@webrtc.org55b0f2e2014-07-11 13:44:02 +0000218 void RegisterSendSideDelayObserver(SendSideDelayObserver* observer);
jiayl@webrtc.orgd1e7fac2014-02-10 19:12:14 +0000219 void GetReceiveBandwidthEstimatorStats(
220 ReceiveBandwidthEstimatorStats* output) const;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000221
sprang@webrtc.orgb70db6d2013-12-13 09:46:59 +0000222 // Called on any new send bitrate estimate.
223 void RegisterSendBitrateObserver(BitrateStatisticsObserver* observer);
224
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000225 int32_t StartRTPDump(const char file_nameUTF8[1024],
226 RTPDirections direction);
227 int32_t StopRTPDump(RTPDirections direction);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000228
229 // Implements RtcpFeedback.
230 // TODO(pwestin) Depricate this functionality.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000231 virtual void OnApplicationDataReceived(const int32_t id,
232 const uint8_t sub_type,
233 const uint32_t name,
234 const uint16_t length,
235 const uint8_t* data);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000236 // Implements RtpFeedback.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000237 virtual int32_t OnInitializeDecoder(
238 const int32_t id,
239 const int8_t payload_type,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000240 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
241 const int frequency,
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000242 const uint8_t channels,
243 const uint32_t rate);
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000244 virtual void OnIncomingSSRCChanged(const int32_t id,
stefan@webrtc.orga20e2d42013-08-21 20:58:21 +0000245 const uint32_t ssrc);
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000246 virtual void OnIncomingCSRCChanged(const int32_t id,
247 const uint32_t CSRC,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000248 const bool added);
stefan@webrtc.orga20e2d42013-08-21 20:58:21 +0000249 virtual void ResetStatistics(uint32_t);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000250
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000251 int32_t SetLocalReceiver(const uint16_t rtp_port,
252 const uint16_t rtcp_port,
253 const char* ip_address);
254 int32_t GetLocalReceiver(uint16_t* rtp_port,
255 uint16_t* rtcp_port,
256 char* ip_address) const;
257 int32_t SetSendDestination(const char* ip_address,
258 const uint16_t rtp_port,
259 const uint16_t rtcp_port,
260 const uint16_t source_rtp_port,
261 const uint16_t source_rtcp_port);
262 int32_t GetSendDestination(char* ip_address,
263 uint16_t* rtp_port,
264 uint16_t* rtcp_port,
265 uint16_t* source_rtp_port,
266 uint16_t* source_rtcp_port) const;
267 int32_t GetSourceInfo(uint16_t* rtp_port,
268 uint16_t* rtcp_port,
269 char* ip_address,
270 uint32_t ip_address_length);
pwestin@webrtc.org912b7f72013-03-13 23:20:57 +0000271
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +0000272 int32_t SetRemoteSSRCType(const StreamType usage, const uint32_t SSRC);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000273
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000274 int32_t StartSend();
275 int32_t StopSend();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000276 bool Sending();
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000277 int32_t StartReceive();
278 int32_t StopReceive();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000279
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000280 int32_t RegisterSendTransport(Transport* transport);
281 int32_t DeregisterSendTransport();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000282
283 // Incoming packet from external transport.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000284 int32_t ReceivedRTPPacket(const void* rtp_packet,
wu@webrtc.orgefeb8ce2013-12-13 00:21:03 +0000285 const int32_t rtp_packet_length,
286 const PacketTime& packet_time);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000287
288 // Incoming packet from external transport.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000289 int32_t ReceivedRTCPPacket(const void* rtcp_packet,
290 const int32_t rtcp_packet_length);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000291
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000292 // Sets the maximum transfer unit size for the network link, i.e. including
293 // IP, UDP and RTP headers.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000294 int32_t SetMTU(uint16_t mtu);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000295
296 // Returns maximum allowed payload size, i.e. the maximum allowed size of
297 // encoded data in each packet.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000298 uint16_t MaxDataPayloadLength() const;
299 int32_t SetMaxPacketBurstSize(uint16_t max_number_of_packets);
300 int32_t SetPacketBurstSpreadState(bool enable, const uint16_t frame_periodMS);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000301
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000302 int32_t EnableColorEnhancement(bool enable);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000303
304 // Gets the modules used by the channel.
305 RtpRtcp* rtp_rtcp();
306
fischman@webrtc.org0329e592013-02-19 22:09:36 +0000307 CallStatsObserver* GetStatsObserver();
mflodman@webrtc.org78696d32012-11-26 12:40:15 +0000308
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000309 // Implements VCMReceiveCallback.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000310 virtual int32_t FrameToRender(I420VideoFrame& video_frame); // NOLINT
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000311
312 // Implements VCMReceiveCallback.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000313 virtual int32_t ReceivedDecodedReferenceFrame(
314 const uint64_t picture_id);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000315
wuchengli@chromium.orgd893b3f2013-08-12 14:20:49 +0000316 // Implements VCMReceiveCallback.
317 virtual void IncomingCodecChanged(const VideoCodec& codec);
318
fischman@webrtc.orgecfef192013-10-23 23:59:45 +0000319 // Implements VCMReceiveStatisticsCallback.
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +0000320 virtual int32_t OnReceiveStatisticsUpdate(const uint32_t bit_rate,
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000321 const uint32_t frame_rate);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000322
fischman@webrtc.orgecfef192013-10-23 23:59:45 +0000323 // Implements VCMDecoderTimingCallback.
324 virtual void OnDecoderTiming(int decode_ms,
325 int max_decode_ms,
326 int current_delay_ms,
327 int target_delay_ms,
328 int jitter_buffer_ms,
329 int min_playout_delay_ms,
330 int render_delay_ms);
331
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000332 // Implements VideoFrameTypeCallback.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000333 virtual int32_t RequestKeyFrame();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000334
335 // Implements VideoFrameTypeCallback.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000336 virtual int32_t SliceLossIndicationRequest(
337 const uint64_t picture_id);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000338
339 // Implements VideoPacketRequestCallback.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000340 virtual int32_t ResendPackets(const uint16_t* sequence_numbers,
341 uint16_t length);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000342
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000343 int32_t SetVoiceChannel(int32_t ve_channel_id,
344 VoEVideoSync* ve_sync_interface);
345 int32_t VoiceChannel();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000346
347 // Implements ViEFrameProviderBase.
348 virtual int FrameCallbackChanged() {return -1;}
349
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000350 int32_t RegisterEffectFilter(ViEEffectFilter* effect_filter);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000351
sprang@webrtc.org2e98d452013-11-26 11:41:59 +0000352 // New-style callbacks, used by VideoReceiveStream.
pbos@webrtc.org63301bd2013-10-21 10:34:43 +0000353 void RegisterPreRenderCallback(I420FrameCallback* pre_render_callback);
sprang@webrtc.org2e98d452013-11-26 11:41:59 +0000354 void RegisterPreDecodeImageCallback(
355 EncodedImageCallback* pre_decode_callback);
pbos@webrtc.org63301bd2013-10-21 10:34:43 +0000356
sprang@webrtc.org5fdd10a2013-12-04 15:09:27 +0000357 void RegisterSendFrameCountObserver(FrameCountObserver* observer);
358
solenberg@webrtc.org2d3624c2014-03-24 20:28:11 +0000359 void ReceivedBWEPacket(int64_t arrival_time_ms, int payload_size,
360 const RTPHeader& header);
361
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000362 protected:
363 static bool ChannelDecodeThreadFunction(void* obj);
364 bool ChannelDecodeProcess();
365
mflodman@webrtc.org78696d32012-11-26 12:40:15 +0000366 void OnRttUpdate(uint32_t rtt);
367
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000368 private:
pbos@webrtc.org88b558f2014-06-30 13:19:09 +0000369 void ReserveRtpRtcpModules(size_t total_modules)
370 EXCLUSIVE_LOCKS_REQUIRED(rtp_rtcp_cs_);
371 RtpRtcp* GetRtpRtcpModule(size_t simulcast_idx) const
372 EXCLUSIVE_LOCKS_REQUIRED(rtp_rtcp_cs_);
373 RtpRtcp* CreateRtpRtcpModule();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000374 // Assumed to be protected.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000375 int32_t StartDecodeThread();
376 int32_t StopDecodeThread();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000377
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000378 int32_t ProcessNACKRequest(const bool enable);
379 int32_t ProcessFECRequest(const bool enable,
380 const unsigned char payload_typeRED,
381 const unsigned char payload_typeFEC);
mikhal@webrtc.org9d6fcb32013-02-15 23:22:18 +0000382 // Compute NACK list parameters for the buffering mode.
383 int GetRequiredNackListSize(int target_delay_ms);
stefan@webrtc.org6845de72014-06-11 13:41:36 +0000384 void SetRtxSendStatus(bool enable);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000385
andresp@webrtc.orgf8ec08e2014-07-08 14:32:58 +0000386 // ViEChannel exposes methods that allow to modify observers and callbacks
387 // to be modified. Such an API-style is cumbersome to implement and maintain
388 // at all the levels when comparing to only setting them at construction. As
389 // so this class instantiates its children with a wrapper that can be modified
390 // at a later time.
391 template <class T>
392 class RegisterableCallback : public T {
393 public:
394 RegisterableCallback()
395 : critsect_(CriticalSectionWrapper::CreateCriticalSection()),
396 callback_(NULL) {}
397
398 void Set(T* callback) {
399 CriticalSectionScoped cs(critsect_.get());
400 callback_ = callback;
401 }
402
403 protected:
404 // Note: this should be implemented with a RW-lock to allow simultaneous
405 // calls into the callback. However that doesn't seem to be needed for the
406 // current type of callbacks covered by this class.
407 scoped_ptr<CriticalSectionWrapper> critsect_;
408 T* callback_ GUARDED_BY(critsect_);
409
410 private:
411 DISALLOW_COPY_AND_ASSIGN(RegisterableCallback);
412 };
413
andresp@webrtc.org8c95e832014-07-10 09:39:23 +0000414 class RegisterableBitrateStatisticsObserver:
415 public RegisterableCallback<BitrateStatisticsObserver> {
andresp@webrtc.orgf8ec08e2014-07-08 14:32:58 +0000416 virtual void Notify(const BitrateStatistics& stats, uint32_t ssrc) {
417 CriticalSectionScoped cs(critsect_.get());
418 if (callback_)
419 callback_->Notify(stats, ssrc);
420 }
421 }
422 send_bitrate_observer_;
423
andresp@webrtc.org8c95e832014-07-10 09:39:23 +0000424 class RegisterableFrameCountObserver
425 : public RegisterableCallback<FrameCountObserver> {
426 virtual void FrameCountUpdated(FrameType frame_type,
427 uint32_t frame_count,
428 const unsigned int ssrc) {
429 CriticalSectionScoped cs(critsect_.get());
430 if (callback_)
431 callback_->FrameCountUpdated(frame_type, frame_count, ssrc);
432 }
433 } send_frame_count_observer_;
434
stefan@webrtc.org55b0f2e2014-07-11 13:44:02 +0000435 class RegisterableSendSideDelayObserver :
436 public RegisterableCallback<SendSideDelayObserver> {
437 virtual void SendSideDelayUpdated(int avg_delay_ms,
438 int max_delay_ms,
439 uint32_t ssrc) OVERRIDE {
440 CriticalSectionScoped cs(critsect_.get());
441 if (callback_)
442 callback_->SendSideDelayUpdated(avg_delay_ms, max_delay_ms, ssrc);
443 }
444 } send_side_delay_observer_;
445
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000446 int32_t channel_id_;
447 int32_t engine_id_;
448 uint32_t number_of_cores_;
449 uint8_t num_socket_threads_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000450
451 // Used for all registered callbacks except rendering.
452 scoped_ptr<CriticalSectionWrapper> callback_cs_;
453 scoped_ptr<CriticalSectionWrapper> rtp_rtcp_cs_;
454
455 RtpRtcp* default_rtp_rtcp_;
456
457 // Owned modules/classes.
458 scoped_ptr<RtpRtcp> rtp_rtcp_;
459 std::list<RtpRtcp*> simulcast_rtp_rtcp_;
mflodman@webrtc.org55e6f582013-02-20 16:00:27 +0000460 std::list<RtpRtcp*> removed_rtp_rtcp_;
pbos@webrtc.org7f545612014-05-23 09:41:07 +0000461 VideoCodingModule* const vcm_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000462 ViEReceiver vie_receiver_;
463 ViESender vie_sender_;
464 ViESyncModule vie_sync_;
465
mflodman@webrtc.org78696d32012-11-26 12:40:15 +0000466 // Helper to report call statistics.
467 scoped_ptr<ChannelStatsObserver> stats_observer_;
468
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000469 // Not owned.
470 ProcessThread& module_process_thread_;
471 ViEDecoderObserver* codec_observer_;
472 bool do_key_frame_callbackRequest_;
473 ViERTPObserver* rtp_observer_;
474 ViERTCPObserver* rtcp_observer_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000475 RtcpIntraFrameObserver* intra_frame_observer_;
asapersson@webrtc.orgc4af4cf2013-11-20 12:46:11 +0000476 RtcpRttStats* rtt_stats_;
pwestin@webrtc.org5e87b5f2012-11-13 21:12:39 +0000477 PacedSender* paced_sender_;
stefan@webrtc.org6845de72014-06-11 13:41:36 +0000478 bool pad_with_redundant_payloads_;
pwestin@webrtc.org5e87b5f2012-11-13 21:12:39 +0000479
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000480 scoped_ptr<RtcpBandwidthObserver> bandwidth_observer_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000481 int send_timestamp_extension_id_;
solenberg@webrtc.org453f9c02013-05-20 12:00:23 +0000482 int absolute_send_time_extension_id_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000483
484 Transport* external_transport_;
485
486 bool decoder_reset_;
wuchengli@chromium.orgd893b3f2013-08-12 14:20:49 +0000487 // Current receive codec used for codec change callback.
488 VideoCodec receive_codec_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000489 bool wait_for_key_frame_;
490 ThreadWrapper* decode_thread_;
491
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000492 ViEEffectFilter* effect_filter_;
493 bool color_enhancement_;
494
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000495 // User set MTU, -1 if not set.
496 uint16_t mtu_;
497 const bool sender_;
mikhal@webrtc.org16196642013-02-01 19:33:21 +0000498
499 int nack_history_size_sender_;
mikhal@webrtc.org9d6fcb32013-02-15 23:22:18 +0000500 int max_nack_reordering_threshold_;
pbos@webrtc.org63301bd2013-10-21 10:34:43 +0000501 I420FrameCallback* pre_render_callback_;
stefan@webrtc.orgd1d198b2014-08-14 15:10:49 +0000502
503 std::map<uint32_t, RTCPReportBlock> prev_report_blocks_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000504};
505
506} // namespace webrtc
507
508#endif // WEBRTC_VIDEO_ENGINE_VIE_CHANNEL_H_