diff --git a/src/module/mpv.c b/src/module/mpv.c index 9180633cde25b5edc238dd355cfa0474176971d3..9482de1c4fe6c15f90f9324cd54fa319a28a2c13 100644 --- a/src/module/mpv.c +++ b/src/module/mpv.c @@ -24,26 +24,27 @@ lmpv_prepare(lkt_db *db) RETURN_UNLESS(ctx, "Failed to create context", NULL); char ___opt[LKT_LINE_MAX]; -#define MPV_SET_OPTION(opt, value) \ - if ((status = mpv_set_option_string(ctx, opt, value)) < 0) { \ - LOG_ERROR("WINDOW", "Failed to set %s to %s: %s", opt, value, mpv_error_string(status)); \ - return NULL; \ +#define MPV_SET_OPTION_PASS_ERRORS(opt, value) mpv_set_option_string(ctx, opt, value) +#define MPV_SET_OPTION(opt, value) \ + if ((status = MPV_SET_OPTION_PASS_ERRORS(opt, value)) < 0) { \ + LOG_ERROR("WINDOW", "Failed to set %s to %s: %s", opt, value, mpv_error_string(status)); \ + return NULL; \ } -#define MPV_SET_FROM_INI(opt, section, key) \ - if (!database_config_get(db, section, key, ___opt, LKT_LINE_MAX)) { \ - LOG_WARN("WINDOW", "Failed to get option " key " in section " section); \ - return ctx; \ - } \ +#define MPV_SET_FROM_INI(opt, section, key) \ + if (!database_config_get(db, section, key, ___opt, LKT_LINE_MAX)) { \ + LOG_WARN("WINDOW", "Failed to get option " key " in section " section); \ + return ctx; \ + } \ MPV_SET_OPTION(opt, ___opt); -#define MPV_SET_OPTION_COND(opt, value, ini_section, ini_option, def) \ - ({ \ - int ___cond; \ - if (!database_config_get(db, ini_section, ini_option, &___cond)) { \ - LOG_WARN("WINDOW", "Default [" ini_section "/" ini_option "] to " #def); \ - ___cond = (def); \ - } \ - if (___cond) \ - MPV_SET_OPTION(opt, value); \ +#define MPV_SET_OPTION_COND(opt, value, ini_section, ini_option, def) \ + ({ \ + int ___cond; \ + if (!database_config_get(db, ini_section, ini_option, &___cond)) { \ + LOG_WARN("WINDOW", "Default [" ini_section "/" ini_option "] to " #def); \ + ___cond = (def); \ + } \ + if (___cond) \ + MPV_SET_OPTION_PASS_ERRORS(opt, value); \ }) // clang-format off @@ -170,7 +171,8 @@ lmpv_toggle_pause(mpv_handle *ctx) } int -lmpv_handle(struct lkt_module *mod, mpv_handle *ctx, struct queue *queue, struct lmpv_handle_arg *arg) +lmpv_handle(struct lkt_module *mod, mpv_handle *ctx, struct queue *queue, + struct lmpv_handle_arg *arg) { size_t ao_volume; mpv_event *event = NULL; @@ -199,8 +201,7 @@ loop: reg_call(mod->reg, "close", 1, mod->data); return 1; - case MPV_EVENT_NONE: - return 1; + case MPV_EVENT_NONE: return 1; case MPV_EVENT_START_FILE: SET_STATE_FLAG(*(arg->state), PLAY); @@ -214,7 +215,8 @@ loop: LOG_DEBUG("WINDOW", "Send play_next event"); lkt_queue_send(queue, LKT_EVENT_PLAY_NEXT, NULL); } else - LOG_DEBUG("WINDOW", "Don't send play_next event, hinib is %d and state is %s", *(arg->hinib), + LOG_DEBUG("WINDOW", "Don't send play_next event, hinib is %d and state is %s", + *(arg->hinib), (*(arg->state) == STATE_STOP) ? "STOP" : (*(arg->state) == STATE_PLAY) ? "PLAY" : (*(arg->state) == STATE_PAUSE) ? "PAUSE" @@ -251,9 +253,7 @@ loop: } break; - case MPV_EVENT_COMMAND_REPLY: - free((void *)event->reply_userdata); - break; + case MPV_EVENT_COMMAND_REPLY: free((void *)event->reply_userdata); break; /* Ignored */ case MPV_EVENT_VIDEO_RECONFIG: @@ -262,14 +262,11 @@ loop: case MPV_EVENT_TRACKS_CHANGED: case MPV_EVENT_FILE_LOADED: case MPV_EVENT_METADATA_UPDATE: - case MPV_EVENT_PLAYBACK_RESTART: - break; + case MPV_EVENT_PLAYBACK_RESTART: break; /* Forgot to ignore an event, or it should not be ignored and should be * handled, or a new event is present in the API */ - default: - LOG_WARN("WINDOW", "Unhandled mpv event '%s'", mpv_event_name(event->event_id)); - break; + default: LOG_WARN("WINDOW", "Unhandled mpv event '%s'", mpv_event_name(event->event_id)); break; } /* Can I seek? */