mac-capture: Fix compiler warnings

CMake build framework 3.0 introduces more strict typing checks, which
require additional code fixes to silence.

* Fixes warnings about multi-character assignments
* Fixes warnings about implicit casts
* Fixes warnings about shadowing variables
This commit is contained in:
PatTheMav
2023-02-18 21:14:46 +01:00
committed by Jim
parent c5bb6218b6
commit f98c2d2514
4 changed files with 70 additions and 69 deletions
+22 -18
View File
@@ -209,9 +209,12 @@ static bool init_display_stream(struct display_capture *dc)
os_event_init(&dc->disp_finished, OS_EVENT_TYPE_MANUAL);
FourCharCode bgra_code = 0;
bgra_code = ('B' << 24) | ('G' << 16) | ('R' << 8) | 'A';
const CGSize *size = &dc->frame.size;
dc->disp = CGDisplayStreamCreateWithDispatchQueue(
disp_id, size->width, size->height, 'BGRA',
disp_id, (size_t)size->width, (size_t)size->height, bgra_code,
(__bridge CFDictionaryRef)dict,
dispatch_queue_create(NULL, NULL),
^(CGDisplayStreamFrameStatus status, uint64_t displayTime,
@@ -280,7 +283,7 @@ static void *display_capture_create(obs_data_t *settings, obs_source_t *source)
init_window(&dc->window, settings);
load_crop(dc, settings);
dc->display = obs_data_get_int(settings, "display");
dc->display = (unsigned int)obs_data_get_int(settings, "display");
pthread_mutex_init(&dc->mutex, NULL);
if (!init_display_stream(dc))
@@ -311,7 +314,7 @@ static void build_sprite(struct gs_vb_data *data, float fcx, float fcy,
static inline void build_sprite_rect(struct gs_vb_data *data, float origin_x,
float origin_y, float end_x, float end_y)
{
build_sprite(data, fabs(end_x - origin_x), fabs(end_y - origin_y),
build_sprite(data, fabsf(end_x - origin_x), fabsf(end_y - origin_y),
origin_x, end_x, origin_y, end_y);
}
@@ -343,7 +346,7 @@ static void display_capture_video_tick(void *data, float seconds)
CGPoint end = {0.f};
switch (dc->crop) {
float x, y;
double x, y;
case CROP_INVALID:
break;
@@ -371,8 +374,9 @@ static void display_capture_video_tick(void *data, float seconds)
}
obs_enter_graphics();
build_sprite_rect(gs_vertexbuffer_get_data(dc->vertbuf), origin.x,
origin.y, end.x, end.y);
build_sprite_rect(gs_vertexbuffer_get_data(dc->vertbuf),
(float)origin.x, (float)origin.y, (float)end.x,
(float)end.y);
if (dc->tex)
gs_texture_rebind_iosurface(dc->tex, dc->prev);
@@ -432,19 +436,19 @@ static uint32_t display_capture_getwidth(void *data)
{
struct display_capture *dc = data;
float crop = dc->crop_rect.origin.x + dc->crop_rect.size.width;
double crop = dc->crop_rect.origin.x + dc->crop_rect.size.width;
switch (dc->crop) {
case CROP_NONE:
return dc->frame.size.width;
return (uint32_t)dc->frame.size.width;
case CROP_MANUAL:
return fabs(dc->frame.size.width - crop);
return (uint32_t)fabs(dc->frame.size.width - crop);
case CROP_TO_WINDOW:
return dc->window_rect.size.width;
return (uint32_t)dc->window_rect.size.width;
case CROP_TO_WINDOW_AND_MANUAL:
return fabs(dc->window_rect.size.width - crop);
return (uint32_t)fabs(dc->window_rect.size.width - crop);
case CROP_INVALID:
break;
@@ -456,19 +460,19 @@ static uint32_t display_capture_getheight(void *data)
{
struct display_capture *dc = data;
float crop = dc->crop_rect.origin.y + dc->crop_rect.size.height;
double crop = dc->crop_rect.origin.y + dc->crop_rect.size.height;
switch (dc->crop) {
case CROP_NONE:
return dc->frame.size.height;
return (uint32_t)dc->frame.size.height;
case CROP_MANUAL:
return fabs(dc->frame.size.height - crop);
return (uint32_t)fabs(dc->frame.size.height - crop);
case CROP_TO_WINDOW:
return dc->window_rect.size.height;
return (uint32_t)dc->window_rect.size.height;
case CROP_TO_WINDOW_AND_MANUAL:
return fabs(dc->window_rect.size.height - crop);
return (uint32_t)fabs(dc->window_rect.size.height - crop);
case CROP_INVALID:
break;
@@ -487,7 +491,7 @@ static void display_capture_defaults(obs_data_t *settings)
void load_crop_mode(enum crop_mode *mode, obs_data_t *settings)
{
*mode = obs_data_get_int(settings, "crop_mode");
*mode = (int)obs_data_get_int(settings, "crop_mode");
if (!crop_mode_valid(*mode))
*mode = CROP_NONE;
}
@@ -532,7 +536,7 @@ static void display_capture_update(void *data, obs_data_t *settings)
if (requires_window(dc->crop))
update_window(&dc->window, settings);
unsigned display = obs_data_get_int(settings, "display");
unsigned display = (unsigned int)obs_data_get_int(settings, "display");
bool show_cursor = obs_data_get_bool(settings, "show_cursor");
if (dc->display == display && dc->hide_cursor != show_cursor)
return;
+40 -41
View File
@@ -254,8 +254,10 @@ static inline void screen_stream_video_update(struct screen_capture *sc,
}
if (needs_to_update_properties) {
[sc->stream_properties setWidth:sc->frame.size.width];
[sc->stream_properties setHeight:sc->frame.size.height];
[sc->stream_properties
setWidth:(size_t)sc->frame.size.width];
[sc->stream_properties
setHeight:(size_t)sc->frame.size.height];
[sc->disp
updateConfiguration:sc->stream_properties
@@ -320,9 +322,9 @@ static inline void screen_stream_audio_update(struct screen_capture *sc,
audio_description->mBytesPerFrame /
audio_description->mChannelsPerFrame);
audio_data.speakers = audio_description->mChannelsPerFrame;
audio_data.samples_per_sec = audio_description->mSampleRate;
audio_data.samples_per_sec = (uint32_t)audio_description->mSampleRate;
audio_data.timestamp =
CMTimeGetSeconds(presentation_time) * NSEC_PER_SEC;
(uint64_t)(CMTimeGetSeconds(presentation_time) * NSEC_PER_SEC);
audio_data.format = AUDIO_FORMAT_FLOAT_PLANAR;
obs_source_output_audio(sc->source, &audio_data);
}
@@ -353,12 +355,13 @@ static bool init_screen_stream(struct screen_capture *sc)
};
void (^set_display_mode)(struct screen_capture *, SCDisplay *) = ^void(
struct screen_capture *sc, SCDisplay *target_display) {
struct screen_capture *capture_data,
SCDisplay *target_display) {
CGDisplayModeRef display_mode =
CGDisplayCopyDisplayMode(target_display.displayID);
[sc->stream_properties
[capture_data->stream_properties
setWidth:CGDisplayModeGetPixelWidth(display_mode)];
[sc->stream_properties
[capture_data->stream_properties
setHeight:CGDisplayModeGetPixelHeight(display_mode)];
CGDisplayModeRelease(display_mode);
};
@@ -398,9 +401,10 @@ static bool init_screen_stream(struct screen_capture *sc)
if (target_window) {
[sc->stream_properties
setWidth:target_window.frame.size.width];
setWidth:(size_t)target_window.frame.size.width];
[sc->stream_properties
setHeight:target_window.frame.size.height];
setHeight:(size_t)target_window.frame.size
.height];
}
} break;
@@ -441,7 +445,9 @@ static bool init_screen_stream(struct screen_capture *sc)
[sc->stream_properties setQueueDepth:8];
[sc->stream_properties setShowsCursor:!sc->hide_cursor];
[sc->stream_properties setColorSpaceName:kCGColorSpaceDisplayP3];
[sc->stream_properties setPixelFormat:'l10r'];
FourCharCode l10r_type = 0;
l10r_type = ('l' << 24) | ('1' << 16) | ('0' << 8) | 'r';
[sc->stream_properties setPixelFormat:l10r_type];
if (@available(macOS 13.0, *)) {
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130000
@@ -463,17 +469,17 @@ static bool init_screen_stream(struct screen_capture *sc)
configuration:sc->stream_properties
delegate:nil];
NSError *error = nil;
NSError *addStreamOutputError = nil;
BOOL did_add_output = [sc->disp addStreamOutput:sc->capture_delegate
type:SCStreamOutputTypeScreen
sampleHandlerQueue:nil
error:&error];
error:&addStreamOutputError];
if (!did_add_output) {
MACCAP_ERR(
"init_screen_stream: Failed to add stream output with error %s\n",
[[error localizedFailureReason]
[[addStreamOutputError localizedFailureReason]
cStringUsingEncoding:NSUTF8StringEncoding]);
[error release];
[addStreamOutputError release];
return !did_add_output;
}
@@ -483,14 +489,14 @@ static bool init_screen_stream(struct screen_capture *sc)
addStreamOutput:sc->capture_delegate
type:SCStreamOutputTypeAudio
sampleHandlerQueue:nil
error:&error];
error:&addStreamOutputError];
if (!did_add_output) {
MACCAP_ERR(
"init_screen_stream: Failed to add audio stream output with error %s\n",
[[error localizedFailureReason]
[[addStreamOutputError localizedFailureReason]
cStringUsingEncoding:
NSUTF8StringEncoding]);
[error release];
[addStreamOutputError release];
return !did_add_output;
}
}
@@ -595,8 +601,7 @@ fail:
return NULL;
}
static void screen_capture_video_tick(void *data,
float seconds __attribute__((unused)))
static void screen_capture_video_tick(void *data, float seconds __unused)
{
struct screen_capture *sc = data;
@@ -628,8 +633,8 @@ static void screen_capture_video_tick(void *data,
}
}
static void screen_capture_video_render(void *data, gs_effect_t *effect
__attribute__((unused)))
static void screen_capture_video_render(void *data,
gs_effect_t *effect __unused)
{
struct screen_capture *sc = data;
@@ -648,7 +653,7 @@ static void screen_capture_video_render(void *data, gs_effect_t *effect
gs_enable_framebuffer_srgb(previous);
}
static const char *screen_capture_getname(void *unused __attribute__((unused)))
static const char *screen_capture_getname(void *unused __unused)
{
if (@available(macOS 13.0, *))
return obs_module_text("SCK.Name");
@@ -660,14 +665,14 @@ static uint32_t screen_capture_getwidth(void *data)
{
struct screen_capture *sc = data;
return sc->frame.size.width;
return (uint32_t)sc->frame.size.width;
}
static uint32_t screen_capture_getheight(void *data)
{
struct screen_capture *sc = data;
return sc->frame.size.height;
return (uint32_t)sc->frame.size.height;
}
static void screen_capture_defaults(obs_data_t *settings)
@@ -767,15 +772,13 @@ static bool build_display_list(struct screen_capture *sc,
[sc->shareable_content.displays enumerateObjectsUsingBlock:^(
SCDisplay *_Nonnull display,
NSUInteger idx
__attribute__((unused)),
BOOL *_Nonnull stop
__attribute__((unused))) {
NSUInteger screen_index = [NSScreen.screens
indexOfObjectPassingTest:^BOOL(
NSScreen *_Nonnull screen,
NSUInteger index __attribute__((unused)),
BOOL *_Nonnull stop) {
NSUInteger idx __unused,
BOOL *_Nonnull _stop __unused) {
NSUInteger screen_index =
[NSScreen.screens indexOfObjectPassingTest:^BOOL(
NSScreen *_Nonnull screen,
NSUInteger index __unused,
BOOL *_Nonnull stop) {
NSNumber *screen_num =
screen.deviceDescription
[@"NSScreenNumber"];
@@ -824,10 +827,8 @@ static bool build_window_list(struct screen_capture *sc,
[sc->shareable_content.windows enumerateObjectsUsingBlock:^(
SCWindow *_Nonnull window,
NSUInteger idx
__attribute__((unused)),
BOOL *_Nonnull stop
__attribute__((unused))) {
NSUInteger idx __unused,
BOOL *_Nonnull stop __unused) {
NSString *app_name = window.owningApplication.applicationName;
NSString *title = window.title;
@@ -863,8 +864,7 @@ static bool build_application_list(struct screen_capture *sc,
[sc->shareable_content.applications
enumerateObjectsUsingBlock:^(
SCRunningApplication *_Nonnull application,
NSUInteger idx __attribute__((unused)),
BOOL *_Nonnull stop __attribute__((unused))) {
NSUInteger idx __unused, BOOL *_Nonnull stop __unused) {
const char *name =
[application.applicationName UTF8String];
const char *bundle_id =
@@ -879,8 +879,7 @@ static bool build_application_list(struct screen_capture *sc,
}
static bool content_settings_changed(void *data, obs_properties_t *props,
obs_property_t *list
__attribute__((unused)),
obs_property_t *list __unused,
obs_data_t *settings)
{
struct screen_capture *sc = data;
+3 -3
View File
@@ -61,10 +61,10 @@ static inline void capture_frame(struct window_capture *wc)
struct obs_source_frame frame = {
.format = VIDEO_FORMAT_BGRA,
.width = width,
.height = height,
.width = (uint32_t)width,
.height = (uint32_t)height,
.data[0] = (uint8_t *)CFDataGetBytePtr(data),
.linesize[0] = CGImageGetBytesPerRow(img),
.linesize[0] = (uint32_t)CGImageGetBytesPerRow(img),
.timestamp = ts,
};
+5 -7
View File
@@ -102,10 +102,8 @@ void init_window(cocoa_window_t cw, obs_data_t *settings)
if (owner_names_match && (ids_match || window_names_match)) {
pthread_mutex_unlock(&cw->name_lock);
NSNumber *window_id = (NSNumber *)dict[WINDOW_NUMBER];
cw->window_id = window_id.intValue;
NSNumber *owner_pid = (NSNumber *)dict[OWNER_PID];
cw->owner_pid = owner_pid.intValue;
cw->window_id = [dict[WINDOW_NUMBER] intValue];
cw->owner_pid = [dict[OWNER_PID] intValue];
obs_data_set_int(settings, "window", cw->window_id);
obs_data_set_int(settings, "owner_pid", cw->owner_pid);
@@ -136,8 +134,8 @@ void update_window(cocoa_window_t cw, obs_data_t *settings)
[cw->window_name retain];
pthread_mutex_unlock(&cw->name_lock);
cw->owner_pid = obs_data_get_int(settings, "owner_pid");
cw->window_id = obs_data_get_int(settings, "window");
cw->owner_pid = (int)obs_data_get_int(settings, "owner_pid");
cw->window_id = (unsigned int)obs_data_get_int(settings, "window");
}
static inline const char *make_name(NSString *owner, NSString *name)
@@ -163,7 +161,7 @@ static inline NSDictionary *find_window_dict(NSArray *arr, int window_id)
static inline bool window_changed_internal(obs_property_t *p,
obs_data_t *settings)
{
int window_id = obs_data_get_int(settings, "window");
int window_id = (int)obs_data_get_int(settings, "window");
NSString *window_owner = @(obs_data_get_string(settings, "owner_name"));
NSString *window_name = @(obs_data_get_string(settings, "window_name"));