2013-01-29 12:09:21 +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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_AUDIO_CODING_NETEQ_PACKET_BUFFER_H_
|
|
|
|
|
#define MODULES_AUDIO_CODING_NETEQ_PACKET_BUFFER_H_
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2018-06-19 13:26:36 +02:00
|
|
|
#include "absl/types/optional.h"
|
2018-05-22 13:21:01 +02:00
|
|
|
#include "modules/audio_coding/neteq/decoder_database.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/neteq/packet.h"
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "modules/include/module_common_types_public.h" // IsNewerTimestamp
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/constructor_magic.h"
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
class DecoderDatabase;
|
2017-07-05 11:17:40 +02:00
|
|
|
class StatisticsCalculator;
|
2016-04-26 07:45:16 -07:00
|
|
|
class TickTimer;
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// This is the actual buffer holding the packets before decoding.
|
|
|
|
|
class PacketBuffer {
|
|
|
|
|
public:
|
|
|
|
|
enum BufferReturnCodes {
|
|
|
|
|
kOK = 0,
|
|
|
|
|
kFlushed,
|
|
|
|
|
kNotFound,
|
|
|
|
|
kBufferEmpty,
|
|
|
|
|
kInvalidPacket,
|
2014-04-28 08:20:04 +00:00
|
|
|
kInvalidPointer
|
2013-01-29 12:09:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Constructor creates a buffer which can hold a maximum of
|
2014-04-28 08:20:04 +00:00
|
|
|
// |max_number_of_packets| packets.
|
2016-04-26 07:45:16 -07:00
|
|
|
PacketBuffer(size_t max_number_of_packets, const TickTimer* tick_timer);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Deletes all packets in the buffer before destroying the buffer.
|
|
|
|
|
virtual ~PacketBuffer();
|
|
|
|
|
|
|
|
|
|
// Flushes the buffer and deletes all packets in it.
|
|
|
|
|
virtual void Flush();
|
|
|
|
|
|
|
|
|
|
// Returns true for an empty buffer.
|
2015-04-09 15:44:22 +02:00
|
|
|
virtual bool Empty() const;
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Inserts |packet| into the buffer. The buffer will take over ownership of
|
|
|
|
|
// the packet object.
|
|
|
|
|
// Returns PacketBuffer::kOK on success, PacketBuffer::kFlushed if the buffer
|
|
|
|
|
// was flushed due to overfilling.
|
2017-07-19 11:44:06 +02:00
|
|
|
virtual int InsertPacket(Packet&& packet, StatisticsCalculator* stats);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Inserts a list of packets into the buffer. The buffer will take over
|
|
|
|
|
// ownership of the packet objects.
|
|
|
|
|
// Returns PacketBuffer::kOK if all packets were inserted successfully.
|
|
|
|
|
// If the buffer was flushed due to overfilling, only a subset of the list is
|
|
|
|
|
// inserted, and PacketBuffer::kFlushed is returned.
|
|
|
|
|
// The last three parameters are included for legacy compatibility.
|
|
|
|
|
// TODO(hlundin): Redesign to not use current_*_payload_type and
|
|
|
|
|
// decoder_database.
|
2016-08-31 03:14:11 -07:00
|
|
|
virtual int InsertPacketList(
|
|
|
|
|
PacketList* packet_list,
|
|
|
|
|
const DecoderDatabase& decoder_database,
|
2018-06-19 13:26:36 +02:00
|
|
|
absl::optional<uint8_t>* current_rtp_payload_type,
|
|
|
|
|
absl::optional<uint8_t>* current_cng_rtp_payload_type,
|
2017-07-19 11:44:06 +02:00
|
|
|
StatisticsCalculator* stats);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Gets the timestamp for the first packet in the buffer and writes it to the
|
|
|
|
|
// output variable |next_timestamp|.
|
|
|
|
|
// Returns PacketBuffer::kBufferEmpty if the buffer is empty,
|
|
|
|
|
// PacketBuffer::kOK otherwise.
|
|
|
|
|
virtual int NextTimestamp(uint32_t* next_timestamp) const;
|
|
|
|
|
|
|
|
|
|
// Gets the timestamp for the first packet in the buffer with a timestamp no
|
|
|
|
|
// lower than the input limit |timestamp|. The result is written to the output
|
|
|
|
|
// variable |next_timestamp|.
|
|
|
|
|
// Returns PacketBuffer::kBufferEmpty if the buffer is empty,
|
|
|
|
|
// PacketBuffer::kOK otherwise.
|
|
|
|
|
virtual int NextHigherTimestamp(uint32_t timestamp,
|
|
|
|
|
uint32_t* next_timestamp) const;
|
|
|
|
|
|
2016-10-18 04:06:13 -07:00
|
|
|
// Returns a (constant) pointer to the first packet in the buffer. Returns
|
|
|
|
|
// NULL if the buffer is empty.
|
|
|
|
|
virtual const Packet* PeekNextPacket() const;
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2016-10-24 08:25:28 -07:00
|
|
|
// Extracts the first packet in the buffer and returns it.
|
|
|
|
|
// Returns an empty optional if the buffer is empty.
|
2018-06-19 13:26:36 +02:00
|
|
|
virtual absl::optional<Packet> GetNextPacket();
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Discards the first packet in the buffer. The packet is deleted.
|
|
|
|
|
// Returns PacketBuffer::kBufferEmpty if the buffer is empty,
|
|
|
|
|
// PacketBuffer::kOK otherwise.
|
2017-07-05 11:17:40 +02:00
|
|
|
virtual int DiscardNextPacket(StatisticsCalculator* stats);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2014-11-04 14:03:58 +00:00
|
|
|
// Discards all packets that are (strictly) older than timestamp_limit,
|
|
|
|
|
// but newer than timestamp_limit - horizon_samples. Setting horizon_samples
|
|
|
|
|
// to zero implies that the horizon is set to half the timestamp range. That
|
|
|
|
|
// is, if a packet is more than 2^31 timestamps into the future compared with
|
|
|
|
|
// timestamp_limit (including wrap-around), it is considered old.
|
2017-07-05 11:17:40 +02:00
|
|
|
virtual void DiscardOldPackets(uint32_t timestamp_limit,
|
|
|
|
|
uint32_t horizon_samples,
|
|
|
|
|
StatisticsCalculator* stats);
|
2014-11-04 14:03:58 +00:00
|
|
|
|
|
|
|
|
// Discards all packets that are (strictly) older than timestamp_limit.
|
2017-07-05 11:17:40 +02:00
|
|
|
virtual void DiscardAllOldPackets(uint32_t timestamp_limit,
|
|
|
|
|
StatisticsCalculator* stats);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2016-09-20 01:38:00 -07:00
|
|
|
// Removes all packets with a specific payload type from the buffer.
|
2017-07-05 11:17:40 +02:00
|
|
|
virtual void DiscardPacketsWithPayloadType(uint8_t payload_type,
|
|
|
|
|
StatisticsCalculator* stats);
|
2016-09-20 01:38:00 -07:00
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
// Returns the number of packets in the buffer, including duplicates and
|
|
|
|
|
// redundant packets.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
virtual size_t NumPacketsInBuffer() const;
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Returns the number of samples in the buffer, including samples carried in
|
|
|
|
|
// duplicate and redundant packets.
|
2016-09-20 01:38:00 -07:00
|
|
|
virtual size_t NumSamplesInBuffer(size_t last_decoded_length) const;
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2018-05-22 13:21:01 +02:00
|
|
|
// Returns true if the packet buffer contains any DTX or CNG packets.
|
|
|
|
|
virtual bool ContainsDtxOrCngPacket(
|
|
|
|
|
const DecoderDatabase* decoder_database) const;
|
|
|
|
|
|
2014-11-04 14:03:58 +00:00
|
|
|
// Static method returning true if |timestamp| is older than |timestamp_limit|
|
|
|
|
|
// but less than |horizon_samples| behind |timestamp_limit|. For instance,
|
|
|
|
|
// with timestamp_limit = 100 and horizon_samples = 10, a timestamp in the
|
|
|
|
|
// range (90, 100) is considered obsolete, and will yield true.
|
|
|
|
|
// Setting |horizon_samples| to 0 is the same as setting it to 2^31, i.e.,
|
|
|
|
|
// half the 32-bit timestamp range.
|
|
|
|
|
static bool IsObsoleteTimestamp(uint32_t timestamp,
|
|
|
|
|
uint32_t timestamp_limit,
|
|
|
|
|
uint32_t horizon_samples) {
|
|
|
|
|
return IsNewerTimestamp(timestamp_limit, timestamp) &&
|
|
|
|
|
(horizon_samples == 0 ||
|
|
|
|
|
IsNewerTimestamp(timestamp, timestamp_limit - horizon_samples));
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-29 12:09:21 +00:00
|
|
|
private:
|
|
|
|
|
size_t max_number_of_packets_;
|
|
|
|
|
PacketList buffer_;
|
2016-04-26 07:45:16 -07:00
|
|
|
const TickTimer* tick_timer_;
|
2015-09-16 05:37:44 -07:00
|
|
|
RTC_DISALLOW_COPY_AND_ASSIGN(PacketBuffer);
|
2013-01-29 12:09:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_AUDIO_CODING_NETEQ_PACKET_BUFFER_H_
|