-
Notifications
You must be signed in to change notification settings - Fork 4
/
pystreamc.py
executable file
·135 lines (97 loc) · 4.31 KB
/
pystreamc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#This file wraps APIs from libstreamc.so in Python
from ctypes import cdll, c_int, c_double, c_ubyte, c_ulong, Structure, POINTER
N = 624
EWIN = 100
DEC_ALLOC = 10000
class MT19937(Structure):
_fields_ = [("mt" , c_ulong * N),
("mti" , c_int)]
class parameters(Structure):
_fields_ = [("gfpower" , c_int),
("pktsize" , c_int),
("repfreq" , c_double),
("seed" , c_int)]
class packet(Structure) :
_fields_ = [("sourceid" , c_int),
("repairid" , c_int),
("win_s" , c_int),
("win_e" , c_int),
("coes" , POINTER(c_ubyte)),
("syms" , POINTER(c_ubyte))]
class ROW_VEC(Structure) :
pass
class encoder(Structure):
_fields_ = [("cp" , POINTER(parameters)),
("count" , c_int),
("nextsid" , c_int),
("rcount" , c_int),
("bufsize" , c_int),
("snum" , c_int),
("head" , c_int),
("tail" , c_int),
("headsid" , c_int),
("tailsid" , c_int),
("srcpkt" , POINTER(POINTER(c_ubyte)))]
class decoder(Structure):
_fields_ = [("cp" , POINTER(parameters)),
("pbuf" , POINTER(packet)),
("active" , c_int),
("inorder" , c_int),
("win_s" , c_int),
("win_e" , c_int),
("dof" , c_int),
("row" , POINTER(POINTER(ROW_VEC))),
("message" , POINTER(POINTER(c_ubyte))),
("recovered" , POINTER(POINTER(c_ubyte))),
("prev_rep" , c_int),
("prng" , MT19937)]
streamc = cdll.LoadLibrary("libstreamc.so")
##########################
# Wrap encoder functions #
##########################
streamc.initialize_encoder.argtypes = [POINTER(parameters), POINTER(c_ubyte), c_int]
streamc.initialize_encoder.restype = POINTER(encoder)
streamc.enqueue_packet.argtypes = [POINTER(encoder), c_int, POINTER(c_ubyte)]
streamc.enqueue_packet.restype = c_int
streamc.output_repair_packet.argtypes = [POINTER(encoder)]
streamc.output_repair_packet.restype = POINTER(packet)
streamc.output_repair_packet_short.argtypes = [POINTER(encoder), c_int]
streamc.output_repair_packet_short.restype = POINTER(packet)
streamc.output_source_packet.argtypes = [POINTER(encoder)]
streamc.output_source_packet.restype = POINTER(packet)
streamc.flush_acked_packets.argtypes = [POINTER(encoder), c_int]
streamc.flush_acked_packets.restype = None
streamc.visualize_buffer.argtypes = [POINTER(encoder)]
streamc.visualize_buffer.restype = None
streamc.free_packet.argtypes = [POINTER(packet)]
streamc.free_packet.restype = None
streamc.serialize_packet.argtypes = [POINTER(encoder), POINTER(packet)]
streamc.serialize_packet.restype = POINTER(c_ubyte)
streamc.free_serialized_packet.argtypes = [POINTER(c_ubyte)]
streamc.free_serialized_packet.restype = None
streamc.free_encoder.argtypes = [POINTER(encoder)]
streamc.free_encoder.restype = None
##########################
# Wrap decoder functions #
##########################
streamc.initialize_decoder.argtypes = [POINTER(parameters)]
streamc.initialize_decoder.restype = POINTER(decoder)
streamc.activate_decoder.argtypes = [POINTER(decoder), POINTER(packet)]
streamc.activate_decoder.restype = c_int
streamc.deactivate_decoder.argtypes = [POINTER(decoder)]
streamc.deactivate_decoder.restype = c_int
streamc.receive_packet.argtypes = [POINTER(decoder), POINTER(packet)]
streamc.receive_packet.restype = c_int
streamc.process_packet.argtypes = [POINTER(decoder), POINTER(packet)]
streamc.process_packet.restype = c_int
streamc.deserialize_packet.argtypes = [POINTER(decoder), POINTER(c_ubyte)]
streamc.deserialize_packet.restype = POINTER(packet)
streamc.free_decoder.argtypes = [POINTER(decoder)]
streamc.free_decoder.restype = None
#################################################
# Wrap pseudo-random number generator functions #
#################################################
#streamc.mt19937_init.argtypes = [c_ulong, c_ulong]
#streamc.mt19937_init.restype = None
#streamc.mt19937_randint.argtypes = [POINTER(c_ulong) , POINTER(c_int)]
#streamc.mt19937_randint.restype = c_ulong