5#include "TinyH264Decoder.h"
6#include "TinyH264Encoder.h"
20#ifndef H264_DEFAULT_ALLOCATOR
22#define H264_DEFAULT_ALLOCATOR tinyh264::PSRAMAllocatorESP32<uint8_t>
24#define H264_DEFAULT_ALLOCATOR tinyh264::StdAllocator<uint8_t>
87 LOGW(
"H264Decoder: unsupported VideoFormat %d", (
int)format);
122 size_t write(
const uint8_t *data,
size_t len)
override {
140 tinyh264::TinyH264Decoder<H264_DEFAULT_ALLOCATOR>
decoder_;
146 static void onFrame(tinyh264::TinyH264Decoder<H264_DEFAULT_ALLOCATOR> &decoder,
158 size_t needed = w * h;
162 LOGE(
"H264Decoder: frame buffer allocation failed (RGB565)");
171 size_t needed = w * h * 3;
175 LOGE(
"H264Decoder: frame buffer allocation failed (RGB666)");
184 size_t needed = w * h * 3;
188 LOGE(
"H264Decoder: frame buffer allocation failed (RGB888)");
197 size_t needed = w * h + 2 * (w / 2) * (h / 2);
201 LOGE(
"H264Decoder: frame buffer allocation failed (I420)");
216 if (
p_out !=
nullptr) result =
p_out->
write((
const uint8_t *)data, len);
253 H264Encoder(
int width = 0,
int height = 0,
int keyframeInterval = 0)
254 :
encoder_(width, height, keyframeInterval) {
289 LOGW(
"H264Encoder: unsupported VideoFormat %d", (
int)format);
316 encoder_.setTargetBitrate(bitsPerSecond, fps);
320 encoder_.setKeyframeInterval(frames);
324 encoder_.setStride(strideY, strideC);
338 LOGE(
"H264Encoder: bitstream buffer allocation failed");
348 bool begin(
bool reserveColorConversionScratch) {
349 encoder_.begin(reserveColorConversionScratch);
367 size_t write(
const uint8_t *data,
size_t len)
override {
372 if (len < ySize + 2 * cSize)
return 0;
373 const uint8_t *srcY = data;
374 const uint8_t *srcU = data + ySize;
375 const uint8_t *srcV = data + ySize + cSize;
376 return writeOut([&](uint8_t *dst,
size_t cap) {
377 return encoder_.encodeFrame(srcY, srcU, srcV, dst, cap);
381 return writeOut([&](uint8_t *dst,
size_t cap) {
382 return encoder_.encodeFrameYuv422(data, dst, cap);
385 return writeOut([&](uint8_t *dst,
size_t cap) {
386 return encoder_.encodeFrameRgb565((
const uint16_t *)data, dst, cap);
389 return writeOut([&](uint8_t *dst,
size_t cap) {
390 return encoder_.encodeFrameRgb666(data, dst, cap);
393 return writeOut([&](uint8_t *dst,
size_t cap) {
394 return encoder_.encodeFrameRgb888(data, dst, cap);
410 tinyh264::TinyH264Encoder<H264_DEFAULT_ALLOCATOR>
encoder_;
418 template <
typename Fn>
424 LOGE(
"H264Encoder: bitstream buffer allocation failed");
429 for (
int attempt = 0; n == 0 && attempt <
kMaxGrowRetries; ++attempt) {
432 LOGE(
"H264Encoder: bitstream buffer grow failed");
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#define LOGE(...)
Definition AudioLoggerIDF.h:30
virtual size_t write(const uint8_t *data, size_t len)
Definition Arduino.h:120
VideoFormat
Video codec/pixel-format identifier, shared by two unrelated uses: the (single) video stream of a con...
Definition Video.h:43