summaryrefslogtreecommitdiffstats
path: root/audio/out
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-05-05 21:47:04 +0200
committerwm4 <wm4@nowhere>2015-05-05 21:47:04 +0200
commit399267393bb96710cde53c2fc7563f55cc32deb8 (patch)
tree4421a331f0bc685ac29c942a057237048232882a /audio/out
parent7a5f5a8adf5921ed8fcee29d76113d9a7f018974 (diff)
downloadmpv-399267393bb96710cde53c2fc7563f55cc32deb8.tar.bz2
mpv-399267393bb96710cde53c2fc7563f55cc32deb8.tar.xz
ao_coreaudio_utils: don't require talloc for fourcc_repr()
Instead, apply a trick to make the caller allocate enough space on the stack.
Diffstat (limited to 'audio/out')
-rw-r--r--audio/out/ao_coreaudio.c8
-rw-r--r--audio/out/ao_coreaudio_utils.c18
-rw-r--r--audio/out/ao_coreaudio_utils.h4
3 files changed, 13 insertions, 17 deletions
diff --git a/audio/out/ao_coreaudio.c b/audio/out/ao_coreaudio.c
index f0de12cbe1..a91ba95c2f 100644
--- a/audio/out/ao_coreaudio.c
+++ b/audio/out/ao_coreaudio.c
@@ -437,8 +437,8 @@ static int hotplug_init(struct ao *ao)
err = AudioObjectAddPropertyListener(
kAudioObjectSystemObject, &addr, hotplug_cb, (void *)ao);
if (err != noErr) {
- char *c1 = fourcc_repr(ao, hotplug_properties[i]);
- char *c2 = fourcc_repr(ao, err);
+ char *c1 = fourcc_repr(hotplug_properties[i]);
+ char *c2 = fourcc_repr(err);
MP_ERR(ao, "failed to set device listener %s (%s)", c1, c2);
goto coreaudio_error;
}
@@ -462,8 +462,8 @@ static void hotplug_uninit(struct ao *ao)
err = AudioObjectRemovePropertyListener(
kAudioObjectSystemObject, &addr, hotplug_cb, (void *)ao);
if (err != noErr) {
- char *c1 = fourcc_repr(ao, hotplug_properties[i]);
- char *c2 = fourcc_repr(ao, err);
+ char *c1 = fourcc_repr(hotplug_properties[i]);
+ char *c2 = fourcc_repr(err);
MP_ERR(ao, "failed to set device listener %s (%s)", c1, c2);
}
}
diff --git a/audio/out/ao_coreaudio_utils.c b/audio/out/ao_coreaudio_utils.c
index 716f0df5e3..e8eccdc5d3 100644
--- a/audio/out/ao_coreaudio_utils.c
+++ b/audio/out/ao_coreaudio_utils.c
@@ -128,7 +128,7 @@ coreaudio_error:
return err;
}
-char *fourcc_repr(void *talloc_ctx, uint32_t code)
+char *fourcc_repr_buf(char *buf, size_t buf_size, uint32_t code)
{
// Extract FourCC letters from the uint32_t and finde out if it's a valid
// code that is made of letters.
@@ -145,23 +145,19 @@ char *fourcc_repr(void *talloc_ctx, uint32_t code)
valid_fourcc = false;
}
- char *repr;
if (valid_fourcc)
- repr = talloc_asprintf(talloc_ctx, "'%c%c%c%c'",
- fcc[0], fcc[1], fcc[2], fcc[3]);
+ snprintf(buf, buf_size, "'%c%c%c%c'", fcc[0], fcc[1], fcc[2], fcc[3]);
else
- repr = talloc_asprintf(NULL, "%u", (unsigned int)code);
+ snprintf(buf, buf_size, "%u", (unsigned int)code);
- return repr;
+ return buf;
}
bool check_ca_st(struct ao *ao, int level, OSStatus code, const char *message)
{
if (code == noErr) return true;
- char *error_string = fourcc_repr(NULL, code);
- mp_msg(ao->log, level, "%s (%s)\n", message, error_string);
- talloc_free(error_string);
+ mp_msg(ao->log, level, "%s (%s)\n", message, fourcc_repr(code));
return false;
}
@@ -245,7 +241,7 @@ void ca_print_asbd(struct ao *ao, const char *description,
const AudioStreamBasicDescription *asbd)
{
uint32_t flags = asbd->mFormatFlags;
- char *format = fourcc_repr(NULL, asbd->mFormatID);
+ char *format = fourcc_repr(asbd->mFormatID);
int mpfmt = ca_asbd_to_mp_format(asbd);
MP_VERBOSE(ao,
@@ -263,8 +259,6 @@ void ca_print_asbd(struct ao *ao, const char *description,
(flags & kAudioFormatFlagIsAlignedHigh) ? " aligned" : "",
(flags & kAudioFormatFlagIsNonInterleaved) ? " P" : "",
mpfmt ? af_fmt_to_str(mpfmt) : "unusable");
-
- talloc_free(format);
}
// Return whether new is an improvement over old. Assume a higher value means
diff --git a/audio/out/ao_coreaudio_utils.h b/audio/out/ao_coreaudio_utils.h
index 2e87cb472d..50498a969e 100644
--- a/audio/out/ao_coreaudio_utils.h
+++ b/audio/out/ao_coreaudio_utils.h
@@ -31,7 +31,9 @@
CFStringRef cfstr_from_cstr(char *str);
char *cfstr_get_cstr(CFStringRef cfstr);
-char *fourcc_repr(void *talloc_ctx, uint32_t code);
+char *fourcc_repr_buf(char *buf, size_t buf_size, uint32_t code);
+#define fourcc_repr(code) fourcc_repr_buf((char[40]){0}, 40, code)
+
bool check_ca_st(struct ao *ao, int level, OSStatus code, const char *message);
#define CHECK_CA_ERROR_L(label, message) \