Skip to content

Commit 0a3f94e

Browse files
authored
Set a callback function for dav1d_log()
The callback function directs dav1d_log() output to the error message buffer in the avifDiagnostics struct.
1 parent 3e6c8db commit 0a3f94e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/codec_dav1d.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#pragma clang diagnostic pop
1616
#endif
1717

18+
#include <stdio.h>
1819
#include <string.h>
1920

2021
// For those building with an older version of dav1d (not recommended).
@@ -37,6 +38,12 @@ static void avifDav1dFreeCallback(const uint8_t * buf, void * cookie)
3738
(void)cookie;
3839
}
3940

41+
static void avifDav1dLogCallback(void * cookie, const char * format, va_list ap)
42+
{
43+
avifCodec * codec = (avifCodec *)cookie;
44+
vsnprintf(codec->diag->error, AVIF_DIAGNOSTICS_ERROR_BUFFER_SIZE, format, ap);
45+
}
46+
4047
static void dav1dCodecDestroyInternal(avifCodec * codec)
4148
{
4249
if (codec->internal->hasPicture) {
@@ -70,6 +77,8 @@ static avifBool dav1dCodecGetNextImage(struct avifCodec * codec,
7077
// a message, so we set frame_size_limit to at most 8192 * 8192 to avoid the dav1d_log
7178
// message.
7279
dav1dSettings.frame_size_limit = (sizeof(size_t) < 8) ? AVIF_MIN(codec->imageSizeLimit, 8192 * 8192) : codec->imageSizeLimit;
80+
dav1dSettings.logger.cookie = codec;
81+
dav1dSettings.logger.callback = avifDav1dLogCallback;
7382
dav1dSettings.operating_point = codec->operatingPoint;
7483
dav1dSettings.all_layers = codec->allLayers;
7584

0 commit comments

Comments
 (0)