FastLED 3.9.15
Loading...
Searching...
No Matches
pixel_stream.h
Go to the documentation of this file.
1#pragma once
2
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"
8namespace fl {
9class filebuf;
10using filebuf_ptr = fl::shared_ptr<filebuf>;
11} // namespace fl
12
13namespace fl {
14namespace video {
15
17
18// PixelStream reads frames from a filebuf to serve data to the video system.
19// A single handle is used for both seekable files and non-seekable streams.
20// Seekability is auto-detected via seek() at begin() time.
21//
22// FLED container support (issue #3072): on seekable handles, begin() peeks
23// the first 12 bytes for the "FLED" magic. If present, the header is
24// consumed, the embedded screenmap JSON is stashed, and frame reads start
25// past the header. Legacy headerless `.rgb` files keep working unchanged.
26// Spec: https://github.com/zackees/ledmapper/blob/main/docs/fled-format.md
28 public:
29 enum Type {
30 kStreaming, // Non-seekable (e.g. memorybuf circular buffer)
31 kFile, // Seekable (e.g. posix_filebuf, SD card)
32 };
33
34 explicit PixelStream(int bytes_per_frame);
35
36 // Opens a handle. Streaming vs seekable is auto-detected:
37 // seek(0, beg) succeeds → kFile, fails → kStreaming.
38 bool begin(fl::filebuf_ptr h);
39
40 void close();
41 i32 bytesPerFrame();
42 bool readPixel(CRGB *dst);
43 size_t readBytes(u8 *dst, size_t len);
44
45 bool readFrame(Frame *frame);
46 bool readFrameAt(fl::u32 frameNumber, Frame *frame);
47 bool hasFrame(fl::u32 frameNumber);
48 i32 framesRemaining() const; // -1 if this is a stream.
49 i32 framesDisplayed() const;
50 bool available() const;
51 bool atEnd() const;
52
53 i32 bytesRemaining() const;
54 i32 bytesRemainingInFrame() const;
55 bool rewind(); // Returns false for non-seekable streams.
56 Type getType() const;
57
58 // FLED v1 container accessors. True/non-empty only when begin() found
59 // a valid FLED header on a seekable handle; otherwise empty / false.
61 const fl::string &embeddedScreenMapJson() const FL_NOEXCEPT;
62
63 private:
67
68 // Byte offset of the first frame in the file. 0 for legacy headerless
69 // `.rgb` files; 12 + jsonLength for FLED-formatted files.
70 fl::size_t mPayloadOffset = 0;
72
73 public:
74 virtual ~PixelStream() FL_NOEXCEPT;
75};
76
77} // namespace video
80} // namespace fl
PixelStream(int bytes_per_frame)
fl::filebuf_ptr mHandle
bool begin(fl::filebuf_ptr h)
bool hasEmbeddedScreenMap() const FL_NOEXCEPT
bool hasFrame(fl::u32 frameNumber)
const fl::string & embeddedScreenMapJson() const FL_NOEXCEPT
bool readFrameAt(fl::u32 frameNumber, Frame *frame)
size_t readBytes(u8 *dst, size_t len)
bool readFrame(Frame *frame)
fl::string mEmbeddedScreenMapJson
unsigned char u8
Definition stdint.h:131
fl::shared_ptr< filebuf > filebuf_ptr
Definition idecoder.h:15
video::PixelStreamPtr PixelStreamPtr
video::PixelStream PixelStream
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:535
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38