Zao SDK for Jetson / libzao-endpoint API リファレンス 1.2.0.0 (2023-10-30)
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
21class PcmBufferReader final {
22 public:
27 PcmBufferReader() noexcept {}
28
37 PcmBufferReader(const std::weak_ptr<PcmBufferPoolInterface>& pool_weak,
38 std::int16_t* pointer, std::size_t readable_samples,
39 TimestampInterface::Rep head_timestamp) noexcept
40 : pool_weak_(pool_weak),
41 pointer_(pointer),
42 readable_samples_(readable_samples),
43 head_timestamp_(head_timestamp) {}
44
50 PcmBufferReader(PcmBufferReader&& other) noexcept {
51 *this = std::move(other);
52 }
53
60 Finalize();
61 std::swap(pool_weak_, other.pool_weak_);
62 std::swap(pointer_, other.pointer_);
63 std::swap(readable_samples_, other.readable_samples_);
64 std::swap(head_timestamp_, other.head_timestamp_);
65 return *this;
66 }
67
68 // コピー構築禁止
69 PcmBufferReader(const PcmBufferReader&) = delete;
70
71 // コピー代入禁止
73
77 ~PcmBufferReader() noexcept { Finalize(); }
78
85 bool IsValid() const noexcept { return !!pointer_; }
86
94 explicit operator bool() const noexcept { return IsValid(); }
95
101 const std::int16_t* GetPointer() const noexcept { return pointer_; }
102
109 std::size_t GetReadableSamples() const noexcept { return readable_samples_; }
110
115 return head_timestamp_;
116 }
117
124 inline void Finalize() noexcept;
125
126 private:
127 std::weak_ptr<PcmBufferPoolInterface> pool_weak_;
128 const std::int16_t* pointer_ = nullptr;
129 std::size_t readable_samples_ = 0;
130 TimestampInterface::Rep head_timestamp_ = 0;
131};
132
133} // namespace audio
134} // namespace endpoint
135} // namespace zao
136
137#include "PcmBufferPoolInterface.hpp"
138
140 if (!pointer_) {
141 return;
142 }
143 if (auto pool = pool_weak_.lock()) {
144 pool->FinalizeReader(*this);
145 }
146 pool_weak_.reset();
147 pointer_ = nullptr;
148 readable_samples_ = 0;
149 head_timestamp_ = 0;
150}
151
152#endif // ZAO_ENDPOINT_AUDIO_PCM_BUFFER_READER_HPP_
タイムスタンプ管理機能のインターフェース
Definition TimestampInterface.hpp:12
std::uint64_t Rep
タイムスタンプの表現に用いる整数型
Definition TimestampInterface.hpp:17
PCMバッファプールのインターフェース
Definition PcmBufferPoolInterface.hpp:18
PCMバッファのReader実装
Definition PcmBufferReader.hpp:21
const std::int16_t * GetPointer() const noexcept
管理対象バッファの先頭ポインタを取得する。
Definition PcmBufferReader.hpp:101
void Finalize() noexcept
バッファからのデータ読み込み完了を通知する。
Definition PcmBufferReader.hpp:139
~PcmBufferReader() noexcept
PcmBufferReaderオブジェクトを破棄する。
Definition PcmBufferReader.hpp:77
PcmBufferReader(PcmBufferReader &&other) noexcept
PcmBufferReaderオブジェクトをムーブ構築する。
Definition PcmBufferReader.hpp:50
TimestampInterface::Rep GetHeadTimestamp() const noexcept
先頭のタイムスタンプを取得する。
Definition PcmBufferReader.hpp:114
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:37
PcmBufferReader() noexcept
PcmBufferReaderオブジェクトを管理対象無しでデフォルト構築する。
Definition PcmBufferReader.hpp:27
bool IsValid() const noexcept
有効なバッファを保持しているか否かを取得する。
Definition PcmBufferReader.hpp:85
std::size_t GetReadableSamples() const noexcept
有効なサンプル数を取得する。
Definition PcmBufferReader.hpp:109
PcmBufferReader & operator=(PcmBufferReader &&other) noexcept
PcmBufferReaderオブジェクトをムーブ代入する。
Definition PcmBufferReader.hpp:59
Zao製品共通の名前空間
Definition FactoryInterface.hpp:11