Set a callback function for dav1d_log()
The callback function directs dav1d_log() output to the error message
buffer in the avifDiagnostics struct.
diff --git a/src/codec_dav1d.c b/src/codec_dav1d.c
index 5aff5a1..666dcef 100644
--- a/src/codec_dav1d.c
+++ b/src/codec_dav1d.c
@@ -15,6 +15,7 @@
#pragma clang diagnostic pop
#endif
+#include <stdio.h>
#include <string.h>
// For those building with an older version of dav1d (not recommended).
@@ -37,6 +38,12 @@
(void)cookie;
}
+static void avifDav1dLogCallback(void * cookie, const char * format, va_list ap)
+{
+ avifCodec * codec = (avifCodec *)cookie;
+ vsnprintf(codec->diag->error, AVIF_DIAGNOSTICS_ERROR_BUFFER_SIZE, format, ap);
+}
+
static void dav1dCodecDestroyInternal(avifCodec * codec)
{
if (codec->internal->hasPicture) {
@@ -70,6 +77,8 @@
// a message, so we set frame_size_limit to at most 8192 * 8192 to avoid the dav1d_log
// message.
dav1dSettings.frame_size_limit = (sizeof(size_t) < 8) ? AVIF_MIN(codec->imageSizeLimit, 8192 * 8192) : codec->imageSizeLimit;
+ dav1dSettings.logger.cookie = codec;
+ dav1dSettings.logger.callback = avifDav1dLogCallback;
dav1dSettings.operating_point = codec->operatingPoint;
dav1dSettings.all_layers = codec->allLayers;