Zao SDK for Jetson / libzao-endpoint API リファレンス 1.6.0.0 (2024-12-24)
Loading...
Searching...
No Matches
PcmBufferWriter.hpp
1#ifndef ZAO_ENDPOINT_AUDIO_PCM_BUFFER_WRITER_HPP_
2#define ZAO_ENDPOINT_AUDIO_PCM_BUFFER_WRITER_HPP_
3
4#include <cstddef>
5#include <cstdint>
6#include <memory>
7
8#include "../TimestampInterface.hpp"
9
10namespace zao {
11namespace endpoint {
12namespace audio {
13
14class PcmBufferPoolInterface;
15
25class PcmBufferWriter final {
26 public:
33 PcmBufferWriter() noexcept {}
34
46 PcmBufferWriter(std::weak_ptr<PcmBufferPoolInterface> pool_weak,
47 std::int16_t* pointer, std::size_t writable_samples) noexcept
48 : pool_weak_(std::move(pool_weak)),
49 pointer_(pointer),
50 writable_samples_(writable_samples) {}
51
59 PcmBufferWriter(PcmBufferWriter&& other) noexcept {
60 *this = std::move(other);
61 }
62
71 Cancel();
72 std::swap(pool_weak_, other.pool_weak_);
73 std::swap(pointer_, other.pointer_);
74 std::swap(writable_samples_, other.writable_samples_);
75 return *this;
76 }
77
78 // コピー構築禁止
79 PcmBufferWriter(const PcmBufferWriter&) = delete;
80
81 // コピー代入禁止
83
88 ~PcmBufferWriter() noexcept { Cancel(); }
89
99 bool IsValid() const noexcept { return !!pointer_; }
100
111 explicit operator bool() const noexcept { return IsValid(); }
112
121 std::int16_t* GetPointer() const noexcept { return pointer_; }
122
136 std::size_t GetWritableSamples() const noexcept { return writable_samples_; }
137
164 inline void Finalize(std::size_t written_samples,
165 TimestampInterface::Rep head_timestamp) noexcept;
166
176 void Cancel() noexcept { Finalize(0, 0); }
177
178 private:
179 std::weak_ptr<PcmBufferPoolInterface> pool_weak_;
180 std::int16_t* pointer_ = nullptr;
181 std::size_t writable_samples_ = 0;
182};
183
184} // namespace audio
185} // namespace endpoint
186} // namespace zao
187
188#include "PcmBufferPoolInterface.hpp"
189
191 std::size_t written_samples,
192 TimestampInterface::Rep head_timestamp) noexcept {
193 if (!pointer_) {
194 return;
195 }
196 if (auto pool = pool_weak_.lock()) {
197 pool->FinalizeWriter(*this, written_samples, head_timestamp);
198 }
199 pool_weak_.reset();
200 pointer_ = nullptr;
201 writable_samples_ = 0;
202}
203
204#endif // ZAO_ENDPOINT_AUDIO_PCM_BUFFER_WRITER_HPP_
std::uint64_t Rep
タイムスタンプの表現に用いる整数型
Definition TimestampInterface.hpp:19
PCMバッファのWriter実装
Definition PcmBufferWriter.hpp:25
void Finalize(std::size_t written_samples, TimestampInterface::Rep head_timestamp) noexcept
バッファへのデータ書き込み完了を通知する。
Definition PcmBufferWriter.hpp:190
void Cancel() noexcept
バッファへのデータ書き込みキャンセルを通知する。
Definition PcmBufferWriter.hpp:176
PcmBufferWriter(PcmBufferWriter &&other) noexcept
PcmBufferWriter オブジェクトをムーブ構築する。
Definition PcmBufferWriter.hpp:59
std::size_t GetWritableSamples() const noexcept
書き込める最大サンプル数を取得する。
Definition PcmBufferWriter.hpp:136
bool IsValid() const noexcept
有効なバッファを保持しているか否かを取得する。
Definition PcmBufferWriter.hpp:99
PcmBufferWriter & operator=(PcmBufferWriter &&other) noexcept
PcmBufferWriter オブジェクトをムーブ代入する。
Definition PcmBufferWriter.hpp:70
std::int16_t * GetPointer() const noexcept
管理対象バッファの先頭ポインタを取得する
Definition PcmBufferWriter.hpp:121
PcmBufferWriter(std::weak_ptr< PcmBufferPoolInterface > pool_weak, std::int16_t *pointer, std::size_t writable_samples) noexcept
PcmBufferWriter オブジェクトを構築する。
Definition PcmBufferWriter.hpp:46
~PcmBufferWriter() noexcept
PcmBufferWriter オブジェクトを破棄する。
Definition PcmBufferWriter.hpp:88
PcmBufferWriter() noexcept
PcmBufferWriter オブジェクトを管理対象無しでデフォルト構築する。
Definition PcmBufferWriter.hpp:33
Zao製品共通の名前空間
Definition FactoryInterface.hpp:11