FastLED 3.10.8
Loading...
Searching...
No Matches
video.cpp.hpp
Go to the documentation of this file.
1#include "fl/fx/video.h"
2
3#include "crgb.h"
5#include "fl/log/log.h"
6#include "fl/math/math.h"
7#include "fl/stl/string.h"
8#include "fl/log/log.h"
9#include "fl/fx/frame.h"
12#include "fl/fled/color.h"
14#include "fl/video/video_impl.h"
15#include "fl/stl/noexcept.h"
16
17#define DBG FL_DBG
18
19namespace fl {
20
22
23Video::Video(size_t pixelsPerFrame, float fps, size_t frame_history_count)
25 mImpl = fl::make_shared<VideoImpl>(pixelsPerFrame, fps, frame_history_count);
26}
27
28void Video::setFade(fl::u32 fadeInTime, fl::u32 fadeOutTime) FL_NO_EXCEPT {
29 mImpl->setFade(fadeInTime, fadeOutTime);
30}
31
32void Video::pause(fl::u32 now) FL_NO_EXCEPT { mImpl->pause(now); }
33
34void Video::resume(fl::u32 now) FL_NO_EXCEPT { mImpl->resume(now); }
35
36Video::~Video() FL_NO_EXCEPT = default;
37Video::Video(const Video &) FL_NO_EXCEPT = default;
38Video &Video::operator=(const Video &) FL_NO_EXCEPT = default;
39
41 if (!mImpl) {
42 FL_WARN("Video::begin: mImpl is null, manually constructed videos "
43 "must include full parameters.");
44 return false;
45 }
46 // Drop a previous admission failure before evaluating this attempt.
47 // Rejecting one source says nothing about the next; only a persistent
48 // setError() failure keeps blocking.
49 if (mAdmissionError) {
50 mError.clear();
51 mAdmissionError = false;
52 }
53 if (!handle) {
54 setAdmissionError("filebuf is null");
56 return false;
57 }
58 if (mError.size()) {
59 FL_DBG(mError);
60 return false;
61 }
62 if (!mImpl->begin(handle)) {
63 setAdmissionError("unsupported or malformed FLED container");
64 return false;
65 }
66 return true;
67}
68
70 if (!mError.empty()) {
71 for (fl::size_t i = 0; i < leds.size(); ++i) {
72 leds[i] = CRGB::Black;
73 }
74 return false;
75 }
76 if (!mImpl) {
77 FL_WARN_IF(!mError.empty(), mError);
78 return false;
79 }
80 bool ok = mImpl->draw(now, leds);
81 if (!ok) {
82 // Interpret not being able to draw as a finished signal.
83 mFinished = true;
84 }
85 return ok;
86}
87
89 draw(context.now, context.leds);
90}
91
93 if (!mImpl) {
94 return -1;
95 }
96 return mImpl->durationMicros();
97}
98
99string Video::fxName() const FL_NO_EXCEPT { return "Video"; }
100
101bool Video::draw(fl::u32 now, Frame *frame) FL_NO_EXCEPT {
102 if (!frame) {
103 return false;
104 }
105 return draw(now, frame->rgb());
106}
107
109 if (mImpl) {
110 mImpl->end();
111 }
112}
113
115 if (!mImpl) {
116 return;
117 }
118 mImpl->setTimeScale(timeScale);
119}
120
122 if (!mImpl) {
123 return 1.0f;
124 }
125 return mImpl->timeScale();
126}
127
128string Video::error() const FL_NO_EXCEPT { return mError; }
129
132 return out != nullptr && videoColor(&color) &&
134}
135
137 return mImpl && mImpl->videoColor(out);
138}
139
141 return mImpl && mImpl->pixelStorage(out);
142}
143
145 return mImpl && mImpl->readSample(out);
146}
147
149 if (mImpl) {
150 mImpl->setBestEffortFled(mode == FledPlaybackMode::BestEffort);
151 }
152}
153
155 if (!mImpl) {
156 return 0;
157 }
158 return mImpl->pixelsPerFrame();
159}
160
162 if (!mImpl) return false;
163 return mImpl->hasEmbeddedScreenMap();
164}
165
167 static const fl::string kEmpty;
168 if (!mImpl) return kEmpty;
169 return mImpl->embeddedScreenMapJson();
170}
171
173 if (!mImpl) {
174 return true;
175 }
176 return mFinished;
177}
178
180 if (!mImpl) {
181 return false;
182 }
183 return mImpl->rewind();
184}
185
187 if (!mFx->hasFixedFrameRate(&mFps)) {
188 FL_WARN("VideoFxWrapper: Fx does not have a fixed frame rate, "
189 "assuming 30fps.");
190 mFps = 30.0f;
191 }
192 mVideo = fl::make_shared<VideoImpl>(mFx->getNumLeds(), mFps, 2);
193 mByteStream = fl::make_shared<memorybuf>(mFx->getNumLeds() * sizeof(CRGB));
194 mVideo->begin(mByteStream);
195}
196
198
200 string out = "video_fx_wrapper: ";
201 out.append(mFx->fxName());
202 return out;
203}
204
206 if (mVideo->needsFrame(context.now)) {
207 mFx->draw(context); // use the leds in the context as a tmp buffer.
208 mByteStream->writeCRGB(
209 context.leds.data(),
210 mFx->getNumLeds()); // now write the leds to the byte stream.
211 }
212 bool ok = mVideo->draw(context.now, context.leds);
213 if (!ok) {
214 FL_WARN("VideoFxWrapper: draw failed.");
215 }
216}
217
218void VideoFxWrapper::setFade(fl::u32 fadeInTime, fl::u32 fadeOutTime) FL_NO_EXCEPT {
219 mVideo->setFade(fadeInTime, fadeOutTime);
220}
221
222} // namespace fl
CRGB leds[1]
Fx1d(u16 numLeds) FL_NO_EXCEPT
Definition fx1d.h:13
size_t pixelsPerFrame() const FL_NO_EXCEPT
void setTimeScale(float timeScale) FL_NO_EXCEPT
bool readSample(video::PixelSample *out) FL_NO_EXCEPT
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
~Video() FL_NO_EXCEPT
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
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
string & append(const bitset_fixed< N > &bs) FL_NO_EXCEPT
Definition string.h:293
void draw(float pos)
Definition curr.h:526
fl::CRGB CRGB
Definition crgb.h:25
#define FL_WARN(...)
Definition log.h:437
#define FL_DBG
Definition log.h:553
#define FL_WARN_IF(COND,...)
Definition log.h:438
Centralized logging categories for FastLED hardware interfaces and subsystems.
shared_ptr< T > make_shared(Args &&... args) FL_NO_EXCEPT
Definition shared_ptr.h:423
__SIZE_TYPE__ size_t
Definition s16x16x4.h:16
bool toSourceProfile(const VideoColor &color, SourceProfile *out) FL_NO_EXCEPT
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
fl::shared_ptr< filebuf > filebuf_ptr
Definition idecoder.h:15
FledPlaybackMode
Definition video.h:33
Base definition for an LED controller.
Definition crgb.hpp:179
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:517
A source declaration, not a container or an output-device selection.