2012-11-09 20:56:23 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2012 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-10-23 11:57:05 +00:00
|
|
|
#ifndef WEBRTC_MODULES_PACING_INCLUDE_PACED_SENDER_H_
|
|
|
|
|
#define WEBRTC_MODULES_PACING_INCLUDE_PACED_SENDER_H_
|
2012-11-09 20:56:23 +00:00
|
|
|
|
|
|
|
|
#include <list>
|
2013-04-25 17:35:56 +00:00
|
|
|
#include <set>
|
2012-11-09 20:56:23 +00:00
|
|
|
|
2014-09-24 06:05:00 +00:00
|
|
|
#include "webrtc/base/thread_annotations.h"
|
2012-11-09 20:56:23 +00:00
|
|
|
#include "webrtc/modules/interface/module.h"
|
|
|
|
|
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
|
|
|
|
|
#include "webrtc/typedefs.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
2014-10-23 11:57:05 +00:00
|
|
|
class BitrateProber;
|
2014-07-04 09:20:42 +00:00
|
|
|
class Clock;
|
2012-11-09 20:56:23 +00:00
|
|
|
class CriticalSectionWrapper;
|
2014-07-04 09:20:42 +00:00
|
|
|
|
2013-06-04 09:36:56 +00:00
|
|
|
namespace paced_sender {
|
|
|
|
|
class IntervalBudget;
|
|
|
|
|
struct Packet;
|
2014-11-04 16:27:16 +00:00
|
|
|
class PacketQueue;
|
2013-06-04 09:36:56 +00:00
|
|
|
} // namespace paced_sender
|
2012-11-09 20:56:23 +00:00
|
|
|
|
|
|
|
|
class PacedSender : public Module {
|
|
|
|
|
public:
|
|
|
|
|
enum Priority {
|
|
|
|
|
kHighPriority = 0, // Pass through; will be sent immediately.
|
|
|
|
|
kNormalPriority = 2, // Put in back of the line.
|
|
|
|
|
kLowPriority = 3, // Put in back of the low priority line.
|
|
|
|
|
};
|
2013-03-22 23:39:29 +00:00
|
|
|
// Low priority packets are mixed with the normal priority packets
|
|
|
|
|
// while we are paused.
|
|
|
|
|
|
2012-11-09 20:56:23 +00:00
|
|
|
class Callback {
|
|
|
|
|
public:
|
|
|
|
|
// Note: packets sent as a result of a callback should not pass by this
|
|
|
|
|
// module again.
|
|
|
|
|
// Called when it's time to send a queued packet.
|
2013-06-20 20:18:31 +00:00
|
|
|
// Returns false if packet cannot be sent.
|
2013-11-13 15:29:21 +00:00
|
|
|
virtual bool TimeToSendPacket(uint32_t ssrc,
|
|
|
|
|
uint16_t sequence_number,
|
|
|
|
|
int64_t capture_time_ms,
|
|
|
|
|
bool retransmission) = 0;
|
2012-11-09 20:56:23 +00:00
|
|
|
// Called when it's a good time to send a padding data.
|
2014-07-04 09:20:42 +00:00
|
|
|
// Returns the number of bytes sent.
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
virtual size_t TimeToSendPadding(size_t bytes) = 0;
|
2014-02-27 22:32:40 +00:00
|
|
|
|
2012-11-09 20:56:23 +00:00
|
|
|
protected:
|
|
|
|
|
virtual ~Callback() {}
|
|
|
|
|
};
|
2013-11-27 14:16:20 +00:00
|
|
|
|
2014-11-17 22:21:14 +00:00
|
|
|
static const int64_t kDefaultMaxQueueLengthMs = 2000;
|
2014-07-04 09:20:42 +00:00
|
|
|
// Pace in kbits/s until we receive first estimate.
|
|
|
|
|
static const int kDefaultInitialPaceKbps = 2000;
|
|
|
|
|
// Pacing-rate relative to our target send rate.
|
|
|
|
|
// Multiplicative factor that is applied to the target bitrate to calculate
|
|
|
|
|
// the number of bytes that can be transmitted per interval.
|
|
|
|
|
// Increasing this factor will result in lower delays in cases of bitrate
|
|
|
|
|
// overshoots from the encoder.
|
|
|
|
|
static const float kDefaultPaceMultiplier;
|
|
|
|
|
|
2014-10-23 11:57:05 +00:00
|
|
|
PacedSender(Clock* clock,
|
|
|
|
|
Callback* callback,
|
|
|
|
|
int bitrate_kbps,
|
|
|
|
|
int max_bitrate_kbps,
|
2014-07-04 09:20:42 +00:00
|
|
|
int min_bitrate_kbps);
|
2012-11-09 20:56:23 +00:00
|
|
|
|
|
|
|
|
virtual ~PacedSender();
|
|
|
|
|
|
|
|
|
|
// Enable/disable pacing.
|
|
|
|
|
void SetStatus(bool enable);
|
|
|
|
|
|
2013-06-04 09:36:56 +00:00
|
|
|
bool Enabled() const;
|
|
|
|
|
|
2013-03-22 23:39:29 +00:00
|
|
|
// Temporarily pause all sending.
|
|
|
|
|
void Pause();
|
|
|
|
|
|
|
|
|
|
// Resume sending packets.
|
|
|
|
|
void Resume();
|
|
|
|
|
|
2015-02-16 15:47:51 +00:00
|
|
|
// Enable bitrate probing. Enabled by default, mostly here to simplify
|
|
|
|
|
// testing. Must be called before any packets are being sent to have an
|
|
|
|
|
// effect.
|
|
|
|
|
void SetProbingEnabled(bool enabled);
|
|
|
|
|
|
2014-10-23 11:57:05 +00:00
|
|
|
// Set target bitrates for the pacer.
|
|
|
|
|
// We will pace out bursts of packets at a bitrate of |max_bitrate_kbps|.
|
|
|
|
|
// |bitrate_kbps| is our estimate of what we are allowed to send on average.
|
|
|
|
|
// Padding packets will be utilized to reach |min_bitrate| unless enough media
|
|
|
|
|
// packets are available.
|
|
|
|
|
void UpdateBitrate(int bitrate_kbps,
|
|
|
|
|
int max_bitrate_kbps,
|
|
|
|
|
int min_bitrate_kbps);
|
2012-11-09 20:56:23 +00:00
|
|
|
|
|
|
|
|
// Returns true if we send the packet now, else it will add the packet
|
|
|
|
|
// information to the queue and call TimeToSendPacket when it's time to send.
|
2013-04-27 00:41:08 +00:00
|
|
|
virtual bool SendPacket(Priority priority,
|
|
|
|
|
uint32_t ssrc,
|
|
|
|
|
uint16_t sequence_number,
|
|
|
|
|
int64_t capture_time_ms,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t bytes,
|
2013-11-13 15:29:21 +00:00
|
|
|
bool retransmission);
|
2012-11-09 20:56:23 +00:00
|
|
|
|
2013-12-13 22:03:27 +00:00
|
|
|
// Returns the time since the oldest queued packet was enqueued.
|
2014-12-15 22:09:40 +00:00
|
|
|
virtual int64_t QueueInMs() const;
|
2013-03-27 16:36:01 +00:00
|
|
|
|
2014-10-23 11:57:05 +00:00
|
|
|
virtual size_t QueueSizePackets() const;
|
|
|
|
|
|
2014-11-04 16:27:16 +00:00
|
|
|
// Returns the number of milliseconds it will take to send the current
|
|
|
|
|
// packets in the queue, given the current size and bitrate, ignoring prio.
|
2014-11-17 22:21:14 +00:00
|
|
|
virtual int64_t ExpectedQueueTimeMs() const;
|
2014-11-04 16:27:16 +00:00
|
|
|
|
2012-11-09 20:56:23 +00:00
|
|
|
// Returns the number of milliseconds until the module want a worker thread
|
|
|
|
|
// to call Process.
|
2014-12-15 22:09:40 +00:00
|
|
|
virtual int64_t TimeUntilNextProcess() OVERRIDE;
|
2012-11-09 20:56:23 +00:00
|
|
|
|
|
|
|
|
// Process any pending packets in the queue(s).
|
2013-07-31 15:18:19 +00:00
|
|
|
virtual int32_t Process() OVERRIDE;
|
2012-11-09 20:56:23 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Updates the number of bytes that can be sent for the next time interval.
|
2014-12-15 22:09:40 +00:00
|
|
|
void UpdateBytesPerInterval(int64_t delta_time_in_ms)
|
2014-07-07 10:20:35 +00:00
|
|
|
EXCLUSIVE_LOCKS_REQUIRED(critsect_);
|
2012-11-09 20:56:23 +00:00
|
|
|
|
2014-11-04 16:27:16 +00:00
|
|
|
bool SendPacket(const paced_sender::Packet& packet)
|
|
|
|
|
EXCLUSIVE_LOCKS_REQUIRED(critsect_);
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
void SendPadding(size_t padding_needed) EXCLUSIVE_LOCKS_REQUIRED(critsect_);
|
2014-07-07 10:20:35 +00:00
|
|
|
|
|
|
|
|
Clock* const clock_;
|
|
|
|
|
Callback* const callback_;
|
2012-11-09 20:56:23 +00:00
|
|
|
|
|
|
|
|
scoped_ptr<CriticalSectionWrapper> critsect_;
|
2014-07-07 10:20:35 +00:00
|
|
|
bool enabled_ GUARDED_BY(critsect_);
|
|
|
|
|
bool paused_ GUARDED_BY(critsect_);
|
2015-02-16 15:47:51 +00:00
|
|
|
bool probing_enabled_;
|
2013-06-04 09:36:56 +00:00
|
|
|
// This is the media budget, keeping track of how many bits of media
|
|
|
|
|
// we can pace out during the current interval.
|
2014-07-07 10:20:35 +00:00
|
|
|
scoped_ptr<paced_sender::IntervalBudget> media_budget_ GUARDED_BY(critsect_);
|
2013-06-04 09:36:56 +00:00
|
|
|
// This is the padding budget, keeping track of how many bits of padding we're
|
2014-03-19 10:59:52 +00:00
|
|
|
// allowed to send out during the current interval. This budget will be
|
|
|
|
|
// utilized when there's no media to send.
|
2014-07-07 10:20:35 +00:00
|
|
|
scoped_ptr<paced_sender::IntervalBudget> padding_budget_
|
|
|
|
|
GUARDED_BY(critsect_);
|
|
|
|
|
|
2014-10-23 11:57:05 +00:00
|
|
|
scoped_ptr<BitrateProber> prober_ GUARDED_BY(critsect_);
|
|
|
|
|
int bitrate_bps_ GUARDED_BY(critsect_);
|
|
|
|
|
|
2014-07-15 16:40:38 +00:00
|
|
|
int64_t time_last_update_us_ GUARDED_BY(critsect_);
|
2014-07-07 10:20:35 +00:00
|
|
|
|
2014-11-04 16:27:16 +00:00
|
|
|
scoped_ptr<paced_sender::PacketQueue> packets_ GUARDED_BY(critsect_);
|
2015-02-16 15:47:51 +00:00
|
|
|
uint64_t packet_counter_;
|
2012-11-09 20:56:23 +00:00
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
2014-10-23 11:57:05 +00:00
|
|
|
#endif // WEBRTC_MODULES_PACING_INCLUDE_PACED_SENDER_H_
|