Enable log information. Disable NPU in U9
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "lock.h"
|
||||
#include "media_codec.h"
|
||||
#include "media_parse.h"
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include "ANSLicense.h" // ANS_DBG macro (gated by ANSCORE_DEBUGVIEW)
|
||||
@@ -14,6 +15,16 @@ extern "C" {
|
||||
#include "libavutil/mem.h"
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Leak diagnostics — exported counters for media allocation balance.
|
||||
// Incremented in allocation sites, decremented in free paths. If (alloc -
|
||||
// free) climbs monotonically over time, the allocator is leaking.
|
||||
// Read by the MEDIA_Leak heartbeat in video_player.cpp (every 60 s).
|
||||
// ---------------------------------------------------------------------------
|
||||
std::atomic<int64_t> g_contiguousAllocs{0};
|
||||
std::atomic<int64_t> g_contiguousFrees{0};
|
||||
std::atomic<int64_t> g_contiguousBytesInFlight{0}; // sum(total) of unfreed buffers
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Contiguous YUV420P allocator — trims per-call malloc overhead and enables
|
||||
// the zero-copy fast path in avframeYUV420PToCvMat for resolutions where the
|
||||
@@ -23,7 +34,20 @@ extern "C" {
|
||||
// single-block layout still improves cache behaviour for the bulk memcpy.)
|
||||
// ---------------------------------------------------------------------------
|
||||
namespace {
|
||||
void anscore_contiguous_free(void* /*opaque*/, uint8_t* data) {
|
||||
// Opaque payload stored in AVBufferRef so the free callback can account
|
||||
// for the exact byte count being returned (no global lookup needed).
|
||||
struct ContiguousOpaque {
|
||||
size_t bytes;
|
||||
};
|
||||
|
||||
void anscore_contiguous_free(void* opaque, uint8_t* data) {
|
||||
if (opaque) {
|
||||
auto* o = static_cast<ContiguousOpaque*>(opaque);
|
||||
g_contiguousBytesInFlight.fetch_sub(static_cast<int64_t>(o->bytes),
|
||||
std::memory_order_relaxed);
|
||||
delete o;
|
||||
}
|
||||
g_contiguousFrees.fetch_add(1, std::memory_order_relaxed);
|
||||
av_free(data);
|
||||
}
|
||||
}
|
||||
@@ -77,13 +101,24 @@ int CVideoDecoder::contiguousGetBuffer2(AVCodecContext* s, AVFrame* frame, int f
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
AVBufferRef* ref = av_buffer_create(buf, (int)total,
|
||||
anscore_contiguous_free, nullptr, 0);
|
||||
if (!ref) {
|
||||
auto* opaque = new (std::nothrow) ContiguousOpaque{total};
|
||||
if (!opaque) {
|
||||
av_free(buf);
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
AVBufferRef* ref = av_buffer_create(buf, (int)total,
|
||||
anscore_contiguous_free, opaque, 0);
|
||||
if (!ref) {
|
||||
delete opaque;
|
||||
av_free(buf);
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
g_contiguousAllocs.fetch_add(1, std::memory_order_relaxed);
|
||||
g_contiguousBytesInFlight.fetch_add(static_cast<int64_t>(total),
|
||||
std::memory_order_relaxed);
|
||||
|
||||
for (int i = 0; i < AV_NUM_DATA_POINTERS; ++i) {
|
||||
frame->buf[i] = nullptr;
|
||||
frame->data[i] = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user