xr_adapter_h handle{};
CheckResult(xr_adapter_create(&handle), AIFW_RESULT_SUCCESS, false);
adapter_.reset(handle);
+ state_ = AdapterState::kStopped;
}
AiProcessorVideoImpl::~AiProcessorVideoImpl() {
AI_LOG(INFO) << __func__;
+ state_ = AdapterState::kNone;
}
void AiProcessorVideoImpl::ProcessVideo(
const scoped_refptr<media::VideoFrame>& video_frame) {
TRACE_EVENT0("webai", "AiProcessorVideoImpl::ProcessVideo");
-
- if (!is_ready_) {
+ if (state_ != AdapterState::kStarted) {
AI_LOG(ERROR) << "Configurate it first.";
return;
}
<< " fps:" << static_cast<int>(configure.fps)
<< " output_width:" << configure.output_width
<< " output_height:" << configure.output_height;
- if (!adapter_) {
- AI_LOG(ERROR) << "There is no adapter.";
+ if (state_ != AdapterState::kStopped) {
+ AI_LOG(ERROR) << "Invalid state:" << static_cast<int>(state_);
return;
}
}
cfg_ = configure;
buffer_pool_ = base::MakeRefCounted<AiVideoFrameBufferPool>();
- is_ready_ = true;
+ state_ = AdapterState::kStarted;
}
void AiProcessorVideoImpl::Stop() {
TRACE_EVENT0("webai", "AiProcessorVideoImpl::Start");
AI_LOG(INFO) << __func__;
+ if (state_ != AdapterState::kStarted) {
+ AI_LOG(ERROR) << "Invalid state:" << static_cast<int>(state_);
+ return;
+ }
+
CheckResult(xr_adapter_deinit(adapter_.get()), AIFW_RESULT_SUCCESS, true);
// Release all buffers.
constexpr gfx::Size max_size{4096, 4096};
buffer_pool_->FlushPool(max_size);
+ state_ = AdapterState::kStopped;
}
scoped_refptr<AiVideoFrameBuffer> AiProcessorVideoImpl::FindReusableBuffer(
auto const& get_client() const { return client_; }
private:
+ enum class AdapterState {
+ kNone,
+ kStarted,
+ kStopped,
+ };
struct AdapterDeleter {
void operator()(xr_adapter_h adapter);
};
absl::optional<std::string> config_json_;
blink::AiConfiguration cfg_;
- bool is_ready_{false};
+ AdapterState state_{};
scoped_refptr<AiVideoFrameBufferPool> buffer_pool_;
std::unique_ptr<std::remove_pointer<xr_adapter_h>::type, AdapterDeleter>
adapter_;