FastLED 3.9.15
Loading...
Searching...
No Matches
video.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stdint.h"
4
5#include "fl/namespace.h"
6#include "fl/memory.h"
7#include "fl/str.h"
8#include "fx/fx1d.h"
9#include "fx/time.h"
10
12struct CRGB;
14
15namespace fl {
16
17// Forward declare classes
24
25// Video represents a video file that can be played back on a LED strip.
26// The video file is expected to be a sequence of frames. You can either use
27// a file handle or a byte stream to read the video data.
28class Video : public Fx1d { // Fx1d because video can be irregular.
29 public:
30 static size_t DefaultFrameHistoryCount() {
31#ifdef __AVR__
32 return 1;
33#else
34 return 2; // Allow interpolation by default.
35#endif
36 }
37 // frameHistoryCount is the number of frames to keep in the buffer after
38 // draw. This allows for time based effects like syncing video speed to
39 // audio triggers. If you are using a filehandle for you video then you can
40 // just leave this as the default. For streaming byte streams you may want
41 // to increase this number to allow momentary re-wind. If you'd like to use
42 // a Video as a buffer for an fx effect then please see VideoFxWrapper.
43 Video();
44 Video(size_t pixelsPerFrame, float fps = 30.0f,
45 size_t frameHistoryCount =
46 DefaultFrameHistoryCount()); // Please use FileSytem to construct
47 // a Video.
49 Video(const Video &);
51
52 // Fx Api
53 void draw(DrawContext context) override;
54 Str fxName() const override;
55
56 // Api
57 bool begin(fl::FileHandlePtr h);
58 bool beginStream(fl::ByteStreamPtr s);
59 bool draw(fl::u32 now, CRGB *leds);
60 bool draw(fl::u32 now, Frame *frame);
61 void end();
62 bool finished();
63 bool rewind();
64 void setTimeScale(float timeScale);
65 float timeScale() const;
66 Str error() const;
67 void setError(const Str &error) { mError = error; }
68 size_t pixelsPerFrame() const;
69 void pause(fl::u32 now) override;
70 void resume(fl::u32 now) override;
71 void setFade(fl::u32 fadeInTime, fl::u32 fadeOutTime);
72 int32_t durationMicros() const; // -1 if this is a stream.
73
74 // make compatible with if statements
75 operator bool() const { return mImpl.get(); }
76
77 private:
78 bool mFinished = false;
79 VideoImplPtr mImpl;
82};
83
84// Wraps an Fx and stores a history of video frames. This allows
85// interpolation between frames for FX for smoother effects.
86// It also allows re-wind on fx that gnore time and always generate
87// the next frame based on the previous frame and internal speed,
88// for example NoisePalette.
89class VideoFxWrapper : public Fx1d {
90 public:
91 VideoFxWrapper(FxPtr fx);
92 ~VideoFxWrapper() override;
93 void draw(DrawContext context) override;
94 Str fxName() const override;
95 void setFade(fl::u32 fadeInTime, fl::u32 fadeOutTime);
96
97 private:
98 FxPtr mFx;
99 VideoImplPtr mVideo;
100 ByteStreamMemoryPtr mByteStream;
101 float mFps = 30.0f;
102};
103
104} // namespace fl
CRGB leds[NUM_LEDS]
Fx1d(u16 numLeds)
Definition fx1d.h:15
_DrawContext DrawContext
Definition fx.h:21
Str error() const
Definition video.cpp:138
bool finished()
Definition video.cpp:147
void draw(DrawContext context) override
Definition video.cpp:94
float timeScale() const
Definition video.cpp:131
void end()
Definition video.cpp:118
bool begin(fl::FileHandlePtr h)
void pause(fl::u32 now) override
Definition video.cpp:38
static size_t DefaultFrameHistoryCount()
Definition video.h:30
Str fxName() const override
Definition video.cpp:109
size_t pixelsPerFrame() const
Definition video.cpp:140
Video(const Video &)
bool mFinished
Definition video.h:78
bool beginStream(fl::ByteStreamPtr s)
Str mError
Definition video.h:80
void setFade(fl::u32 fadeInTime, fl::u32 fadeOutTime)
Definition video.cpp:34
void setTimeScale(float timeScale)
Definition video.cpp:124
Video & operator=(const Video &)
VideoImplPtr mImpl
Definition video.h:79
void setError(const Str &error)
Definition video.h:67
void resume(fl::u32 now) override
Definition video.cpp:40
bool rewind()
Definition video.cpp:154
int32_t durationMicros() const
Definition video.cpp:102
Str mName
Definition video.h:81
void setFade(fl::u32 fadeInTime, fl::u32 fadeOutTime)
Definition video.cpp:193
Str fxName() const override
Definition video.cpp:174
VideoImplPtr mVideo
Definition video.h:99
VideoFxWrapper(FxPtr fx)
ByteStreamMemoryPtr mByteStream
Definition video.h:100
void draw(DrawContext context) override
Definition video.cpp:180
~VideoFxWrapper() override
#define FASTLED_NAMESPACE_END
Definition namespace.h:23
#define FASTLED_NAMESPACE_BEGIN
Definition namespace.h:22
Implements the FastLED namespace macros.
fl::string Str
Definition str.h:36
IMPORTANT!
Definition crgb.h:20
#define FASTLED_SMART_PTR(type)
Definition ptr.h:33
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86