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 | |
| 11 | #ifndef WEBRTC_MODULES_VIDEO_CODING_RECEIVER_H_ |
| 12 | #define WEBRTC_MODULES_VIDEO_CODING_RECEIVER_H_ |
| 13 | |
| 14 | #include "critical_section_wrapper.h" |
| 15 | #include "jitter_buffer.h" |
henrik.lundin@webrtc.org | 7d8c72e | 2011-12-21 15:24:01 +0000 | [diff] [blame] | 16 | #include "modules/video_coding/main/source/tick_time_base.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | #include "timing.h" |
| 18 | #include "packet.h" |
| 19 | |
| 20 | namespace webrtc |
| 21 | { |
| 22 | |
| 23 | class VCMEncodedFrame; |
| 24 | |
| 25 | enum VCMNackStatus |
| 26 | { |
| 27 | kNackOk, |
| 28 | kNackNeedMoreMemory, |
| 29 | kNackKeyFrameRequest |
| 30 | }; |
| 31 | |
| 32 | |
| 33 | enum VCMReceiverState |
| 34 | { |
| 35 | kReceiving, |
| 36 | kPassive, |
| 37 | kWaitForPrimaryDecode |
| 38 | }; |
| 39 | |
| 40 | class VCMReceiver |
| 41 | { |
| 42 | public: |
| 43 | VCMReceiver(VCMTiming& timing, |
henrik.lundin@webrtc.org | 7d8c72e | 2011-12-21 15:24:01 +0000 | [diff] [blame] | 44 | TickTimeBase* clock, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | WebRtc_Word32 vcmId = -1, |
| 46 | WebRtc_Word32 receiverId = -1, |
| 47 | bool master = true); |
| 48 | ~VCMReceiver(); |
| 49 | |
henrik.lundin@webrtc.org | baf6db5 | 2011-11-02 18:58:39 +0000 | [diff] [blame] | 50 | void Reset(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | WebRtc_Word32 Initialize(); |
| 52 | void UpdateRtt(WebRtc_UWord32 rtt); |
| 53 | WebRtc_Word32 InsertPacket(const VCMPacket& packet, |
| 54 | WebRtc_UWord16 frameWidth, |
| 55 | WebRtc_UWord16 frameHeight); |
| 56 | VCMEncodedFrame* FrameForDecoding(WebRtc_UWord16 maxWaitTimeMs, |
| 57 | WebRtc_Word64& nextRenderTimeMs, |
| 58 | bool renderTiming = true, |
| 59 | VCMReceiver* dualReceiver = NULL); |
| 60 | void ReleaseFrame(VCMEncodedFrame* frame); |
| 61 | WebRtc_Word32 ReceiveStatistics(WebRtc_UWord32& bitRate, WebRtc_UWord32& frameRate); |
| 62 | WebRtc_Word32 ReceivedFrameCount(VCMFrameCount& frameCount) const; |
stefan@webrtc.org | 791eec7 | 2011-10-11 07:53:43 +0000 | [diff] [blame] | 63 | WebRtc_UWord32 DiscardedPackets() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | |
| 65 | // NACK |
| 66 | void SetNackMode(VCMNackMode nackMode); |
| 67 | VCMNackMode NackMode() const; |
| 68 | VCMNackStatus NackList(WebRtc_UWord16* nackList, WebRtc_UWord16& size); |
| 69 | |
| 70 | // Dual decoder |
| 71 | bool DualDecoderCaughtUp(VCMEncodedFrame* dualFrame, VCMReceiver& dualReceiver) const; |
| 72 | VCMReceiverState State() const; |
| 73 | |
| 74 | private: |
| 75 | VCMEncodedFrame* FrameForDecoding(WebRtc_UWord16 maxWaitTimeMs, |
| 76 | WebRtc_Word64 nextrenderTimeMs, |
| 77 | VCMReceiver* dualReceiver); |
| 78 | VCMEncodedFrame* FrameForRendering(WebRtc_UWord16 maxWaitTimeMs, |
| 79 | WebRtc_Word64 nextrenderTimeMs, |
| 80 | VCMReceiver* dualReceiver); |
| 81 | void CopyJitterBufferStateFromReceiver(const VCMReceiver& receiver); |
| 82 | void UpdateState(VCMReceiverState newState); |
| 83 | void UpdateState(VCMEncodedFrame& frame); |
| 84 | static WebRtc_Word32 GenerateReceiverId(); |
| 85 | |
stefan@webrtc.org | 7889a9b | 2011-12-12 08:18:24 +0000 | [diff] [blame] | 86 | CriticalSectionWrapper* _critSect; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | WebRtc_Word32 _vcmId; |
henrik.lundin@webrtc.org | 7d8c72e | 2011-12-21 15:24:01 +0000 | [diff] [blame] | 88 | TickTimeBase* _clock; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | WebRtc_Word32 _receiverId; |
| 90 | bool _master; |
| 91 | VCMJitterBuffer _jitterBuffer; |
| 92 | VCMTiming& _timing; |
| 93 | VCMEvent& _renderWaitEvent; |
| 94 | VCMReceiverState _state; |
| 95 | |
| 96 | static WebRtc_Word32 _receiverIdCounter; |
| 97 | }; |
| 98 | |
| 99 | } // namespace webrtc |
| 100 | |
| 101 | #endif // WEBRTC_MODULES_VIDEO_CODING_RECEIVER_H_ |