mirror of
https://github.com/thinkonmay/sunshine-sdk.git
synced 2026-01-07 19:58:06 +00:00
style(macos): various code style fixes (#2086)
This commit is contained in:
parent
dea1155983
commit
76e160bb0a
@ -130,9 +130,9 @@
|
||||
|
||||
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];
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -37,8 +37,8 @@
|
||||
|
||||
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];
|
||||
|
||||
@ -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 @@ namespace platf {
|
||||
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 @@ namespace platf {
|
||||
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)) {
|
||||
@ -101,9 +100,9 @@ namespace platf {
|
||||
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
|
||||
@ -177,7 +176,7 @@ namespace platf {
|
||||
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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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 @@ namespace platf {
|
||||
};
|
||||
|
||||
struct macos_audio_control_t: public audio_control_t {
|
||||
AVCaptureDevice *audio_capture_device;
|
||||
AVCaptureDevice *audio_capture_device {};
|
||||
|
||||
public:
|
||||
int
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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 @@ namespace platf {
|
||||
// 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 @@ namespace platf {
|
||||
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 @@ namespace platf {
|
||||
|
||||
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 @@ namespace platf {
|
||||
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 @@ namespace platf {
|
||||
|
||||
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 @@ namespace platf {
|
||||
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;
|
||||
|
||||
@ -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"
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user