Zao SDK for Jetson / libzao-endpoint API リファレンス 1.5.0.0 (2024-09-25)
Loading...
Searching...
No Matches
PcmBufferReader.hpp
1#ifndef ZAO_ENDPOINT_AUDIO_PCM_BUFFER_READER_HPP_
2#define ZAO_ENDPOINT_AUDIO_PCM_BUFFER_READER_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 PcmBufferReader final {
26 public:
33 PcmBufferReader() noexcept {}
34
48 PcmBufferReader(const std::weak_ptr<PcmBufferPoolInterface>& pool_weak,
49 std::int16_t* pointer, std::size_t readable_samples,
50 TimestampInterface::Rep head_timestamp) noexcept
51 : pool_weak_(pool_weak),
52 pointer_(pointer),
53 readable_samples_(readable_samples),
54 head_timestamp_(head_timestamp) {}
55
63 PcmBufferReader(PcmBufferReader&& other) noexcept {
64 *this = std::move(other);
65 }
66
75 Finalize();
76 std::swap(pool_weak_, other.pool_weak_);
77 std::swap(pointer_, other.pointer_);
78 std::swap(readable_samples_, other.readable_samples_);
79 std::swap(head_timestamp_, other.head_timestamp_);
80 return *this;
81 }
82
83 // コピー構築禁止
84 PcmBufferReader(const PcmBufferReader&) = delete;
85
86 // コピー代入禁止
88
93 ~PcmBufferReader() noexcept { Finalize(); }
94
104 bool IsValid() const noexcept { return !!pointer_; }
105
116 explicit operator bool() const noexcept { return IsValid(); }
117
126 const std::int16_t* GetPointer() const noexcept { return pointer_; }
127
140 std::size_t GetReadableSamples() const noexcept { return readable_samples_; }
141
147 return head_timestamp_;
148 }
149
159 inline void Finalize() noexcept;
160
161 private:
162 std::weak_ptr<PcmBufferPoolInterface> pool_weak_;
163 const std::int16_t* pointer_ = nullptr;
164 std::size_t readable_samples_ = 0;
165 TimestampInterface::Rep head_timestamp_ = 0;
166};
167
168} // namespace audio
169} // namespace endpoint
170} // namespace zao
171
172#include "PcmBufferPoolInterface.hpp"
173
175 if (!pointer_) {
176 return;
177 }
178 if (auto pool = pool_weak_.lock()) {
179 pool->FinalizeReader(*this);
180 }
181 pool_weak_.reset();
182 pointer_ = nullptr;
183 readable_samples_ = 0;
184 head_timestamp_ = 0;
185}
186
187#endif // ZAO_ENDPOINT_AUDIO_PCM_BUFFER_READER_HPP_
タイムスタンプ管理機能のインターフェース
Definition TimestampInterface.hpp:13
std::uint64_t Rep
タイムスタンプの表現に用いる整数型
Definition TimestampInterface.hpp:19
PCMバッファプールのインターフェース
Definition PcmBufferPoolInterface.hpp:19
PCMバッファのReader実装
Definition PcmBufferReader.hpp:25
const std::int16_t * GetPointer() const noexcept
管理対象バッファの先頭ポインタを取得する。
Definition PcmBufferReader.hpp:126
void Finalize() noexcept
バッファからのデータ読み込み完了を通知する。
Definition PcmBufferReader.hpp:174
~PcmBufferReader() noexcept
PcmBufferReaderオブジェクトを破棄する。
Definition PcmBufferReader.hpp:93
PcmBufferReader(PcmBufferReader &&other) noexcept
PcmBufferReaderオブジェクトをムーブ構築する。
Definition PcmBufferReader.hpp:63
TimestampInterface::Rep GetHeadTimestamp() const noexcept
先頭のタイムスタンプを取得する。
Definition PcmBufferReader.hpp:146
PcmBufferReader(const std::weak_ptr< PcmBufferPoolInterface > &pool_weak, std::int16_t *pointer, std::size_t readable_samples, TimestampInterface::Rep head_timestamp) noexcept
PcmBufferReaderオブジェクトを構築する。
Definition PcmBufferReader.hpp:48
PcmBufferReader() noexcept
PcmBufferReaderオブジェクトを管理対象無しでデフォルト構築する。
Definition PcmBufferReader.hpp:33
bool IsValid() const noexcept
有効なバッファを保持しているか否かを取得する。
Definition PcmBufferReader.hpp:104
std::size_t GetReadableSamples() const noexcept
有効なサンプル数を取得する。
Definition PcmBufferReader.hpp:140
PcmBufferReader & operator=(PcmBufferReader &&other) noexcept
PcmBufferReaderオブジェクトをムーブ代入する。
Definition PcmBufferReader.hpp:74
Zao製品共通の名前空間
Definition FactoryInterface.hpp:11