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