Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(513)

Unified Diff: webrtc/modules/video_coding/protection_bitrate_calculator.h

Issue 1972083002: Move logic for calculating needed bitrate overhead used by NACK and FEC to VideoSender. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed Åsas comments. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/video_coding/protection_bitrate_calculator.h
diff --git a/webrtc/video/send_delay_stats.h b/webrtc/modules/video_coding/protection_bitrate_calculator.h
similarity index 20%
copy from webrtc/video/send_delay_stats.h
copy to webrtc/modules/video_coding/protection_bitrate_calculator.h
index 20a97814c72e808b3acfd5a920290e01a993cc8d..cdbab102d4937fa69e6826c139d1a9cb428387fe 100644
--- a/webrtc/video/send_delay_stats.h
+++ b/webrtc/modules/video_coding/protection_bitrate_calculator.h
@@ -8,86 +8,75 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#ifndef WEBRTC_VIDEO_SEND_DELAY_STATS_H_
-#define WEBRTC_VIDEO_SEND_DELAY_STATS_H_
+#ifndef WEBRTC_MODULES_VIDEO_CODING_PROTECTION_BITRATE_CALCULATOR_H_
+#define WEBRTC_MODULES_VIDEO_CODING_PROTECTION_BITRATE_CALCULATOR_H_
-#include <map>
+#include <list>
#include <memory>
-#include <set>
#include "webrtc/base/criticalsection.h"
-#include "webrtc/base/thread_annotations.h"
-#include "webrtc/common_types.h"
#include "webrtc/modules/include/module_common_types.h"
+#include "webrtc/modules/video_coding/include/video_coding.h"
+#include "webrtc/modules/video_coding/media_opt_util.h"
#include "webrtc/system_wrappers/include/clock.h"
-#include "webrtc/video_send_stream.h"
namespace webrtc {
-class SendDelayStats : public SendPacketObserver {
+// ProtectionBitrateCalculator calculates how much of the allocated network
+// capacity that can be used by an encoder and how much that
+// is needed for redundant packets such as FEC and NACK. It uses an
+// implementation of |VCMProtectionCallback| to set new FEC parameters and get
+// the bitrate currently used for FEC and NACK.
+// Usage:
+// Setup by calling SetProtectionMethod and SetEncodingData.
+// For each encoded image, call UpdateWithEncodedData.
+// Each time the bandwidth estimate change, call SetTargetRates. SetTargetRates
+// will return the bitrate that can be used by an encoder.
+// A lock is used to protect internal states, so methods can be called on an
+// arbitrary thread.
+class ProtectionBitrateCalculator {
public:
- explicit SendDelayStats(Clock* clock);
- virtual ~SendDelayStats();
-
- // Adds the configured ssrcs for the rtp streams.
- // Stats will be calculated for these streams.
- void AddSsrcs(const VideoSendStream::Config& config);
-
- // Called when a packet is sent (leaving socket).
- bool OnSentPacket(int packet_id, int64_t time_ms);
-
- protected:
- // From SendPacketObserver.
- // Called when a packet is sent to the transport.
- void OnSendPacket(uint16_t packet_id,
- int64_t capture_time_ms,
- uint32_t ssrc) override;
+ ProtectionBitrateCalculator(Clock* clock,
+ VCMProtectionCallback* protection_callback);
+ ~ProtectionBitrateCalculator();
+
+ void SetProtectionMethod(bool enable_fec, bool enable_nack);
+
+ // Informs media optimization of initial encoding state.
+ void SetEncodingData(uint32_t estimated_bitrate_bps,
+ uint16_t width,
+ uint16_t height,
+ uint32_t frame_rate,
+ size_t num_temporal_layers,
+ size_t max_payload_size);
+
+ // Returns target rate for the encoder given the channel parameters.
+ // Inputs: estimated_bitrate_bps - the estimated network bitrate in bits/s.
+ // actual_framerate - encoder frame rate.
+ // fraction_lost - packet loss rate in % in the network.
+ // round_trip_time_ms - round trip time in milliseconds.
+ uint32_t SetTargetRates(uint32_t estimated_bitrate_bps,
+ int actual_framerate,
+ uint8_t fraction_lost,
+ int64_t round_trip_time_ms);
+
+ // Informs of encoded output.
+ void UpdateWithEncodedData(const EncodedImage& encoded_image);
private:
- // Map holding sent packets (mapped by sequence number).
- struct SequenceNumberOlderThan {
- bool operator()(uint16_t seq1, uint16_t seq2) const {
- return IsNewerSequenceNumber(seq2, seq1);
- }
- };
- struct Packet {
- Packet(uint32_t ssrc, int64_t capture_time_ms, int64_t send_time_ms)
- : ssrc(ssrc),
- capture_time_ms(capture_time_ms),
- send_time_ms(send_time_ms) {}
- uint32_t ssrc;
- int64_t capture_time_ms;
- int64_t send_time_ms;
- };
- typedef std::map<uint16_t, Packet, SequenceNumberOlderThan> PacketMap;
-
- class SampleCounter {
- public:
- SampleCounter() : sum(0), num_samples(0) {}
- ~SampleCounter() {}
- void Add(int sample);
- int Avg(int min_required_samples) const;
-
- private:
- int sum;
- int num_samples;
- };
-
- void UpdateHistograms();
- void RemoveOld(int64_t now, PacketMap* packets)
- EXCLUSIVE_LOCKS_REQUIRED(crit_);
+ struct EncodedFrameSample;
+ enum { kBitrateAverageWinMs = 1000 };
Clock* const clock_;
- rtc::CriticalSection crit_;
+ VCMProtectionCallback* const protection_callback_;
- PacketMap packets_ GUARDED_BY(crit_);
- size_t num_old_packets_ GUARDED_BY(crit_);
- size_t num_skipped_packets_ GUARDED_BY(crit_);
+ rtc::CriticalSection crit_sect_;
+ std::unique_ptr<media_optimization::VCMLossProtectionLogic> loss_prot_logic_
+ GUARDED_BY(crit_sect_);
+ size_t max_payload_size_ GUARDED_BY(crit_sect_);
- std::set<uint32_t> ssrcs_ GUARDED_BY(crit_);
- std::map<uint32_t, SampleCounter> send_delay_counters_
- GUARDED_BY(crit_); // Mapped by SSRC.
+ RTC_DISALLOW_COPY_AND_ASSIGN(ProtectionBitrateCalculator);
};
} // namespace webrtc
-#endif // WEBRTC_VIDEO_SEND_DELAY_STATS_H_
+#endif // WEBRTC_MODULES_VIDEO_CODING_PROTECTION_BITRATE_CALCULATOR_H_

Powered by Google App Engine
This is Rietveld 408576698