From 76e160bb0abf1b0b564c9ef512d43fc6d93253ed Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sun, 4 Feb 2024 18:37:44 -0500 Subject: [PATCH] style(macos): various code style fixes (#2086) --- src/platform/macos/av_audio.m | 4 ++-- src/platform/macos/av_img_t.h | 8 ++++---- src/platform/macos/av_video.m | 4 ++-- src/platform/macos/display.mm | 21 ++++++++++---------- src/platform/macos/input.cpp | 26 ++++++++++++------------- src/platform/macos/microphone.mm | 7 +++---- src/platform/macos/misc.h | 2 +- src/platform/macos/misc.mm | 14 ++++++------- src/platform/macos/nv12_zero_device.cpp | 12 +++++++----- src/platform/macos/nv12_zero_device.h | 6 +++--- src/platform/macos/publish.cpp | 2 +- 11 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/platform/macos/av_audio.m b/src/platform/macos/av_audio.m index af695179c7b..cb0c83c2e97 100644 --- a/src/platform/macos/av_audio.m +++ b/src/platform/macos/av_audio.m @@ -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]; diff --git a/src/platform/macos/av_img_t.h b/src/platform/macos/av_img_t.h index 6002bdcb221..fb0d7ecd0f5 100644 --- a/src/platform/macos/av_img_t.h +++ b/src/platform/macos/av_img_t.h @@ -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() { @@ -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); } diff --git a/src/platform/macos/av_video.m b/src/platform/macos/av_video.m index c64597656cc..5cdf5a9898e 100644 --- a/src/platform/macos/av_video.m +++ b/src/platform/macos/av_video.m @@ -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]; diff --git a/src/platform/macos/display.mm b/src/platform/macos/display.mm index f424cf4ece2..5c3d37477f8 100644 --- a/src/platform/macos/display.mm +++ b/src/platform/macos/display.mm @@ -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 @@ -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]; } @@ -45,9 +44,9 @@ av_img->pixel_buffer = std::make_shared(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)) { @@ -101,9 +100,9 @@ av_img->pixel_buffer = std::make_shared(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 @@ -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; diff --git a/src/platform/macos/input.cpp b/src/platform/macos/input.cpp index 66d0d130861..36484054a7a 100644 --- a/src/platform/macos/input.cpp +++ b/src/platform/macos/input.cpp @@ -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 }; @@ -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( @@ -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); @@ -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); diff --git a/src/platform/macos/microphone.mm b/src/platform/macos/microphone.mm index 854ca6faffe..1baf52606ab 100644 --- a/src/platform/macos/microphone.mm +++ b/src/platform/macos/microphone.mm @@ -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]; } @@ -42,7 +41,7 @@ }; struct macos_audio_control_t: public audio_control_t { - AVCaptureDevice *audio_capture_device; + AVCaptureDevice *audio_capture_device {}; public: int diff --git a/src/platform/macos/misc.h b/src/platform/macos/misc.h index a6fb1df3244..ca74f0ea478 100644 --- a/src/platform/macos/misc.h +++ b/src/platform/macos/misc.h @@ -9,7 +9,7 @@ #include namespace dyn { - typedef void (*apiproc)(void); + typedef void (*apiproc)(); int load(void *handle, const std::vector> &funcs, bool strict = true); diff --git a/src/platform/macos/misc.mm b/src/platform/macos/misc.mm index 2cfa2970163..76e50349f6c 100644 --- a/src/platform/macos/misc.mm +++ b/src/platform/macos/misc.mm @@ -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 @@ -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" @@ -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]; @@ -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; } @@ -336,7 +336,7 @@ 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; @@ -344,7 +344,7 @@ 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; @@ -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; diff --git a/src/platform/macos/nv12_zero_device.cpp b/src/platform/macos/nv12_zero_device.cpp index f376bdcd413..c217c637661 100644 --- a/src/platform/macos/nv12_zero_device.cpp +++ b/src/platform/macos/nv12_zero_device.cpp @@ -2,6 +2,8 @@ * @file src/platform/macos/nv12_zero_device.cpp * @brief todo */ +#include + #include "src/platform/macos/nv12_zero_device.h" #include "src/video.h" @@ -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]); @@ -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; @@ -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; diff --git a/src/platform/macos/nv12_zero_device.h b/src/platform/macos/nv12_zero_device.h index f1ee2702aad..b83210cb94f 100644 --- a/src/platform/macos/nv12_zero_device.h +++ b/src/platform/macos/nv12_zero_device.h @@ -26,12 +26,12 @@ namespace platf { using pixel_format_fn_t = std::function; 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 av_frame; diff --git a/src/platform/macos/publish.cpp b/src/platform/macos/publish.cpp index 8fca07b848a..55dec40a8e7 100644 --- a/src/platform/macos/publish.cpp +++ b/src/platform/macos/publish.cpp @@ -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 {