12 : m_container(container)
15 container->register_state_change_callback(
16 [
this](
const auto& c,
auto s) {
36 std::source_location::current(),
37 "VideoStreamReader: Container not ready for processing");
41 auto texture_buffer = std::dynamic_pointer_cast<TextureBuffer>(buffer);
42 if (!texture_buffer) {
44 std::source_location::current(),
45 "VideoStreamReader: Buffer must be a TextureBuffer");
51 buffer->mark_for_processing(
true);
54 }
catch (
const std::exception& e) {
56 "VideoStreamReader: Error during on_attach: {}", e.what());
79 buffer->mark_for_removal();
88 buffer->mark_for_removal();
101 auto texture_buffer = std::dynamic_pointer_cast<TextureBuffer>(buffer);
102 if (!texture_buffer) {
109 buffer->mark_for_processing(
true);
119 }
catch (
const std::exception& e) {
121 "VideoStreamReader: Error during processing: {}", e.what());
135 auto& processed_data =
m_container->get_processed_data();
136 if (processed_data.empty()) {
140 const auto* pixel_vec = std::get_if<std::vector<uint8_t>>(&processed_data[0]);
141 if (!pixel_vec || pixel_vec->empty()) {
145 uint64_t expected_size =
static_cast<uint64_t
>(texture_buffer->get_width())
146 * texture_buffer->get_height()
149 size_t copy_size = std::min(pixel_vec->size(),
static_cast<size_t>(expected_size));
151 if (copy_size < expected_size) {
153 "VideoStreamReader: processed frame is {} bytes, texture expects {}; "
154 "uploading a partial surface",
155 pixel_vec->size(), expected_size);
158 texture_buffer->set_pixel_data(pixel_vec->data(), copy_size);
175 m_reader_id = container->register_dimension_reader(0);
176 container->register_state_change_callback(
177 [
this](
const auto& c,
auto s) {
188 const std::shared_ptr<Kakshya::SignalSourceContainer>& ,
194 "VideoStreamReader: Container marked for removal");
199 "VideoStreamReader: Container entered ERROR state");
214 const std::shared_ptr<Kakshya::StreamContainer>& container,
217 if (
auto vsc = std::dynamic_pointer_cast<Kakshya::VideoStreamContainer>(container))
218 return vsc->get_format();
225 const std::shared_ptr<Kakshya::StreamContainer>& container,
228 static_cast<uint32_t>(container->get_structure().get_width()),
229 static_cast<uint32_t>(container->get_structure().get_height()),
230 resolve_container_format(container, format))
231 , m_container(container)
235 std::source_location::current(),
236 "VideoContainerBuffer: container must not be null");
242 "VideoContainerBuffer created: {}x{} from container",
248 auto self = std::dynamic_pointer_cast<VideoContainerBuffer>(shared_from_this());
255 auto texture_proc = std::make_shared<TextureProcessor>();
256 texture_proc->set_streaming_mode(
true);
257 texture_proc->set_processing_token(token);
262 chain = std::make_shared<BufferProcessingChain>();
265 chain->set_preferred_token(token);
266 chain->add_preprocessor(texture_proc, self);
269 "VideoContainerBuffer setup_processors: VideoStreamReader as default, "
270 "TextureProcessor as preprocessor");
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(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.
static size_t get_bytes_per_pixel(ImageFormat format)
Get bytes per pixel for a format.
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.