summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--other/fun/BUILD.bazel4
-rw-r--r--testing/BUILD.bazel6
-rw-r--r--toxav/rtp.c8
-rw-r--r--toxav/rtp.h12
-rw-r--r--toxav/rtp_test.cpp72
6 files changed, 80 insertions, 23 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a52f11bb..70c234d5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -469,6 +469,7 @@ endfunction()
469 469
470# The actual unit tests follow. 470# The actual unit tests follow.
471# 471#
472unit_test(toxav rtp)
472unit_test(toxcore crypto_core) 473unit_test(toxcore crypto_core)
473unit_test(toxcore util) 474unit_test(toxcore util)
474 475
diff --git a/other/fun/BUILD.bazel b/other/fun/BUILD.bazel
index c3ab510e..93009543 100644
--- a/other/fun/BUILD.bazel
+++ b/other/fun/BUILD.bazel
@@ -10,18 +10,18 @@ cc_binary(
10cc_binary( 10cc_binary(
11 name = "sign", 11 name = "sign",
12 srcs = ["sign.c"], 12 srcs = ["sign.c"],
13 copts = ["-w"],
13 deps = [ 14 deps = [
14 "//c-toxcore/testing:misc_tools", 15 "//c-toxcore/testing:misc_tools",
15 "@libsodium", 16 "@libsodium",
16 ], 17 ],
17 copts = ["-w"],
18) 18)
19 19
20cc_binary( 20cc_binary(
21 name = "strkey", 21 name = "strkey",
22 srcs = ["strkey.c"], 22 srcs = ["strkey.c"],
23 copts = ["-w"],
23 deps = [ 24 deps = [
24 "@libsodium", 25 "@libsodium",
25 ], 26 ],
26 copts = ["-w"],
27) 27)
diff --git a/testing/BUILD.bazel b/testing/BUILD.bazel
index ca354998..afb1a8aa 100644
--- a/testing/BUILD.bazel
+++ b/testing/BUILD.bazel
@@ -30,15 +30,13 @@ cc_binary(
30cc_binary( 30cc_binary(
31 name = "av_test", 31 name = "av_test",
32 srcs = ["av_test.c"], 32 srcs = ["av_test.c"],
33 linkopts = [
34 "-lopencv_highgui",
35 "-lopencv_core",
36 ],
37 deps = [ 33 deps = [
38 "//c-toxcore/toxav", 34 "//c-toxcore/toxav",
39 "//c-toxcore/toxav:monolith", 35 "//c-toxcore/toxav:monolith",
40 "//c-toxcore/toxcore", 36 "//c-toxcore/toxcore",
41 "@portaudio", 37 "@portaudio",
42 "@sndfile", 38 "@sndfile",
39 "@opencv//:core",
40 "@opencv//:highgui",
43 ], 41 ],
44) 42)
diff --git a/toxav/rtp.c b/toxav/rtp.c
index 650fbaf0..06bc6df5 100644
--- a/toxav/rtp.c
+++ b/toxav/rtp.c
@@ -52,8 +52,8 @@ size_t rtp_header_pack(uint8_t *const rdata, const struct RTPHeader *header)
52 p += net_pack_u32(p, header->data_length_full); 52 p += net_pack_u32(p, header->data_length_full);
53 p += net_pack_u32(p, header->received_length_full); 53 p += net_pack_u32(p, header->received_length_full);
54 54
55 for (size_t i = 0; i < sizeof header->csrc / sizeof header->csrc[0]; i++) { 55 for (size_t i = 0; i < RTP_PADDING_FIELDS; i++) {
56 p += net_pack_u32(p, header->csrc[i]); 56 p += net_pack_u32(p, 0);
57 } 57 }
58 58
59 p += net_pack_u16(p, header->offset_lower); 59 p += net_pack_u16(p, header->offset_lower);
@@ -84,9 +84,7 @@ size_t rtp_header_unpack(const uint8_t *data, struct RTPHeader *header)
84 p += net_unpack_u32(p, &header->data_length_full); 84 p += net_unpack_u32(p, &header->data_length_full);
85 p += net_unpack_u32(p, &header->received_length_full); 85 p += net_unpack_u32(p, &header->received_length_full);
86 86
87 for (size_t i = 0; i < sizeof header->csrc / sizeof header->csrc[0]; i++) { 87 p += sizeof(uint32_t) * RTP_PADDING_FIELDS;
88 p += net_unpack_u32(p, &header->csrc[i]);
89 }
90 88
91 p += net_unpack_u16(p, &header->offset_lower); 89 p += net_unpack_u16(p, &header->offset_lower);
92 p += net_unpack_u16(p, &header->data_length_lower); 90 p += net_unpack_u16(p, &header->data_length_lower);
diff --git a/toxav/rtp.h b/toxav/rtp.h
index 3f684ee5..c8af08d7 100644
--- a/toxav/rtp.h
+++ b/toxav/rtp.h
@@ -37,6 +37,12 @@ extern "C" {
37#define RTP_HEADER_SIZE 80 37#define RTP_HEADER_SIZE 80
38 38
39/** 39/**
40 * Number of 32 bit padding fields between \ref RTPHeader::offset_lower and
41 * everything before it.
42 */
43#define RTP_PADDING_FIELDS 11
44
45/**
40 * Payload type identifier. Also used as rtp callback prefix. 46 * Payload type identifier. Also used as rtp callback prefix.
41 */ 47 */
42enum { 48enum {
@@ -98,12 +104,6 @@ struct RTPHeader {
98 uint32_t received_length_full; 104 uint32_t received_length_full;
99 105
100 /** 106 /**
101 * Unused fields. If you want to add more information to this header, remove
102 * one csrc and add the appropriate number of fields in its place.
103 */
104 uint32_t csrc[11];
105
106 /**
107 * Data offset of the current part (lower bits). 107 * Data offset of the current part (lower bits).
108 */ 108 */
109 uint16_t offset_lower; 109 uint16_t offset_lower;
diff --git a/toxav/rtp_test.cpp b/toxav/rtp_test.cpp
index e3b6f10e..60534b07 100644
--- a/toxav/rtp_test.cpp
+++ b/toxav/rtp_test.cpp
@@ -4,17 +4,77 @@
4 4
5#include <gtest/gtest.h> 5#include <gtest/gtest.h>
6 6
7namespace
8{
9
10RTPHeader random_header()
11{
12 return {
13 random_u16(),
14 random_u16(),
15 random_u16(),
16 random_u16(),
17 random_u16(),
18 random_u16(),
19 random_u16(),
20 random_u32(),
21 random_u32(),
22 random_u64(),
23 random_u32(),
24 random_u32(),
25 random_u32(),
26 random_u16(),
27 random_u16(),
28 };
29}
30
7TEST(Rtp, Deserialisation) 31TEST(Rtp, Deserialisation)
8{ 32{
9 RTPHeader header; 33 RTPHeader const header = random_header();
10 random_bytes((uint8_t *)&header, sizeof header);
11 34
12 uint8_t rdata[sizeof(RTPHeader)]; 35 uint8_t rdata[RTP_HEADER_SIZE];
13 EXPECT_EQ(rtp_header_pack(rdata, &header), RTP_HEADER_SIZE); 36 EXPECT_EQ(rtp_header_pack(rdata, &header), RTP_HEADER_SIZE);
14 37
15 RTPHeader unpacked; 38 RTPHeader unpacked = {0};
16 EXPECT_EQ(rtp_header_unpack(rdata, &unpacked), RTP_HEADER_SIZE); 39 EXPECT_EQ(rtp_header_unpack(rdata, &unpacked), RTP_HEADER_SIZE);
17 40
18 EXPECT_EQ(std::string((char const *)&header, sizeof header), 41 EXPECT_EQ(header.protocol_version, unpacked.protocol_version);
19 std::string((char const *)&unpacked, sizeof unpacked)); 42 EXPECT_EQ(header.pe, unpacked.pe);
43 EXPECT_EQ(header.xe, unpacked.xe);
44 EXPECT_EQ(header.cc, unpacked.cc);
45 EXPECT_EQ(header.ma, unpacked.ma);
46 EXPECT_EQ(header.pt, unpacked.pt);
47 EXPECT_EQ(header.sequnum, unpacked.sequnum);
48 EXPECT_EQ(header.timestamp, unpacked.timestamp);
49 EXPECT_EQ(header.ssrc, unpacked.ssrc);
50 EXPECT_EQ(header.flags, unpacked.flags);
51 EXPECT_EQ(header.offset_full, unpacked.offset_full);
52 EXPECT_EQ(header.data_length_full, unpacked.data_length_full);
53 EXPECT_EQ(header.received_length_full, unpacked.received_length_full);
54 EXPECT_EQ(header.offset_lower, unpacked.offset_lower);
55 EXPECT_EQ(header.data_length_lower, unpacked.data_length_lower);
20} 56}
57
58TEST(Rtp, SerialisingAllOnes)
59{
60 RTPHeader header;
61 memset(&header, 0xff, sizeof header);
62
63 uint8_t rdata[RTP_HEADER_SIZE];
64 rtp_header_pack(rdata, &header);
65
66 EXPECT_EQ(std::string((char const *)rdata, sizeof rdata),
67 std::string("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
68 "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
69 "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
70 "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
71 "\x00\x00\x00\x00\x00\x00\x00\x00"
72 "\x00\x00\x00\x00\x00\x00\x00\x00"
73 "\x00\x00\x00\x00\x00\x00\x00\x00"
74 "\x00\x00\x00\x00\x00\x00\x00\x00"
75 "\x00\x00\x00\x00\x00\x00\x00\x00"
76 "\x00\x00\x00\x00\xFF\xFF\xFF\xFF",
77 RTP_HEADER_SIZE));
78}
79
80} // namespace