blob: c037303978f88c355da9948aa7eb21e3992ddba3 [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
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000011#ifndef WEBRTC_MODULES_VIDEO_CODING_MAIN_SOURCE_RECEIVER_H_
12#define WEBRTC_MODULES_VIDEO_CODING_MAIN_SOURCE_RECEIVER_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000014#include "webrtc/modules/video_coding/main/source/jitter_buffer.h"
15#include "webrtc/modules/video_coding/main/source/packet.h"
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000016#include "webrtc/modules/video_coding/main/source/timing.h"
pbos@webrtc.orga4407322013-07-16 12:32:05 +000017#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
agalusza@google.coma7e360e2013-08-01 03:15:08 +000018#include "webrtc/modules/video_coding/main/interface/video_coding.h"
19#include "webrtc/modules/video_coding/main/interface/video_coding_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000021namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000022
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +000023class Clock;
niklase@google.com470e71d2011-07-07 08:21:25 +000024class VCMEncodedFrame;
25
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000026enum VCMNackStatus {
27 kNackOk,
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000028 kNackKeyFrameRequest
niklase@google.com470e71d2011-07-07 08:21:25 +000029};
30
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000031enum VCMReceiverState {
32 kReceiving,
33 kPassive,
34 kWaitForPrimaryDecode
niklase@google.com470e71d2011-07-07 08:21:25 +000035};
36
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000037class VCMReceiver {
38 public:
39 VCMReceiver(VCMTiming* timing,
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +000040 Clock* clock,
stefan@webrtc.org2baf5f52013-03-13 08:46:25 +000041 EventFactory* event_factory,
stefan@webrtc.org2baf5f52013-03-13 08:46:25 +000042 bool master);
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000043 ~VCMReceiver();
niklase@google.com470e71d2011-07-07 08:21:25 +000044
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000045 void Reset();
46 int32_t Initialize();
47 void UpdateRtt(uint32_t rtt);
48 int32_t InsertPacket(const VCMPacket& packet,
49 uint16_t frame_width,
50 uint16_t frame_height);
51 VCMEncodedFrame* FrameForDecoding(uint16_t max_wait_time_ms,
52 int64_t& next_render_time_ms,
53 bool render_timing = true,
54 VCMReceiver* dual_receiver = NULL);
55 void ReleaseFrame(VCMEncodedFrame* frame);
56 void ReceiveStatistics(uint32_t* bitrate, uint32_t* framerate);
57 void ReceivedFrameCount(VCMFrameCount* frame_count) const;
58 uint32_t DiscardedPackets() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000059
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000060 // NACK.
stefan@webrtc.orga64300a2013-03-04 15:24:40 +000061 void SetNackMode(VCMNackMode nackMode,
62 int low_rtt_nack_threshold_ms,
63 int high_rtt_nack_threshold_ms);
stefan@webrtc.orgbecf9c82013-02-01 15:09:57 +000064 void SetNackSettings(size_t max_nack_list_size,
stefan@webrtc.orgef144882013-05-07 19:16:33 +000065 int max_packet_age_to_nack,
66 int max_incomplete_time_ms);
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000067 VCMNackMode NackMode() const;
stefan@webrtc.orga64300a2013-03-04 15:24:40 +000068 VCMNackStatus NackList(uint16_t* nackList, uint16_t size,
69 uint16_t* nack_list_length);
niklase@google.com470e71d2011-07-07 08:21:25 +000070
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000071 // Dual decoder.
72 bool DualDecoderCaughtUp(VCMEncodedFrame* dual_frame,
73 VCMReceiver& dual_receiver) const;
74 VCMReceiverState State() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000075
mikhal@webrtc.orgef9f76a2013-02-15 23:22:18 +000076 // Receiver video delay.
77 int SetMinReceiverDelay(int desired_delay_ms);
78
mikhal@webrtc.orgdc3cd212013-04-25 20:27:04 +000079 // Decoding with errors.
agalusza@google.coma7e360e2013-08-01 03:15:08 +000080 void SetDecodeErrorMode(VCMDecodeErrorMode decode_error_mode);
81 VCMDecodeErrorMode DecodeErrorMode() const;
mikhal@webrtc.orgdc3cd212013-04-25 20:27:04 +000082
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000083 // Returns size in time (milliseconds) of complete continuous frames in the
mikhal@webrtc.org759b0412013-05-07 16:36:00 +000084 // jitter buffer. The render time is estimated based on the render delay at
85 // the time this function is called.
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000086 int RenderBufferSizeMs();
87
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000088 private:
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000089 void CopyJitterBufferStateFromReceiver(const VCMReceiver& receiver);
90 void UpdateState(VCMReceiverState new_state);
91 void UpdateState(const VCMEncodedFrame& frame);
92 static int32_t GenerateReceiverId();
niklase@google.com470e71d2011-07-07 08:21:25 +000093
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000094 CriticalSectionWrapper* crit_sect_;
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +000095 Clock* clock_;
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +000096 bool master_;
97 VCMJitterBuffer jitter_buffer_;
98 VCMTiming* timing_;
stefan@webrtc.org2baf5f52013-03-13 08:46:25 +000099 scoped_ptr<EventWrapper> render_wait_event_;
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +0000100 VCMReceiverState state_;
mikhal@webrtc.orgef9f76a2013-02-15 23:22:18 +0000101 int max_video_delay_ms_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +0000103 static int32_t receiver_id_counter_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000104};
105
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +0000106} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
stefan@webrtc.org1ea4b502013-01-07 08:49:41 +0000108#endif // WEBRTC_MODULES_VIDEO_CODING_MAIN_SOURCE_RECEIVER_H_