Skip to content

Commit

Permalink
RPi build: still unstable but it builds and plays audio for a bit, wi…
Browse files Browse the repository at this point in the history
…th good CPU
  • Loading branch information
sfjohnson committed Mar 13, 2024
1 parent a572f5b commit eff2ab0
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion linux-x64.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PROTOC = bin/protoc
PROTOCFLAGS = --cpp_out=.

CFLAGS = -D_POSIX_C_SOURCE=200809L -std=c17 -O3 -fstrict-aliasing -pedantic -pedantic-errors -Wall -Wextra -I./include -I./include/deps -I./include/deps/ck
CPPFLAGS = -std=c++20 -O3 -fstrict-aliasing -pedantic -pedantic-errors -Wall -Wextra -I./include -I./include/deps -I./include/deps/ck
CPPFLAGS = -std=c++20 -O3 -fstrict-aliasing -Wall -Wextra -I./include -I./include/deps -I./include/deps/ck
ORIGIN=$ORIGIN
O=$$O
LDFLAGS = -Llib/linux-x64 -pthread
Expand Down
2 changes: 1 addition & 1 deletion pull-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ download () {
fi
}

download all v25.2.19 protobuf libprotobuf-lite
download all v25.2.24 protobuf libprotobuf-lite
download all v0.7.23 ck libck
download linux v2.1.3 tinyalsa libtinyalsa
download macos v19.7.5 portaudio libportaudio
Expand Down
6 changes: 2 additions & 4 deletions rpi.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ PROTOC = bin/protoc
PROTOCFLAGS = --cpp_out=.

CFLAGS = --sysroot=$(TOOLCHAIN)/arm-rpi-linux-gnueabihf/sysroot -D_POSIX_C_SOURCE=200809L -std=c17 -O3 -fstrict-aliasing -pedantic -pedantic-errors -Wall -Wextra -I./include -I./include/deps -I./include/deps/ck
# DEBUG: put -pedantic back
# CPPFLAGS = --sysroot=$(TOOLCHAIN)/arm-rpi-linux-gnueabihf/sysroot -std=c++17 -O3 -fstrict-aliasing -pedantic -pedantic-errors -Wall -Wextra -I./include -I./include/deps -I./include/deps/ck
CPPFLAGS = --sysroot=$(TOOLCHAIN)/arm-rpi-linux-gnueabihf/sysroot -std=c++20 -O3 -fstrict-aliasing -Wall -Wextra -I./include -I./include/deps -I./include/deps/ck
CPPFLAGS = --sysroot=$(TOOLCHAIN)/arm-rpi-linux-gnueabihf/sysroot -std=c++20 -O3 -fstrict-aliasing -pedantic -pedantic-errors -Wall -Wextra -I./include -I./include/deps -I./include/deps/ck
ORIGIN=$ORIGIN
O=$$O
LDFLAGS = -Llib/rpi -pthread
LIBS = -lstdc++ -ldl -lm -lopus -luwebsockets -lraptorq -lck -lr8brain -lprotobuf-lite -lboringtun -ltinyalsa
LIBS = -lstdc++ -ldl -latomic -lm -lopus -luwebsockets -lraptorq -lck -lr8brain -lprotobuf-lite -lboringtun -ltinyalsa

TARGET = waterslide-rpi
PROTOBUFS = init-config.proto monitor.proto
Expand Down
8 changes: 6 additions & 2 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
#include <string.h>
#include "globals.h"
#include "utils.h"
// the Abseil people don't "endorse" -Wpedantic *eyeroll*
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#include "protobufs/init-config.pb.h"
#pragma GCC diagnostic pop
#include "config.h"
#if defined(__linux__) || defined(__ANDROID__)
#include "tinyalsa/mixer.h"
Expand All @@ -26,7 +30,7 @@ typedef struct {
} mixerControl_t;

