… | |
… | |
46 | |
46 | |
47 | #include <loader.h> |
47 | #include <loader.h> |
48 | |
48 | |
49 | #define BG_SCRUB_RATE 4 // how often to send a face in the background |
49 | #define BG_SCRUB_RATE 4 // how often to send a face in the background |
50 | |
50 | |
51 | #define MAX_QUEUE_DEPTH 500 |
51 | #define MAX_QUEUE_DEPTH 50 |
52 | #define MAX_QUEUE_BACKLOG 3. |
52 | #define MAX_QUEUE_BACKLOG 3. |
53 | |
53 | |
54 | void |
54 | void |
55 | client::reset_state () |
55 | client::reset_state () |
56 | { |
56 | { |
… | |
… | |
165 | while (scrub_idx < faces.size () - 1) |
165 | while (scrub_idx < faces.size () - 1) |
166 | { |
166 | { |
167 | ++scrub_idx; |
167 | ++scrub_idx; |
168 | |
168 | |
169 | if (!faces_sent [scrub_idx]) |
169 | if (!faces_sent [scrub_idx]) |
|
|
170 | if (faceinfo *f = face_info (scrub_idx)) |
|
|
171 | if (f->type == FT_FACE) // only scrub faces for now |
170 | { |
172 | { |
171 | send_face (scrub_idx); |
173 | send_face (scrub_idx, -120); |
172 | flush_fx (); |
174 | flush_fx (); |
173 | |
175 | |
174 | bg_scrub = 1; // send up to one face per tick, unless an image was requested |
176 | bg_scrub = 1; // send up to one face per tick, unless an image was requested |
175 | break; |
177 | break; |
176 | } |
178 | } |
177 | } |
179 | } |
178 | |
180 | |
179 | rate_avail = max_rate - outputbuffer_len (); |
181 | rate_avail = max_rate - outputbuffer_len (); |
180 | } |
182 | } |
181 | else |
183 | else |
182 | { |
184 | { |
183 | int ol = outputbuffer_len (); |
185 | int ol = outputbuffer_len (); |
184 | |
186 | |
185 | rate_avail = min (max_rate, rate_avail + max_rate); |
187 | rate_avail = min (max_rate + mss, rate_avail + max_rate); |
|
|
188 | |
|
|
189 | int avail = rate_avail; |
|
|
190 | |
|
|
191 | // if we can split images, round to next-lowest mss |
|
|
192 | if (fxix) avail -= avail % mss; |
|
|
193 | |
186 | rate_avail -= ol; |
194 | rate_avail -= ol; |
|
|
195 | avail -= ol; |
187 | |
196 | |
188 | int avail = rate_avail; |
197 | #if HAVE_TCP_INFO |
189 | |
198 | // further restrict the available bandwidth by the excess bandwidth available |
190 | // if we can split images, transfer up to mss-sized packets if possible |
199 | avail = max (0, min (avail, (tcpi.tcpi_snd_cwnd - tcpi.tcpi_unacked + tcpi.tcpi_sacked) * mss)); |
191 | // but never 768 bytes more. |
200 | #endif |
192 | if (fxix) avail += min (768, mss - (ol % mss)); |
|
|
193 | |
201 | |
194 | bg_scrub = BG_SCRUB_RATE; |
202 | bg_scrub = BG_SCRUB_RATE; |
195 | |
203 | |
196 | while (avail > 0) |
204 | while (avail > 0) |
197 | { |
205 | { |
… | |
… | |
199 | |
207 | |
200 | if (facedata *d = face_data (ix.idx, faceset)) |
208 | if (facedata *d = face_data (ix.idx, faceset)) |
201 | { |
209 | { |
202 | if (fxix) |
210 | if (fxix) |
203 | { |
211 | { |
204 | // 9 bytes is enough for fx_FFFOOO, 240 leaves some room for image data |
212 | // estimate the packet header overhead "ix " + idx + (new)ofs |
205 | int chunk = min (min (avail - 240, MAXSOCKBUF - 9), ix.ofs); |
213 | int pktlen = 3 + ber32::encoded_size (ix.idx) + ber32::encoded_size (ix.ofs); |
|
|
214 | int chunk = min (avail - packet::hdrlen, MAXSOCKBUF) - pktlen; |
206 | |
215 | |
|
|
216 | // only transfer something if the amount of data transferred |
|
|
217 | // has a healthy relation to the header overhead |
207 | if (chunk <= 0) |
218 | if (chunk < 64) |
208 | break; |
219 | break; |
209 | |
220 | |
|
|
221 | chunk = min (chunk, (int)ix.ofs); |
|
|
222 | |
210 | ix.ofs -= chunk; |
223 | ix.ofs -= chunk; |
|
|
224 | |
|
|
225 | //fprintf (stderr, "i%dx %6d: %5d+%4d (%4d)\n", fxix, ix.idx,ix.ofs,chunk, ixface.size());//D |
211 | |
226 | |
212 | packet sl ("ix"); |
227 | packet sl ("ix"); |
213 | |
228 | |
214 | sl << ber32 (ix.idx) |
229 | sl << ber32 (ix.idx) |
215 | << ber32 (ix.ofs) |
230 | << ber32 (ix.ofs) |