11 : m_container(container)
14 container->register_state_change_callback(
15 [
this](
const auto& c,
auto s) {
35 std::source_location::current(),
36 "VideoStreamReader: Container not ready for processing");
40 auto texture_buffer = std::dynamic_pointer_cast<TextureBuffer>(buffer);
41 if (!texture_buffer) {
43 std::source_location::current(),
44 "VideoStreamReader: Buffer must be a TextureBuffer");
50 buffer->mark_for_processing(
true);
53 }
catch (
const std::exception& e) {
55 "VideoStreamReader: Error during on_attach: {}", e.what());
78 buffer->mark_for_removal();
87 buffer->mark_for_removal();
100 auto texture_buffer = std::dynamic_pointer_cast<TextureBuffer>(buffer);
101 if (!texture_buffer) {
108 buffer->mark_for_processing(
true);
118 }
catch (
const std::exception& e) {
120 "VideoStreamReader: Error during processing: {}", e.what());
134 auto& processed_data =
m_container->get_processed_data();
135 if (processed_data.empty()) {
139 const auto* pixel_vec = std::get_if<std::vector<uint8_t>>(&processed_data[0]);
140 if (!pixel_vec || pixel_vec->empty()) {
144 uint64_t expected_size =
static_cast<uint64_t
>(texture_buffer->get_width())
145 * texture_buffer->get_height() * 4;
147 size_t copy_size = std::min(pixel_vec->size(),
static_cast<size_t>(expected_size));
149 texture_buffer->set_pixel_data(pixel_vec->data(), copy_size);
166 m_reader_id = container->register_dimension_reader(0);
167 container->register_state_change_callback(
168 [
this](
const auto& c,
auto s) {
179 const std::shared_ptr<Kakshya::SignalSourceContainer>& ,
185 "VideoStreamReader: Container marked for removal");
190 "VideoStreamReader: Container entered ERROR state");
203 const std::shared_ptr<Kakshya::StreamContainer>& container,
206 static_cast<uint32_t>(container->get_structure().get_width()),
207 static_cast<uint32_t>(container->get_structure().get_height()),
209 , m_container(container)
213 std::source_location::current(),
214 "VideoContainerBuffer: container must not be null");
220 "VideoContainerBuffer created: {}x{} from container",
226 auto self = std::dynamic_pointer_cast<VideoContainerBuffer>(shared_from_this());
233 auto texture_proc = std::make_shared<TextureProcessor>();
234 texture_proc->set_streaming_mode(
true);
235 texture_proc->set_processing_token(token);
240 chain = std::make_shared<BufferProcessingChain>();
243 chain->set_preferred_token(token);
244 chain->add_preprocessor(texture_proc, self);
247 "VideoContainerBuffer setup_processors: VideoStreamReader as default, "
248 "TextureProcessor as preprocessor");
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
uint32_t get_width() const
uint32_t get_height() const
void set_texture_processor(const std::shared_ptr< TextureProcessor > &processor)
Allow inherited classes to set the TextureProcessor directly.
A hybrid buffer managing both a textured quad geometry and its pixel data.
std::shared_ptr< Buffers::BufferProcessingChain > get_processing_chain() override
Access the buffer's processing chain.
void set_default_processor(const std::shared_ptr< BufferProcessor > &processor) override
Set the buffer's default processor.
void set_processing_chain(const std::shared_ptr< BufferProcessingChain > &chain, bool force=false) override
Replace the buffer's processing chain.
void enforce_default_processing(bool should_process) override
Controls whether the buffer should use default processing.
std::shared_ptr< Kakshya::StreamContainer > m_container
std::shared_ptr< VideoStreamReader > m_video_reader
void set_container(const std::shared_ptr< Kakshya::StreamContainer > &container)
Replace the backing container at runtime.
VideoContainerBuffer(const std::shared_ptr< Kakshya::StreamContainer > &container, Portal::Graphics::ImageFormat format=Portal::Graphics::ImageFormat::RGBA8)
Construct a VideoContainerBuffer from a video container.
void setup_processors(ProcessingToken token) override
Override to wire VideoStreamReader as default and TextureProcessor as preprocessor.
void on_attach(const std::shared_ptr< Buffer > &buffer) override
Attach the reader to a TextureBuffer.
void on_detach(const std::shared_ptr< Buffer > &buffer) override
Detach the reader from its TextureBuffer.
void set_container(const std::shared_ptr< Kakshya::StreamContainer > &container)
Replace the backing container.
void extract_frame_data(const std::shared_ptr< TextureBuffer > &texture_buffer)
Extract frame pixel data from processed_data into the TextureBuffer.
void processing_function(const std::shared_ptr< Buffer > &buffer) override
Extract the current frame from the container into the TextureBuffer.
void on_container_state_change(const std::shared_ptr< Kakshya::SignalSourceContainer > &container, Kakshya::ProcessingState state)
Respond to container state changes.
std::shared_ptr< Kakshya::StreamContainer > m_container
VideoStreamReader(const std::shared_ptr< Kakshya::StreamContainer > &container)
Construct a VideoStreamReader for the given container.
ProcessingToken
Bitfield enum defining processing characteristics and backend requirements for buffer operations.
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Init
Engine/subsystem initialization.
@ Buffers
Buffers, Managers, processors and processing chains.
ProcessingState
Represents the current processing lifecycle state of a container.
@ READY
Container has data loaded and is ready for processing.
@ NEEDS_REMOVAL
Container is marked for removal from the system.
@ ERROR
Container is in an error state and cannot proceed.
@ PROCESSED
Container has completed processing and results are available.
ImageFormat
User-friendly image format enum.