Fix debug

This commit is contained in:
2026-05-07 23:35:18 +10:00
parent 75693cadd9
commit aa323a07a3
4 changed files with 220 additions and 186 deletions
+40 -15
View File
@@ -943,18 +943,20 @@ BOOL CVideoDecoder::decode(AVPacket* pkt)
if (!m_bInited)
{
log_print(HT_LOG_ERR, "%s, Decoder not initialized\r\n", __FUNCTION__);
// Hot-path pre-check; per-packet during early frames if decode() races
// with init.
ANS_DBG("MEDIA_Decode", "decode(pkt) called but decoder not initialized");
return FALSE;
}
if (!m_bRunning)
{
log_print(HT_LOG_WARN, "%s, Decoder not running\r\n", __FUNCTION__);
ANS_DBG("MEDIA_Decode", "decode(pkt) called but decoder not running");
return FALSE;
}
if (!m_pContext) {
log_print(HT_LOG_ERR, "%s, Context is NULL\r\n", __FUNCTION__);
ANS_DBG("MEDIA_Decode", "decode(pkt) called but m_pContext is NULL");
return FALSE;
}
@@ -968,7 +970,12 @@ BOOL CVideoDecoder::decode(AVPacket* pkt)
{
if (!readFrame())
{
log_print(HT_LOG_ERR, "%s, Failed to read frame during retry %d\r\n", __FUNCTION__, retryCount);
// Hot-path error: was log_print() which fflushes per call and can
// spike per-packet during stream stress. ANS_DBG is silent in
// production; the per-frame error count is also visible via
// MEDIA_Pulse drop(err=) so observability is preserved.
ANS_DBG("MEDIA_Decode",
"send_packet retry %d: readFrame failed", retryCount);
return FALSE;
}
Sleep(1); // Reduced sleep time
@@ -980,7 +987,8 @@ BOOL CVideoDecoder::decode(AVPacket* pkt)
{
char error_buf[AV_ERROR_MAX_STRING_SIZE];
av_strerror(ret, error_buf, sizeof(error_buf));
log_print(HT_LOG_ERR, "%s, avcodec_send_packet failed: %s (ret=%d)\r\n", __FUNCTION__, error_buf, ret);
ANS_DBG("MEDIA_Decode",
"avcodec_send_packet failed: %s (ret=%d)", error_buf, ret);
return FALSE;
}
@@ -993,25 +1001,29 @@ BOOL CVideoDecoder::decode(uint8* data, int len, int64_t pts)
if (!m_bInited)
{
log_print(HT_LOG_ERR, "%s, Decoder not initialized\r\n", __FUNCTION__);
// Hot-path: per-packet if decoder isn't initialised. Was log_print
// which fflushes per call.
ANS_DBG("MEDIA_Decode", "decode called but decoder not initialized");
return FALSE;
}
if (!m_bRunning)
{
log_print(HT_LOG_WARN, "%s, Decoder not running\r\n", __FUNCTION__);
// Per-packet during start/stop transitions.
ANS_DBG("MEDIA_Decode", "decode called but decoder not running");
return FALSE;
}
if (!data || len <= 0) {
log_print(HT_LOG_ERR, "%s, Invalid input data\r\n", __FUNCTION__);
ANS_DBG("MEDIA_Decode", "decode called with invalid input (data=%p len=%d)",
(void*)data, len);
return FALSE;
}
// Allocate packet
AVPacket* packet = av_packet_alloc();
if (!packet) {
log_print(HT_LOG_ERR, "%s, Failed to allocate AVPacket\r\n", __FUNCTION__);
ANS_DBG("MEDIA_Decode", "av_packet_alloc failed (OOM?)");
return FALSE;
}
@@ -1020,7 +1032,8 @@ BOOL CVideoDecoder::decode(uint8* data, int len, int64_t pts)
if (ret < 0) {
char error_buf[AV_ERROR_MAX_STRING_SIZE];
av_strerror(ret, error_buf, sizeof(error_buf));
log_print(HT_LOG_ERR, "%s, Failed to allocate packet data: %s\r\n", __FUNCTION__, error_buf);
ANS_DBG("MEDIA_Decode",
"av_new_packet failed (len=%d): %s", len, error_buf);
av_packet_free(&packet);
return FALSE;
}
@@ -1061,13 +1074,21 @@ BOOL CVideoDecoder::readFrame()
else if (ret < 0) {
char error_buf[AV_ERROR_MAX_STRING_SIZE];
av_strerror(ret, error_buf, sizeof(error_buf));
log_print(HT_LOG_ERR, "%s, avcodec_receive_frame failed: %s (ret=%d)\r\n", __FUNCTION__, error_buf, ret);
// Hot-path error during stream stress (UDP loss, corrupt I-frame).
// Was log_print(HT_LOG_ERR, ...) which fflushes per call and could
// fire ~25/sec on a degraded stream — observed as sudden GetImage
// slowness. ANS_DBG is silent in production; pulse counter
// MEDIA_Pulse drop(err=) preserves observability.
ANS_DBG("MEDIA_Decode",
"avcodec_receive_frame failed: %s (ret=%d)", error_buf, ret);
return FALSE;
}
// Check if we got a valid frame
if (!m_pFrame || m_pFrame->width <= 0 || m_pFrame->height <= 0) {
log_print(HT_LOG_WARN, "%s, Received invalid frame\r\n", __FUNCTION__);
ANS_DBG("MEDIA_Decode", "received invalid frame (w=%d h=%d)",
m_pFrame ? m_pFrame->width : -1,
m_pFrame ? m_pFrame->height : -1);
av_frame_unref(m_pFrame);
continue;
}
@@ -1090,8 +1111,10 @@ BOOL CVideoDecoder::readFrame()
{
char error_buf[AV_ERROR_MAX_STRING_SIZE];
av_strerror(ret, error_buf, sizeof(error_buf));
log_print(HT_LOG_ERR, "%s, Error transferring hardware frame to system memory: %s (ret=%d)\r\n",
__FUNCTION__, error_buf, ret);
// Hot-path: HW→SW transfer failure. Per-frame on degraded HW
// decoder. Gated to avoid fflush spike during stress.
ANS_DBG("MEDIA_Decode",
"hwframe_transfer_data failed: %s (ret=%d)", error_buf, ret);
av_frame_unref(m_pFrame);
if (m_pCudaHWFrame) av_frame_free(&m_pCudaHWFrame);
continue;
@@ -1139,7 +1162,9 @@ int CVideoDecoder::render(AVFrame* frame)
m_pCallback(frame, m_pUserdata);
}
catch (...) {
log_print(HT_LOG_ERR, "%s, Exception in callback function\r\n", __FUNCTION__);
// Hot-path: per-frame if onVideoFrame ever throws. Was log_print
// which fflushes per call.
ANS_DBG("MEDIA_Decode", "exception in onVideoFrame callback");
return 0;
}
}