Skip to content

Commit 0572ae3

Browse files
authored
Create .clang-format and reformat sources (#29)
1 parent 9da0e39 commit 0572ae3

30 files changed

+4946
-4152
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
BasedOnStyle: Google
2+
IndentWidth: 4
3+
TabWidth: 4
4+
UseTab: Never
5+
AlignAfterOpenBracket: AlwaysBreak
6+
BreakBeforeBraces: Custom
7+
BraceWrapping:
8+
BeforeElse: true
9+
AfterFunction: true
10+
AfterEnum: true
11+
AfterControlStatement: Always
12+
AfterClass: true
13+
AfterCaseLabel: true
14+
AfterNamespace: true
15+
AfterObjCDeclaration: true
16+
AfterStruct: true
17+
AfterUnion: true
18+
AfterExternBlock: true
19+
BeforeCatch: true
20+
BeforeLambdaBody: true
21+
BeforeWhile: true
22+
IndentBraces: false
23+
SplitEmptyFunction: true
24+
SplitEmptyRecord: false
25+
SplitEmptyNamespace: true
26+
AllowShortFunctionsOnASingleLine: Inline
27+
ColumnLimit: 120
28+
NamespaceIndentation: None
29+
AccessModifierOffset: -2
30+
AlignConsecutiveAssignments: true
31+
AlignConsecutiveDeclarations: true
32+
AlignOperands: true
33+
AlignTrailingComments: true
34+
BinPackArguments: false
35+
BinPackParameters: false
36+
PointerAlignment: Left
37+
DerivePointerAlignment: false
38+
SpaceBeforeParens: ControlStatements
39+
SpaceAfterCStyleCast: true
40+
SpacesInAngles: false
41+
SpacesInParentheses: false
42+
SpacesInSquareBrackets: false
43+
SortIncludes: true
44+
IncludeBlocks: Preserve
45+
IndentCaseLabels: true

app/videonative/src/main/cpp/AndroidThreadPrioValues.hpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88
// The values for android thread priorities and
99
// the values used by my FPV_VR app (2 different namespaces though)
1010

11-
namespace AndroidThreadPriorityValues {
12-
//This one was taken from https://android.googlesource.com/platform/system/core/+/jb-dev/include/system/graphics.h
13-
constexpr auto HAL_PRIORITY_URGENT_DISPLAY = -8;
14-
// values taken from https://android.googlesource.com/platform/frameworks/native/+/android-4.2.2_r1/include/utils/ThreadDefs.h
11+
namespace AndroidThreadPriorityValues
12+
{
13+
// This one was taken from https://android.googlesource.com/platform/system/core/+/jb-dev/include/system/graphics.h
14+
constexpr auto HAL_PRIORITY_URGENT_DISPLAY = -8;
15+
// values taken from
16+
// https://android.googlesource.com/platform/frameworks/native/+/android-4.2.2_r1/include/utils/ThreadDefs.h
1517
#ifdef __cplusplus
16-
extern "C" {
18+
extern "C"
19+
{
1720
#endif
18-
enum {
21+
enum
22+
{
1923
/*
2024
* ***********************************************
2125
* ** Keep in sync with android.os.Process.java **
@@ -52,27 +56,28 @@ namespace AndroidThreadPriorityValues {
5256
ANDROID_PRIORITY_URGENT_AUDIO = -19,
5357
/* should never be used in practice. regular process might not
5458
* be allowed to use this level */
55-
ANDROID_PRIORITY_HIGHEST = -20,
56-
ANDROID_PRIORITY_DEFAULT = ANDROID_PRIORITY_NORMAL,
59+
ANDROID_PRIORITY_HIGHEST = -20,
60+
ANDROID_PRIORITY_DEFAULT = ANDROID_PRIORITY_NORMAL,
5761
ANDROID_PRIORITY_MORE_FAVORABLE = -1,
5862
ANDROID_PRIORITY_LESS_FAVORABLE = +1,
5963
};
6064
#ifdef __cplusplus
61-
} // extern "C"
65+
} // extern "C"
6266
#endif
63-
}
67+
} // namespace AndroidThreadPriorityValues
6468

6569
// All these values are for FPVue_Android
66-
//namespace FPV_VR_PRIORITY{
70+
// namespace FPV_VR_PRIORITY{
6771
// constexpr int CPU_PRIORITY_GLRENDERER_STEREO_FB=-19; //This one needs a whole CPU core all the time anyways
6872
// constexpr int CPU_PRIORITY_GLRENDERER_STEREO=-16; //The GL thread also should get 1 whole cpu core
6973
// constexpr int CPU_PRIORITY_UDPRECEIVER_VIDEO=-16; //needs low latency and does not use the cpu that much
7074
// constexpr int CPU_PRIORITY_DECODER_OUTPUT=-16; //needs low latency and does not use the cpu that much
71-
// constexpr int CPU_PRIORITY_UVC_FRAME_CALLBACK=-17; //needs low latency but uses CPU a lot (decoding). More prio than GLRenderer
75+
// constexpr int CPU_PRIORITY_UVC_FRAME_CALLBACK=-17; //needs low latency but uses CPU a lot (decoding). More prio
76+
// than GLRenderer
7277
// // These are much lower
7378
// constexpr int CPU_PRIORITY_GLRENDERER_MONO=-4; //only shows the OSD not video
74-
// constexpr int CPU_PRIORITY_UDPRECEIVER_TELEMETRY=-4; //not as important as video but also needs almost no CPU processing time
75-
// constexpr int CPU_PRIORITY_UDPSENDER_HEADTRACKING=-4;
79+
// constexpr int CPU_PRIORITY_UDPRECEIVER_TELEMETRY=-4; //not as important as video but also needs almost no CPU
80+
// processing time constexpr int CPU_PRIORITY_UDPSENDER_HEADTRACKING=-4;
7681
//}
7782

78-
#endif //FPVUE_ANDROIDTHREADPRIOVALUES_HPP
83+
#endif // FPVUE_ANDROIDTHREADPRIOVALUES_HPP

app/videonative/src/main/cpp/AudioDecoder.cpp

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@
1010
#define SAMPLE_RATE 8000
1111
#define CHANNELS 1
1212

13-
AudioDecoder::AudioDecoder() {
13+
AudioDecoder::AudioDecoder()
14+
{
1415
initAudio();
1516
}
1617

17-
AudioDecoder::~AudioDecoder() {
18-
18+
AudioDecoder::~AudioDecoder()
19+
{
1920
stopAudioProcessing();
2021
delete pOpusDecoder;
2122
AAudioStream_requestStop(m_stream);
2223
AAudioStream_close(m_stream);
2324
}
2425

25-
void AudioDecoder::enqueueAudio(const uint8_t *data, const std::size_t data_length)
26+
void AudioDecoder::enqueueAudio(const uint8_t* data, const std::size_t data_length)
2627
{
2728
{
2829
std::lock_guard<std::mutex> lock(m_mtxQueue);
@@ -31,15 +32,19 @@ void AudioDecoder::enqueueAudio(const uint8_t *data, const std::size_t data_leng
3132
m_cvQueue.notify_one();
3233
}
3334

34-
void AudioDecoder::processAudioQueue() {
35-
while (true) {
35+
void AudioDecoder::processAudioQueue()
36+
{
37+
while (true)
38+
{
3639
std::unique_lock<std::mutex> lock(m_mtxQueue);
3740
m_cvQueue.wait(lock, [this] { return !m_audioQueue.empty() || stopAudioFlag; });
3841

39-
if (stopAudioFlag) {
42+
if (stopAudioFlag)
43+
{
4044
break;
4145
}
42-
if (!m_audioQueue.empty()) {
46+
if (!m_audioQueue.empty())
47+
{
4348
AudioUDPPacket audioPkt = m_audioQueue.front();
4449
onNewAudioData(audioPkt.data, audioPkt.len);
4550
m_audioQueue.pop();
@@ -48,7 +53,8 @@ void AudioDecoder::processAudioQueue() {
4853
}
4954
}
5055

51-
void AudioDecoder::initAudio() {
56+
void AudioDecoder::initAudio()
57+
{
5258
__android_log_print(ANDROID_LOG_DEBUG, TAG, "initAudio");
5359
int error;
5460
pOpusDecoder = opus_decoder_create(SAMPLE_RATE, CHANNELS, &error);
@@ -57,8 +63,8 @@ void AudioDecoder::initAudio() {
5763

5864
// Set the stream format
5965
AAudioStreamBuilder_setFormat(m_builder, AAUDIO_FORMAT_PCM_I16);
60-
AAudioStreamBuilder_setChannelCount(m_builder, CHANNELS); // Mono
61-
AAudioStreamBuilder_setSampleRate(m_builder, SAMPLE_RATE); // 8000 Hz
66+
AAudioStreamBuilder_setChannelCount(m_builder, CHANNELS); // Mono
67+
AAudioStreamBuilder_setSampleRate(m_builder, SAMPLE_RATE); // 8000 Hz
6268

6369
AAudioStreamBuilder_setBufferCapacityInFrames(m_builder, BUFFER_CAPACITY_IN_FRAMES);
6470

@@ -80,22 +86,24 @@ void AudioDecoder::stopAudio()
8086
isInit = false;
8187
}
8288

83-
void AudioDecoder::onNewAudioData(const uint8_t *data, const std::size_t data_length) {
84-
const int rtp_header_size = 12;
85-
const uint8_t* opus_payload = data + rtp_header_size;
86-
int opus_payload_size = data_length - rtp_header_size;
89+
void AudioDecoder::onNewAudioData(const uint8_t* data, const std::size_t data_length)
90+
{
91+
const int rtp_header_size = 12;
92+
const uint8_t* opus_payload = data + rtp_header_size;
93+
int opus_payload_size = data_length - rtp_header_size;
8794

8895
int frame_size = opus_packet_get_samples_per_frame(opus_payload, SAMPLE_RATE);
89-
int nb_frames = opus_packet_get_nb_frames(opus_payload, opus_payload_size);
96+
int nb_frames = opus_packet_get_nb_frames(opus_payload, opus_payload_size);
9097

9198
// Decode the frame
9299
int pcm_size = frame_size * nb_frames * CHANNELS;
93-
if(pOpusDecoder && m_stream) {
100+
if (pOpusDecoder && m_stream)
101+
{
94102
opus_int16 pcm[pcm_size];
95-
int decoded_samples = opus_decode(pOpusDecoder, opus_payload, opus_payload_size, pcm,
96-
pcm_size, 0);
103+
int decoded_samples = opus_decode(pOpusDecoder, opus_payload, opus_payload_size, pcm, pcm_size, 0);
97104

98-
if (decoded_samples < 0) {
105+
if (decoded_samples < 0)
106+
{
99107
return;
100108
}
101109
// Process the decoded PCM data

app/videonative/src/main/cpp/AudioDecoder.h

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,68 @@
44

55
#ifndef PIXELPILOT_AUDIODECODER_H
66
#define PIXELPILOT_AUDIODECODER_H
7-
#include "libs/include/opus.h"
87
#include <aaudio/AAudio.h>
8+
#include <condition_variable>
99
#include <memory>
10-
#include <queue>
1110
#include <mutex>
12-
#include <condition_variable>
11+
#include <queue>
1312
#include <thread>
13+
#include "libs/include/opus.h"
1414

15-
typedef struct _AudioUDPPacket{
15+
typedef struct _AudioUDPPacket
16+
{
1617
_AudioUDPPacket(const uint8_t* _data, size_t _len)
1718
{
1819
memcpy(data, _data, _len);
1920
len = _len;
2021
};
2122
uint8_t data[250];
22-
size_t len;
23+
size_t len;
2324
} AudioUDPPacket;
2425

25-
class AudioDecoder {
26-
public:
26+
class AudioDecoder
27+
{
28+
public:
2729
AudioDecoder();
2830
~AudioDecoder();
2931

3032
// Audio buffer
3133
void initAudio();
32-
void enqueueAudio(const uint8_t *data, const std::size_t data_length);
33-
void startAudioProcessing() {
34+
void enqueueAudio(const uint8_t* data, const std::size_t data_length);
35+
void startAudioProcessing()
36+
{
3437
stopAudioFlag = false;
3538
m_audioThread = std::thread(&AudioDecoder::processAudioQueue, this);
3639
}
3740

38-
void stopAudioProcessing() {
41+
void stopAudioProcessing()
42+
{
3943
{
4044
std::lock_guard<std::mutex> lock(m_mtxQueue);
4145
stopAudioFlag = true;
4246
}
4347
m_cvQueue.notify_all();
44-
if (m_audioThread.joinable()) {
48+
if (m_audioThread.joinable())
49+
{
4550
m_audioThread.join();
4651
}
4752
}
4853
void processAudioQueue();
4954
void stopAudio();
5055
bool isInit = false;
5156

52-
private:
53-
void onNewAudioData(const uint8_t *data, const std::size_t data_length);
57+
private:
58+
void onNewAudioData(const uint8_t* data, const std::size_t data_length);
5459

55-
private:
56-
const int BUFFER_CAPACITY_IN_FRAMES = (1024 + 256);
60+
private:
61+
const int BUFFER_CAPACITY_IN_FRAMES = (1024 + 256);
5762
std::queue<AudioUDPPacket> m_audioQueue;
58-
std::mutex m_mtxQueue;
59-
std::condition_variable m_cvQueue;
60-
bool stopAudioFlag = false;
61-
std::thread m_audioThread;
62-
AAudioStreamBuilder* m_builder = nullptr;
63-
AAudioStream* m_stream = nullptr;
64-
OpusDecoder *pOpusDecoder = nullptr;
63+
std::mutex m_mtxQueue;
64+
std::condition_variable m_cvQueue;
65+
bool stopAudioFlag = false;
66+
std::thread m_audioThread;
67+
AAudioStreamBuilder* m_builder = nullptr;
68+
AAudioStream* m_stream = nullptr;
69+
OpusDecoder* pOpusDecoder = nullptr;
6570
};
66-
#endif //PIXELPILOT_AUDIODECODER_H
71+
#endif // PIXELPILOT_AUDIODECODER_H

0 commit comments

Comments
 (0)