#if defined(__linux__) || defined(__ANDROID__)
static int applyMixerConfig (unsigned int cardId, const google::protobuf::RepeatedPtrField<InitConfigProto_MixerControl> *controls) {
static int applyMixerConfig (unsigned int cardId, const google::protobuf::RepeatedPtrField<Audio_MixerControl> *controls) {
// Save the mixer state on the first call and restore it on the second call
static unsigned int savedCardId = 0;
static mixerControl_t *savedControls = NULL;
Expand Down Expand Up @@ -160,7 +164,7 @@ static int parseAudio (int mode, const Audio &audio, const Audio_SenderReceiver
return -4;
}
auto linux = senderReceiver.linux();
err = applyMixerConfig(linux.cardid(), &linux.controls());
int err = applyMixerConfig(linux.cardid(), &linux.controls());
if (err < 0) return err - 4;
globals_set1i(audio, deviceChannelCount, linux.devicechannelcount());
globals_set1i(audio, cardId, linux.cardid());
Expand Down
13 changes: 2 additions & 11 deletions src/endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ static void sendBufToAll (const uint8_t *buf, int bufLen) {
globals_add1uiv(statsEndpoints, sendCongestion, i, 1);
} else {
// send failed, close this endpoint and re-open after a delay
// printf("(5) state %d -> Close\n", ep->state); // DEBUG: log
ep->state = Close;
}
} else {
Expand Down Expand Up @@ -187,7 +186,6 @@ static void handleRes (int epIndex, uint8_t *buf, ssize_t len) {

memcpy(&ep->peerAddr, &buf[32], 4);
memcpy(&ep->peerPort, &buf[36], 2);
// printf("(6) state %d -> GotPeerAddr\n", ep->state); // DEBUG: log
ep->state = GotPeerAddr;
ep->lastPacketUTime = utils_getCurrentUTime();
globals_set1uiv(statsEndpoints, open, epIndex, 1);
Expand Down Expand Up @@ -249,23 +247,20 @@ static void *openCloseLoop (UNUSED void *arg) {
endpoint_t *ep = &endpoints[epIndex];

if (ep->state == Open) {
if (openEndpoint(epIndex) < 0) {
// printf("(7) state %d -> Close\n", ep->state); // DEBUG: log
int err = openEndpoint(epIndex);
if (err < 0) {
ep->state = Close;
} else {
ep->discoveryTickCounter = ENDPOINT_DISCOVERY_INTERVAL;
// printf("(8) state %d -> Discovery\n", ep->state); // DEBUG: log
ep->state = Discovery;
}
} else if (ep->state == Close) {
globals_set1uiv(statsEndpoints, open, epIndex, 0);
close(ep->sock);
ep->reopenTickCounter = utils_randBetween(ENDPOINT_REOPEN_INTERVAL_MIN, ENDPOINT_REOPEN_INTERVAL_MAX);
// printf("(9) state %d -> WaitForReopen\n", ep->state); // DEBUG: log
ep->state = WaitForReopen;
} else if (ep->state == WaitForReopen) {
if (--ep->reopenTickCounter == 0) {
// printf("(10) state %d -> Open\n", ep->state); // DEBUG: log
ep->state = Open;
}
}
Expand Down Expand Up @@ -309,7 +304,6 @@ static void *dataLoop (UNUSED void *arg) {
utils_getElapsedUTime(endpoints[i].lastPacketUTime) > 5000 * ENDPOINT_KEEP_ALIVE_MS
) {
// wait for at least 5 dropped keepalive packets before closing
// printf("(1) state %d -> Close\n", endpoints[i].state); // DEBUG: log
endpoints[i].state = Close;
}

Expand Down Expand Up @@ -345,7 +339,6 @@ static void *dataLoop (UNUSED void *arg) {

if (pfds[i].revents == 0) continue;
if (pfds[i].revents != POLLIN) {
// printf("(2) state %d -> Close\n", ep->state); // DEBUG: log
ep->state = Close;
continue;
}
Expand All @@ -356,7 +349,6 @@ static void *dataLoop (UNUSED void *arg) {
// otherwise port-restricted cone NAT might not work properly

if (recvLen < 0 || recvAddrLen != sizeof(recvAddr)) {
// printf("(3) state %d -> Close\n", ep->state); // DEBUG: log
ep->state = Close;
continue;
}
Expand Down Expand Up @@ -407,7 +399,6 @@ int endpoint_init (int (*onPacket)(const uint8_t*, size_t, int)) {
if (ifLen <= 0) return -4;

memcpy(endpoints[i].ifName, ifName, ifLen + 1);
// printf("(4) state %d -> Open\n", endpoints[i].state); // DEBUG: log
endpoints[i].state = Open;
endpoints[i].lastPacketUTime = -1;
}
Expand Down
3 changes: 3 additions & 0 deletions src/monitor-udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#include "protobufs/monitor.pb.h"
#pragma GCC diagnostic pop
#include "globals.h"
#include "config.h"
#include "monitor.h"
Expand Down
3 changes: 3 additions & 0 deletions src/monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
#include <stdint.h>
#include <string.h>
#include "uWebSockets/libuwebsockets.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#include "protobufs/monitor.pb.h"
#pragma GCC diagnostic pop
#include "globals.h"
#include "config.h"
#include "monitor.h"
Expand Down
2 changes: 1 addition & 1 deletion src/receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#include "xwait.h"
#include <stdio.h>
#include <stdlib.h>
#include "opus/opus_multistream.h"
Expand All @@ -14,7 +15,6 @@
#include "pcm.h"
#include "endpoint.h"
#include "config.h"
#include "xwait.h"
#include "receiver.h"

static OpusMSDecoder *decoder = NULL;
Expand Down

0 comments on commit eff2ab0

Please sign in to comment.