Chromium Code Reviews| Index: webrtc/modules/video_coding/nack_module.h |
| diff --git a/webrtc/modules/video_coding/nack_module.h b/webrtc/modules/video_coding/nack_module.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2f1ea6cefdca526b769b7700a11bf1329e45ff75 |
| --- /dev/null |
| +++ b/webrtc/modules/video_coding/nack_module.h |
| @@ -0,0 +1,112 @@ |
| +/* |
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#ifndef WEBRTC_MODULES_VIDEO_CODING_NACK_MODULE_H_ |
| +#define WEBRTC_MODULES_VIDEO_CODING_NACK_MODULE_H_ |
| + |
| +#include <map> |
| +#include <vector> |
| +#include <set> |
| + |
| +#include "webrtc/base/thread_annotations.h" |
| +#include "webrtc/modules/include/module.h" |
| +#include "webrtc/modules/video_coding/include/video_coding_defines.h" |
| +#include "webrtc/modules/video_coding/packet.h" |
| +#include "webrtc/system_wrappers/include/clock.h" |
| +#include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| + |
| +namespace webrtc { |
| + |
| +class NackModule : public Module { |
| + public: |
|
stefan-webrtc
2016/02/26 09:26:55
I think we need a method which can be used to info
philipel
2016/02/26 15:12:07
Agree, implemented.
|
| + NackModule(Clock* clock, |
| + VCMNackSender* nack_sender, |
| + VCMKeyFrameRequestSender* keyframe_request_sender); |
| + |
| + void OnReceivedPacket(const VCMPacket& packet); |
| + void UpdateRtt(int64_t rtt_ms); |
| + void Stop(); |
| + |
| + // Module implementation |
| + int64_t TimeUntilNextProcess() override; |
| + int32_t Process() override; |
| + |
| + private: |
| + static const uint16_t kMaxNackPackets = 1000; |
| + static const uint16_t kMaxReorderedPackets = 128; |
| + static const uint16_t kNumReorderingBuckets = 5; |
| + static const uint16_t kDefaultRttMs = 100; |
| + static const uint8_t kMaxNackRetries = 10; |
| + static const uint8_t kProcessFrequency = 50; |
| + static const uint8_t kProcessIntervalMs = 1000 / kProcessFrequency; |
| + |
| + // This class holds the sequence number of the packet that is in the nack list |
| + // as well as the meta data about when it should be nacked and how many times |
| + // we have tried to nack this packet. |
| + struct NackInfo { |
| + NackInfo(); |
| + NackInfo(uint16_t seq_num, uint16_t send_at_seq_num); |
| + |
| + uint16_t seq_num; |
| + uint16_t send_at_seq_num; |
| + int64_t send_at_time; |
|
stefan-webrtc
2016/02/26 09:26:55
Would it be more logical to have "sent_at_time" an
philipel
2016/02/26 15:12:07
For the timestamp I think this is a good idea.
|
| + int retries; |
| + }; |
| + |
| + void AddPacketsToNack(uint16_t seq_num_start, uint16_t seq_num_end) |
| + EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| + |
| + // Removes packets from the nack list until the next |
| + // keyframe. Returns true if packets were removed. |
| + bool RemovePacketsUntilKeyframe() |
| + EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| + void RemovePacketFromNack(uint16_t seq_num) |
| + EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| + |
| + // Which fields to consider when deciding |
| + // which packet to nack in GetNackBatch. |
| + enum NackFilterOptions {kSeqNumOnly, |
| + kTimeOnly, |
| + kSeqNumAndTime}; |
|
stefan-webrtc
2016/02/26 09:26:55
Place type definitions directly after "private:"
philipel
2016/02/26 15:12:07
Done.
|
| + std::vector<uint16_t> GetNackBatch(NackFilterOptions options) |
| + EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| + |
| + // Update the reordering distribution. |
| + void UpdateReorderingStatistics(uint16_t seq_num) |
| + EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| + |
| + // Returns how many packets we have to wait in order to receive |
| + // the packet with probability |probabilty| or higher. |
| + int WaitNumberOfPackets(float probability) const |
| + EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| + |
| + rtc::CriticalSection crit_; |
| + Clock* const clock_; |
| + VCMNackSender* const nack_sender_; |
| + VCMKeyFrameRequestSender* const keyframe_request_sender_; |
| + |
| + SequenceNumberUnwrapper unwrapper_; |
| + std::map<int64_t, NackInfo> nack_list_ GUARDED_BY(crit_); |
| + std::set<int64_t> seq_num_keyframes_ GUARDED_BY(crit_); |
|
stefan-webrtc
2016/02/26 09:26:55
std::set<uint16_t>, right?
philipel
2016/02/26 15:12:07
I use the unrolled sequence number as the key, may
|
| + bool running_ GUARDED_BY(crit_); |
| + bool initialized_ GUARDED_BY(crit_); |
| + int64_t rtt_ms_ GUARDED_BY(crit_); |
| + uint16_t last_seq_num_ GUARDED_BY(crit_); |
| + int64_t last_process_time_ms_ GUARDED_BY(crit_); |
| + |
| + uint8_t reordering_index_ GUARDED_BY(crit_); |
| + uint8_t reordering_count_ GUARDED_BY(crit_); |
|
stefan-webrtc
2016/02/26 09:26:55
int
philipel
2016/02/26 15:12:07
Done.
|
| + int8_t reordering_occurences_[kMaxReorderedPackets] GUARDED_BY(crit_); |
|
stefan-webrtc
2016/02/26 09:26:55
int
philipel
2016/02/26 15:12:07
Done.
|
| + uint8_t reordering_buckets_[kNumReorderingBuckets] GUARDED_BY(crit_); |
|
stefan-webrtc
2016/02/26 09:26:55
int
philipel
2016/02/26 15:12:07
Done.
|
| +}; |
| + |
| +} // namespace webrtc |
| + |
| +#endif // WEBRTC_MODULES_VIDEO_CODING_NACK_MODULE_H_ |