FastLED 3.9.15
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"
10#include "fl/stl/noexcept.h"
11
12namespace fl {
13
14struct CRGB;
15using CRGB = fl::CRGB; // CRGB is now a typedef
16
17// Forward declare classes
18class filebuf;
23
24namespace video {
25class VideoImpl;
26} // namespace video
29
30// Video represents a video file that can be played back on a LED strip.
31// The video file is expected to be a sequence of frames. Pass any filebuf
32// to begin() — streaming vs seekable is auto-detected.
33class Video : public Fx1d { // Fx1d because video can be irregular.
34 public:
35 static size_t DefaultFrameHistoryCount() {
36#ifdef FL_IS_AVR
37 return 1;
38#else
39 return 2; // Allow interpolation by default.
40#endif
41 }
42 // frameHistoryCount is the number of frames to keep in the buffer after
43 // draw. This allows for time based effects like syncing video speed to
44 // audio triggers. If you are using a filehandle for you video then you can
45 // just leave this as the default. For streaming byte streams you may want
46 // to increase this number to allow momentary re-wind. If you'd like to use
47 // a Video as a buffer for an fx effect then please see VideoFxWrapper.
49 Video(size_t pixelsPerFrame, float fps = 30.0f,
50 size_t frameHistoryCount =
51 DefaultFrameHistoryCount()); // Please use FileSytem to construct
52 // a Video.
55 Video &operator=(const Video &) FL_NOEXCEPT;
56
57 // Fx Api
58 void draw(DrawContext context) override;
59 string fxName() const override;
60
61 // Api
62 bool begin(fl::filebuf_ptr h);
63 bool draw(fl::u32 now, fl::span<CRGB> leds);
64 bool draw(fl::u32 now, Frame *frame);
65 void end();
66 bool finished();
67 bool rewind();
68 void setTimeScale(float timeScale);
69 float timeScale() const;
70 string error() const;
71 void setError(const string &error) { mError = error; }
72 size_t pixelsPerFrame() const;
73
74 // FLED v1 container (issue #3072): true / non-empty only when begin()
75 // opened a FLED-formatted file (12-byte "FLED" magic header). Legacy
76 // headerless `.rgb` files return false / empty string.
77 // Spec: https://github.com/zackees/ledmapper/blob/main/docs/fled-format.md
79 const fl::string &embeddedScreenMapJson() const FL_NOEXCEPT;
80 void pause(fl::u32 now) override;
81 void resume(fl::u32 now) override;
82 void setFade(fl::u32 fadeInTime, fl::u32 fadeOutTime);
83 i32 durationMicros() const; // -1 if this is a stream.
84
85 // make compatible with if statements
86 operator bool() const { return mImpl.get(); }
87
88 private:
89 bool mFinished = false;
91 string mError;
92 string mName;
93};
94
95// Wraps an Fx and stores a history of video frames. This allows
96// interpolation between frames for FX for smoother effects.
97// It also allows re-wind on fx that gnore time and always generate
98// the next frame based on the previous frame and internal speed,
99// for example NoisePalette.
100class VideoFxWrapper : public Fx1d {
101 public:
102 VideoFxWrapper(FxPtr fx);
104 void draw(DrawContext context) override;
105 string fxName() const override;
106 void setFade(fl::u32 fadeInTime, fl::u32 fadeOutTime);
107
108 private:
109 FxPtr mFx;
111 memorybufPtr mByteStream;
112 float mFps = 30.0f;
113};
114
115} // namespace fl
fl::CRGB leds[NUM_LEDS]
Fx1d(u16 numLeds)
Definition fx1d.h:12
bool finished()
void draw(DrawContext context) override
Definition video.cpp.hpp:71
float timeScale() const
void end()
Definition video.cpp.hpp:95
bool begin(fl::filebuf_ptr h)
Definition video.cpp.hpp:38
Video() FL_NOEXCEPT
Definition video.cpp.hpp:19
void pause(fl::u32 now) override
Definition video.cpp.hpp:30
static size_t DefaultFrameHistoryCount()
Definition video.h:35
string fxName() const override
Definition video.cpp.hpp:86
size_t pixelsPerFrame() const
string mError
Definition video.h:91
bool mFinished
Definition video.h:89
void setFade(fl::u32 fadeInTime, fl::u32 fadeOutTime)
Definition video.cpp.hpp:26
string error() const
void setTimeScale(float timeScale)
void setError(const string &error)
Definition video.h:71
string mName
Definition video.h:92
VideoImplPtr mImpl
Definition video.h:90
bool hasEmbeddedScreenMap() const FL_NOEXCEPT
void resume(fl::u32 now) override
Definition video.cpp.hpp:32
bool rewind()
const fl::string & embeddedScreenMapJson() const FL_NOEXCEPT
i32 durationMicros() const
Definition video.cpp.hpp:79
void setFade(fl::u32 fadeInTime, fl::u32 fadeOutTime)
~VideoFxWrapper() FL_NOEXCEPT override
VideoImplPtr mVideo
Definition video.h:110
VideoFxWrapper(FxPtr fx)
string fxName() const override
memorybufPtr mByteStream
Definition video.h:111
void draw(DrawContext context) override
video::VideoImpl VideoImpl
Definition video.h:27
detail::memorybuf memorybuf
fl::shared_ptr< filebuf > filebuf_ptr
Definition idecoder.h:15
fl::shared_ptr< VideoImpl > VideoImplPtr
Definition video.h:28
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT
#define FASTLED_SHARED_PTR_NO_FWD(type)
Definition shared_ptr.h:546
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:535
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38