50 fl::size totalRead = 0;
54 fl::size toRead =
fl::min(bytesToRead, rem);
57 mCurrentPos += toRead; totalRead += toRead; bytesToRead -= toRead;
68 const char*
path()
const override {
return mPath.c_str(); }
82 fl::size nFrameHistory) {
83 Video video(pixelsPerFrame, fps, nFrameHistory);
88 config.
targetFps =
static_cast<fl::u16
>(fps);
93 if (!decoder) {
video.setError(
fl::string(
"Failed to create MPEG1 decoder: ").append(error_message));
return video; }
94 if (!decoder->begin(file.
rdbuf())) {
95 fl::string decoder_error; decoder->hasError(&decoder_error);
96 video.setError(
fl::string(
"Failed to initialize MPEG1 decoder: ").append(decoder_error));
return video;
99 if (!
video.begin(mpeg1Stream)) {
video.setError(
fl::string(
"Failed to initialize video with MPEG1 stream"));
return video; }
107 if (error_message) { *error_message =
"Failed to open file: "; error_message->
append(path); }
108 FL_WARN(
"Failed to open JPEG file: " << path);
return FramePtr();
110 fl::size fileSize = file.
size();
112 if (error_message) { *error_message =
"File is empty: "; error_message->
append(path); }
113 file.
close();
return FramePtr();
117 fl::size bytesRead = 0;
118 while (bytesRead < fileSize && file.
available()) {
119 fl::size chunkSize =
min<fl::size>(4096, fileSize - bytesRead);
120 fl::size n = file.
read(buffer.
data() + bytesRead, chunkSize);
125 if (bytesRead != fileSize) {
127 *error_message =
"Failed to read complete file. Expected ";
128 error_message->
append(
static_cast<u32
>(fileSize));
129 error_message->
append(
" bytes, got ");
130 error_message->
append(
static_cast<u32
>(bytesRead));
132 FL_WARN(
"Failed to read complete JPEG file: " << path);
return FramePtr();
135 FramePtr frame =
Jpeg::decode(config, jpegData, error_message);
136 if (!frame && error_message && error_message->
empty()) {
137 *error_message =
"Failed to decode JPEG from file: "; error_message->
append(path);
145 if (error_message) { *error_message =
"Failed to open file: "; error_message->
append(path); }
151 if (error_message) { *error_message =
"Failed to initialize MP3 decoder: "; error_message->
append(decoder_error); }
Video openMpeg1Video(const char *path, fl::size pixelsPerFrame, float fps=30.0f, fl::size nFrameHistory=0)
fl::ifstream openRead(const char *path)
fl::Mp3DecoderPtr openMp3(const char *path, fl::string *error_message=nullptr)
FramePtr loadJpeg(const char *path, const JpegConfig &config=JpegConfig(), fl::string *error_message=nullptr)
static bool decode(const JpegConfig &config, fl::span< const fl::u8 > data, Frame *frame, fl::string *error_message=nullptr)
static Mp3DecoderPtr createDecoder(fl::string *error_message=nullptr)
bool begin(fl::filebuf_ptr stream)
bool hasError(fl::string *msg=nullptr) const
static IDecoderPtr createDecoder(const Mpeg1Config &config, fl::string *error_message=nullptr)
bool available() const override
fl::size_t read(char *dst, fl::size_t bytesToRead) override
fl::size_t tell() override
void clear_error() override
bool decodeNextFrameIfNeeded()
Mpeg1FileHandle(IDecoderPtr decoder, fl::size pixelsPerFrame, const char *path)
bool is_eof() const override
const char * error_message() const override
bool is_open() const override
fl::size_t bytes_left() const override
fl::size_t size() const override
fl::shared_ptr< Frame > mCurrentFrame
bool seek(fl::size_t, seek_dir) override
int error_code() const override
fl::size_t write(const char *, fl::size_t) override
bool has_error() const override
const char * path() const override
bool empty() const FL_NOEXCEPT
virtual bool seek(fl::size_t pos, seek_dir dir)=0
virtual fl::size_t read(char *buffer, fl::size_t count)=0
ifstream & read(char *buffer, fl::size_t count)
filebuf_ptr rdbuf() const
string & append(const bitset_fixed< N > &bs) FL_NOEXCEPT
fl::size size() const FL_NOEXCEPT
void reserve(fl::size n) FL_NOEXCEPT
void resize(fl::size n) FL_NOEXCEPT
Centralized logging categories for FastLED hardware interfaces and subsystems.
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
void * memcpy(void *dest, const void *src, size_t n) FL_NOEXCEPT
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
expected< T, E > result
Alias for expected (Rust-style naming)
third_party::Mpeg1Config Mpeg1Config
fl::shared_ptr< Mp3Decoder > Mp3DecoderPtr
Base definition for an LED controller.