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