FastLED 3.9.15
Loading...
Searching...
No Matches
software_decoder.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/codec/common.h"
4#include "fl/stl/noexcept.h"
5#include "fl/stl/vector.h"
6#include "fl/stl/shared_ptr.h"
8
9namespace fl {
10namespace third_party {
11
12// MPEG1-specific configuration
14 enum FrameMode { SingleFrame, Streaming }; // TODO: Why is this needed?
15
17 fl::u16 targetFps = 30;
18 bool looping = false;
19 bool skipAudio = false; // Enable audio by default
20 bool immediateMode = true; // For real-time LED applications - bypass frame buffering
21 fl::u8 bufferFrames = 2; // Only used when immediateMode = false
22 AudioFrameCallback audioCallback; // Optional callback for audio frames (default-constructed is empty)
23
24 Mpeg1Config() = default;
25 Mpeg1Config(FrameMode m, fl::u16 fps = 30) FL_NOEXCEPT
26 : mode(m), targetFps(fps) {}
27};
28
29// Software MPEG1 decoder implementation
30// Based on pl_mpeg library concepts but simplified for microcontrollers
32private:
33 struct Mpeg1DecoderData;
39 bool ready_ = false;
40 bool hasError_ = false;
41
42 // Frame buffering for streaming mode
46 bool endOfStream_ = false;
47
48 // Internal methods
52 void setError(const fl::string& message) FL_NOEXCEPT;
57
58public:
59 explicit SoftwareMpeg1Decoder(const Mpeg1Config& config) FL_NOEXCEPT;
61
62 // IDecoder interface
63 bool begin(fl::filebuf_ptr stream) FL_NOEXCEPT override;
64 void end() FL_NOEXCEPT override;
65 bool isReady() const FL_NOEXCEPT override { return ready_; }
66 bool hasError(fl::string* msg = nullptr) const FL_NOEXCEPT override;
67
70 bool hasMoreFrames() const FL_NOEXCEPT override;
71
72 // MPEG1-specific methods
73 fl::u32 getFrameCount() const FL_NOEXCEPT override;
74 fl::u32 getCurrentFrameIndex() const FL_NOEXCEPT override { return currentFrameIndex_; }
75 bool seek(fl::u32 frameIndex) FL_NOEXCEPT override;
76
77 // Get video properties
78 fl::u16 getWidth() const FL_NOEXCEPT;
79 fl::u16 getHeight() const FL_NOEXCEPT;
80 fl::u16 getFrameRate() const FL_NOEXCEPT;
81
82 // Static callback for pl_mpeg video decoding
83 static void videoDecodeCallback(fl::third_party::plm_t* plm, fl::third_party::plm_frame_t* frame, void* user) FL_NOEXCEPT;
84
85 // Static callback for pl_mpeg audio decoding
86 static void audioDecodeCallback(fl::third_party::plm_t* plm, fl::third_party::plm_samples_t* samples, void* user) FL_NOEXCEPT;
87
88 // IDecoder audio interface overrides
89 bool hasAudio() const FL_NOEXCEPT override;
90 void setAudioCallback(AudioFrameCallback callback) FL_NOEXCEPT override;
91 int getAudioSampleRate() const FL_NOEXCEPT override;
92};
93
94} // namespace third_party
95} // namespace fl
Frame getCurrentFrame() FL_NOEXCEPT override
bool begin(fl::filebuf_ptr stream) FL_NOEXCEPT override
int getAudioSampleRate() const FL_NOEXCEPT override
fl::u32 getCurrentFrameIndex() const FL_NOEXCEPT override
void setError(const fl::string &message) FL_NOEXCEPT
bool hasAudio() const FL_NOEXCEPT override
bool hasMoreFrames() const FL_NOEXCEPT override
SoftwareMpeg1Decoder(const Mpeg1Config &config) FL_NOEXCEPT
static void audioDecodeCallback(fl::third_party::plm_t *plm, fl::third_party::plm_samples_t *samples, void *user) FL_NOEXCEPT
void setAudioCallback(AudioFrameCallback callback) FL_NOEXCEPT override
fl::u32 getFrameCount() const FL_NOEXCEPT override
bool isReady() const FL_NOEXCEPT override
static void videoDecodeCallback(fl::third_party::plm_t *plm, fl::third_party::plm_frame_t *frame, void *user) FL_NOEXCEPT
bool hasError(fl::string *msg=nullptr) const FL_NOEXCEPT override
bool seek(fl::u32 frameIndex) FL_NOEXCEPT override
fl::vector< fl::shared_ptr< Frame > > frameBuffer_
DecodeResult decode() FL_NOEXCEPT override
unsigned char u8
Definition coder.h:132
fl::shared_ptr< filebuf > filebuf_ptr
Definition idecoder.h:15
DecodeResult
Definition idecoder.h:18
fl::function< void(const audio::Sample &)> AudioFrameCallback
Definition idecoder.h:28
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT
Mpeg1Config(FrameMode m, fl::u16 fps=30) FL_NOEXCEPT
AudioFrameCallback audioCallback