summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-12-21 20:03:36 +0100
committerwm4 <wm4@nowhere>2013-12-21 21:43:16 +0100
commit9242c34fa26aafb09a9973a5175c281233a13bdc (patch)
treec94bf638a38ce29c8c6e37c9c6167968e8d3cc34
parentd8d42b44fc717c695af59c14213d54885088ea37 (diff)
downloadmpv-9242c34fa26aafb09a9973a5175c281233a13bdc.tar.bz2
mpv-9242c34fa26aafb09a9973a5175c281233a13bdc.tar.xz
m_option: add mp_log callback to OPT_STRING_VALIDATE options
And also convert a bunch of other code, especially ao_wasapi and ao_portaudio.
-rw-r--r--audio/out/ao_openal.c10
-rw-r--r--audio/out/ao_portaudio.c49
-rw-r--r--audio/out/ao_wasapi.c63
-rw-r--r--options/m_option.c2
-rw-r--r--options/m_option.h4
-rw-r--r--video/out/gl_common.c10
-rw-r--r--video/out/gl_common.h4
-rw-r--r--video/out/gl_lcms.c4
-rw-r--r--video/out/gl_video.c14
9 files changed, 81 insertions, 79 deletions
diff --git a/audio/out/ao_openal.c b/audio/out/ao_openal.c
index d613b74208..3cb8ba5149 100644
--- a/audio/out/ao_openal.c
+++ b/audio/out/ao_openal.c
@@ -79,18 +79,18 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg)
return CONTROL_UNKNOWN;
}
-static int validate_device_opt(const m_option_t *opt, struct bstr name,
- struct bstr param)
+static int validate_device_opt(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param)
{
if (bstr_equals0(param, "help")) {
if (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_TRUE) {
- mp_msg(MSGT_AO, MSGL_FATAL, "Device listing not supported.\n");
+ mp_fatal(log, "Device listing not supported.\n");
return M_OPT_EXIT;
}
const char *list = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
- mp_msg(MSGT_AO, MSGL_INFO, "OpenAL devices:\n");
+ mp_info(log, "OpenAL devices:\n");
while (list && *list) {
- mp_msg(MSGT_AO, MSGL_INFO, " '%s'\n", list);
+ mp_info(log, " '%s'\n", list);
list = list + strlen(list) + 1;
}
return M_OPT_EXIT - 1;
diff --git a/audio/out/ao_portaudio.c b/audio/out/ao_portaudio.c
index 8b4efe7944..8b7e3041cd 100644
--- a/audio/out/ao_portaudio.c
+++ b/audio/out/ao_portaudio.c
@@ -65,21 +65,21 @@ static const struct format_map format_maps[] = {
{AF_FORMAT_UNKNOWN, 0}
};
-static bool check_pa_ret(int ret)
+static bool check_pa_ret(struct mp_log *log, int ret)
{
if (ret < 0) {
- mp_msg(MSGT_AO, MSGL_ERR, "[ao/portaudio] %s\n",
- Pa_GetErrorText(ret));
+ mp_err(log, "%s\n", Pa_GetErrorText(ret));
if (ret == paUnanticipatedHostError) {
const PaHostErrorInfo* hosterr = Pa_GetLastHostErrorInfo();
- mp_msg(MSGT_AO, MSGL_ERR, "[ao/portaudio] Host error: %s\n",
- hosterr->errorText);
+ mp_err(log, "Host error: %s\n", hosterr->errorText);
}
return false;
}
return true;
}
+#define CHECK_PA_RET(ret) check_pa_ret(ao->log, (ret))
+
static int seconds_to_bytes(struct ao *ao, double seconds)
{
return af_fmt_seconds_to_bytes(ao->format, seconds, ao->channels.num,
@@ -93,23 +93,23 @@ static int to_int(const char *s, int return_on_error)
return (s[0] && !endptr[0]) ? res : return_on_error;
}
-static int find_device(const char *name)
+static int find_device(struct mp_log *log, const char *name)
{
int found = paNoDevice;
if (!name)
return found;
int help = strcmp(name, "help") == 0;
int count = Pa_GetDeviceCount();
- check_pa_ret(count);
+ check_pa_ret(log, count);
int index = to_int(name, -1);
if (help)
- mp_msg(MSGT_AO, MSGL_INFO, "PortAudio devices:\n");
+ mp_info(log, "PortAudio devices:\n");
for (int n = 0; n < count; n++) {
const PaDeviceInfo* info = Pa_GetDeviceInfo(n);
if (help) {
if (info->maxOutputChannels < 1)
continue;
- mp_msg(MSGT_AO, MSGL_INFO, " %d '%s', %d channels, latency: %.2f "
+ mp_info(log, " %d '%s', %d channels, latency: %.2f "
"ms, sample rate: %.0f\n", n, info->name,
info->maxOutputChannels,
info->defaultHighOutputLatency * 1000,
@@ -121,21 +121,20 @@ static int find_device(const char *name)
}
}
if (found == paNoDevice && !help)
- mp_msg(MSGT_AO, MSGL_WARN, "[ao/portaudio] Device '%s' not found!\n",
- name);
+ mp_warn(log, "Device '%s' not found!\n", name);
return found;
}
-static int validate_device_opt(const m_option_t *opt, struct bstr name,
- struct bstr param)
+static int validate_device_opt(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param)
{
// Note: we do not check whether the device actually exist, because this
// might break elaborate configs with several AOs trying several
// devices. We do it merely for making "help" special.
if (bstr_equals0(param, "help")) {
- if (!check_pa_ret(Pa_Initialize()))
+ if (!check_pa_ret(log, Pa_Initialize()))
return M_OPT_EXIT;
- find_device("help");
+ find_device(log, "help");
Pa_Terminate();
return M_OPT_EXIT - 1;
}
@@ -205,9 +204,9 @@ static void uninit(struct ao *ao, bool cut_audio)
pthread_mutex_unlock(&priv->ring_mutex);
- check_pa_ret(Pa_StopStream(priv->stream));
+ CHECK_PA_RET(Pa_StopStream(priv->stream));
}
- check_pa_ret(Pa_CloseStream(priv->stream));
+ CHECK_PA_RET(Pa_CloseStream(priv->stream));
}
pthread_mutex_destroy(&priv->ring_mutex);
@@ -218,14 +217,14 @@ static int init(struct ao *ao)
{
struct priv *priv = ao->priv;
- if (!check_pa_ret(Pa_Initialize()))
+ if (!CHECK_PA_RET(Pa_Initialize()))
return -1;
pthread_mutex_init(&priv->ring_mutex, NULL);
int pa_device = Pa_GetDefaultOutputDevice();
if (priv->cfg_device && priv->cfg_device[0])
- pa_device = find_device(priv->cfg_device);
+ pa_device = find_device(ao->log, priv->cfg_device);
if (pa_device == paNoDevice)
goto error_exit;
@@ -264,9 +263,9 @@ static int init(struct ao *ao)
priv->framelen = ao->channels.num * (af_fmt2bits(ao->format) / 8);
ao->bps = ao->samplerate * priv->framelen;
- if (!check_pa_ret(Pa_IsFormatSupported(NULL, &sp, ao->samplerate)))
+ if (!CHECK_PA_RET(Pa_IsFormatSupported(NULL, &sp, ao->samplerate)))
goto error_exit;
- if (!check_pa_ret(Pa_OpenStream(&priv->stream, NULL, &sp, ao->samplerate,
+ if (!CHECK_PA_RET(Pa_OpenStream(&priv->stream, NULL, &sp, ao->samplerate,
paFramesPerBufferUnspecified, paNoFlag,
stream_callback, ao)))
goto error_exit;
@@ -293,7 +292,7 @@ static int play(struct ao *ao, void **data, int samples, int flags)
pthread_mutex_unlock(&priv->ring_mutex);
if (Pa_IsStreamStopped(priv->stream) == 1)
- check_pa_ret(Pa_StartStream(priv->stream));
+ CHECK_PA_RET(Pa_StartStream(priv->stream));
return write_len / ao->sstride;
}
@@ -333,7 +332,7 @@ static void reset(struct ao *ao)
struct priv *priv = ao->priv;
if (Pa_IsStreamStopped(priv->stream) != 1)
- check_pa_ret(Pa_AbortStream(priv->stream));
+ CHECK_PA_RET(Pa_AbortStream(priv->stream));
pthread_mutex_lock(&priv->ring_mutex);
@@ -349,7 +348,7 @@ static void pause(struct ao *ao)
{
struct priv *priv = ao->priv;
- check_pa_ret(Pa_AbortStream(priv->stream));
+ CHECK_PA_RET(Pa_AbortStream(priv->stream));
double stream_time = Pa_GetStreamTime(priv->stream);
@@ -368,7 +367,7 @@ static void resume(struct ao *ao)
{
struct priv *priv = ao->priv;
- check_pa_ret(Pa_StartStream(priv->stream));
+ CHECK_PA_RET(Pa_StartStream(priv->stream));
}
#define OPT_BASE_STRUCT struct priv
diff --git a/audio/out/ao_wasapi.c b/audio/out/ao_wasapi.c
index 344790cee4..3d0d1ddf3d 100644
--- a/audio/out/ao_wasapi.c
+++ b/audio/out/ao_wasapi.c
@@ -697,7 +697,9 @@ end:
return found;
}
-static HRESULT enumerate_with_state(char *header, int status, int with_id) {
+static HRESULT enumerate_with_state(struct mp_log *log, char *header,
+ int status, int with_id)
+{
HRESULT hr;
IMMDeviceEnumerator *pEnumerator = NULL;
IMMDeviceCollection *pDevices = NULL;
@@ -724,7 +726,7 @@ static HRESULT enumerate_with_state(char *header, int status, int with_id) {
int count;
IMMDeviceCollection_GetCount(pDevices, &count);
if (count > 0) {
- mp_msg(MSGT_AO, MSGL_INFO, "ao-wasapi: %s\n", header);
+ mp_info(log, "%s\n", header);
}
for (int i = 0; i < count; i++) {
@@ -739,11 +741,9 @@ static HRESULT enumerate_with_state(char *header, int status, int with_id) {
mark = " (default)";
if (with_id) {
- mp_msg(MSGT_AO, MSGL_INFO, "ao-wasapi: Device #%d: %s, ID: %s%s\n",
- i, name, id, mark);
+ mp_info(log, "Device #%d: %s, ID: %s%s\n", i, name, id, mark);
} else {
- mp_msg(MSGT_AO, MSGL_INFO, "ao-wasapi: %s, ID: %s%s\n",
- name, id, mark);
+ mp_info(log, "%s, ID: %s%s\n", name, id, mark);
}
free(name);
@@ -763,24 +763,27 @@ exit_label:
return hr;
}
-static int enumerate_devices(void) {
+static int enumerate_devices(struct mp_log *log)
+{
HRESULT hr;
CoInitialize(NULL);
- hr = enumerate_with_state("Active devices:", DEVICE_STATE_ACTIVE, 1);
+ hr = enumerate_with_state(log, "Active devices:", DEVICE_STATE_ACTIVE, 1);
EXIT_ON_ERROR(hr);
- hr = enumerate_with_state("Unplugged devices:", DEVICE_STATE_UNPLUGGED, 0);
+ hr = enumerate_with_state(log, "Unplugged devices:", DEVICE_STATE_UNPLUGGED, 0);
EXIT_ON_ERROR(hr);
CoUninitialize();
return 0;
exit_label:
- mp_msg(MSGT_AO, MSGL_ERR, "Error enumerating devices: HRESULT %08"PRIx32" \"%s\"\n",
- (uint32_t)hr, explain_err(hr));
+ mp_err(log, "Error enumerating devices: HRESULT %08"PRIx32" \"%s\"\n",
+ (uint32_t)hr, explain_err(hr));
CoUninitialize();
return 1;
}
-static HRESULT find_and_load_device(IMMDevice **ppDevice, char *search) {
+static HRESULT find_and_load_device(struct ao *ao, IMMDevice **ppDevice,
+ char *search)
+{
HRESULT hr;
IMMDeviceEnumerator *pEnumerator = NULL;
IMMDeviceCollection *pDevices = NULL;
@@ -810,16 +813,16 @@ static HRESULT find_and_load_device(IMMDevice **ppDevice, char *search) {
IMMDeviceCollection_GetCount(pDevices, &count);
if (devno >= count) {
- mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: no device #%d!\n", devno);
+ MP_ERR(ao, "no device #%d!\n", devno);
} else {
- mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: finding device #%d\n", devno);
+ MP_VERBOSE(ao, "finding device #%d\n", devno);
hr = IMMDeviceCollection_Item(pDevices, devno, &pTempDevice);
EXIT_ON_ERROR(hr);
hr = IMMDevice_GetId(pTempDevice, &deviceID);
EXIT_ON_ERROR(hr);
- mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: found device #%d\n", devno);
+ MP_VERBOSE(ao, "found device #%d\n", devno);
}
} else {
hr = IMMDeviceEnumerator_EnumAudioEndpoints(pEnumerator, eRender,
@@ -830,7 +833,7 @@ static HRESULT find_and_load_device(IMMDevice **ppDevice, char *search) {
int count;
IMMDeviceCollection_GetCount(pDevices, &count);
- mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: finding device %s\n", devid);
+ MP_VERBOSE(ao, "finding device %s\n", devid);
IMMDevice *prevDevice = NULL;
@@ -848,14 +851,14 @@ static HRESULT find_and_load_device(IMMDevice **ppDevice, char *search) {
if (deviceID) {
char *name;
if (!search_err) {
- mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: multiple matching devices found!\n");
+ MP_ERR(ao, "multiple matching devices found!\n");
name = get_device_name(prevDevice);
- mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: %s\n", name);
+ MP_ERR(ao, "%s\n", name);
free(name);
search_err = 1;
}
name = get_device_name(pTempDevice);
- mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: %s\n", name);
+ MP_ERR(ao, "%s\n", name);
free(name);
}
hr = IMMDevice_GetId(pTempDevice, &deviceID);
@@ -867,7 +870,7 @@ static HRESULT find_and_load_device(IMMDevice **ppDevice, char *search) {
}
if (deviceID == NULL) {
- mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: could not find device %s!\n", devid);
+ MP_ERR(ao, "could not find device %s!\n", devid);
}
}
@@ -877,12 +880,12 @@ static HRESULT find_and_load_device(IMMDevice **ppDevice, char *search) {
if (deviceID == NULL || search_err) {
hr = E_NOTFOUND;
} else {
- mp_msg(MSGT_AO, MSGL_V, "ao-wasapi: loading device %S\n", deviceID);
+ MP_VERBOSE(ao, "loading device %S\n", deviceID);
hr = IMMDeviceEnumerator_GetDevice(pEnumerator, deviceID, ppDevice);
if (FAILED(hr)) {
- mp_msg(MSGT_AO, MSGL_ERR, "ao-wasapi: could not load requested device!\n");
+ MP_ERR(ao, "could not load requested device!\n");
}
}
@@ -893,14 +896,15 @@ exit_label:
return hr;
}
-static int validate_device(const m_option_t *opt, struct bstr name,
- struct bstr param) {
+static int validate_device(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param)
+{
if (bstr_equals0(param, "help")) {
- enumerate_devices();
+ enumerate_devices(log);
return M_OPT_EXIT;
}
- mp_msg(MSGT_AO, MSGL_DBG2, "ao-wasapi: validating device=%s\n", param.start);
+ mp_dbg(log, "validating device=%s\n", param.start);
char *end;
int devno = (int) strtol(param.start, &end, 10);
@@ -909,8 +913,7 @@ static int validate_device(const m_option_t *opt, struct bstr name,
if ((end == (void*)param.start || *end) && devno < 0)
ret = M_OPT_OUT_OF_RANGE;
- mp_msg(MSGT_AO, MSGL_DBG2, "ao-wasapi: device=%s %svalid\n",
- param.start, ret == 1 ? "" : "not ");
+ mp_dbg(log, "device=%s %svalid\n", param.start, ret == 1 ? "" : "not ");
return ret;
}
@@ -935,7 +938,7 @@ static int thread_init(struct ao *ao)
MP_VERBOSE(ao, "default device ID: %s\n", id);
free(id);
} else {
- hr = find_and_load_device(&state->pDevice, state->opt_device);
+ hr = find_and_load_device(ao, &state->pDevice, state->opt_device);
}
EXIT_ON_ERROR(hr);
@@ -1210,7 +1213,7 @@ static int init(struct ao *ao)
fill_VistaBlob(state);
if (state->opt_list) {
- enumerate_devices();
+ enumerate_devices(state->log);
}
if (state->opt_exclusive) {
diff --git a/options/m_option.c b/options/m_option.c
index 69d8ba0376..f3b7afcd18 100644
--- a/options/m_option.c
+++ b/options/m_option.c
@@ -801,7 +801,7 @@ static int parse_str(struct mp_log *log, const m_option_t *opt,
m_opt_string_validate_fn validate = opt->priv;
if (validate) {
- r = validate(opt, name, param);
+ r = validate(log, opt, name, param);
if (r < 0)
goto exit;
}
diff --git a/options/m_option.h b/options/m_option.h
index 5abe605e95..7caa103f2f 100644
--- a/options/m_option.h
+++ b/options/m_option.h
@@ -160,8 +160,8 @@ struct m_opt_choice_alternatives {
};
// For OPT_STRING_VALIDATE(). Behaves like m_option_type.parse().
-typedef int (*m_opt_string_validate_fn)(const m_option_t *opt, struct bstr name,
- struct bstr param);
+typedef int (*m_opt_string_validate_fn)(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param);
// m_option.priv points to this if M_OPT_TYPE_USE_SUBSTRUCT is used
struct m_sub_options {
diff --git a/video/out/gl_common.c b/video/out/gl_common.c
index f31ecdb64e..881cd62835 100644
--- a/video/out/gl_common.c
+++ b/video/out/gl_common.c
@@ -908,14 +908,14 @@ int mpgl_find_backend(const char *name)
return -2;
}
-int mpgl_validate_backend_opt(const struct m_option *opt, struct bstr name,
- struct bstr param)
+int mpgl_validate_backend_opt(struct mp_log *log, const struct m_option *opt,
+ struct bstr name, struct bstr param)
{
if (bstr_equals0(param, "help")) {
- mp_msg(MSGT_VO, MSGL_INFO, "OpenGL windowing backends:\n");
- mp_msg(MSGT_VO, MSGL_INFO, " auto (autodetect)\n");
+ mp_info(log, "OpenGL windowing backends:\n");
+ mp_info(log, " auto (autodetect)\n");
for (const struct backend *entry = backends; entry->name; entry++)
- mp_msg(MSGT_VO, MSGL_INFO, " %s\n", entry->name);
+ mp_info(log, " %s\n", entry->name);
return M_OPT_EXIT - 1;
}
char s[20];
diff --git a/video/out/gl_common.h b/video/out/gl_common.h
index 45ff9a0110..f678dbf12a 100644
--- a/video/out/gl_common.h
+++ b/video/out/gl_common.h
@@ -157,8 +157,8 @@ bool mpgl_config_window(struct MPGLContext *ctx, int gl_caps, uint32_t d_width,
int mpgl_find_backend(const char *name);
struct m_option;
-int mpgl_validate_backend_opt(const struct m_option *opt, struct bstr name,
- struct bstr param);
+int mpgl_validate_backend_opt(struct mp_log *log, const struct m_option *opt,
+ struct bstr name, struct bstr param);
void mpgl_set_backend_cocoa(MPGLContext *ctx);
void mpgl_set_backend_w32(MPGLContext *ctx);
diff --git a/video/out/gl_lcms.c b/video/out/gl_lcms.c
index fb2098324d..db4c7dc97b 100644
--- a/video/out/gl_lcms.c
+++ b/video/out/gl_lcms.c
@@ -58,8 +58,8 @@ static bool parse_3dlut_size(const char *arg, int *p1, int *p2, int *p3)
return true;
}
-static int validate_3dlut_size_opt(const m_option_t *opt, struct bstr name,
- struct bstr param)
+static int validate_3dlut_size_opt(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param)
{
int p1, p2, p3;
char s[20];
diff --git a/video/out/gl_video.c b/video/out/gl_video.c
index b27638b904..2e662f65ff 100644
--- a/video/out/gl_video.c
+++ b/video/out/gl_video.c
@@ -298,8 +298,8 @@ const struct gl_video_opts gl_video_opts_hq_def = {
.alpha_mode = 2,
};
-static int validate_scaler_opt(const m_option_t *opt, struct bstr name,
- struct bstr param);
+static int validate_scaler_opt(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param);
#define OPT_BASE_STRUCT struct gl_video_opts
const struct m_sub_options gl_video_conf = {
@@ -2219,15 +2219,15 @@ bool gl_video_get_equalizer(struct gl_video *p, const char *name, int *val)
return mp_csp_equalizer_get(&p->video_eq, name, val) >= 0;
}
-static int validate_scaler_opt(const m_option_t *opt, struct bstr name,
- struct bstr param)
+static int validate_scaler_opt(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param)
{
if (bstr_equals0(param, "help")) {
- mp_msg(MSGT_VO, MSGL_INFO, "Available scalers:\n");
+ mp_info(log, "Available scalers:\n");
for (const char **filter = fixed_scale_filters; *filter; filter++)
- mp_msg(MSGT_VO, MSGL_INFO, " %s\n", *filter);
+ mp_info(log, " %s\n", *filter);
for (int n = 0; mp_filter_kernels[n].name; n++)
- mp_msg(MSGT_VO, MSGL_INFO, " %s\n", mp_filter_kernels[n].name);
+ mp_info(log, " %s\n", mp_filter_kernels[n].name);
return M_OPT_EXIT - 1;
}
char s[20];