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_SYNC_BUFFER_H_
|
|
|
|
|
#define MODULES_AUDIO_CODING_NETEQ_SYNC_BUFFER_H_
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <vector>
|
|
|
|
|
|
2018-04-12 22:44:09 +02:00
|
|
|
#include "api/audio/audio_frame.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/neteq/audio_multi_vector.h"
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "modules/audio_coding/neteq/audio_vector.h"
|
2018-09-05 18:14:52 +02:00
|
|
|
#include "rtc_base/buffer.h"
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2013-09-30 20:38:44 +00:00
|
|
|
class SyncBuffer : public AudioMultiVector {
|
2013-01-29 12:09:21 +00:00
|
|
|
public:
|
|
|
|
|
SyncBuffer(size_t channels, size_t length)
|
2013-09-30 20:38:44 +00:00
|
|
|
: AudioMultiVector(channels, length),
|
2013-01-29 12:09:21 +00:00
|
|
|
next_index_(length),
|
|
|
|
|
end_timestamp_(0),
|
|
|
|
|
dtmf_index_(0) {}
|
|
|
|
|
|
2022-01-21 09:49:39 +09:00
|
|
|
SyncBuffer(const SyncBuffer&) = delete;
|
|
|
|
|
SyncBuffer& operator=(const SyncBuffer&) = delete;
|
|
|
|
|
|
2017-04-26 07:47:32 -07:00
|
|
|
// Returns the number of samples yet to play out from the buffer.
|
2013-01-29 12:09:21 +00:00
|
|
|
size_t FutureLength() const;
|
|
|
|
|
|
2021-07-28 20:00:17 +02:00
|
|
|
// Adds the contents of `append_this` to the back of the SyncBuffer. Removes
|
2013-01-29 12:09:21 +00:00
|
|
|
// the same number of samples from the beginning of the SyncBuffer, to
|
2021-07-28 20:00:17 +02:00
|
|
|
// maintain a constant buffer size. The `next_index_` is updated to reflect
|
2013-01-29 12:09:21 +00:00
|
|
|
// the move of the beginning of "future" data.
|
2015-04-09 15:44:22 +02:00
|
|
|
void PushBack(const AudioMultiVector& append_this) override;
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2018-09-05 18:14:52 +02:00
|
|
|
// Like PushBack, but reads the samples channel-interleaved from the input.
|
|
|
|
|
void PushBackInterleaved(const rtc::BufferT<int16_t>& append_this);
|
|
|
|
|
|
2021-07-28 20:00:17 +02:00
|
|
|
// Adds `length` zeros to the beginning of each channel. Removes
|
2013-01-29 12:09:21 +00:00
|
|
|
// the same number of samples from the end of the SyncBuffer, to
|
2021-07-28 20:00:17 +02:00
|
|
|
// maintain a constant buffer size. The `next_index_` is updated to reflect
|
2013-01-29 12:09:21 +00:00
|
|
|
// the move of the beginning of "future" data.
|
|
|
|
|
// Note that this operation may delete future samples that are waiting to
|
|
|
|
|
// be played.
|
|
|
|
|
void PushFrontZeros(size_t length);
|
|
|
|
|
|
2021-07-28 20:00:17 +02:00
|
|
|
// Inserts `length` zeros into each channel at index `position`. The size of
|
|
|
|
|
// the SyncBuffer is kept constant, which means that the last `length`
|
2013-01-29 12:09:21 +00:00
|
|
|
// elements in each channel will be purged.
|
|
|
|
|
virtual void InsertZerosAtIndex(size_t length, size_t position);
|
|
|
|
|
|
|
|
|
|
// Overwrites each channel in this SyncBuffer with values taken from
|
2021-07-28 20:00:17 +02:00
|
|
|
// `insert_this`. The values are taken from the beginning of `insert_this` and
|
|
|
|
|
// are inserted starting at `position`. `length` values are written into each
|
|
|
|
|
// channel. The size of the SyncBuffer is kept constant. That is, if `length`
|
|
|
|
|
// and `position` are selected such that the new data would extend beyond the
|
2013-01-29 12:09:21 +00:00
|
|
|
// end of the current SyncBuffer, the buffer is not extended.
|
2021-07-28 20:00:17 +02:00
|
|
|
// The `next_index_` is not updated.
|
2013-09-30 20:38:44 +00:00
|
|
|
virtual void ReplaceAtIndex(const AudioMultiVector& insert_this,
|
2013-01-29 12:09:21 +00:00
|
|
|
size_t length,
|
|
|
|
|
size_t position);
|
|
|
|
|
|
2021-07-28 20:00:17 +02:00
|
|
|
// Same as the above method, but where all of `insert_this` is written (with
|
2013-01-29 12:09:21 +00:00
|
|
|
// the same constraints as above, that the SyncBuffer is not extended).
|
2013-09-30 20:38:44 +00:00
|
|
|
virtual void ReplaceAtIndex(const AudioMultiVector& insert_this,
|
2013-01-29 12:09:21 +00:00
|
|
|
size_t position);
|
|
|
|
|
|
2021-07-28 20:00:17 +02:00
|
|
|
// Reads `requested_len` samples from each channel and writes them interleaved
|
|
|
|
|
// into `output`. The `next_index_` is updated to point to the sample to read
|
|
|
|
|
// next time. The AudioFrame `output` is first reset, and the `data_`,
|
|
|
|
|
// `num_channels_`, and `samples_per_channel_` fields are updated.
|
2016-03-04 10:34:21 -08:00
|
|
|
void GetNextAudioInterleaved(size_t requested_len, AudioFrame* output);
|
2013-01-29 12:09:21 +00:00
|
|
|
|
2021-07-28 20:00:17 +02:00
|
|
|
// Adds `increment` to `end_timestamp_`.
|
2013-01-29 12:09:21 +00:00
|
|
|
void IncreaseEndTimestamp(uint32_t increment);
|
|
|
|
|
|
|
|
|
|
// Flushes the buffer. The buffer will contain only zeros after the flush, and
|
2021-07-28 20:00:17 +02:00
|
|
|
// `next_index_` will point to the end, like when the buffer was first
|
2013-01-29 12:09:21 +00:00
|
|
|
// created.
|
|
|
|
|
void Flush();
|
|
|
|
|
|
2014-04-11 18:47:55 +00:00
|
|
|
const AudioVector& Channel(size_t n) const { return *channels_[n]; }
|
|
|
|
|
AudioVector& Channel(size_t n) { return *channels_[n]; }
|
2013-01-29 12:09:21 +00:00
|
|
|
|
|
|
|
|
// Accessors and mutators.
|
|
|
|
|
size_t next_index() const { return next_index_; }
|
|
|
|
|
void set_next_index(size_t value);
|
|
|
|
|
uint32_t end_timestamp() const { return end_timestamp_; }
|
|
|
|
|
void set_end_timestamp(uint32_t value) { end_timestamp_ = value; }
|
|
|
|
|
size_t dtmf_index() const { return dtmf_index_; }
|
|
|
|
|
void set_dtmf_index(size_t value);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
size_t next_index_;
|
|
|
|
|
uint32_t end_timestamp_; // The timestamp of the last sample in the buffer.
|
|
|
|
|
size_t dtmf_index_; // Index to the first non-DTMF sample in the buffer.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_AUDIO_CODING_NETEQ_SYNC_BUFFER_H_
|