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
11#ifndef WEBRTC_MODULES_VIDEO_CODING_RECEIVER_H_
12#define WEBRTC_MODULES_VIDEO_CODING_RECEIVER_H_
13
14#include <vector>
15
16#include "webrtc/modules/video_coding/jitter_buffer.h"
17#include "webrtc/modules/video_coding/packet.h"
18#include "webrtc/modules/video_coding/timing.h"
19#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
20#include "webrtc/modules/video_coding/include/video_coding.h"
21#include "webrtc/modules/video_coding/include/video_coding_defines.h"
22
23namespace webrtc {
24
25class Clock;
26class VCMEncodedFrame;
27
28class VCMReceiver {
29 public:
30  VCMReceiver(VCMTiming* timing, Clock* clock, EventFactory* event_factory);
31
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
41  ~VCMReceiver();
42
43  void Reset();
44  void UpdateRtt(int64_t rtt);
45  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,
49                                    int64_t* next_render_time_ms,
50                                    bool prefer_late_decoding);
51  void ReleaseFrame(VCMEncodedFrame* frame);
52  void ReceiveStatistics(uint32_t* bitrate, uint32_t* framerate);
53  uint32_t DiscardedPackets() const;
54
55  // NACK.
56  void SetNackMode(VCMNackMode nackMode,
57                   int64_t low_rtt_nack_threshold_ms,
58                   int64_t high_rtt_nack_threshold_ms);
59  void SetNackSettings(size_t max_nack_list_size,
60                       int max_packet_age_to_nack,
61                       int max_incomplete_time_ms);
62  VCMNackMode NackMode() const;
63  std::vector<uint16_t> NackList(bool* request_key_frame);
64
65  // Receiver video delay.
66  int SetMinReceiverDelay(int desired_delay_ms);
67
68  // Decoding with errors.
69  void SetDecodeErrorMode(VCMDecodeErrorMode decode_error_mode);
70  VCMDecodeErrorMode DecodeErrorMode() const;
71
72  // Returns size in time (milliseconds) of complete continuous frames in the
73  // jitter buffer. The render time is estimated based on the render delay at
74  // the time this function is called.
75  int RenderBufferSizeMs();
76
77  void RegisterStatsCallback(VCMReceiveStatisticsCallback* callback);
78
79  void TriggerDecoderShutdown();
80
81 private:
82  CriticalSectionWrapper* crit_sect_;
83  Clock* const clock_;
84  VCMJitterBuffer jitter_buffer_;
85  VCMTiming* timing_;
86  rtc::scoped_ptr<EventWrapper> render_wait_event_;
87  int max_video_delay_ms_;
88};
89
90}  // namespace webrtc
91
92#endif  // WEBRTC_MODULES_VIDEO_CODING_RECEIVER_H_
93