Commit c98bbeb3 authored by James Almer's avatar James Almer

add a logging callback mechanism

parent 0749f4b0
......@@ -34,8 +34,10 @@
#ifdef __GNUC__
#define ATTR_ALIAS __attribute__((may_alias))
#define ATTR_FORMAT_PRINTF(fmt, attr) __attribute__((__format__(__printf__, fmt, attr)));
#else
#define ATTR_ALIAS
#define ATTR_FORMAT_PRINTF(fmt, attr)
#endif
#if ARCH_X86_64
......
......@@ -33,6 +33,7 @@ extern "C" {
#endif
#include <errno.h>
#include <stdarg.h>
#include "common.h"
#include "picture.h"
......@@ -44,10 +45,23 @@ typedef struct Dav1dRef Dav1dRef;
#define DAV1D_MAX_FRAME_THREADS 256
#define DAV1D_MAX_TILE_THREADS 64
typedef struct Dav1dLogger {
void *cookie; ///< Custom data to pass to the callback.
/**
* Logger callback. Default prints to stderr. May be NULL to disable logging.
*
* @param cookie Custom pointer passed to all calls.
* @param format The vprintf compatible format string.
* @param ap List of arguments referenced by the format string.
*/
void (*callback)(void *cookie, const char *format, va_list ap);
} Dav1dLogger;
typedef struct Dav1dSettings {
int n_frame_threads;
int n_tile_threads;
Dav1dPicAllocator allocator;
Dav1dLogger logger;
int apply_grain;
int operating_point; ///< select an operating point for scalable AV1 bitstreams (0 - 31)
int all_layers; ///< output all spatial layers of a scalable AV1 biststream
......
......@@ -70,6 +70,10 @@ if is_asm_enabled and get_option('b_sanitize') == 'memory'
error('asm causes false positive with memory sanitizer. Use \'-Dbuild_asm=false\'.')
endif
# Logging option
if get_option('logging')
cdata.set('CONFIG_LOG', 1)
endif
#
# OS/Compiler checks and defines
......
......@@ -20,6 +20,11 @@ option('build_tests',
value: true,
description: 'Build dav1d tests')
option('logging',
type: 'boolean',
value: true,
description: 'Print error log messages using the provided callback function')
option('testdata_tests',
type: 'boolean',
value: false,
......
......@@ -123,6 +123,8 @@ struct Dav1dContext {
unsigned operating_point_idc;
int all_layers;
int drain;
Dav1dLogger logger;
};
struct Dav1dFrameContext {
......
......@@ -38,6 +38,7 @@
#include "common/validate.h"
#include "src/internal.h"
#include "src/log.h"
#include "src/obu.h"
#include "src/qm.h"
#include "src/ref.h"
......@@ -62,6 +63,8 @@ void dav1d_default_settings(Dav1dSettings *const s) {
s->allocator.cookie = NULL;
s->allocator.alloc_picture_callback = default_picture_allocator;
s->allocator.release_picture_callback = default_picture_release;
s->logger.cookie = NULL;
s->logger.callback = dav1d_log_default_callback;
s->operating_point = 0;
s->all_layers = 1; // just until the tests are adjusted
}
......@@ -90,6 +93,7 @@ int dav1d_open(Dav1dContext **const c_out,
memset(c, 0, sizeof(*c));
c->allocator = s->allocator;
c->logger = s->logger;
c->apply_grain = s->apply_grain;
c->operating_point = s->operating_point;
c->all_layers = s->all_layers;
......
/*
* Copyright © 2018, VideoLAN and dav1d authors
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include <stdarg.h>
#include <stdio.h>
#include "dav1d/dav1d.h"
#include "common/validate.h"
#include "src/internal.h"
#include "src/log.h"
void dav1d_log_default_callback(void *const cookie,
const char *const format, va_list ap)
{
vfprintf(stderr, format, ap);
}
#if CONFIG_LOG
void dav1d_log(Dav1dContext *const c, const char *const format, ...) {
validate_input(c != NULL);
if (!c->logger.callback)
return;
va_list ap;
va_start(ap, format);
c->logger.callback(c->logger.cookie, format, ap);
va_end(ap);
}
#endif
/*
* Copyright © 2018, VideoLAN and dav1d authors
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __DAV1D_SRC_LOG_H__
#define __DAV1D_SRC_LOG_H__
#include "config.h"
#include <stdarg.h>
#include "dav1d/dav1d.h"
#include "common/attributes.h"
void dav1d_log_default_callback(void *cookie, const char *format, va_list ap);
#if CONFIG_LOG
#define dav1d_log dav1d_log
void dav1d_log(Dav1dContext *c, const char *format, ...) ATTR_FORMAT_PRINTF(2, 3);
#else
#define dav1d_log(...) do { } while(0)
#endif
#endif /* __DAV1D_SRC_LOG_H__ */
......@@ -32,6 +32,7 @@ libdav1d_sources = files(
'cpu.c',
'data.c',
'ref.c',
'log.c',
'getbits.c',
'obu.c',
'decode.c',
......
......@@ -39,6 +39,7 @@
#include "src/decode.h"
#include "src/getbits.h"
#include "src/levels.h"
#include "src/log.h"
#include "src/obu.h"
#include "src/ref.h"
#include "src/thread_task.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment