pstreamer / src / measures.c @ dc99f5c4
History | View | Annotate | Download (2.96 KB)
1 |
/*
|
---|---|
2 |
* Copyright (c) 2017 Luca Baldesi
|
3 |
*
|
4 |
* This file is part of PeerStreamer.
|
5 |
*
|
6 |
* PeerStreamer is free software: you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU Affero General Public License as
|
8 |
* published by the Free Software Foundation, either version 3 of the
|
9 |
* License, or (at your option) any later version.
|
10 |
*
|
11 |
* PeerStreamer is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
|
14 |
* General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU Affero General Public License
|
17 |
* along with PeerStreamer. If not, see <http://www.gnu.org/licenses/>.
|
18 |
*
|
19 |
*/
|
20 |
|
21 |
#include<measures.h> |
22 |
#include<string.h> |
23 |
|
24 |
#define DEFAULT_CHUNK_INTERVAL (1000000/25) |
25 |
|
26 |
enum data_state {deinit, loading, ready};
|
27 |
|
28 |
struct chunk_interval_estimate {
|
29 |
uint32_t first_index; |
30 |
uint32_t last_index; |
31 |
uint64_t first_timestamp; |
32 |
suseconds_t chunk_interval; |
33 |
enum data_state state;
|
34 |
}; |
35 |
|
36 |
struct measures {
|
37 |
char * filename;
|
38 |
struct chunk_interval_estimate cie;
|
39 |
}; |
40 |
|
41 |
void chunk_interval_estimate_init(struct chunk_interval_estimate * cie) |
42 |
{ |
43 |
cie->state = deinit; |
44 |
} |
45 |
|
46 |
struct measures * measures_create(const char * filename) |
47 |
{ |
48 |
struct measures * m;
|
49 |
m = malloc(sizeof(struct measures)); |
50 |
chunk_interval_estimate_init(&(m->cie)); |
51 |
return m;
|
52 |
} |
53 |
|
54 |
void measures_destroy(struct measures ** m) |
55 |
{ |
56 |
if (m && *m)
|
57 |
{ |
58 |
free((*m)); |
59 |
} |
60 |
} |
61 |
|
62 |
int8_t measures_add_node(struct measures * m, struct nodeID * id) |
63 |
{ |
64 |
return 0; |
65 |
} |
66 |
|
67 |
int8_t reg_chunk_playout(struct measures * m, int id, bool b, uint64_t timestamp) |
68 |
{ |
69 |
return 0; |
70 |
} |
71 |
|
72 |
int8_t reg_chunk_duplicate(struct measures * m)
|
73 |
{ |
74 |
return 0; |
75 |
} |
76 |
|
77 |
int8_t reg_neigh_size(struct measures * m, size_t t)
|
78 |
{ |
79 |
return 0; |
80 |
} |
81 |
|
82 |
int8_t reg_offer_accept_in(struct measures * m, uint8_t t)
|
83 |
{ |
84 |
return 0; |
85 |
} |
86 |
|
87 |
int8_t reg_chunk_receive(struct measures * m, int cid, uint64_t ctimestamp, int hopcount, int8_t old, int8_t duplicate) |
88 |
{ |
89 |
if (!duplicate) // chunk interval estimation |
90 |
{ |
91 |
switch (m->cie.state) {
|
92 |
case deinit:
|
93 |
m->cie.first_index = cid; |
94 |
m->cie.last_index = cid; |
95 |
m->cie.first_timestamp = ctimestamp; |
96 |
m->cie.state = loading; |
97 |
break;
|
98 |
case loading:
|
99 |
case ready:
|
100 |
if (cid > (int64_t)m->cie.last_index)
|
101 |
{ |
102 |
m->cie.chunk_interval = ((ctimestamp - m->cie.first_timestamp))/(cid - m->cie.first_index); |
103 |
m->cie.last_index = cid; |
104 |
} |
105 |
m->cie.state = ready; |
106 |
break;
|
107 |
} |
108 |
} |
109 |
return 0; |
110 |
} |
111 |
|
112 |
int8_t reg_offer_accept_out(struct measures * m, uint8_t t)
|
113 |
{ |
114 |
return 0; |
115 |
} |
116 |
|
117 |
int8_t reg_chunk_send(struct measures * m, int id) |
118 |
{ |
119 |
return 0; |
120 |
} |
121 |
|
122 |
int8_t timeout_reception_measure(const struct nodeID * id) |
123 |
{ |
124 |
return 0; |
125 |
} |
126 |
|
127 |
int8_t offer_accept_rtt_measure(const struct nodeID * id, uint64_t rtt) |
128 |
{ |
129 |
return 0; |
130 |
} |
131 |
|
132 |
int8_t reception_measure(const struct nodeID * id) |
133 |
{ |
134 |
return 0; |
135 |
} |
136 |
|
137 |
suseconds_t chunk_interval_measure(const struct measures *m) |
138 |
{ |
139 |
if (m->cie.state == ready)
|
140 |
return m->cie.chunk_interval;
|
141 |
return DEFAULT_CHUNK_INTERVAL;
|
142 |
} |