mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-17 14:15:47 -04:00
dep/cubeb: Update to dc511c6
This commit is contained in:
@ -12,10 +12,10 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <mutex>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <type_traits>
|
||||
#if defined(_WIN32)
|
||||
#include "cubeb_utils_win.h"
|
||||
@ -24,8 +24,9 @@
|
||||
#endif
|
||||
|
||||
/** Similar to memcpy, but accounts for the size of an element. */
|
||||
template<typename T>
|
||||
void PodCopy(T * destination, const T * source, size_t count)
|
||||
template <typename T>
|
||||
void
|
||||
PodCopy(T * destination, const T * source, size_t count)
|
||||
{
|
||||
static_assert(std::is_trivial<T>::value, "Requires trivial type");
|
||||
assert(destination && source);
|
||||
@ -33,8 +34,9 @@ void PodCopy(T * destination, const T * source, size_t count)
|
||||
}
|
||||
|
||||
/** Similar to memmove, but accounts for the size of an element. */
|
||||
template<typename T>
|
||||
void PodMove(T * destination, const T * source, size_t count)
|
||||
template <typename T>
|
||||
void
|
||||
PodMove(T * destination, const T * source, size_t count)
|
||||
{
|
||||
static_assert(std::is_trivial<T>::value, "Requires trivial type");
|
||||
assert(destination && source);
|
||||
@ -42,133 +44,118 @@ void PodMove(T * destination, const T * source, size_t count)
|
||||
}
|
||||
|
||||
/** Similar to a memset to zero, but accounts for the size of an element. */
|
||||
template<typename T>
|
||||
void PodZero(T * destination, size_t count)
|
||||
template <typename T>
|
||||
void
|
||||
PodZero(T * destination, size_t count)
|
||||
{
|
||||
static_assert(std::is_trivial<T>::value, "Requires trivial type");
|
||||
assert(destination);
|
||||
memset(destination, 0, count * sizeof(T));
|
||||
memset(destination, 0, count * sizeof(T));
|
||||
}
|
||||
|
||||
namespace {
|
||||
template<typename T, typename Trait>
|
||||
void Copy(T * destination, const T * source, size_t count, Trait)
|
||||
template <typename T, typename Trait>
|
||||
void
|
||||
Copy(T * destination, const T * source, size_t count, Trait)
|
||||
{
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
destination[i] = source[i];
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Copy(T * destination, const T * source, size_t count, std::true_type)
|
||||
template <typename T>
|
||||
void
|
||||
Copy(T * destination, const T * source, size_t count, std::true_type)
|
||||
{
|
||||
PodCopy(destination, source, count);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
/**
|
||||
* This allows copying a number of elements from a `source` pointer to a
|
||||
* `destination` pointer, using `memcpy` if it is safe to do so, or a loop that
|
||||
* calls the constructors and destructors otherwise.
|
||||
*/
|
||||
template<typename T>
|
||||
void Copy(T * destination, const T * source, size_t count)
|
||||
template <typename T>
|
||||
void
|
||||
Copy(T * destination, const T * source, size_t count)
|
||||
{
|
||||
assert(destination && source);
|
||||
Copy(destination, source, count, typename std::is_trivial<T>::type());
|
||||
}
|
||||
|
||||
namespace {
|
||||
template<typename T, typename Trait>
|
||||
void ConstructDefault(T * destination, size_t count, Trait)
|
||||
template <typename T, typename Trait>
|
||||
void
|
||||
ConstructDefault(T * destination, size_t count, Trait)
|
||||
{
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
destination[i] = T();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void ConstructDefault(T * destination,
|
||||
size_t count, std::true_type)
|
||||
template <typename T>
|
||||
void
|
||||
ConstructDefault(T * destination, size_t count, std::true_type)
|
||||
{
|
||||
PodZero(destination, count);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
/**
|
||||
* This allows zeroing (using memset) or default-constructing a number of
|
||||
* elements calling the constructors and destructors if necessary.
|
||||
*/
|
||||
template<typename T>
|
||||
void ConstructDefault(T * destination, size_t count)
|
||||
template <typename T>
|
||||
void
|
||||
ConstructDefault(T * destination, size_t count)
|
||||
{
|
||||
assert(destination);
|
||||
ConstructDefault(destination, count,
|
||||
typename std::is_arithmetic<T>::type());
|
||||
ConstructDefault(destination, count, typename std::is_arithmetic<T>::type());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class auto_array
|
||||
{
|
||||
template <typename T> class auto_array {
|
||||
public:
|
||||
explicit auto_array(uint32_t capacity = 0)
|
||||
: data_(capacity ? new T[capacity] : nullptr)
|
||||
, capacity_(capacity)
|
||||
, length_(0)
|
||||
{}
|
||||
|
||||
~auto_array()
|
||||
: data_(capacity ? new T[capacity] : nullptr), capacity_(capacity),
|
||||
length_(0)
|
||||
{
|
||||
delete [] data_;
|
||||
}
|
||||
|
||||
~auto_array() { delete[] data_; }
|
||||
|
||||
/** Get a constant pointer to the underlying data. */
|
||||
T * data() const
|
||||
{
|
||||
return data_;
|
||||
}
|
||||
T * data() const { return data_; }
|
||||
|
||||
T * end() const
|
||||
{
|
||||
return data_ + length_;
|
||||
}
|
||||
T * end() const { return data_ + length_; }
|
||||
|
||||
const T& at(size_t index) const
|
||||
const T & at(size_t index) const
|
||||
{
|
||||
assert(index < length_ && "out of range");
|
||||
return data_[index];
|
||||
}
|
||||
|
||||
T& at(size_t index)
|
||||
T & at(size_t index)
|
||||
{
|
||||
assert(index < length_ && "out of range");
|
||||
return data_[index];
|
||||
}
|
||||
|
||||
/** Get how much underlying storage this auto_array has. */
|
||||
size_t capacity() const
|
||||
{
|
||||
return capacity_;
|
||||
}
|
||||
size_t capacity() const { return capacity_; }
|
||||
|
||||
/** Get how much elements this auto_array contains. */
|
||||
size_t length() const
|
||||
{
|
||||
return length_;
|
||||
}
|
||||
size_t length() const { return length_; }
|
||||
|
||||
/** Keeps the storage, but removes all the elements from the array. */
|
||||
void clear()
|
||||
{
|
||||
length_ = 0;
|
||||
}
|
||||
void clear() { length_ = 0; }
|
||||
|
||||
/** Change the storage of this auto array, copying the elements to the new
|
||||
* storage.
|
||||
* @returns true in case of success
|
||||
* @returns false if the new capacity is not big enough to accomodate for the
|
||||
* elements in the array.
|
||||
*/
|
||||
/** Change the storage of this auto array, copying the elements to the new
|
||||
* storage.
|
||||
* @returns true in case of success
|
||||
* @returns false if the new capacity is not big enough to accomodate for the
|
||||
* elements in the array.
|
||||
*/
|
||||
bool reserve(size_t new_capacity)
|
||||
{
|
||||
if (new_capacity < length_) {
|
||||
@ -179,17 +166,17 @@ public:
|
||||
PodCopy(new_data, data_, length_);
|
||||
}
|
||||
capacity_ = new_capacity;
|
||||
delete [] data_;
|
||||
delete[] data_;
|
||||
data_ = new_data;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Append `length` elements to the end of the array, resizing the array if
|
||||
* needed.
|
||||
* @parameter elements the elements to append to the array.
|
||||
* @parameter length the number of elements to append to the array.
|
||||
*/
|
||||
/** Append `length` elements to the end of the array, resizing the array if
|
||||
* needed.
|
||||
* @parameter elements the elements to append to the array.
|
||||
* @parameter length the number of elements to append to the array.
|
||||
*/
|
||||
void push(const T * elements, size_t length)
|
||||
{
|
||||
if (length_ + length > capacity_) {
|
||||
@ -227,17 +214,14 @@ public:
|
||||
}
|
||||
|
||||
/** Return the number of free elements in the array. */
|
||||
size_t available() const
|
||||
{
|
||||
return capacity_ - length_;
|
||||
}
|
||||
size_t available() const { return capacity_ - length_; }
|
||||
|
||||
/** Copies `length` elements to `elements` if it is not null, and shift
|
||||
* the remaining elements of the `auto_array` to the beginning.
|
||||
* @parameter elements a buffer to copy the elements to, or nullptr.
|
||||
* @parameter length the number of elements to copy.
|
||||
* @returns true in case of success.
|
||||
* @returns false if the auto_array contains less than `length` elements. */
|
||||
* the remaining elements of the `auto_array` to the beginning.
|
||||
* @parameter elements a buffer to copy the elements to, or nullptr.
|
||||
* @parameter length the number of elements to copy.
|
||||
* @returns true in case of success.
|
||||
* @returns false if the auto_array contains less than `length` elements. */
|
||||
bool pop(T * elements, size_t length)
|
||||
{
|
||||
if (length > length_) {
|
||||
@ -285,56 +269,38 @@ template <typename T>
|
||||
struct auto_array_wrapper_impl : public auto_array_wrapper {
|
||||
auto_array_wrapper_impl() {}
|
||||
|
||||
explicit auto_array_wrapper_impl(uint32_t size)
|
||||
: ar(size)
|
||||
{}
|
||||
explicit auto_array_wrapper_impl(uint32_t size) : ar(size) {}
|
||||
|
||||
void push(void * elements, size_t length) override {
|
||||
void push(void * elements, size_t length) override
|
||||
{
|
||||
ar.push(static_cast<T *>(elements), length);
|
||||
}
|
||||
|
||||
size_t length() override {
|
||||
return ar.length();
|
||||
}
|
||||
size_t length() override { return ar.length(); }
|
||||
|
||||
void push_silence(size_t length) override {
|
||||
ar.push_silence(length);
|
||||
}
|
||||
void push_silence(size_t length) override { ar.push_silence(length); }
|
||||
|
||||
bool pop(size_t length) override {
|
||||
return ar.pop(nullptr, length);
|
||||
}
|
||||
bool pop(size_t length) override { return ar.pop(nullptr, length); }
|
||||
|
||||
void * data() override {
|
||||
return ar.data();
|
||||
}
|
||||
void * data() override { return ar.data(); }
|
||||
|
||||
void * end() override {
|
||||
return ar.end();
|
||||
}
|
||||
void * end() override { return ar.end(); }
|
||||
|
||||
void clear() override {
|
||||
ar.clear();
|
||||
}
|
||||
void clear() override { ar.clear(); }
|
||||
|
||||
bool reserve(size_t capacity) override {
|
||||
return ar.reserve(capacity);
|
||||
}
|
||||
bool reserve(size_t capacity) override { return ar.reserve(capacity); }
|
||||
|
||||
void set_length(size_t length) override {
|
||||
ar.set_length(length);
|
||||
}
|
||||
void set_length(size_t length) override { ar.set_length(length); }
|
||||
|
||||
~auto_array_wrapper_impl() {
|
||||
ar.clear();
|
||||
}
|
||||
~auto_array_wrapper_impl() { ar.clear(); }
|
||||
|
||||
private:
|
||||
auto_array<T> ar;
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
size_t cubeb_sample_size(cubeb_sample_format format);
|
||||
size_t
|
||||
cubeb_sample_size(cubeb_sample_format format);
|
||||
}
|
||||
|
||||
using auto_lock = std::lock_guard<owned_critical_section>;
|
||||
|
Reference in New Issue
Block a user