mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-19 13:09:39 -07:00
Add SeqNum
This commit is contained in:
parent
76a3d67f5e
commit
d9cb444ec6
5 changed files with 132 additions and 2 deletions
|
@ -20,7 +20,8 @@ set(HEADER_FILES
|
||||||
include/chiaki/audioreceiver.h
|
include/chiaki/audioreceiver.h
|
||||||
include/chiaki/video.h
|
include/chiaki/video.h
|
||||||
include/chiaki/videoreceiver.h
|
include/chiaki/videoreceiver.h
|
||||||
include/chiaki/frameprocessor.h)
|
include/chiaki/frameprocessor.h
|
||||||
|
include/chiaki/seqnum.h)
|
||||||
|
|
||||||
set(SOURCE_FILES
|
set(SOURCE_FILES
|
||||||
src/common.c
|
src/common.c
|
||||||
|
|
56
lib/include/chiaki/seqnum.h
Normal file
56
lib/include/chiaki/seqnum.h
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Chiaki.
|
||||||
|
*
|
||||||
|
* Chiaki is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Chiaki is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CHIAKI_SEQNUM_H
|
||||||
|
#define CHIAKI_SEQNUM_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef uint16_t ChiakiSeqNum16;
|
||||||
|
|
||||||
|
#define CHIAKI_SEQ_NUM_16_MAX 0xffff
|
||||||
|
|
||||||
|
static inline bool chiaki_seq_num_16_lt(ChiakiSeqNum16 a, ChiakiSeqNum16 b)
|
||||||
|
{
|
||||||
|
if(a == b)
|
||||||
|
return false;
|
||||||
|
int32_t d = (int32_t)b - (int32_t)a;
|
||||||
|
return (a < b && d < (1 << 15))
|
||||||
|
|| ((a > b) && -d > (1 << 15));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool chiaki_seq_num_16_gt(ChiakiSeqNum16 a, ChiakiSeqNum16 b)
|
||||||
|
{
|
||||||
|
if(a == b)
|
||||||
|
return false;
|
||||||
|
int32_t d = (int32_t)b - (int32_t)a;
|
||||||
|
return (a < b && d > (1 << 15))
|
||||||
|
|| ((a > b) && -d < (1 << 15));
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // CHIAKI_SEQNUM_H
|
|
@ -7,7 +7,8 @@ add_executable(chiaki-unit
|
||||||
http.c
|
http.c
|
||||||
rpcrypt.c
|
rpcrypt.c
|
||||||
gkcrypt.c
|
gkcrypt.c
|
||||||
takion.c)
|
takion.c
|
||||||
|
seqnum.c)
|
||||||
|
|
||||||
target_link_libraries(chiaki-unit chiaki-lib munit)
|
target_link_libraries(chiaki-unit chiaki-lib munit)
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,20 @@
|
||||||
|
|
||||||
#include <munit.h>
|
#include <munit.h>
|
||||||
|
|
||||||
|
extern MunitTest tests_seq_num[];
|
||||||
extern MunitTest tests_http[];
|
extern MunitTest tests_http[];
|
||||||
extern MunitTest tests_rpcrypt[];
|
extern MunitTest tests_rpcrypt[];
|
||||||
extern MunitTest tests_gkcrypt[];
|
extern MunitTest tests_gkcrypt[];
|
||||||
extern MunitTest tests_takion[];
|
extern MunitTest tests_takion[];
|
||||||
|
|
||||||
static MunitSuite suites[] = {
|
static MunitSuite suites[] = {
|
||||||
|
{
|
||||||
|
"/seq_num",
|
||||||
|
tests_seq_num,
|
||||||
|
NULL,
|
||||||
|
1,
|
||||||
|
MUNIT_SUITE_OPTION_NONE
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"/http",
|
"/http",
|
||||||
tests_http,
|
tests_http,
|
||||||
|
|
64
test/seqnum.c
Normal file
64
test/seqnum.c
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Chiaki.
|
||||||
|
*
|
||||||
|
* Chiaki is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Chiaki is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <munit.h>
|
||||||
|
|
||||||
|
#include <chiaki/seqnum.h>
|
||||||
|
|
||||||
|
|
||||||
|
static MunitResult test_seq_num_16(const MunitParameter params[], void *user)
|
||||||
|
{
|
||||||
|
ChiakiSeqNum16 a = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
ChiakiSeqNum16 b = a + 1;
|
||||||
|
munit_assert(chiaki_seq_num_16_gt(b, a));
|
||||||
|
munit_assert(!chiaki_seq_num_16_gt(a, b));
|
||||||
|
munit_assert(chiaki_seq_num_16_lt(a, b));
|
||||||
|
munit_assert(!chiaki_seq_num_16_lt(b, a));
|
||||||
|
a = b;
|
||||||
|
} while(a);
|
||||||
|
|
||||||
|
a = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
ChiakiSeqNum16 b = a + 0xfff;
|
||||||
|
munit_assert(chiaki_seq_num_16_gt(b, a));
|
||||||
|
munit_assert(!chiaki_seq_num_16_gt(a, b));
|
||||||
|
munit_assert(chiaki_seq_num_16_lt(a, b));
|
||||||
|
munit_assert(!chiaki_seq_num_16_lt(b, a));
|
||||||
|
a++;
|
||||||
|
} while(a);
|
||||||
|
|
||||||
|
munit_assert(chiaki_seq_num_16_gt(1, 0xfff5));
|
||||||
|
munit_assert(!chiaki_seq_num_16_gt(0xfff5, 1));
|
||||||
|
|
||||||
|
return MUNIT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MunitTest tests_seq_num[] = {
|
||||||
|
{
|
||||||
|
"/seq_num_16",
|
||||||
|
test_seq_num_16,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
MUNIT_TEST_OPTION_NONE,
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue