Skip to content

Commit

Permalink
style: adjust clang-format rules (#2186)
Browse files Browse the repository at this point in the history
Co-authored-by: Vithorio Polten <[email protected]>
  • Loading branch information
ReenigneArcher and Hazer authored Jan 20, 2025
1 parent f57aee9 commit c242042
Show file tree
Hide file tree
Showing 158 changed files with 8,704 additions and 9,944 deletions.
63 changes: 53 additions & 10 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,34 @@
# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignAfterOpenBracket: BlockIndent
AlignConsecutiveAssignments: None
AlignEscapedNewlines: DontAlign
AlignOperands: Align
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLambdasOnASingleLine: All
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: true
AlignTrailingComments: false
AlwaysBreakAfterReturnType: All
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: MultiLine
BreakBeforeBraces: Custom
BinPackArguments: false
BinPackParameters: false
BracedInitializerIndentWidth: 2
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterExternBlock: true
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
Expand All @@ -36,39 +43,75 @@ BraceWrapping:
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
BreakArrays: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: Always
ExperimentalAutoDetectBinPacking: true
FixNamespaceComments: true
IncludeBlocks: Regroup
IndentAccessModifiers: false
IndentCaseBlocks: true
IndentCaseLabels: true
IndentExternBlock: Indent
IndentGotoLabels: true
IndentPPDirectives: BeforeHash
IndentWidth: 2
IndentWrappedFunctionNames: true
InsertBraces: true
InsertNewlineAtEOF: true
KeepEmptyLinesAtTheStartOfBlocks: false
LineEnding: LF
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBinPackProtocolList: Never
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PackConstructorInitializers: Never
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 1
PenaltyBreakString: 1
PenaltyBreakFirstLessLess: 0
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 100000000
PointerAlignment: Right
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
RemoveSemicolon: false
SeparateDefinitionBlocks: Always
SortIncludes: CaseInsensitive
SortUsingDeclarations: Lexicographic
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: false
SpaceBeforeInheritanceColon: false
SpaceBeforeJsonColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: Never
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInLineCommentPrefix:
Maximum: 3
Minimum: 1
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 2
Cpp11BracedListStyle: false
UseTab: Never
4 changes: 2 additions & 2 deletions scripts/update_clang_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
'src',
'tests',
'tools',
os.path.join('third-party', 'glad'),
os.path.join('third-party', 'nvfbc'),
]
file_types = [
'cpp',
'cu',
'h',
'hpp',
'm',
'mm'
]
Expand Down
53 changes: 22 additions & 31 deletions src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
* @file src/audio.cpp
* @brief Definitions for audio capture and encoding.
*/
// standard includes
#include <thread>

// lib includes
#include <opus/opus_multistream.h>

#include "platform/common.h"

// local includes
#include "audio.h"
#include "config.h"
#include "globals.h"
#include "logging.h"
#include "platform/common.h"
#include "thread_safe.h"
#include "utility.h"

Expand All @@ -20,15 +22,11 @@ namespace audio {
using opus_t = util::safe_ptr<OpusMSEncoder, opus_multistream_encoder_destroy>;
using sample_queue_t = std::shared_ptr<safe::queue_t<std::vector<float>>>;

static int
start_audio_control(audio_ctx_t &ctx);
static void
stop_audio_control(audio_ctx_t &);
static void
apply_surround_params(opus_stream_config_t &stream, const stream_params_t &params);
static int start_audio_control(audio_ctx_t &ctx);
static void stop_audio_control(audio_ctx_t &);
static void apply_surround_params(opus_stream_config_t &stream, const stream_params_t &params);

int
map_stream(int channels, bool quality);
int map_stream(int channels, bool quality);

constexpr auto SAMPLE_RATE = 48000;

Expand Down Expand Up @@ -85,8 +83,7 @@ namespace audio {
},
};

