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::setFade(uint32_t fadeInTime, uint32_t fadeOutTime) {
36 mImpl->setFade(fadeInTime, fadeOutTime);
39void Video::pause(uint32_t now) {
43void 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);
106int32_t Video::durationMicros()
const {
110 return mImpl->durationMicros();
113Str Video::fxName()
const {
117bool Video::draw(uint32_t now, Frame *frame) {
121 return mImpl->draw(now, frame);
130void Video::setTimeScale(
float timeScale) {
134 mImpl->setTimeScale(timeScale);
137float Video::timeScale()
const {
141 return mImpl->timeScale();
144Str Video::error()
const {
148size_t Video::pixelsPerFrame()
const {
152 return mImpl->pixelsPerFrame();
155bool Video::finished() {
162bool Video::rewind() {
166 return mImpl->rewind();
170VideoFxWrapper::VideoFxWrapper(Ptr<Fx> fx) : Fx1d(fx->getNumLeds()), mFx(fx) {
171 if (!mFx->hasFixedFrameRate(&mFps)) {
172 FASTLED_WARN(
"VideoFxWrapper: Fx does not have a fixed frame rate, assuming 30fps.");
175 mVideo = VideoImplPtr::New(mFx->getNumLeds(), mFps, 2);
176 mByteStream = ByteStreamMemoryPtr::New(mFx->getNumLeds() *
sizeof(
CRGB));
177 mVideo->beginStream(mByteStream);
181VideoFxWrapper::~VideoFxWrapper() =
default;
183Str VideoFxWrapper::fxName()
const {
184 Str out =
"video_fx_wrapper: ";
185 out.append(mFx->fxName());
190 if (mVideo->needsFrame(context.now)) {
192 mByteStream->writeCRGB(context.leds, mFx->getNumLeds());
194 bool ok = mVideo->draw(context.now, context.leds);
196 FASTLED_WARN(
"VideoFxWrapper: draw failed.");
200void VideoFxWrapper::setFade(uint32_t fadeInTime, uint32_t fadeOutTime) {
201 mVideo->setFade(fadeInTime, fadeOutTime);
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)