Adding clang-tidy and refactoring src/packet/hello.c

This commit is contained in:
Sergiotarxz 2023-03-28 20:09:13 +02:00
parent c8ea2f847b
commit 97db819b1e
2 changed files with 26 additions and 17 deletions

9
.clang-tidy Normal file
View File

@ -0,0 +1,9 @@
Checks: '-*,readability-identifier-naming'
CheckOptions:
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.PrivateMemberPrefix, value: _ }
- { key: readability-identifier-naming.StructCase, value: CamelCase }
- { key: readability-identifier-naming.FunctionCase, value: camelBack }
- { key: readability-identifier-naming.VariableCase, value: camelBack }
- { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE }

View File

@ -45,12 +45,12 @@ msThreadCallbackSetFrame(struct mCoreThread *threadContext) {
unsigned width, height;
unsigned char *rawData = NULL;
size_t rawDataLen = 0;
struct msPacketSendFrame *send_frame = NULL;
struct msPacketSendFrame *sendFrame = NULL;
struct msPacket *packet = NULL;
struct timespec current_date;
timespec_get(&current_date, TIME_UTC);
uint64_t nano_current = SEC_TO_NANO(current_date.tv_sec % 1000) + current_date.tv_nsec;
uint64_t nano_last = SEC_TO_NANO(data->lastFrameDate->tv_sec % 1000) + data->lastFrameDate->tv_nsec + (SEC_TO_NANO(1) / 60);
struct timespec currentDate;
timespec_get(&currentDate, TIME_UTC);
uint64_t nanoCurrent = SEC_TO_NANO(currentDate.tv_sec % 1000) + currentDate.tv_nsec;
uint64_t nanoLast = SEC_TO_NANO(data->lastFrameDate->tv_sec % 1000) + data->lastFrameDate->tv_nsec + (SEC_TO_NANO(1) / 60);
if (!data || !data->coreController) {
goto return_ms_thread_callback_set_frame;
@ -58,17 +58,17 @@ msThreadCallbackSetFrame(struct mCoreThread *threadContext) {
stride = data->coreController->stride;
outputBuffer = data->coreController->outputBuffer;
while (nano_current < nano_last && nano_last != 0 && nano_last - nano_current < SEC_TO_NANO(10)) {
while (nanoCurrent < nanoLast && nanoLast != 0 && nanoLast - nanoCurrent < SEC_TO_NANO(10)) {
usleep(500);
timespec_get(&current_date, TIME_UTC);
nano_current = SEC_TO_NANO(current_date.tv_sec % 1000) + current_date.tv_nsec;
timespec_get(&currentDate, TIME_UTC);
nanoCurrent = SEC_TO_NANO(currentDate.tv_sec % 1000) + currentDate.tv_nsec;
}
*data->lastFrameDate = current_date;
*data->lastFrameDate = currentDate;
data->coreController->threadContext.core->desiredVideoDimensions(data->coreController->threadContext.core, &width, &height);
send_frame = msPacketSendFrameNew(stride, width * height, outputBuffer);
rawData = msPacketSendFrameSerialize(send_frame, &rawDataLen);
sendFrame = msPacketSendFrameNew(stride, width * height, outputBuffer);
rawData = msPacketSendFrameSerialize(sendFrame, &rawDataLen);
if (!rawData) {
goto return_ms_thread_callback_set_frame;
}
@ -77,8 +77,8 @@ msThreadCallbackSetFrame(struct mCoreThread *threadContext) {
msPacketSend(packet, data);
return_ms_thread_callback_set_frame:
if (send_frame) {
msPacketSendFrameDestroy(&send_frame);
if (sendFrame) {
msPacketSendFrameDestroy(&sendFrame);
}
if (packet) {
msPacketDestroy(&packet);
@ -119,7 +119,7 @@ msPacketHelloGet(const struct msPacket *packet, int client_fd,
size_t sizeRom = 0;
size_t sizeSavestate = 0;
size_t reads[4] = { 0,0,0,0 };
size_t total_read = 0;
size_t totalRead = 0;
size_t to_read_size;
#define FREAD(target, size, count, fp, n, goto_to) \
@ -145,10 +145,10 @@ msPacketHelloGet(const struct msPacket *packet, int client_fd,
FREAD(savestate, sizeof *savestate, sizeSavestate, fp, 3, return_get_packet_hello);
for (int i = 0; i<4; i++) {
total_read += reads[i];
totalRead += reads[i];
}
if (total_read != packet->size) {
fprintf (stderr, "Total read (%lu) != packet->size (%lu)\n", total_read, packet->size);
if (totalRead != packet->size) {
fprintf (stderr, "Total read (%lu) != packet->size (%lu)\n", totalRead, packet->size);
goto return_get_packet_hello;
}
hello = calloc(1, sizeof *hello);