| 182 | } |
| 183 | |
| 184 | static void *async_buffer_task(void *arg) |
| 185 | { |
| 186 | URLContext *h = arg; |
| 187 | AsyncContext *c = h->priv_data; |
| 188 | RingBuffer *ring = &c->ring; |
| 189 | int ret = 0; |
| 190 | int64_t seek_ret; |
| 191 | |
| 192 | ff_thread_setname("async"); |
| 193 | |
| 194 | while (1) { |
| 195 | int fifo_space, to_copy; |
| 196 | |
| 197 | pthread_mutex_lock(&c->mutex); |
| 198 | if (async_check_interrupt(h)) { |
| 199 | c->io_eof_reached = 1; |
| 200 | c->io_error = AVERROR_EXIT; |
| 201 | pthread_cond_signal(&c->cond_wakeup_main); |
| 202 | pthread_mutex_unlock(&c->mutex); |
| 203 | break; |
| 204 | } |
| 205 | |
| 206 | if (c->seek_request) { |
| 207 | seek_ret = ffurl_seek(c->inner, c->seek_pos, c->seek_whence); |
| 208 | if (seek_ret >= 0) { |
| 209 | c->io_eof_reached = 0; |
| 210 | c->io_error = 0; |
| 211 | ring_reset(ring); |
| 212 | } |
| 213 | |
| 214 | c->seek_completed = 1; |
| 215 | c->seek_ret = seek_ret; |
| 216 | c->seek_request = 0; |
| 217 | |
| 218 | |
| 219 | pthread_cond_signal(&c->cond_wakeup_main); |
| 220 | pthread_mutex_unlock(&c->mutex); |
| 221 | continue; |
| 222 | } |
| 223 | |
| 224 | fifo_space = ring_space(ring); |
| 225 | if (c->io_eof_reached || fifo_space <= 0) { |
| 226 | pthread_cond_signal(&c->cond_wakeup_main); |
| 227 | pthread_cond_wait(&c->cond_wakeup_background, &c->mutex); |
| 228 | pthread_mutex_unlock(&c->mutex); |
| 229 | continue; |
| 230 | } |
| 231 | pthread_mutex_unlock(&c->mutex); |
| 232 | |
| 233 | to_copy = FFMIN(4096, fifo_space); |
| 234 | ret = ring_write(ring, h, to_copy); |
| 235 | |
| 236 | pthread_mutex_lock(&c->mutex); |
| 237 | if (ret <= 0) { |
| 238 | c->io_eof_reached = 1; |
| 239 | if (c->inner_io_error < 0) |
| 240 | c->io_error = c->inner_io_error; |
| 241 | } |
nothing calls this directly
no test coverage detected