| 338 | } |
| 339 | |
| 340 | static int async_read_internal(URLContext *h, void *dest, int size) |
| 341 | { |
| 342 | AsyncContext *c = h->priv_data; |
| 343 | RingBuffer *ring = &c->ring; |
| 344 | int read_complete = !dest; |
| 345 | int to_read = size; |
| 346 | int ret = 0; |
| 347 | |
| 348 | pthread_mutex_lock(&c->mutex); |
| 349 | |
| 350 | while (to_read > 0) { |
| 351 | int fifo_size, to_copy; |
| 352 | if (async_check_interrupt(h)) { |
| 353 | ret = AVERROR_EXIT; |
| 354 | break; |
| 355 | } |
| 356 | fifo_size = ring_size(ring); |
| 357 | to_copy = FFMIN(to_read, fifo_size); |
| 358 | if (to_copy > 0) { |
| 359 | ring_read(ring, dest, to_copy); |
| 360 | if (dest) |
| 361 | dest = (uint8_t *)dest + to_copy; |
| 362 | c->logical_pos += to_copy; |
| 363 | to_read -= to_copy; |
| 364 | ret = size - to_read; |
| 365 | |
| 366 | if (to_read <= 0 || !read_complete) |
| 367 | break; |
| 368 | } else if (c->io_eof_reached) { |
| 369 | if (ret <= 0) { |
| 370 | if (c->io_error) |
| 371 | ret = c->io_error; |
| 372 | else |
| 373 | ret = AVERROR_EOF; |
| 374 | } |
| 375 | break; |
| 376 | } |
| 377 | pthread_cond_signal(&c->cond_wakeup_background); |
| 378 | pthread_cond_wait(&c->cond_wakeup_main, &c->mutex); |
| 379 | } |
| 380 | |
| 381 | pthread_cond_signal(&c->cond_wakeup_background); |
| 382 | pthread_mutex_unlock(&c->mutex); |
| 383 | |
| 384 | return ret; |
| 385 | } |
| 386 | |
| 387 | static int async_read(URLContext *h, unsigned char *buf, int size) |
| 388 | { |
no test coverage detected