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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_MODULES_PACED_SENDER_H_
|
|
|
|
|
#define WEBRTC_MODULES_PACED_SENDER_H_
|
|
|
|
|
|
|
|
|
|
#include <list>
|
2013-04-25 17:35:56 +00:00
|
|
|
#include <set>
|
2012-11-09 20:56:23 +00:00
|
|
|
|
|
|
|
|
#include "webrtc/modules/interface/module.h"
|
|
|
|
|
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
|
|
|
|
|
#include "webrtc/system_wrappers/interface/tick_util.h"
|
|
|
|
|
#include "webrtc/typedefs.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
class CriticalSectionWrapper;
|
2013-06-04 09:36:56 +00:00
|
|
|
namespace paced_sender {
|
|
|
|
|
class IntervalBudget;
|
|
|
|
|
struct Packet;
|
|
|
|
|
class PacketList;
|
|
|
|
|
} // 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.
|
2013-06-04 09:36:56 +00:00
|
|
|
virtual int TimeToSendPadding(int 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
|
|
|
|
|
|
|
|
static const int kDefaultMaxQueueLengthMs = 2000;
|
|
|
|
|
|
2014-03-19 10:59:52 +00:00
|
|
|
PacedSender(Callback* callback, int max_bitrate_kbps, 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();
|
|
|
|
|
|
2014-03-19 10:59:52 +00:00
|
|
|
// Set target bitrates for the pacer. Padding packets will be utilized to
|
|
|
|
|
// reach |min_bitrate| unless enough media packets are available.
|
|
|
|
|
void UpdateBitrate(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,
|
2013-11-13 15:29:21 +00:00
|
|
|
int bytes,
|
|
|
|
|
bool retransmission);
|
2012-11-09 20:56:23 +00:00
|
|
|
|
2013-11-27 14:16:20 +00:00
|
|
|
// Sets the max length of the pacer queue in milliseconds.
|
|
|
|
|
// A negative queue size is interpreted as infinite.
|
|
|
|
|
virtual void set_max_queue_length_ms(int max_queue_length_ms);
|
|
|
|
|
|
2013-12-13 22:03:27 +00:00
|
|
|
// Returns the time since the oldest queued packet was enqueued.
|
2013-04-27 00:41:08 +00:00
|
|
|
virtual int QueueInMs() const;
|
2013-03-27 16:36:01 +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.
|
2013-07-31 15:18:19 +00:00
|
|
|
virtual int32_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:
|
2013-06-20 20:18:31 +00:00
|
|
|
// Return true if next packet in line should be transmitted.
|
|
|
|
|
// Return packet list that contains the next packet.
|
|
|
|
|
bool ShouldSendNextPacket(paced_sender::PacketList** packet_list);
|
2012-11-09 20:56:23 +00:00
|
|
|
|
2013-03-22 23:39:29 +00:00
|
|
|
// Local helper function to GetNextPacket.
|
2013-12-13 22:03:27 +00:00
|
|
|
paced_sender::Packet GetNextPacketFromList(paced_sender::PacketList* packets);
|
2013-03-22 23:39:29 +00:00
|
|
|
|
2013-11-27 14:16:20 +00:00
|
|
|
bool SendPacketFromList(paced_sender::PacketList* packet_list);
|
|
|
|
|
|
2012-11-09 20:56:23 +00:00
|
|
|
// Updates the number of bytes that can be sent for the next time interval.
|
|
|
|
|
void UpdateBytesPerInterval(uint32_t delta_time_in_ms);
|
|
|
|
|
|
|
|
|
|
// Updates the buffers with the number of bytes that we sent.
|
2013-06-04 09:36:56 +00:00
|
|
|
void UpdateMediaBytesSent(int num_bytes);
|
2012-11-09 20:56:23 +00:00
|
|
|
|
|
|
|
|
Callback* callback_;
|
2013-06-04 09:36:56 +00:00
|
|
|
bool enabled_;
|
2013-03-22 23:39:29 +00:00
|
|
|
bool paused_;
|
2013-11-27 14:16:20 +00:00
|
|
|
int max_queue_length_ms_;
|
2012-11-09 20:56:23 +00:00
|
|
|
scoped_ptr<CriticalSectionWrapper> critsect_;
|
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.
|
|
|
|
|
scoped_ptr<paced_sender::IntervalBudget> media_budget_;
|
|
|
|
|
// 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.
|
2013-06-04 09:36:56 +00:00
|
|
|
scoped_ptr<paced_sender::IntervalBudget> padding_budget_;
|
|
|
|
|
|
2012-11-09 20:56:23 +00:00
|
|
|
TickTime time_last_update_;
|
|
|
|
|
TickTime time_last_send_;
|
2013-05-02 19:02:17 +00:00
|
|
|
int64_t capture_time_ms_last_queued_;
|
|
|
|
|
int64_t capture_time_ms_last_sent_;
|
2012-11-09 20:56:23 +00:00
|
|
|
|
2013-06-04 09:36:56 +00:00
|
|
|
scoped_ptr<paced_sender::PacketList> high_priority_packets_;
|
|
|
|
|
scoped_ptr<paced_sender::PacketList> normal_priority_packets_;
|
|
|
|
|
scoped_ptr<paced_sender::PacketList> low_priority_packets_;
|
2012-11-09 20:56:23 +00:00
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
#endif // WEBRTC_MODULES_PACED_SENDER_H_
|