Skip to content

Commit

Permalink
style(macos): various code style fixes (#2086)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher authored Feb 4, 2024
1 parent dea1155 commit 76e160b
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/platform/macos/av_audio.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ - (void)captureOutput:(AVCaptureOutput *)output

CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, NULL, &audioBufferList, sizeof(audioBufferList), NULL, NULL, 0, &blockBuffer);

// NSAssert(audioBufferList.mNumberBuffers == 1, @"Expected interlveaved PCM format but buffer contained %u streams", audioBufferList.mNumberBuffers);
// NSAssert(audioBufferList.mNumberBuffers == 1, @"Expected interleaved PCM format but buffer contained %u streams", audioBufferList.mNumberBuffers);

// this is safe, because an interleaved PCM stream has exactly one buffer
// this is safe, because an interleaved PCM stream has exactly one buffer,
// and we don't want to do sanity checks in a performance critical exec path
AudioBuffer audioBuffer = audioBufferList.mBuffers[0];

Expand Down
8 changes: 4 additions & 4 deletions src/platform/macos/av_img_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace platf {
struct av_sample_buf_t {
av_sample_buf_t(CMSampleBufferRef buf):
explicit av_sample_buf_t(CMSampleBufferRef buf):
buf((CMSampleBufferRef) CFRetain(buf)) {}

~av_sample_buf_t() {
Expand All @@ -22,12 +22,12 @@ namespace platf {
};

struct av_pixel_buf_t {
av_pixel_buf_t(CVPixelBufferRef buf):
explicit av_pixel_buf_t(CVPixelBufferRef buf):
buf((CVPixelBufferRef) CFRetain(buf)),
locked(false) {}

uint8_t *
lock() {
[[nodiscard]] uint8_t *
lock() const {
if (!locked) {
CVPixelBufferLockBaseAddress(buf, kCVPixelBufferLock_ReadOnly);
}
Expand Down
4 changes: 2 additions & 2 deletions src/platform/macos/av_video.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ - (id)initWithDisplay:(CGDirectDisplayID)displayID frameRate:(int)frameRate {

self.displayID = displayID;
self.pixelFormat = kCVPixelFormatType_32BGRA;
self.frameWidth = CGDisplayModeGetPixelWidth(mode);
self.frameHeight = CGDisplayModeGetPixelHeight(mode);
self.frameWidth = (int) CGDisplayModeGetPixelWidth(mode);
self.frameHeight = (int) CGDisplayModeGetPixelHeight(mode);
self.minFrameDuration = CMTimeMake(1, frameRate);
self.session = [[AVCaptureSession alloc] init];
self.videoOutputs = [[NSMapTable alloc] init];
Expand Down
21 changes: 10 additions & 11 deletions src/platform/macos/display.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "src/platform/macos/nv12_zero_device.h"

#include "src/config.h"
#include "src/main.h"

// Avoid conflict between AVFoundation and libavutil both defining AVMediaType
#define AVMediaType AVMediaType_FFmpeg
Expand All @@ -21,10 +20,10 @@
using namespace std::literals;

struct av_display_t: public display_t {
AVVideo *av_capture;
CGDirectDisplayID display_id;
AVVideo *av_capture {};
CGDirectDisplayID display_id {};

~av_display_t() {
~av_display_t() override {
[av_capture release];
}

Expand All @@ -45,9 +44,9 @@
av_img->pixel_buffer = std::make_shared<av_pixel_buf_t>(pixelBuffer);
img_out->data = av_img->pixel_buffer->lock();

img_out->width = CVPixelBufferGetWidth(pixelBuffer);
img_out->height = CVPixelBufferGetHeight(pixelBuffer);
img_out->row_pitch = CVPixelBufferGetBytesPerRow(pixelBuffer);
img_out->width = (int) CVPixelBufferGetWidth(pixelBuffer);
img_out->height = (int) CVPixelBufferGetHeight(pixelBuffer);
img_out->row_pitch = (int) CVPixelBufferGetBytesPerRow(pixelBuffer);
img_out->pixel_pitch = img_out->row_pitch / img_out->width;

if (!push_captured_image_cb(std::move(img_out), true)) {
Expand Down Expand Up @@ -101,9 +100,9 @@
av_img->pixel_buffer = std::make_shared<av_pixel_buf_t>(pixelBuffer);
img->data = av_img->pixel_buffer->lock();

img->width = CVPixelBufferGetWidth(pixelBuffer);
img->height = CVPixelBufferGetHeight(pixelBuffer);
img->row_pitch = CVPixelBufferGetBytesPerRow(pixelBuffer);
img->width = (int) CVPixelBufferGetWidth(pixelBuffer);
img->height = (int) CVPixelBufferGetHeight(pixelBuffer);
img->row_pitch = (int) CVPixelBufferGetBytesPerRow(pixelBuffer);
img->pixel_pitch = img->row_pitch / img->width;

// returning false here stops capture backend
Expand Down Expand Up @@ -177,7 +176,7 @@
display_names.reserve([display_array count]);
[display_array enumerateObjectsUsingBlock:^(NSDictionary *_Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) {
NSString *name = obj[@"name"];
display_names.push_back(name.UTF8String);
display_names.emplace_back(name.UTF8String);
}];

return display_names;
Expand Down
26 changes: 13 additions & 13 deletions src/platform/macos/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ namespace platf {

struct macos_input_t {
public:
CGDirectDisplayID display;
CGFloat displayScaling;
CGEventSourceRef source;
CGDirectDisplayID display {};
CGFloat displayScaling {};
CGEventSourceRef source {};

// keyboard related stuff
CGEventRef kb_event;
CGEventFlags kb_flags;
CGEventRef kb_event {};
CGEventFlags kb_flags {};

// mouse related stuff
CGEventRef mouse_event; // mouse event source
bool mouse_down[3]; // mouse button status
CGEventRef mouse_event {}; // mouse event source
bool mouse_down[3] {}; // mouse button status
std::chrono::steady_clock::steady_clock::time_point last_mouse_event[3][2]; // timestamp of last mouse events
};

Expand Down Expand Up @@ -221,7 +221,7 @@ const KeyCodeMap kKeyCodesMap[] = {

int
keysym(int keycode) {
KeyCodeMap key_map;
KeyCodeMap key_map {};

key_map.win_keycode = keycode;
const KeyCodeMap *temp_map = std::lower_bound(
Expand Down Expand Up @@ -330,13 +330,13 @@ const KeyCodeMap kKeyCodesMap[] = {

if (location.x < 0)
location.x = 0;
if (location.x >= CGDisplayPixelsWide(display))
location.x = CGDisplayPixelsWide(display) - 1;
if (location.x >= (double) CGDisplayPixelsWide(display))
location.x = (double) CGDisplayPixelsWide(display) - 1;

if (location.y < 0)
location.y = 0;
if (location.y >= CGDisplayPixelsHigh(display))
location.y = CGDisplayPixelsHigh(display) - 1;
if (location.y >= (double) CGDisplayPixelsHigh(display))
location.y = (double) CGDisplayPixelsHigh(display) - 1;

CGEventSetType(event, type);
CGEventSetLocation(event, location);
Expand Down Expand Up @@ -428,7 +428,7 @@ const KeyCodeMap kKeyCodesMap[] = {
void
scroll(input_t &input, int high_res_distance) {
CGEventRef upEvent = CGEventCreateScrollWheelEvent(
NULL,
nullptr,
kCGScrollEventUnitLine,
2, high_res_distance > 0 ? 1 : -1, high_res_distance);
CGEventPost(kCGHIDEventTap, upEvent);
Expand Down
7 changes: 3 additions & 4 deletions src/platform/macos/microphone.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
#include "src/platform/macos/av_audio.h"

#include "src/config.h"
#include "src/main.h"

namespace platf {
using namespace std::literals;

struct av_mic_t: public mic_t {
AVAudio *av_audio_capture;
AVAudio *av_audio_capture {};

~av_mic_t() {
~av_mic_t() override {
[av_audio_capture release];
}

Expand Down Expand Up @@ -42,7 +41,7 @@
};

struct macos_audio_control_t: public audio_control_t {
AVCaptureDevice *audio_capture_device;
AVCaptureDevice *audio_capture_device {};

public:
int
Expand Down
2 changes: 1 addition & 1 deletion src/platform/macos/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <CoreGraphics/CoreGraphics.h>

namespace dyn {
typedef void (*apiproc)(void);
typedef void (*apiproc)();

int
load(void *handle, const std::vector<std::tuple<apiproc *, const char *>> &funcs, bool strict = true);
Expand Down
14 changes: 7 additions & 7 deletions src/platform/macos/misc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

// Required for IPV6_PKTINFO with Darwin headers
#ifndef __APPLE_USE_RFC_3542
#ifndef __APPLE_USE_RFC_3542 // NOLINT(bugprone-reserved-identifier)
#define __APPLE_USE_RFC_3542 1
#endif

Expand Down Expand Up @@ -53,7 +53,7 @@
// Xcode 12.2 and later, these functions are not weakly linked and will never
// be null, and therefore generate this warning. Since we are weakly linking
// when compiling with earlier Xcode versions, the check for null is
// necessary and so we ignore the warning.
// necessary, and so we ignore the warning.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
#pragma clang diagnostic ignored "-Wtautological-pointer-compare"
Expand Down Expand Up @@ -141,7 +141,7 @@
std::string mac_address;

if (getifaddrs(&ifap) == 0) {
for (ifaptr = ifap; ifaptr != NULL; ifaptr = (ifaptr)->ifa_next) {
for (ifaptr = ifap; ifaptr != nullptr; ifaptr = (ifaptr)->ifa_next) {
if (!strcmp((ifaptr)->ifa_name, pos->ifa_name) && (((ifaptr)->ifa_addr)->sa_family == AF_LINK)) {
ptr = (unsigned char *) LLADDR((struct sockaddr_dl *) (ifaptr)->ifa_addr);
char buff[100];
Expand All @@ -155,7 +155,7 @@

freeifaddrs(ifap);

if (ifaptr != NULL) {
if (ifaptr != nullptr) {
BOOST_LOG(verbose) << "Found MAC of "sv << pos->ifa_name << ": "sv << mac_address;
return mac_address;
}
Expand Down Expand Up @@ -336,15 +336,15 @@
union {
char buf[std::max(CMSG_SPACE(sizeof(struct in_pktinfo)), CMSG_SPACE(sizeof(struct in6_pktinfo)))];
struct cmsghdr alignment;
} cmbuf;
} cmbuf {};
socklen_t cmbuflen = 0;

msg.msg_control = cmbuf.buf;
msg.msg_controllen = sizeof(cmbuf.buf);

auto pktinfo_cm = CMSG_FIRSTHDR(&msg);
if (send_info.source_address.is_v6()) {
struct in6_pktinfo pktInfo;
struct in6_pktinfo pktInfo {};

struct sockaddr_in6 saddr_v6 = to_sockaddr(send_info.source_address.to_v6(), 0);
pktInfo.ipi6_addr = saddr_v6.sin6_addr;
Expand All @@ -358,7 +358,7 @@
memcpy(CMSG_DATA(pktinfo_cm), &pktInfo, sizeof(pktInfo));
}
else {
struct in_pktinfo pktInfo;
struct in_pktinfo pktInfo {};

struct sockaddr_in saddr_v4 = to_sockaddr(send_info.source_address.to_v4(), 0);
pktInfo.ipi_spec_dst = saddr_v4.sin_addr;
Expand Down
12 changes: 7 additions & 5 deletions src/platform/macos/nv12_zero_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* @file src/platform/macos/nv12_zero_device.cpp
* @brief todo
*/
#include <utility>

#include "src/platform/macos/nv12_zero_device.h"

#include "src/video.h"
Expand All @@ -24,7 +26,7 @@ namespace platf {

int
nv12_zero_device::convert(platf::img_t &img) {
av_img_t *av_img = (av_img_t *) &img;
auto *av_img = (av_img_t *) &img;

// Release any existing CVPixelBuffer previously retained for encoding
av_buffer_unref(&av_frame->buf[0]);
Expand All @@ -34,7 +36,7 @@ namespace platf {
//
// The presence of the AVBufferRef allows FFmpeg to simply add a reference to the buffer
// rather than having to perform a deep copy of the data buffers in avcodec_send_frame().
av_frame->buf[0] = av_buffer_create((uint8_t *) CFRetain(av_img->pixel_buffer->buf), 0, free_buffer, NULL, 0);
av_frame->buf[0] = av_buffer_create((uint8_t *) CFRetain(av_img->pixel_buffer->buf), 0, free_buffer, nullptr, 0);

// Place a CVPixelBufferRef at data[3] as required by AV_PIX_FMT_VIDEOTOOLBOX
av_frame->data[3] = (uint8_t *) av_img->pixel_buffer->buf;
Expand All @@ -54,15 +56,15 @@ namespace platf {
}

int
nv12_zero_device::init(void *display, pix_fmt_e pix_fmt, resolution_fn_t resolution_fn, pixel_format_fn_t pixel_format_fn) {
nv12_zero_device::init(void *display, pix_fmt_e pix_fmt, resolution_fn_t resolution_fn, const pixel_format_fn_t &pixel_format_fn) {
pixel_format_fn(display, pix_fmt == pix_fmt_e::nv12 ?
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange :
kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange);

this->display = display;
this->resolution_fn = resolution_fn;
this->resolution_fn = std::move(resolution_fn);

// we never use this pointer but it's existence is checked/used
// we never use this pointer, but its existence is checked/used
// by the platform independent code
data = this;

Expand Down
6 changes: 3 additions & 3 deletions src/platform/macos/nv12_zero_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ namespace platf {
using pixel_format_fn_t = std::function<void(void *display, int pixelFormat)>;

int
init(void *display, pix_fmt_e pix_fmt, resolution_fn_t resolution_fn, pixel_format_fn_t pixel_format_fn);
init(void *display, pix_fmt_e pix_fmt, resolution_fn_t resolution_fn, const pixel_format_fn_t &pixel_format_fn);

int
convert(img_t &img);
convert(img_t &img) override;
int
set_frame(AVFrame *frame, AVBufferRef *hw_frames_ctx);
set_frame(AVFrame *frame, AVBufferRef *hw_frames_ctx) override;

private:
util::safe_ptr<AVFrame, free_frame> av_frame;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/macos/publish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ namespace platf::publish {
public:
std::thread poll_thread;

deinit_t(std::thread poll_thread):
explicit deinit_t(std::thread poll_thread):
poll_thread { std::move(poll_thread) } {}

~deinit_t() override {
Expand Down

0 comments on commit 76e160b

Please sign in to comment.