[feat] enable Android MediaCodec decoding and simplify tests

This commit is contained in:
dijunkun
2026-10-02 02:11:33 +08:00
parent e76cfecac8
commit ff706857bd
32 changed files with 315 additions and 1043 deletions
+24 -2
View File
@@ -1,4 +1,11 @@
#pragma once
/*
* @Author: DI JUNKUN
* @Date: 2026-10-02
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _VIDEO_PICTURE_H_
#define _VIDEO_PICTURE_H_
#include <minirtc.h>
#include <climits>
@@ -14,6 +21,12 @@ struct VideoPicture {
std::vector<uint8_t> pixels;
std::shared_ptr<void> native_owner;
MiniRtcCpuNv12Frame planes{};
MiniRtcAndroidMediaCodecFrame media_codec{};
bool IsSurface() const { return media_codec.render && native_owner; }
int RenderSurface(void* window) const {
return IsSurface() ? media_codec.render(native_owner.get(), window) : -1;
}
const uint8_t* Y() const { return native_owner ? planes.y_plane : pixels.data(); }
const uint8_t* UV() const { return native_owner ? planes.uv_plane : pixels.data() + size_t(width) * height; }
@@ -26,10 +39,17 @@ struct VideoPicture {
if (!w || !h || w > 8192 || h > 8192 || (w & 1) || (h & 1) ||
static_cast<uint64_t>(w) * h > 33554432) return std::nullopt;
VideoPicture result{w, h, frame.captured_timestamp, frame.received_timestamp,
generation, {}, {}, {}};
generation, {}, {}, {}, {}};
const auto* native = frame.native_frame;
const bool valid_native = native && native->struct_size >= sizeof(*native) &&
native->width == w && native->height == h && native->owner;
if (valid_native && native->type == MiniRtcNativeVideoFrameAndroidMediaCodec &&
native->retain && native->release && native->payload.android_media_codec.render) {
native->retain(native->owner);
result.native_owner = std::shared_ptr<void>(native->owner, native->release);
result.media_codec = native->payload.android_media_codec;
return result;
}
if (valid_native && native->type == MiniRtcNativeVideoFrameCpuNv12 &&
native->retain && native->release) {
const auto& planes = native->payload.cpu_nv12;
@@ -56,3 +76,5 @@ struct VideoPicture {
}
};
} // namespace crossdesk::android_controller
#endif