4#include "fx/video/pixel_stream.h"
6#include "fx/video/frame_interpolator.h"
10#include "fl/math_macros.h"
11#include "fx/video/video_impl.h"
12#include "fx/video/pixel_stream.h"
13#include "fl/bytestreammemory.h"
15#define DBG FASTLED_DBG
17using fl::FileHandlePtr;
18using fl::ByteStreamPtr;
24FASTLED_SMART_PTR(PixelStream);
25FASTLED_SMART_PTR(FrameInterpolator);
26FASTLED_SMART_PTR(Frame);
28Video::Video(): Fx1d(0) {
31Video::Video(
size_t pixelsPerFrame,
float fps,
size_t frame_history_count): Fx1d(pixelsPerFrame) {
32 mImpl = VideoImplPtr::New(pixelsPerFrame, fps, frame_history_count);
35void Video::pause(uint32_t now) {
41void Video::resume(uint32_t now) {
47Video::~Video() =
default;
48Video::Video(
const Video &) =
default;
49Video &Video::operator=(
const Video &) =
default;
51bool Video::begin(FileHandlePtr handle) {
53 FASTLED_WARN(
"Video::begin: mImpl is null, manually constructed videos must include full parameters.");
57 mError =
"FileHandle is null";
58 FASTLED_DBG(mError.c_str());
62 FASTLED_DBG(mError.c_str());
70bool Video::beginStream(ByteStreamPtr bs) {
72 mError =
"FileHandle is null";
73 FASTLED_DBG(mError.c_str());
77 FASTLED_DBG(mError.c_str());
81 mImpl->beginStream(bs);
85bool Video::draw(uint32_t now,
CRGB *leds) {
87 FASTLED_WARN_IF(!mError.empty(), mError.c_str());
90 bool ok = mImpl->draw(now, leds);
100 FASTLED_WARN_IF(!mError.empty(), mError.c_str());
103 mImpl->draw(context.now, context.leds);
106Str Video::fxName()
const {
110bool Video::draw(uint32_t now, Frame *frame) {
114 return mImpl->draw(now, frame);
123void Video::setTimeScale(
float timeScale) {
127 mImpl->setTimeScale(timeScale);
130float Video::timeScale()
const {
134 return mImpl->timeScale();
137Str Video::error()
const {
141size_t Video::pixelsPerFrame()
const {
145 return mImpl->pixelsPerFrame();
148bool Video::finished() {
155bool Video::rewind() {
159 return mImpl->rewind();
163VideoFxWrapper::VideoFxWrapper(Ptr<Fx> fx) : Fx1d(fx->getNumLeds()), mFx(fx) {
164 if (!mFx->hasFixedFrameRate(&mFps)) {
165 FASTLED_WARN(
"VideoFxWrapper: Fx does not have a fixed frame rate, assuming 30fps.");
168 mVideo = VideoImplPtr::New(fx->getNumLeds(), mFps, 2);
169 mByteStream = ByteStreamMemoryPtr::New(fx->getNumLeds() *
sizeof(
CRGB));
170 mVideo->beginStream(mByteStream);
173VideoFxWrapper::~VideoFxWrapper() =
default;
175Str VideoFxWrapper::fxName()
const {
176 Str out =
"video_fx_wrapper: ";
177 out.append(mFx->fxName());
182 if (mVideo->needsFrame(context.now)) {
184 mByteStream->writeCRGB(context.leds, mFx->getNumLeds());
186 bool ok = mVideo->draw(context.now, context.leds);
188 FASTLED_WARN(
"VideoFxWrapper: draw failed.");
void draw(DrawContext context) override
Defines the red, green, and blue (RGB) pixel struct.
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Representation of an RGB pixel (Red, Green, Blue)