MCPcopy Create free account
hub / github.com/FastLED/FastLED / validateMp4

Function validateMp4

tests/fl/codec/decode_file.hpp:93–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91// ---------------------------------------------------------------------------
92
93static void validateMp4(const fl::vector<fl::u8>& data) {
94 fl::string error;
95 fl::Mp4TrackInfo track = fl::parseMp4(data, &error);
96 FL_CHECK_MESSAGE(track.isValid, "MP4 parse failed: " << error);
97 if (track.isValid) {
98 FL_CHECK_GT(track.width, 0);
99 FL_CHECK_GT(track.height, 0);
100 FL_CHECK_GT(track.sps.size(), 0);
101 FL_CHECK_GT(track.pps.size(), 0);
102 FL_MESSAGE("MP4: " << track.width << "x" << track.height
103 << " profile=" << (int)track.profile
104 << " level=" << (int)track.level);
105 }
106
107 fl::H264Info info = fl::H264::parseH264Info(data, &error);
108 FL_CHECK_MESSAGE(info.isValid, "H264 info parse failed: " << error);
109 if (info.isValid) {
110 FL_CHECK_GT(info.width, 0);
111 FL_CHECK_GT(info.height, 0);
112 FL_MESSAGE("H264: " << info.width << "x" << info.height);
113 }
114
115 if (track.isValid) {
116 fl::vector<fl::u8> annexB = fl::extractH264NalUnits(data, track, &error);
117 FL_CHECK_GT(annexB.size(), 0);
118 }
119
120 // Attempt frame decoding (mirrors validateMpeg/validateGif pattern)
121 if (fl::H264::isSupported()) {
122 fl::H264Config config;
123 fl::string dec_error;
124 auto decoder = fl::H264::createDecoder(config, &dec_error);
125 FL_REQUIRE_MESSAGE(decoder, "H264 decoder creation failed: " << dec_error);
126 auto stream = fl::make_shared<fl::memorybuf>(data.size());
127 stream->write(data);
128 FL_CHECK(decoder->begin(stream));
129 auto result = decoder->decode();
130 if (result == fl::DecodeResult::Success) {
131 fl::Frame frame = decoder->getCurrentFrame();
132 FL_CHECK(frame.isValid());
133 FL_CHECK_GT(frame.getWidth(), 0);
134 FL_CHECK_GT(frame.getHeight(), 0);
135 FL_MESSAGE("H264 first frame: " << frame.getWidth() << "x" << frame.getHeight());
136 auto pixels = frame.rgb();
137 int count = pixels.size() < 16 ? (int)pixels.size() : 16;
138 for (int i = 0; i < count; i++) {
139 FL_MESSAGE(" pixel[" << i << "] = ("
140 << (int)pixels[i].r << ","
141 << (int)pixels[i].g << ","
142 << (int)pixels[i].b << ")");
143 }
144 }
145 decoder->end();
146 } else {
147 FL_MESSAGE("H264 decoder not supported on this platform");
148 }
149}
150

Callers 1

FL_TEST_FILEFunction · 0.85

Calls 12

parseMp4Function · 0.85
extractH264NalUnitsFunction · 0.85
sizeMethod · 0.45
writeMethod · 0.45
beginMethod · 0.45
decodeMethod · 0.45
getCurrentFrameMethod · 0.45
isValidMethod · 0.45
getWidthMethod · 0.45
getHeightMethod · 0.45
rgbMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected