Zao SDK for Jetson / libzep API リファレンス  1.0.0.0 (2023-05-08)
PcmBufferReader.hpp
1 #ifndef ZEP_AUDIO_PCM_BUFFER_READER_HPP_
2 #define ZEP_AUDIO_PCM_BUFFER_READER_HPP_
3 
4 #include <cstddef>
5 #include <cstdint>
6 #include <memory>
7 
8 #include "../TimestampInterface.hpp"
9 
10 namespace zep {
11 namespace audio {
12 
13 class PcmBufferPoolInterface;
14 
20 class PcmBufferReader final {
21  public:
26  PcmBufferReader() noexcept {}
27 
36  PcmBufferReader(const std::weak_ptr<PcmBufferPoolInterface>& pool_weak,
37  std::int16_t* pointer, std::size_t readable_samples,
38  TimestampInterface::Rep head_timestamp) noexcept
39  : pool_weak_(pool_weak),
40  pointer_(pointer),
41  readable_samples_(readable_samples),
42  head_timestamp_(head_timestamp) {}
43 
49  PcmBufferReader(PcmBufferReader&& other) noexcept {
50  *this = std::move(other);
51  }
52 
59  Finalize();
60  std::swap(pool_weak_, other.pool_weak_);
61  std::swap(pointer_, other.pointer_);
62  std::swap(readable_samples_, other.readable_samples_);
63  std::swap(head_timestamp_, other.head_timestamp_);
64  return *this;
65  }
66 
67  // コピー構築禁止
68  PcmBufferReader(const PcmBufferReader&) = delete;
69 
70  // コピー代入禁止
71  PcmBufferReader& operator=(const PcmBufferReader&) = delete;
72 
76  ~PcmBufferReader() noexcept { Finalize(); }
77 
84  bool IsValid() const noexcept { return !!pointer_; }
85 
93  explicit operator bool() const noexcept { return IsValid(); }
94 
100  const std::int16_t* GetPointer() const noexcept { return pointer_; }
101 
108  std::size_t GetReadableSamples() const noexcept { return readable_samples_; }
109 
114  return head_timestamp_;
115  }
116 
123  inline void Finalize() noexcept;
124 
125  private:
126  std::weak_ptr<PcmBufferPoolInterface> pool_weak_;
127  const std::int16_t* pointer_ = nullptr;
128  std::size_t readable_samples_ = 0;
129  TimestampInterface::Rep head_timestamp_ = 0;
130 };
131 
132 } // namespace audio
133 } // namespace zep
134 
135 #include "PcmBufferPoolInterface.hpp"
136 
138  if (!pointer_) {
139  return;
140  }
141  if (auto pool = pool_weak_.lock()) {
142  pool->FinalizeReader(*this);
143  }
144  pool_weak_.reset();
145  pointer_ = nullptr;
146  readable_samples_ = 0;
147  head_timestamp_ = 0;
148 }
149 
150 #endif // ZEP_AUDIO_PCM_BUFFER_READER_HPP_
bool IsValid() const noexcept
有効なバッファを保持しているか否かを取得する。
Definition: PcmBufferReader.hpp:84
std::uint64_t Rep
タイムスタンプの表現に用いる整数型
Definition: TimestampInterface.hpp:16
TimestampInterface::Rep GetHeadTimestamp() const noexcept
先頭のタイムスタンプを取得する。
Definition: PcmBufferReader.hpp:113
ZEP SDK用名前空間
Definition: FactoryInterface.hpp:10
~PcmBufferReader() noexcept
PcmBufferReaderオブジェクトを破棄する。
Definition: PcmBufferReader.hpp:76
PcmBufferReader & operator=(PcmBufferReader &&other) noexcept
PcmBufferReaderオブジェクトをムーブ代入する。
Definition: PcmBufferReader.hpp:58
PcmBufferReader() noexcept
PcmBufferReaderオブジェクトを管理対象無しでデフォルト構築する。
Definition: PcmBufferReader.hpp:26
void Finalize() noexcept
バッファからのデータ読み込み完了を通知する。
Definition: PcmBufferReader.hpp:137
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:36
std::size_t GetReadableSamples() const noexcept
有効なサンプル数を取得する。
Definition: PcmBufferReader.hpp:108
PCMバッファのReader実装
Definition: PcmBufferReader.hpp:20
const std::int16_t * GetPointer() const noexcept
管理対象バッファの先頭ポインタを取得する。
Definition: PcmBufferReader.hpp:100
PcmBufferReader(PcmBufferReader &&other) noexcept
PcmBufferReaderオブジェクトをムーブ構築する。
Definition: PcmBufferReader.hpp:49