From 3f78c11a44a4277048b52d34a3a6ae1a1fb5aced Mon Sep 17 00:00:00 2001 From: James Hutchinson Date: Fri, 16 May 2025 16:09:11 +0100 Subject: [PATCH] transcode: improve logging of packet transcode errors Improve visibility of decoding failures during transcoding by logging the error code, a human-readable description, and the packet PTS when the hardware decoder fails to process a packet. Previously, these errors would silently trigger `tvh_stream_stop()` on the affected stream, with minimal context about the underlying cause. This made it difficult to diagnose issues such as hardware acceleration glitches or codec-specific decode failures. With this change, such errors are logged at warning level, and full packet details are included if trace logging is enabled. This provides valuable diagnostic information when investigating stream interruptions or video dropout. This commit does not alter transcoder behavior; errors are still filtered or handled by other components as before. It simply makes decoder error conditions more transparent for debugging purposes. --- src/transcoding/transcode/stream.c | 2 +- src/transcoding/transcode/transcoder.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/transcoding/transcode/stream.c b/src/transcoding/transcode/stream.c index ff10fdb59..b2b5d20de 100644 --- a/src/transcoding/transcode/stream.c +++ b/src/transcoding/transcode/stream.c @@ -164,7 +164,7 @@ int tvh_stream_handle(TVHStream *self, th_pkt_t *pkt) { if (pkt->pkt_payload && self->context) { - return (tvh_context_handle(self->context, pkt) < 0) ? -1 : 0; + return tvh_context_handle(self->context, pkt); } pkt_ref_inc(pkt); return tvh_transcoder_deliver(self->transcoder, pkt); diff --git a/src/transcoding/transcode/transcoder.c b/src/transcoding/transcode/transcoder.c index e19ccfff1..d3657681d 100644 --- a/src/transcoding/transcode/transcoder.c +++ b/src/transcoding/transcode/transcoder.c @@ -88,11 +88,23 @@ static void tvh_transcoder_handle(TVHTranscoder *self, th_pkt_t *pkt) { TVHStream *stream = NULL; + int err = 0; + char averr_buf[256]; SLIST_FOREACH(stream, &self->streams, link) { if (pkt->pkt_componentindex == stream->index) { - if (tvh_stream_handle(stream, pkt)) { + err = tvh_stream_handle(stream, pkt); + if (err) { tvh_stream_stop(stream, 0); + if (av_strerror(err, averr_buf, sizeof(averr_buf)) < 0) { + snprintf(averr_buf, sizeof(averr_buf), "unknown error"); + } + tvh_context_log(stream->context, LOG_WARNING, + "failed to transcode packet at pts: %"PRId64" error %d: %s", + pkt->pkt_pts, err, averr_buf); + if (tvhtrace_enabled()) { + pkt_trace(LS_TRANSCODE, pkt, "packet details"); + } } break; } -- 2.47.2