9#include <condition_variable>
12class VideoFileContainer;
13class SoundFileContainer;
31 return static_cast<VideoReadOptions>(
static_cast<uint32_t
>(
a) |
static_cast<uint32_t
>(
b));
36 return static_cast<VideoReadOptions>(
static_cast<uint32_t
>(
a) &
static_cast<uint32_t
>(
b));
67 bool can_read(
const std::string& filepath)
const override;
70 void close()
override;
71 [[nodiscard]]
bool is_open()
const override;
73 [[nodiscard]] std::optional<FileMetadata>
get_metadata()
const override;
74 [[nodiscard]] std::vector<FileRegion>
get_regions()
const override;
76 std::vector<Kakshya::DataVariant>
read_all()
override;
80 bool load_into_container(std::shared_ptr<Kakshya::SignalSourceContainer> container)
override;
83 bool seek(
const std::vector<uint64_t>& position)
override;
87 [[nodiscard]] std::type_index
get_data_type()
const override {
return typeid(std::vector<uint8_t>); }
205 void setup_io_service(
const std::shared_ptr<Registry::Service::IOService>& io_service, uint64_t reader_id);
277 bool seek_internal(
const std::shared_ptr<FFmpegDemuxContext>& demux,
278 const std::shared_ptr<VideoStreamContext>& video,
279 uint64_t frame_position);
281 void build_metadata(
const std::shared_ptr<FFmpegDemuxContext>& demux,
282 const std::shared_ptr<VideoStreamContext>& video)
const;
284 void build_regions(
const std::shared_ptr<FFmpegDemuxContext>& demux,
285 const std::shared_ptr<VideoStreamContext>& video)
const;
287 void set_error(
const std::string& msg)
const;
Abstract interface for reading various file formats into containers.
std::condition_variable m_decode_cv
uint64_t decode_batch(Kakshya::VideoFileContainer &vc, uint64_t batch_size)
Decode up to batch_size frames starting at m_decode_head.
void set_error(const std::string &msg) const
AudioReadOptions m_audio_options
void start_decode_thread()
uint32_t m_decode_batch_size
std::vector< FileRegion > m_cached_regions
std::atomic< bool > m_decode_stop
void set_ring_capacity(uint32_t n)
Set the number of decoded frame slots in the ring buffer.
void set_decode_batch_size(uint32_t n)
Set the number of frames decoded per batch by the background thread.
std::vector< FileRegion > get_regions() const override
Get semantic regions from the file.
void build_metadata(const std::shared_ptr< FFmpegDemuxContext > &demux, const std::shared_ptr< VideoStreamContext > &video) const
void set_target_dimensions(uint32_t width, uint32_t height)
VideoReadOptions m_video_options
std::vector< uint8_t > m_sws_buf
One-frame sws scratch buffer (padded linesize, reused by decode thread).
std::type_index get_data_type() const override
Get the data type this reader produces.
void build_regions(const std::shared_ptr< FFmpegDemuxContext > &demux, const std::shared_ptr< VideoStreamContext > &video) const
bool open(const std::string &filepath, FileReadOptions options=FileReadOptions::ALL) override
Open a file for reading.
uint64_t get_preferred_chunk_size() const override
Get the preferred chunk size for streaming.
uint64_t get_reader_id() const
Returns the reader_id active for this instance.
std::vector< Kakshya::DataVariant > read_all() override
Read all data from the file into memory.
std::weak_ptr< Kakshya::VideoFileContainer > m_container_ref
std::shared_ptr< FFmpegDemuxContext > m_demux
std::shared_ptr< Registry::Service::IOService > m_io_service
bool seek(const std::vector< uint64_t > &position) override
Seek to a specific position in the file.
std::vector< std::string > get_supported_extensions() const override
Get supported file extensions for this reader.
std::atomic< bool > m_decode_active
bool seek_internal(const std::shared_ptr< FFmpegDemuxContext > &demux, const std::shared_ptr< VideoStreamContext > &video, uint64_t frame_position)
bool load_into_container(std::shared_ptr< Kakshya::SignalSourceContainer > container) override
Load file data into an existing container.
uint32_t m_target_sample_rate
FileReadOptions m_options
bool is_open() const override
Check if a file is currently open.
void set_refill_threshold(uint32_t n)
Start refilling when fewer than this many frames remain ahead of the consumer read head.
std::shared_mutex m_context_mutex
std::string get_last_error() const override
Get the last error message.
std::vector< uint64_t > get_read_position() const override
Get current read position in primary dimension.
void set_audio_options(AudioReadOptions options)
void decode_thread_func()
std::shared_ptr< VideoStreamContext > m_video
std::optional< FileMetadata > get_metadata() const override
Get metadata from the open file.
std::mutex m_metadata_mutex
void set_reader_id(uint64_t id)
Assign an externally-managed reader_id before load_into_container().
void set_target_sample_rate(uint32_t sample_rate)
std::shared_ptr< AudioStreamContext > m_audio
void close() override
Close the currently open file.
std::optional< FileMetadata > m_cached_metadata
void stop_decode_thread()
std::shared_ptr< Kakshya::SignalSourceContainer > create_container() override
Create and initialize a container from the file.
std::shared_ptr< Kakshya::SoundFileContainer > get_audio_container() const
After load_into_container(), retrieve the audio container if EXTRACT_AUDIO was set.
std::shared_ptr< Kakshya::SoundFileContainer > m_audio_container
uint32_t m_refill_threshold
void setup_io_service(uint64_t reader_id=0)
Internal setup for IOService integration.
std::atomic< uint64_t > m_decode_head
bool can_read(const std::string &filepath) const override
Check if a file can be read by this reader.
std::type_index get_container_type() const override
Get the container type this reader creates.
bool supports_streaming() const override
Check if streaming is supported for the current file.
void signal_decode()
Non-blocking signal to the background decode thread.
std::thread m_decode_thread
void set_video_options(VideoReadOptions options)
~VideoFileReader() override
size_t get_num_dimensions() const override
Get the dimensionality of the file data.
std::mutex m_decode_mutex
std::vector< Kakshya::DataVariant > read_region(const FileRegion ®ion) override
Read a specific region of data.
std::vector< uint64_t > get_dimension_sizes() const override
Get size of each dimension in the file data.
Streaming FFmpeg-based video file reader with background decode.
File-backed video container — semantic marker over VideoStreamContainer.
AudioReadOptions
Audio-specific reading options.
FileReadOptions
Generic options for file reading behavior.
@ ALL
All options enabled.
@ NONE
No special options.
FileReadOptions operator&(FileReadOptions a, FileReadOptions b)
VideoReadOptions
Video-specific reading options.
FileReadOptions operator|(FileReadOptions a, FileReadOptions b)
Generic region descriptor for any file type.