FastLED 3.10.8
Loading...
Searching...
No Matches
pixel_stream.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/fs/fs.h"
4#include "fl/stl/shared_ptr.h" // For FASTLED_SHARED_PTR macros
5#include "fl/stl/int.h"
6#include "fl/stl/noexcept.h"
7#include "fl/stl/string.h"
9namespace fl {
10class filebuf;
11using filebuf_ptr = fl::shared_ptr<filebuf>;
12} // namespace fl
13
14namespace fl {
15namespace video {
16
18
19// PixelStream reads frames from a filebuf to serve data to the video system.
20// A single handle is used for both seekable files and non-seekable streams.
21// Seekability is auto-detected via seek() at begin() time.
22//
23// FLED container support (issue #3072): on seekable handles, begin() peeks
24// the first 12 bytes for the "FLED" magic. If present, the header is
25// consumed, the embedded screenmap JSON is stashed, and frame reads start
26// past the header. Legacy headerless `.rgb` files keep working unchanged.
27// Spec: https://github.com/zackees/ledmapper/blob/main/docs/fled-format.md
29 public:
30 enum Type {
31 kStreaming, // Non-seekable (e.g. memorybuf circular buffer)
32 kFile, // Seekable (e.g. posix_filebuf, SD card)
33 };
34
35 explicit PixelStream(int bytes_per_frame) FL_NO_EXCEPT;
36
37 // Opens a handle. Streaming vs seekable is auto-detected:
38 // seek(0, beg) succeeds → kFile, fails → kStreaming.
40
41 void close() FL_NO_EXCEPT;
43 bool readPixel(CRGB *dst) FL_NO_EXCEPT;
45 size_t readBytes(u8 *dst, size_t len) FL_NO_EXCEPT;
46
47 bool readFrame(Frame *frame) FL_NO_EXCEPT;
48 bool readFrameAt(fl::u32 frameNumber, Frame *frame) FL_NO_EXCEPT;
49 bool hasFrame(fl::u32 frameNumber) FL_NO_EXCEPT;
50 i32 framesRemaining() const FL_NO_EXCEPT; // -1 if this is a stream.
51 i32 framesDisplayed() const FL_NO_EXCEPT;
52 bool available() const FL_NO_EXCEPT;
53 bool atEnd() const FL_NO_EXCEPT;
54
55 i32 bytesRemaining() const FL_NO_EXCEPT;
57 bool rewind() FL_NO_EXCEPT; // Returns false for non-seekable streams.
59
60 // FLED v1 container accessors. True/non-empty only when begin() found
61 // a valid FLED header on a seekable handle; otherwise empty / false.
63 const fl::string &embeddedScreenMapJson() const FL_NO_EXCEPT;
64 bool videoColor(fled::VideoColor *out) const FL_NO_EXCEPT;
65 bool pixelStorage(fled::PixelStorage *out) const FL_NO_EXCEPT;
66 // True only when the active source can be consumed by the legacy CRGB
67 // playback path. Typed formats require a separate ingress consumer.
68 bool isRgb8Playback() const FL_NO_EXCEPT;
69 void setBestEffortFled(bool enabled) FL_NO_EXCEPT { mBestEffortFled = enabled; }
70
71 private:
73 const fl::i32 mBaseBytesPerFrame;
76
77 // Byte offset of the first frame in the file. 0 for legacy headerless
78 // `.rgb` files; 12 + jsonLength for FLED-formatted files.
83 bool mHasFledContainer = false;
85 bool mHasVideoColor = false;
86 bool mBestEffortFled = false;
87
88 // Non-seekable handles need a small magic probe. Raw stream bytes read
89 // for that probe are replayed before the underlying handle is consumed.
90 mutable fl::u8 mStreamingPrefix[4] = {};
93 mutable bool mStreamingProbePending = false;
94 mutable bool mStreamingRejected = false;
95
97
98 public:
99 virtual ~PixelStream() FL_NO_EXCEPT;
100};
101
102} // namespace video
105} // namespace fl
i32 bytesRemainingInFrame() const FL_NO_EXCEPT
bool readFrame(Frame *frame) FL_NO_EXCEPT
fl::filebuf_ptr mHandle
PixelStream(int bytes_per_frame) FL_NO_EXCEPT
i32 bytesPerFrame() FL_NO_EXCEPT
i32 framesRemaining() const FL_NO_EXCEPT
bool readSample(PixelSample *out) FL_NO_EXCEPT
bool hasEmbeddedScreenMap() const FL_NO_EXCEPT
const fl::i32 mBaseBytesPerFrame
bool probeStreamingMagic() const FL_NO_EXCEPT
bool begin(fl::filebuf_ptr h) FL_NO_EXCEPT
bool readPixel(CRGB *dst) FL_NO_EXCEPT
const fl::string & embeddedScreenMapJson() const FL_NO_EXCEPT
bool pixelStorage(fled::PixelStorage *out) const FL_NO_EXCEPT
fl::size_t mStreamingPrefixPos
i32 bytesRemaining() const FL_NO_EXCEPT
size_t readBytes(u8 *dst, size_t len) FL_NO_EXCEPT
void close() FL_NO_EXCEPT
void setBestEffortFled(bool enabled) FL_NO_EXCEPT
bool hasFrame(fl::u32 frameNumber) FL_NO_EXCEPT
Type getType() const FL_NO_EXCEPT
fl::size_t mStreamingPrefixSize
bool atEnd() const FL_NO_EXCEPT
fled::VideoColor mVideoColor
bool videoColor(fled::VideoColor *out) const FL_NO_EXCEPT
bool readFrameAt(fl::u32 frameNumber, Frame *frame) FL_NO_EXCEPT
fl::string mEmbeddedScreenMapJson
i32 framesDisplayed() const FL_NO_EXCEPT
bool rewind() FL_NO_EXCEPT
bool isRgb8Playback() const FL_NO_EXCEPT
__SIZE_TYPE__ size_t
Definition s16x16x4.h:16
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
fl::shared_ptr< filebuf > filebuf_ptr
Definition idecoder.h:15
int available() FL_NO_EXCEPT
video::PixelStreamPtr PixelStreamPtr
video::PixelStream PixelStream
Base definition for an LED controller.
Definition crgb.hpp:179
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:577
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38