niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 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.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_VIDEO_CODING_MAIN_SOURCE_RECEIVER_H_ |
| 12 | #define WEBRTC_MODULES_VIDEO_CODING_MAIN_SOURCE_RECEIVER_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 14 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 15 | #include "webrtc/modules/video_coding/main/source/jitter_buffer.h" |
| 16 | #include "webrtc/modules/video_coding/main/source/packet.h" |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 17 | #include "webrtc/modules/video_coding/main/source/timing.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 19 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 21 | class Clock; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | class VCMEncodedFrame; |
| 23 | |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 24 | enum VCMNackStatus { |
| 25 | kNackOk, |
| 26 | kNackNeedMoreMemory, |
| 27 | kNackKeyFrameRequest |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | }; |
| 29 | |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 30 | enum VCMReceiverState { |
| 31 | kReceiving, |
| 32 | kPassive, |
| 33 | kWaitForPrimaryDecode |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 36 | class VCMReceiver { |
| 37 | public: |
| 38 | VCMReceiver(VCMTiming* timing, |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 39 | Clock* clock, |
stefan@webrtc.org | 2baf5f5 | 2013-03-13 08:46:25 +0000 | [diff] [blame] | 40 | EventFactory* event_factory, |
| 41 | int32_t vcm_id, |
| 42 | int32_t receiver_id, |
| 43 | bool master); |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 44 | ~VCMReceiver(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 46 | void Reset(); |
| 47 | int32_t Initialize(); |
| 48 | void UpdateRtt(uint32_t rtt); |
| 49 | int32_t InsertPacket(const VCMPacket& packet, |
| 50 | uint16_t frame_width, |
| 51 | uint16_t frame_height); |
| 52 | VCMEncodedFrame* FrameForDecoding(uint16_t max_wait_time_ms, |
| 53 | int64_t& next_render_time_ms, |
| 54 | bool render_timing = true, |
| 55 | VCMReceiver* dual_receiver = NULL); |
| 56 | void ReleaseFrame(VCMEncodedFrame* frame); |
| 57 | void ReceiveStatistics(uint32_t* bitrate, uint32_t* framerate); |
| 58 | void ReceivedFrameCount(VCMFrameCount* frame_count) const; |
| 59 | uint32_t DiscardedPackets() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 61 | // NACK. |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 62 | void SetNackMode(VCMNackMode nackMode, |
| 63 | int low_rtt_nack_threshold_ms, |
| 64 | int high_rtt_nack_threshold_ms); |
stefan@webrtc.org | becf9c8 | 2013-02-01 15:09:57 +0000 | [diff] [blame] | 65 | void SetNackSettings(size_t max_nack_list_size, |
| 66 | int max_packet_age_to_nack); |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 67 | VCMNackMode NackMode() const; |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 68 | VCMNackStatus NackList(uint16_t* nackList, uint16_t size, |
| 69 | uint16_t* nack_list_length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 71 | // Dual decoder. |
| 72 | bool DualDecoderCaughtUp(VCMEncodedFrame* dual_frame, |
| 73 | VCMReceiver& dual_receiver) const; |
| 74 | VCMReceiverState State() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | |
mikhal@webrtc.org | ef9f76a | 2013-02-15 23:22:18 +0000 | [diff] [blame] | 76 | // Receiver video delay. |
| 77 | int SetMinReceiverDelay(int desired_delay_ms); |
| 78 | |
mikhal@webrtc.org | dc3cd21 | 2013-04-25 20:27:04 +0000 | [diff] [blame] | 79 | // Decoding with errors. |
| 80 | void SetDecodeWithErrors(bool enable); |
| 81 | bool DecodeWithErrors() const; |
| 82 | |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 83 | // Returns size in time (milliseconds) of complete continuous frames in the |
stefan@webrtc.org | 4ce19b1 | 2013-05-06 13:16:51 +0000 | [diff] [blame] | 84 | // jitter buffer. |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 85 | int RenderBufferSizeMs(); |
| 86 | |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 87 | private: |
stefan@webrtc.org | 4ce19b1 | 2013-05-06 13:16:51 +0000 | [diff] [blame] | 88 | VCMEncodedFrame* FrameForDecoding(uint16_t max_wait_time_ms, |
| 89 | int64_t nextrender_time_ms, |
| 90 | VCMReceiver* dual_receiver); |
| 91 | VCMEncodedFrame* FrameForRendering(uint16_t max_wait_time_ms, |
| 92 | int64_t nextrender_time_ms, |
| 93 | VCMReceiver* dual_receiver); |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 94 | void CopyJitterBufferStateFromReceiver(const VCMReceiver& receiver); |
| 95 | void UpdateState(VCMReceiverState new_state); |
| 96 | void UpdateState(const VCMEncodedFrame& frame); |
| 97 | static int32_t GenerateReceiverId(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 99 | CriticalSectionWrapper* crit_sect_; |
| 100 | int32_t vcm_id_; |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 101 | Clock* clock_; |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 102 | int32_t receiver_id_; |
| 103 | bool master_; |
| 104 | VCMJitterBuffer jitter_buffer_; |
| 105 | VCMTiming* timing_; |
stefan@webrtc.org | 2baf5f5 | 2013-03-13 08:46:25 +0000 | [diff] [blame] | 106 | scoped_ptr<EventWrapper> render_wait_event_; |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 107 | VCMReceiverState state_; |
mikhal@webrtc.org | ef9f76a | 2013-02-15 23:22:18 +0000 | [diff] [blame] | 108 | int max_video_delay_ms_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 110 | static int32_t receiver_id_counter_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | }; |
| 112 | |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 113 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | |
stefan@webrtc.org | 1ea4b50 | 2013-01-07 08:49:41 +0000 | [diff] [blame] | 115 | #endif // WEBRTC_MODULES_VIDEO_CODING_MAIN_SOURCE_RECEIVER_H_ |