FastLED 3.9.7
Loading...
Searching...
No Matches
video.h
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
19FASTLED_SMART_PTR(FileHandle);
20FASTLED_SMART_PTR(ByteStream);
21FASTLED_SMART_PTR(Frame);
22FASTLED_SMART_PTR(VideoImpl);
23FASTLED_SMART_PTR(VideoFxWrapper);
24FASTLED_SMART_PTR(ByteStreamMemory);
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.
46 ~Video();
47 Video(const Video&);
48 Video& operator=(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
70 // make compatible with if statements
71 operator bool() const { return mImpl.get(); }
72private:
73 bool mFinished = false;
74 VideoImplPtr mImpl;
75 Str mError;
76 Str mName;
77};
78
79
80
81// Wraps an Fx and stores a history of video frames. This allows
82// interpolation between frames for FX for smoother effects.
83// It also allows re-wind on fx that gnore time and always generate
84// the next frame based on the previous frame and internal speed,
85// for example NoisePalette.
86class VideoFxWrapper : public Fx1d {
87 public:
88 VideoFxWrapper(FxPtr fx);
89 ~VideoFxWrapper() override;
90 void draw(DrawContext context) override;
91 Str fxName() const override;
92
93 private:
94 FxPtr mFx;
95 VideoImplPtr mVideo;
96 ByteStreamMemoryPtr mByteStream;
97 float mFps = 30.0f;
98};
99
100
101} // namespace fl
102
Definition str.h:336
void draw(DrawContext context) override
Definition video.cpp:181
void draw(DrawContext context) override
Definition video.cpp:98
Implements the FastLED namespace macros.
#define FASTLED_NAMESPACE_END
End of the FastLED namespace.
Definition namespace.h:16
#define FASTLED_NAMESPACE_BEGIN
Start of the FastLED namespace.
Definition namespace.h:14
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