void
encodeThread(sample_queue_t samples, config_t config, void *channel_data) {
void encodeThread(sample_queue_t samples, config_t config, void *channel_data) {
auto packets = mail::man->queue<packet_t>(mail::audio_packets);
auto stream = stream_configs[map_stream(config.channels, config.flags[config_t::HIGH_QUALITY])];
if (config.flags[config_t::CUSTOM_SURROUND_PARAMS]) {
Expand All @@ -96,14 +93,15 @@ namespace audio {
// Encoding takes place on this thread
platf::adjust_thread_priority(platf::thread_priority_e::high);

opus_t opus { opus_multistream_encoder_create(
opus_t opus {opus_multistream_encoder_create(
stream.sampleRate,
stream.channelCount,
stream.streams,
stream.coupledStreams,
stream.mapping,
OPUS_APPLICATION_RESTRICTED_LOWDELAY,
nullptr) };
nullptr
)};

opus_multistream_encoder_ctl(opus.get(), OPUS_SET_BITRATE(stream.bitrate));
opus_multistream_encoder_ctl(opus.get(), OPUS_SET_VBR(0));
Expand All @@ -114,7 +112,7 @@ namespace audio {

auto frame_size = config.packetDuration * stream.sampleRate / 1000;
while (auto sample = samples->pop()) {
buffer_t packet { 1400 };
buffer_t packet {1400};

int bytes = opus_multistream_encode_float(opus.get(), sample->data(), frame_size, std::begin(packet), packet.size());
if (bytes < 0) {
Expand All @@ -129,8 +127,7 @@ namespace audio {
}
}

void
capture(safe::mail_t mail, config_t config, void *channel_data) {
void capture(safe::mail_t mail, config_t config, void *channel_data) {
auto shutdown_event = mail->event<bool>(mail::shutdown);
auto stream = stream_configs[map_stream(config.channels, config.flags[config_t::HIGH_QUALITY])];
if (config.flags[config_t::CUSTOM_SURROUND_PARAMS]) {
Expand Down Expand Up @@ -204,7 +201,7 @@ namespace audio {
platf::adjust_thread_priority(platf::thread_priority_e::critical);

auto samples = std::make_shared<sample_queue_t::element_type>(30);
std::thread thread { encodeThread, samples, config, channel_data };
std::thread thread {encodeThread, samples, config, channel_data};

auto fg = util::fail_guard([&]() {
samples->stop();
Expand Down Expand Up @@ -243,14 +240,12 @@ namespace audio {
}
}

audio_ctx_ref_t
get_audio_ctx_ref() {
static auto control_shared { safe::make_shared<audio_ctx_t>(start_audio_control, stop_audio_control) };
audio_ctx_ref_t get_audio_ctx_ref() {
static auto control_shared {safe::make_shared<audio_ctx_t>(start_audio_control, stop_audio_control)};
return control_shared.ref();
}

bool
is_audio_ctx_sink_available(const audio_ctx_t &ctx) {
bool is_audio_ctx_sink_available(const audio_ctx_t &ctx) {
if (!ctx.control) {
return false;
}
Expand All @@ -263,8 +258,7 @@ namespace audio {
return ctx.control->is_sink_available(sink);
}

int
map_stream(int channels, bool quality) {
int map_stream(int channels, bool quality) {
int shift = quality ? 1 : 0;
switch (channels) {
case 2:
Expand All @@ -277,8 +271,7 @@ namespace audio {
return STEREO;
}

int
start_audio_control(audio_ctx_t &ctx) {
int start_audio_control(audio_ctx_t &ctx) {
auto fg = util::fail_guard([]() {
BOOST_LOG(warning) << "There will be no audio"sv;
});
Expand All @@ -305,8 +298,7 @@ namespace audio {
return 0;
}

void
stop_audio_control(audio_ctx_t &ctx) {
void stop_audio_control(audio_ctx_t &ctx) {
// restore audio-sink if applicable
if (!ctx.restore_sink) {
return;
Expand All @@ -320,8 +312,7 @@ namespace audio {
}
}

void
apply_surround_params(opus_stream_config_t &stream, const stream_params_t &params) {
void apply_surround_params(opus_stream_config_t &stream, const stream_params_t &params) {
stream.channelCount = params.channelCount;
stream.streams = params.streams;
stream.coupledStreams = params.coupledStreams;
Expand Down
9 changes: 3 additions & 6 deletions src/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ namespace audio {
using packet_t = std::pair<void *, buffer_t>;
using audio_ctx_ref_t = safe::shared_t<audio_ctx_t>::ptr_t;

void
capture(safe::mail_t mail, config_t config, void *channel_data);
void capture(safe::mail_t mail, config_t config, void *channel_data);

/**
* @brief Get the reference to the audio context.
Expand All @@ -84,8 +83,7 @@ namespace audio {
* audio_ctx_ref_t audio = get_audio_ctx_ref()
* @examples_end
*/
audio_ctx_ref_t
get_audio_ctx_ref();
audio_ctx_ref_t get_audio_ctx_ref();

/**
* @brief Check if the audio sink held by audio context is available.
Expand All @@ -101,6 +99,5 @@ namespace audio {
* return false;
* @examples_end
*/
bool
is_audio_ctx_sink_available(const audio_ctx_t &ctx);
bool is_audio_ctx_sink_available(const audio_ctx_t &ctx);
} // namespace audio
Loading

0 comments on commit c242042

Please sign in to comment.