7#include "TinyMPGDecoder.h"
8#include "TinyMPGEncoder.h"
11#ifndef MPG_DEFAULT_ALLOCATOR
13# define MPG_DEFAULT_ALLOCATOR tinympg::PSRAMAllocatorESP32<uint8_t>
15# define MPG_DEFAULT_ALLOCATOR tinympg::StdAllocator<uint8_t>
67 for (
size_t i = 0; i + 3 < len; i++) {
68 if (data[i] == 0 && data[i + 1] == 0 && data[i + 2] == 1 &&
69 data[i + 3] == 0xB3) {
88 LOGW(
"MPGDecoder: unsupported VideoFormat %d", (
int)format);
188 tinympg::TinyMPGDecoder<MPG_DEFAULT_ALLOCATOR>
decoder_;
196 static void onFrame(tinympg::TinyMPGDecoder<MPG_DEFAULT_ALLOCATOR> &decoder,
201 void writeFrame(tinympg::TinyMPGDecoder<MPG_DEFAULT_ALLOCATOR> &decoder) {
204 size_t w = decoder.width();
205 size_t h = decoder.height();
210 size_t needed = w * h;
214 LOGE(
"MPGDecoder: frame buffer allocation failed (RGB565)");
222 for (
size_t i = 0; i < n; i++) {
224 px[i] = (uint16_t)((v << 8) | (v >> 8));
232 size_t needed = w * h * 3;
236 LOGE(
"MPGDecoder: frame buffer allocation failed (RGB888)");
245 size_t needed = w * h * 3;
249 LOGE(
"MPGDecoder: frame buffer allocation failed (RGB666)");
258 size_t needed = w * h + 2 * (w / 2) * (h / 2);
262 LOGE(
"MPGDecoder: frame buffer allocation failed (I420)");
325 LOGW(
"MPGEncoder: unsupported VideoFormat %d", (
int)format);
352 LOGE(
"MPGEncoder: bitstream buffer allocation failed");
358 LOGE(
"MPGEncoder: invalid size - call setSize() first");
362 LOGE(
"MPGEncoder: failed to allocate bitstream buffer");
373 LOGE(
"MPGEncoder: invalid size - call setSize() first");
377 LOGE(
"MPGEncoder: bitstream buffer not available");
384 size_t uv_size = y_size / 4;
385 size_t min_size = y_size + uv_size + uv_size;
386 if (len < min_size) {
387 LOGE(
"MPGEncoder: input buffer too small for I420 frame");
391 const uint8_t *srcU = data + y_size;
392 const uint8_t *srcV = data + y_size + uv_size;
394 return encoder_.encodeFrame(srcY, srcU, srcV, dst, cap);
399 return encoder_.encodeFrameYuv422(data, dst, cap);
403 return encoder_.encodeFrameRgb565((
const uint16_t *)data, dst, cap);
407 return encoder_.encodeFrameRgb666(data, dst, cap);
411 return encoder_.encodeFrameRgb888(data, dst, cap);
424 tinympg::TinyMPGEncoder<MPG_DEFAULT_ALLOCATOR>
encoder_;
432 template <
typename Fn>
436 for (
int attempt = 0; encoded == 0 && attempt <
kMaxGrowRetries; ++attempt) {
439 LOGE(
"MPGEncoder: bitstream buffer grow failed");
445 LOGE(
"MPGEncoder: encode failed (status=%d)", (
int)
encoder_.lastStatus());
#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 VideoOutput.h:29
bool isMpeg1KeyFrame(const uint8_t *data, size_t len)
True if the given MPEG-1/2 video access unit's picture header declares picture_coding_type == 1 (I-pi...
Definition Video.h:71