Skip to content

Commit c92a4dc

Browse files
committed
sub/sd_sbr: add logging callback
1 parent 58bb4b9 commit c92a4dc

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ if features['libdl']
358358
dependencies += libdl
359359
endif
360360

361-
subrandr = dependency('subrandr', required: get_option('subrandr'))
361+
subrandr = dependency('subrandr', version: '>= 0.1.1', required: get_option('subrandr'))
362362
features += {'subrandr': subrandr.found()}
363363
if features['subrandr']
364364
sources += files('demux/demux_sbr.c', 'sub/sd_sbr.c')

sub/sd_sbr.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <limits.h>
2020

2121
#include <subrandr/subrandr.h>
22+
#include <subrandr/logging.h>
2223

2324
#include "mpv_talloc.h"
2425

@@ -53,6 +54,37 @@ static void enable_output(struct sd *sd, bool enable)
5354
}
5455
}
5556

57+
static inline int mp_level_from_sbr_log_level(sbr_log_level level)
58+
{
59+
switch (level) {
60+
case SBR_LOG_LEVEL_TRACE:
61+
return MSGL_TRACE;
62+
case SBR_LOG_LEVEL_DEBUG:
63+
return MSGL_DEBUG;
64+
case SBR_LOG_LEVEL_INFO: // fallthrough
65+
case SBR_LOG_LEVEL_WARN:
66+
return MSGL_V;
67+
case SBR_LOG_LEVEL_ERROR: // fallthrough
68+
default:
69+
return MSGL_WARN;
70+
}
71+
}
72+
73+
static void mp_msg_sbr_log_callback(sbr_log_level level,
74+
const char *source, size_t source_len,
75+
const char *message, size_t message_len,
76+
void *user_data)
77+
{
78+
struct sd *sd = user_data;
79+
int mp_level = mp_level_from_sbr_log_level(level);
80+
81+
if (mp_msg_test(sd->log, mp_level)) {
82+
if (source_len > 0)
83+
mp_msg(sd->log, mp_level, "[%.*s] ", (int)source_len, source);
84+
mp_msg(sd->log, mp_level, "%.*s\n", (int)message_len, message);
85+
}
86+
}
87+
5688
static int init(struct sd *sd)
5789
{
5890
if (!sd->codec->codec)
@@ -65,6 +97,8 @@ static int init(struct sd *sd)
6597

6698
ctx->sbr_library = sbr_library_init();
6799
mp_require(ctx->sbr_library);
100+
sbr_library_set_log_callback(ctx->sbr_library, mp_msg_sbr_log_callback, sd);
101+
68102
ctx->bitmaps = talloc_zero(ctx, struct sub_bitmaps);
69103
ctx->bitmaps->format = SUBBITMAP_BGRA;
70104
ctx->bitmaps->num_parts = 1;

0 commit comments

Comments
 (0)