FastLED 3.10.8
Loading...
Searching...
No Matches
video.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/stdint.h"
4
5#include "fl/stl/shared_ptr.h" // For FASTLED_SHARED_PTR macros
6#include "fl/stl/span.h"
7#include "fl/stl/string.h"
9#include "fl/fx/fx1d.h"
11#include "fl/stl/noexcept.h"
12
13namespace fl {
14
15struct SourceProfile; // fl/gfx/color_profile.h
16
17struct CRGB;
18using CRGB = fl::CRGB; // CRGB is now a typedef
19
20// Forward declare classes
21class filebuf;
26
27namespace video {
28class VideoImpl;
29} // namespace video
32
37
38// Video represents a video file that can be played back on a LED strip.
39// The video file is expected to be a sequence of frames. Pass any filebuf
40// to begin() — streaming vs seekable is auto-detected.
41class Video : public Fx1d { // Fx1d because video can be irregular.
42 public:
44#ifdef FL_IS_AVR
45 return 1;
46#else
47 return 2; // Allow interpolation by default.
48#endif
49 }
50 // frameHistoryCount is the number of frames to keep in the buffer after
51 // draw. This allows for time based effects like syncing video speed to
52 // audio triggers. If you are using a filehandle for you video then you can
53 // just leave this as the default. For streaming byte streams you may want
54 // to increase this number to allow momentary re-wind. If you'd like to use
55 // a Video as a buffer for an fx effect then please see VideoFxWrapper.
57 Video(size_t pixelsPerFrame, float fps = 30.0f,
58 size_t frameHistoryCount =
59 DefaultFrameHistoryCount()) FL_NO_EXCEPT; // Please use FileSytem to construct
60 // a Video.
63 Video &operator=(const Video &) FL_NO_EXCEPT;
64
65 // Fx Api
66 void draw(DrawContext context) FL_NO_EXCEPT override;
67 string fxName() const FL_NO_EXCEPT override;
68
69 // Api
71 bool draw(fl::u32 now, fl::span<CRGB> leds) FL_NO_EXCEPT;
72 bool draw(fl::u32 now, Frame *frame) FL_NO_EXCEPT;
73 void end() FL_NO_EXCEPT;
75 bool rewind() FL_NO_EXCEPT;
77 float timeScale() const FL_NO_EXCEPT;
78 string error() const FL_NO_EXCEPT;
79 // A caller-supplied error is persistent: it blocks admission until the
80 // caller clears it. Admission errors recorded by begin() are not -- see
81 // mAdmissionError.
82 void setError(const string &error) FL_NO_EXCEPT {
83 mError = error;
84 mAdmissionError = false;
85 }
86 size_t pixelsPerFrame() const FL_NO_EXCEPT;
87
88 // FLED v1 container (issue #3072): true / non-empty only when begin()
89 // opened a FLED-formatted file (12-byte "FLED" magic header). Legacy
90 // headerless `.rgb` files return false / empty string.
91 // Spec: https://github.com/zackees/ledmapper/blob/main/docs/fled-format.md
93 const fl::string &embeddedScreenMapJson() const FL_NO_EXCEPT;
94 bool videoColor(fled::VideoColor *out) const FL_NO_EXCEPT;
102 bool pixelStorage(fled::PixelStorage *out) const FL_NO_EXCEPT;
103 bool readSample(video::PixelSample *out) FL_NO_EXCEPT;
105 void pause(fl::u32 now) FL_NO_EXCEPT override;
106 void resume(fl::u32 now) FL_NO_EXCEPT override;
107 void setFade(fl::u32 fadeInTime, fl::u32 fadeOutTime) FL_NO_EXCEPT;
108 i32 durationMicros() const FL_NO_EXCEPT; // -1 if this is a stream.
109
110 // make compatible with if statements
111 operator bool() const FL_NO_EXCEPT { return mImpl.get(); }
112
113 private:
114 // True when mError was recorded by a failed begin() rather than by
115 // setError(). Such a failure describes one rejected source, not a dead
116 // object, so the next begin() clears it and admits a new handle.
118 mError = error;
119 mAdmissionError = true;
120 }
121
122 bool mFinished = false;
123 bool mAdmissionError = false;
125 string mError;
126 string mName;
127};
128
129// Wraps an Fx and stores a history of video frames. This allows
130// interpolation between frames for FX for smoother effects.
131// It also allows re-wind on fx that gnore time and always generate
132// the next frame based on the previous frame and internal speed,
133// for example NoisePalette.
134class VideoFxWrapper : public Fx1d {
135 public:
138 void draw(DrawContext context) FL_NO_EXCEPT override;
139 string fxName() const FL_NO_EXCEPT override;
140 void setFade(fl::u32 fadeInTime, fl::u32 fadeOutTime) FL_NO_EXCEPT;
141
142 private:
143 FxPtr mFx;
145 memorybufPtr mByteStream;
146 float mFps = 30.0f;
147};
148
149} // namespace fl
CRGB leds[1]
Fx1d(u16 numLeds) FL_NO_EXCEPT
Definition fx1d.h:13
void setError(const string &error) FL_NO_EXCEPT
Definition video.h:82
size_t pixelsPerFrame() const FL_NO_EXCEPT
void setTimeScale(float timeScale) FL_NO_EXCEPT
bool readSample(video::PixelSample *out) FL_NO_EXCEPT
static size_t DefaultFrameHistoryCount() FL_NO_EXCEPT
Definition video.h:43
void setFade(fl::u32 fadeInTime, fl::u32 fadeOutTime) FL_NO_EXCEPT
Definition video.cpp.hpp:28
i32 durationMicros() const FL_NO_EXCEPT
Definition video.cpp.hpp:92
string mError
Definition video.h:125
void setAdmissionError(const string &error) FL_NO_EXCEPT
Definition video.h:117
bool mFinished
Definition video.h:122
Video() FL_NO_EXCEPT
Definition video.cpp.hpp:21
string error() const FL_NO_EXCEPT
bool rewind() FL_NO_EXCEPT
bool hasEmbeddedScreenMap() const FL_NO_EXCEPT
const fl::string & embeddedScreenMapJson() const FL_NO_EXCEPT
bool videoColor(fled::VideoColor *out) const FL_NO_EXCEPT
void end() FL_NO_EXCEPT
void pause(fl::u32 now) FL_NO_EXCEPT override
Definition video.cpp.hpp:32
string fxName() const FL_NO_EXCEPT override
Definition video.cpp.hpp:99
bool pixelStorage(fled::PixelStorage *out) const FL_NO_EXCEPT
string mName
Definition video.h:126
void draw(DrawContext context) FL_NO_EXCEPT override
Definition video.cpp.hpp:88
bool sourceProfile(SourceProfile *out) const FL_NO_EXCEPT
The colour-pipeline source profile the file declares (or the default tuple of its pixel format).
bool finished() FL_NO_EXCEPT
VideoImplPtr mImpl
Definition video.h:124
void resume(fl::u32 now) FL_NO_EXCEPT override
Definition video.cpp.hpp:34
bool begin(fl::filebuf_ptr h) FL_NO_EXCEPT
Definition video.cpp.hpp:40
float timeScale() const FL_NO_EXCEPT
bool mAdmissionError
Definition video.h:123
void setFledPlaybackMode(FledPlaybackMode mode) FL_NO_EXCEPT
VideoImplPtr mVideo
Definition video.h:144
string fxName() const FL_NO_EXCEPT override
memorybufPtr mByteStream
Definition video.h:145
VideoFxWrapper(FxPtr fx) FL_NO_EXCEPT
~VideoFxWrapper() FL_NO_EXCEPT override
void setFade(fl::u32 fadeInTime, fl::u32 fadeOutTime) FL_NO_EXCEPT
void draw(DrawContext context) FL_NO_EXCEPT override
unsigned char u8
Definition s16x16x4.h:132
video::VideoImpl VideoImpl
Definition video.h:30
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
detail::memorybuf memorybuf
fl::shared_ptr< filebuf > filebuf_ptr
Definition idecoder.h:15
fl::shared_ptr< VideoImpl > VideoImplPtr
Definition video.h:31
FledPlaybackMode
Definition video.h:33
Base definition for an LED controller.
#define FASTLED_SHARED_PTR_NO_FWD(type)
Definition shared_ptr.h:588
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:577
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38
A source declaration, not a container or an output-device selection.