mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-14 23:34:08 +00:00
mac-capture: Use libobs CFString utils
This commit is contained in:
parent
b2ece640e5
commit
26a96c618f
|
@ -14,7 +14,6 @@ include_directories(${COREAUDIO}
|
|||
|
||||
set(mac-capture_HEADERS
|
||||
audio-device-enum.h
|
||||
mac-helpers.h
|
||||
window-utils.h)
|
||||
|
||||
set(mac-capture_SOURCES
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#include <CoreFoundation/CFString.h>
|
||||
#include <CoreAudio/CoreAudio.h>
|
||||
|
||||
#include "mac-helpers.h"
|
||||
#include <util/apple/cfstring-utils.h>
|
||||
|
||||
#include "audio-device-enum.h"
|
||||
|
||||
/* ugh, because mac has no means of capturing output, we have to basically
|
||||
|
@ -114,9 +115,9 @@ static bool coreaudio_enum_add_device(void *param, CFStringRef cf_name,
|
|||
|
||||
memset(&item, 0, sizeof(item));
|
||||
|
||||
if (!cf_to_dstr(cf_name, &item.name))
|
||||
if (!cfstr_copy_dstr(cf_name, kCFStringEncodingUTF8, &item.name))
|
||||
goto fail;
|
||||
if (!cf_to_dstr(cf_uid, &item.value))
|
||||
if (!cfstr_copy_dstr(cf_uid, kCFStringEncodingUTF8, &item.value))
|
||||
goto fail;
|
||||
|
||||
if (data->input || !device_is_input(item.value.array))
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
#include <obs-module.h>
|
||||
#include <util/threading.h>
|
||||
#include <util/c99defs.h>
|
||||
#include <util/apple/cfstring-utils.h>
|
||||
|
||||
#include "mac-helpers.h"
|
||||
#include "audio-device-enum.h"
|
||||
|
||||
#define PROPERTY_DEFAULT_DEVICE kAudioHardwarePropertyDefaultInputDevice
|
||||
|
@ -496,7 +496,7 @@ static bool coreaudio_get_device_name(struct coreaudio_data *ca)
|
|||
{
|
||||
CFStringRef cf_name = NULL;
|
||||
UInt32 size = sizeof(CFStringRef);
|
||||
char name[1024];
|
||||
char *name = NULL;
|
||||
|
||||
const AudioObjectPropertyAddress addr = {
|
||||
kAudioDevicePropertyDeviceNameCFString,
|
||||
|
@ -512,14 +512,15 @@ static bool coreaudio_get_device_name(struct coreaudio_data *ca)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!cf_to_cstr(cf_name, name, 1024)) {
|
||||
name = cfstr_copy_cstr(cf_name, kCFStringEncodingUTF8);
|
||||
if (!name) {
|
||||
blog(LOG_WARNING, "[coreaudio_get_device_name] failed to "
|
||||
"convert name to cstr for some reason");
|
||||
return false;
|
||||
}
|
||||
|
||||
bfree(ca->device_name);
|
||||
ca->device_name = bstrdup(name);
|
||||
ca->device_name = name;
|
||||
|
||||
if (cf_name)
|
||||
CFRelease(cf_name);
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <util/dstr.h>
|
||||
|
||||
static inline bool mac_success(OSStatus stat, const char *action)
|
||||
{
|
||||
if (stat != noErr) {
|
||||
blog(LOG_WARNING, "%s failed: %d", action, (int)stat);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool cf_to_cstr(CFStringRef ref, char *buf, size_t size)
|
||||
{
|
||||
if (!ref) return false;
|
||||
return (bool)CFStringGetCString(ref, buf, size, kCFStringEncodingUTF8);
|
||||
}
|
||||
|
||||
static inline bool cf_to_dstr(CFStringRef ref, struct dstr *str)
|
||||
{
|
||||
size_t size;
|
||||
if (!ref) return false;
|
||||
|
||||
size = (size_t)CFStringGetLength(ref);
|
||||
if (!size)
|
||||
return false;
|
||||
|
||||
dstr_resize(str, size);
|
||||
|
||||
return (bool)CFStringGetCString(ref, str->array, size+1,
|
||||
kCFStringEncodingUTF8);
|
||||
}
|
Loading…
Reference in a new issue