blob: ff0eef8a6af54b2dff435f68b97e980e25b347ae [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
2 * Copyright (c) 2011 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
Henrik Kjellander2557b862015-11-18 22:00:21 +010011#ifndef WEBRTC_MODULES_VIDEO_CODING_RECEIVER_H_
12#define WEBRTC_MODULES_VIDEO_CODING_RECEIVER_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
philipel9d3ab612015-12-21 04:12:39 -080014#include <vector>
15
Henrik Kjellander2557b862015-11-18 22:00:21 +010016#include "webrtc/modules/video_coding/jitter_buffer.h"
17#include "webrtc/modules/video_coding/packet.h"
18#include "webrtc/modules/video_coding/timing.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010019#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
Henrik Kjellander2557b862015-11-18 22:00:21 +010020#include "webrtc/modules/video_coding/include/video_coding.h"
21#include "webrtc/modules/video_coding/include/video_coding_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000022
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000023namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000024
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +000025class Clock;
niklase@google.com470e71d2011-07-07 08:21:25 +000026class VCMEncodedFrame;
27
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000028class VCMReceiver {
29 public:
philipel9d3ab612015-12-21 04:12:39 -080030 VCMReceiver(VCMTiming* timing, Clock* clock, EventFactory* event_factory);
Qiang Chend4cec152015-06-19 09:17:00 -070031
32 // Using this constructor, you can specify a different event factory for the
33 // jitter buffer. Useful for unit tests when you want to simulate incoming
34 // packets, in which case the jitter buffer's wait event is different from
35 // that of VCMReceiver itself.
36 VCMReceiver(VCMTiming* timing,
37 Clock* clock,
38 rtc::scoped_ptr<EventWrapper> receiver_event,
39 rtc::scoped_ptr<EventWrapper> jitter_buffer_event);
40
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000041 ~VCMReceiver();
niklase@google.com470e71d2011-07-07 08:21:25 +000042
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000043 void Reset();
pkasting@chromium.org16825b12015-01-12 21:51:21 +000044 void UpdateRtt(int64_t rtt);
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000045 int32_t InsertPacket(const VCMPacket& packet,
46 uint16_t frame_width,
47 uint16_t frame_height);
48 VCMEncodedFrame* FrameForDecoding(uint16_t max_wait_time_ms,
philipel9d3ab612015-12-21 04:12:39 -080049 int64_t* next_render_time_ms,
perkj796cfaf2015-12-10 09:27:38 -080050 bool prefer_late_decoding);
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000051 void ReleaseFrame(VCMEncodedFrame* frame);
52 void ReceiveStatistics(uint32_t* bitrate, uint32_t* framerate);
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000053 uint32_t DiscardedPackets() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000054
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000055 // NACK.
stefan@webrtc.orga64300a2013-03-04 15:24:40 +000056 void SetNackMode(VCMNackMode nackMode,
pkasting@chromium.org16825b12015-01-12 21:51:21 +000057 int64_t low_rtt_nack_threshold_ms,
58 int64_t high_rtt_nack_threshold_ms);
stefan@webrtc.orgbecf9c82013-02-01 15:09:57 +000059 void SetNackSettings(size_t max_nack_list_size,
stefan@webrtc.orgef144882013-05-07 19:16:33 +000060 int max_packet_age_to_nack,
61 int max_incomplete_time_ms);
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000062 VCMNackMode NackMode() const;
Wan-Teh Changb1825a42015-06-03 15:03:35 -070063 std::vector<uint16_t> NackList(bool* request_key_frame);
niklase@google.com470e71d2011-07-07 08:21:25 +000064
mikhal@webrtc.orgef9f76a2013-02-15 23:22:18 +000065 // Receiver video delay.
66 int SetMinReceiverDelay(int desired_delay_ms);
67
mikhal@webrtc.orgdc3cd212013-04-25 20:27:04 +000068 // Decoding with errors.
agalusza@google.coma7e360e2013-08-01 03:15:08 +000069 void SetDecodeErrorMode(VCMDecodeErrorMode decode_error_mode);
70 VCMDecodeErrorMode DecodeErrorMode() const;
mikhal@webrtc.orgdc3cd212013-04-25 20:27:04 +000071
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000072 // Returns size in time (milliseconds) of complete continuous frames in the
mikhal@webrtc.org759b0412013-05-07 16:36:00 +000073 // jitter buffer. The render time is estimated based on the render delay at
74 // the time this function is called.
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000075 int RenderBufferSizeMs();
76
pbos@webrtc.org55707692014-12-19 15:45:03 +000077 void RegisterStatsCallback(VCMReceiveStatisticsCallback* callback);
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +000078
pbos@webrtc.org4dd40d62015-02-17 13:22:43 +000079 void TriggerDecoderShutdown();
80
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000081 private:
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000082 CriticalSectionWrapper* crit_sect_;
pbos@webrtc.org4dd40d62015-02-17 13:22:43 +000083 Clock* const clock_;
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000084 VCMJitterBuffer jitter_buffer_;
85 VCMTiming* timing_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000086 rtc::scoped_ptr<EventWrapper> render_wait_event_;
mikhal@webrtc.orgef9f76a2013-02-15 23:22:18 +000087 int max_video_delay_ms_;
niklase@google.com470e71d2011-07-07 08:21:25 +000088};
89
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000090} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000091
Henrik Kjellander2557b862015-11-18 22:00:21 +010092#endif // WEBRTC_MODULES_VIDEO_CODING_RECEIVER_H_