… | |
… | |
156 | draw_client_map (pl); |
156 | draw_client_map (pl); |
157 | |
157 | |
158 | if (update_look) |
158 | if (update_look) |
159 | esrv_draw_look (pl); |
159 | esrv_draw_look (pl); |
160 | |
160 | |
|
|
161 | bool overload = false; |
|
|
162 | |
|
|
163 | #if HAVE_TCP_INFO |
|
|
164 | // do bandwidth checking |
|
|
165 | if (tcpi.tcpi_unacked + 1 > max (4, tcpi.tcpi_snd_cwnd)) |
|
|
166 | { |
|
|
167 | overload = true; |
|
|
168 | if (next_rate_adjust <= NOW) |
|
|
169 | { |
|
|
170 | next_rate_adjust = NOW + 2; |
|
|
171 | max_rate = max (max_rate >> 1, int (5000 * TICK)); |
|
|
172 | LOG (llevDebug, "tcp %s overloaded (%d + 1 > 4 | %d), rate now %d\n", |
|
|
173 | host, (int)tcpi.tcpi_unacked, (int)tcpi.tcpi_snd_cwnd, int (max_rate / TICK));//D |
|
|
174 | send_packet_printf ("drawinfo %d Due to possible network congestion, your output-rate has been reduced to %dbps.", |
|
|
175 | NDI_RED, int (max_rate / TICK)); |
|
|
176 | } |
|
|
177 | } |
|
|
178 | #endif |
|
|
179 | |
|
|
180 | if (!overload) |
|
|
181 | { |
161 | if (ixface.empty ()) |
182 | if (ixface.empty ()) |
162 | { |
183 | { |
163 | // regularly send a new face when queue is empty |
184 | // regularly send a new face when queue is empty |
164 | if (bg_scrub && !--bg_scrub && enable_bg_scrub) |
185 | if (bg_scrub && !--bg_scrub && enable_bg_scrub) |
165 | while (scrub_idx < faces.size () - 1) |
186 | while (scrub_idx < faces.size () - 1) |
166 | { |
|
|
167 | ++scrub_idx; |
|
|
168 | |
|
|
169 | if (!faces_sent [scrub_idx]) |
|
|
170 | { |
187 | { |
|
|
188 | ++scrub_idx; |
|
|
189 | |
|
|
190 | if (!faces_sent [scrub_idx]) |
|
|
191 | if (faceinfo *f = face_info (scrub_idx)) |
|
|
192 | if (f->type == FT_FACE) // only scrub faces for now |
|
|
193 | { |
171 | send_face (scrub_idx); |
194 | send_face (scrub_idx, -120); |
172 | flush_fx (); |
195 | flush_fx (); |
173 | |
196 | |
174 | bg_scrub = 1; // send up to one face per tick, unless an image was requested |
197 | bg_scrub = 1; // send up to one face per tick, unless an image was requested |
175 | break; |
198 | break; |
|
|
199 | } |
176 | } |
200 | } |
177 | } |
|
|
178 | |
201 | |
179 | rate_avail = max_rate - outputbuffer_len (); |
202 | rate_avail = max_rate - outputbuffer_len (); |
180 | } |
203 | } |
181 | else |
204 | else |
182 | { |
205 | { |
183 | int ol = outputbuffer_len (); |
206 | int ol = outputbuffer_len (); |
184 | |
207 | |
185 | rate_avail = min (max_rate, rate_avail + max_rate); |
208 | rate_avail = min (max_rate, rate_avail + max_rate); |
186 | rate_avail -= ol; |
209 | rate_avail -= ol; |
187 | |
210 | |
188 | int avail = rate_avail; |
211 | int avail = rate_avail; |
189 | |
212 | |
190 | // if we can split images, transfer up to mss-sized packets if possible |
213 | // if we can split images, transfer up to mss-sized packets if possible |
191 | // but never 768 bytes more. |
214 | // but never 768 bytes more. |
192 | if (fxix) avail += min (768, mss - (ol % mss)); |
215 | if (fxix) avail += min (768, mss - (ol % mss)); |
193 | |
216 | |
194 | bg_scrub = BG_SCRUB_RATE; |
217 | bg_scrub = BG_SCRUB_RATE; |
195 | |
218 | |
196 | while (avail > 0) |
219 | while (avail > 0) |
197 | { |
|
|
198 | ixsend &ix = ixface.back (); |
|
|
199 | |
|
|
200 | if (facedata *d = face_data (ix.idx, faceset)) |
|
|
201 | { |
220 | { |
202 | if (fxix) |
221 | ixsend &ix = ixface.back (); |
|
|
222 | |
|
|
223 | if (facedata *d = face_data (ix.idx, faceset)) |
203 | { |
224 | { |
|
|
225 | if (fxix) |
|
|
226 | { |
204 | // only transfer something if the amount of data transferred |
227 | // only transfer something if the amount of data transferred |
205 | // has a healthy relation to the header overhead |
228 | // has a healthy relation to the header overhead |
206 | if (avail <= 40) |
229 | if (avail <= 40) |
207 | break; |
230 | break; |
208 | |
231 | |
209 | // 9 bytes is enough for fx_FFFOOO |
232 | // 9 bytes is enough for fx_FFFOOO |
210 | int chunk = min (min (avail, MAXSOCKBUF - 9), (int)ix.ofs); |
233 | int chunk = min (min (avail, MAXSOCKBUF - 9), (int)ix.ofs); |
211 | |
234 | |
212 | if (chunk <= 0) |
235 | if (chunk <= 0) |
213 | break; |
236 | break; |
214 | |
237 | |
215 | ix.ofs -= chunk; |
238 | ix.ofs -= chunk; |
216 | |
239 | |
|
|
240 | //fprintf (stderr, "i%dx %6d: %5d+%4d (%4d)\n", fxix, ix.idx,ix.ofs,chunk, ixface.size());//D |
|
|
241 | |
217 | packet sl ("ix"); |
242 | packet sl ("ix"); |
218 | |
243 | |
219 | sl << ber32 (ix.idx) |
244 | sl << ber32 (ix.idx) |
220 | << ber32 (ix.ofs) |
245 | << ber32 (ix.ofs) |
221 | << data (d->data.data () + ix.ofs, chunk); |
246 | << data (d->data.data () + ix.ofs, chunk); |
222 | |
247 | |
223 | send_packet (sl); |
248 | send_packet (sl); |
|
|
249 | } |
|
|
250 | else |
|
|
251 | { |
|
|
252 | send_image (ix.idx); |
|
|
253 | ix.ofs = 0; |
|
|
254 | } |
224 | } |
255 | } |
225 | else |
256 | else |
|
|
257 | ix.ofs = 0; |
|
|
258 | |
|
|
259 | int consumed = outputbuffer_len () - ol; |
|
|
260 | |
|
|
261 | avail -= consumed; |
|
|
262 | rate_avail -= consumed; |
|
|
263 | |
|
|
264 | ol = outputbuffer_len (); |
|
|
265 | |
|
|
266 | if (!ix.ofs) |
226 | { |
267 | { |
227 | send_image (ix.idx); |
268 | ixface.pop_back (); |
228 | ix.ofs = 0; |
269 | |
|
|
270 | if (ixface.empty ()) |
|
|
271 | break; |
229 | } |
272 | } |
230 | } |
273 | } |
231 | else |
|
|
232 | ix.ofs = 0; |
|
|
233 | |
|
|
234 | int consumed = outputbuffer_len () - ol; |
|
|
235 | |
|
|
236 | avail -= consumed; |
|
|
237 | rate_avail -= consumed; |
|
|
238 | |
|
|
239 | ol = outputbuffer_len (); |
|
|
240 | |
|
|
241 | if (!ix.ofs) |
|
|
242 | { |
|
|
243 | ixface.pop_back (); |
|
|
244 | |
|
|
245 | if (ixface.empty ()) |
|
|
246 | break; |
|
|
247 | } |
274 | } |
248 | } |
|
|
249 | } |
275 | } |
250 | } |
276 | } |
251 | |
277 | |