diff options
author | Michael Maltese <[email protected]> | 2017-04-01 17:12:01 -0700 |
---|---|---|
committer | Matthew Gregan <[email protected]> | 2017-04-13 09:22:09 +1200 |
commit | 38d7491392df98034922d8c4e54c8131f19f5f62 (patch) | |
tree | 5cf3a35b3e409a124741e0e4d2cdd6289f8e72ad /src/cubeb_utils.h | |
parent | ebf8674229d9c7d14203eb8d2bf78698b46ecfdf (diff) | |
download | cubeb-38d7491392df98034922d8c4e54c8131f19f5f62.tar.gz cubeb-38d7491392df98034922d8c4e54c8131f19f5f62.zip |
audiounit: extract auto_array_wrapper to cubeb_utils
And handle the locking logic separately.
Diffstat (limited to 'src/cubeb_utils.h')
-rw-r--r-- | src/cubeb_utils.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/cubeb_utils.h b/src/cubeb_utils.h index a7f4c8c..e923d37 100644 --- a/src/cubeb_utils.h +++ b/src/cubeb_utils.h @@ -259,6 +259,54 @@ private: size_t length_; }; +struct auto_array_wrapper { + virtual void push(void * elements, size_t length) = 0; + virtual size_t length() = 0; + virtual void push_silence(size_t length) = 0; + virtual bool pop(size_t length) = 0; + virtual void * data() = 0; + virtual void clear() = 0; + virtual ~auto_array_wrapper() {} +}; + +template <typename T> +struct auto_array_wrapper_impl : public auto_array_wrapper { + explicit auto_array_wrapper_impl(uint32_t size) + : ar(size) + {} + + void push(void * elements, size_t length) override { + ar.push(static_cast<T *>(elements), length); + } + + size_t length() override { + return ar.length(); + } + + void push_silence(size_t length) override { + ar.push_silence(length); + } + + bool pop(size_t length) override { + return ar.pop(nullptr, length); + } + + void * data() override { + return ar.data(); + } + + void clear() override { + ar.clear(); + } + + ~auto_array_wrapper_impl() { + ar.clear(); + } + +private: + auto_array<T> ar; +}; + using auto_lock = std::lock_guard<owned_critical_section>; #endif /* CUBEB_UTILS */ |