| 248 | } |
| 249 | |
| 250 | static int async_open(URLContext *h, const char *arg, int flags, AVDictionary **options) |
| 251 | { |
| 252 | AsyncContext *c = h->priv_data; |
| 253 | int ret; |
| 254 | AVIOInterruptCB interrupt_callback = {.callback = async_check_interrupt, .opaque = h}; |
| 255 | |
| 256 | av_strstart(arg, "async:", &arg); |
| 257 | |
| 258 | ret = ring_init(&c->ring, BUFFER_CAPACITY, READ_BACK_CAPACITY); |
| 259 | if (ret < 0) |
| 260 | goto fifo_fail; |
| 261 | |
| 262 | /* wrap interrupt callback */ |
| 263 | c->interrupt_callback = h->interrupt_callback; |
| 264 | ret = ffurl_open_whitelist(&c->inner, arg, flags, &interrupt_callback, options, h->protocol_whitelist, h->protocol_blacklist, h); |
| 265 | if (ret != 0) { |
| 266 | av_log(h, AV_LOG_ERROR, "ffurl_open failed : %s, %s\n", av_err2str(ret), arg); |
| 267 | goto url_fail; |
| 268 | } |
| 269 | |
| 270 | c->logical_size = ffurl_size(c->inner); |
| 271 | h->is_streamed = c->inner->is_streamed; |
| 272 | |
| 273 | ret = pthread_mutex_init(&c->mutex, NULL); |
| 274 | if (ret != 0) { |
| 275 | ret = AVERROR(ret); |
| 276 | av_log(h, AV_LOG_ERROR, "pthread_mutex_init failed : %s\n", av_err2str(ret)); |
| 277 | goto mutex_fail; |
| 278 | } |
| 279 | |
| 280 | ret = pthread_cond_init(&c->cond_wakeup_main, NULL); |
| 281 | if (ret != 0) { |
| 282 | ret = AVERROR(ret); |
| 283 | av_log(h, AV_LOG_ERROR, "pthread_cond_init failed : %s\n", av_err2str(ret)); |
| 284 | goto cond_wakeup_main_fail; |
| 285 | } |
| 286 | |
| 287 | ret = pthread_cond_init(&c->cond_wakeup_background, NULL); |
| 288 | if (ret != 0) { |
| 289 | ret = AVERROR(ret); |
| 290 | av_log(h, AV_LOG_ERROR, "pthread_cond_init failed : %s\n", av_err2str(ret)); |
| 291 | goto cond_wakeup_background_fail; |
| 292 | } |
| 293 | |
| 294 | ret = pthread_create(&c->async_buffer_thread, NULL, async_buffer_task, h); |
| 295 | if (ret) { |
| 296 | ret = AVERROR(ret); |
| 297 | av_log(h, AV_LOG_ERROR, "pthread_create failed : %s\n", av_err2str(ret)); |
| 298 | goto thread_fail; |
| 299 | } |
| 300 | |
| 301 | return 0; |
| 302 | |
| 303 | thread_fail: |
| 304 | pthread_cond_destroy(&c->cond_wakeup_background); |
| 305 | cond_wakeup_background_fail: |
| 306 | pthread_cond_destroy(&c->cond_wakeup_main); |
| 307 | cond_wakeup_main_fail: |
nothing calls this directly
no test coverage detected