FastLED 3.9.15
Loading...
Searching...
No Matches
idecoder.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/shared_ptr.h" // IWYU pragma: keep
4#include "fl/stl/string.h"
5#include "fl/stl/stdint.h"
6#include "fl/stl/detail/file_handle.h" // For fl::filebuf
7#include "fl/stl/shared_ptr.h" // IWYU pragma: keep
8#include "fl/stl/function.h"
9#include "fl/audio/audio.h"
10#include "fl/fx/frame.h"
11#include "fl/stl/noexcept.h"
12
13namespace fl {
14
15using filebuf_ptr = fl::shared_ptr<filebuf>; // filebuf is defined in file_handle.h
16
17// Decoder result types
25
26// Audio frame callback - called when audio frames are decoded
27// Not all decoders will support audio
29
30// Base decoder interface for multimedia codecs
31// This interface provides a unified API for decoding various formats including:
32// - Animated GIFs (multi-frame)
33// - MPEG1 video (streaming)
34// - Future codec implementations
35class IDecoder {
36public:
37 virtual ~IDecoder() FL_NOEXCEPT = default;
38
39 // Lifecycle methods
40 virtual bool begin(fl::filebuf_ptr stream) = 0;
41 virtual void end() = 0;
42 virtual bool isReady() const = 0;
43 virtual bool hasError(fl::string* msg = nullptr) const = 0;
44
45 // Decoding methods
46 virtual DecodeResult decode() = 0;
47 virtual Frame getCurrentFrame() = 0;
48 virtual bool hasMoreFrames() const = 0;
49
50 // Optional methods for advanced usage
51 virtual fl::u32 getFrameCount() const { return 0; }
52 virtual fl::u32 getCurrentFrameIndex() const { return 0; }
53 virtual bool seek(fl::u32 frameIndex) { (void)frameIndex; return false; }
54
55 // Audio support (optional - default implementations for decoders without audio)
56 virtual bool hasAudio() const { return false; }
57 virtual void setAudioCallback(AudioFrameCallback callback) { (void)callback; }
58 virtual int getAudioSampleRate() const { return 0; }
59};
60
61// Null decoder implementation for unsupported platforms
62class NullDecoder : public IDecoder {
63public:
64 bool begin(fl::filebuf_ptr) override { return false; }
65 void end() override {}
66 bool isReady() const override { return false; }
67 bool hasError(fl::string* msg = nullptr) const override {
68 if (msg) {
69 *msg = "Codec not supported on this platform";
70 }
71 return true;
72 }
73
75 Frame getCurrentFrame() override { return Frame(0); }
76 bool hasMoreFrames() const override { return false; }
77};
78
79// Smart pointer typedef - must come after class definition
81
82
83} // namespace fl
virtual fl::u32 getFrameCount() const
Definition idecoder.h:51
virtual fl::u32 getCurrentFrameIndex() const
Definition idecoder.h:52
virtual bool hasAudio() const
Definition idecoder.h:56
virtual bool isReady() const =0
virtual Frame getCurrentFrame()=0
virtual bool hasMoreFrames() const =0
virtual DecodeResult decode()=0
virtual bool hasError(fl::string *msg=nullptr) const =0
virtual int getAudioSampleRate() const
Definition idecoder.h:58
virtual bool begin(fl::filebuf_ptr stream)=0
virtual ~IDecoder() FL_NOEXCEPT=default
virtual void end()=0
virtual bool seek(fl::u32 frameIndex)
Definition idecoder.h:53
virtual void setAudioCallback(AudioFrameCallback callback)
Definition idecoder.h:57
DecodeResult decode() override
Definition idecoder.h:74
void end() override
Definition idecoder.h:65
bool begin(fl::filebuf_ptr) override
Definition idecoder.h:64
Frame getCurrentFrame() override
Definition idecoder.h:75
bool hasError(fl::string *msg=nullptr) const override
Definition idecoder.h:67
bool isReady() const override
Definition idecoder.h:66
bool hasMoreFrames() const override
Definition idecoder.h:76
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
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:535