Zao SDK for Jetson / libzep API Reference
Loading...
Searching...
No Matches
PcmBufferWriter.hpp
1/*
2 * Copyright (c) 2022-2023, Soliton Systems K.K. All rights reserved.
3 * Use in source and binary forms, with or without modification,
4 * is permitted provided that the following a condition is met:
5 *
6 * Use is permitted only in accordance with the terms and
7 * conditions set forth in the Software License Agreement available
8 * at https://zao-sdk.org/license-agreement/.
9 */
10#ifndef ZEP_AUDIO_PCM_BUFFER_WRITER_HPP_
11#define ZEP_AUDIO_PCM_BUFFER_WRITER_HPP_
12
13#include <cstddef>
14#include <cstdint>
15#include <memory>
16
17#include "../TimestampInterface.hpp"
18
19namespace zep {
20namespace audio {
21
22class PcmBufferPoolInterface;
23
29class PcmBufferWriter final {
30 public:
35 PcmBufferWriter() noexcept {}
36
44 PcmBufferWriter(const std::weak_ptr<PcmBufferPoolInterface>& pool_weak,
45 std::int16_t* pointer, std::size_t writable_samples) noexcept
46 : pool_weak_(pool_weak),
47 pointer_(pointer),
48 writable_samples_(writable_samples) {}
49
55 PcmBufferWriter(PcmBufferWriter&& other) noexcept {
56 *this = std::move(other);
57 }
58
65 Cancel();
66 std::swap(pool_weak_, other.pool_weak_);
67 std::swap(pointer_, other.pointer_);
68 std::swap(writable_samples_, other.writable_samples_);
69 return *this;
70 }
71
72 // コピー構築禁止
73 PcmBufferWriter(const PcmBufferWriter&) = delete;
74
75 // コピー代入禁止
77
81 ~PcmBufferWriter() noexcept { Cancel(); }
82
89 bool IsValid() const noexcept { return !!pointer_; }
90
98 explicit operator bool() const noexcept { return IsValid(); }
99
105 std::int16_t* GetPointer() const noexcept { return pointer_; }
106
113 std::size_t GetWritableSamples() const noexcept { return writable_samples_; }
114
129 inline void Finalize(std::size_t written_samples,
130 TimestampInterface::Rep head_timestamp) noexcept;
131
138 void Cancel() noexcept { Finalize(0, 0); }
139
140 private:
141 std::weak_ptr<PcmBufferPoolInterface> pool_weak_;
142 std::int16_t* pointer_ = nullptr;
143 std::size_t writable_samples_ = 0;
144};
145
146} // namespace audio
147} // namespace zep
148
149#include "PcmBufferPoolInterface.hpp"
150
152 std::size_t written_samples,
153 TimestampInterface::Rep head_timestamp) noexcept {
154 if (!pointer_) {
155 return;
156 }
157 if (auto pool = pool_weak_.lock()) {
158 pool->FinalizeWriter(*this, written_samples, head_timestamp);
159 }
160 pool_weak_.reset();
161 pointer_ = nullptr;
162 writable_samples_ = 0;
163}
164
165#endif // ZEP_AUDIO_PCM_BUFFER_WRITER_HPP_
std::uint64_t Rep
Integer type used to represent timestamps.
Definition TimestampInterface.hpp:25
Writer implementation of PCM buffer.
Definition PcmBufferWriter.hpp:29
bool IsValid() const noexcept
有効なバッファを保持しているか否かを取得する。
Definition PcmBufferWriter.hpp:89
void Finalize(std::size_t written_samples, TimestampInterface::Rep head_timestamp) noexcept
バッファへのデータ書き込み完了を通知する。
void Cancel() noexcept
Notify the cancellation of writing data into the buffer.
Definition PcmBufferWriter.hpp:137
PcmBufferWriter & operator=(PcmBufferWriter &&other) noexcept
PcmBufferWriterオブジェクトをムーブ代入する。
Definition PcmBufferWriter.hpp:64
~PcmBufferWriter() noexcept
PcmBufferWriterオブジェクトを破棄する。
Definition PcmBufferWriter.hpp:81
std::size_t GetWritableSamples() const noexcept
書き込める最大サンプル数を取得する。
Definition PcmBufferWriter.hpp:113
std::int16_t * GetPointer() const noexcept
管理対象バッファの先頭ポインタを取得する
Definition PcmBufferWriter.hpp:105
PcmBufferWriter() noexcept
PcmBufferWriterオブジェクトを管理対象無しでデフォルト構築する。
Definition PcmBufferWriter.hpp:35
PcmBufferWriter(PcmBufferWriter &&other) noexcept
PcmBufferWriterオブジェクトをムーブ構築する。
Definition PcmBufferWriter.hpp:55
PcmBufferWriter(const std::weak_ptr< PcmBufferPoolInterface > &pool_weak, std::int16_t *pointer, std::size_t writable_samples) noexcept
PcmBufferWriterオブジェクトを構築する。
Definition PcmBufferWriter.hpp:44
void Finalize() noexcept
Notify the completion of reading data from the buffer.
Namespace for ZEP SDK.
Definition FactoryInterface.hpp:19