MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / async_seek

Function async_seek

libavformat/async.c:392–473  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

390}
391
392static int64_t async_seek(URLContext *h, int64_t pos, int whence)
393{
394 AsyncContext *c = h->priv_data;
395 RingBuffer *ring = &c->ring;
396 int64_t ret;
397 int64_t new_logical_pos;
398 int fifo_size;
399 int fifo_size_of_read_back;
400
401 if (whence == AVSEEK_SIZE) {
402 av_log(h, AV_LOG_TRACE, "async_seek: AVSEEK_SIZE: %"PRId64"\n", (int64_t)c->logical_size);
403 return c->logical_size;
404 } else if (whence == SEEK_CUR) {
405 av_log(h, AV_LOG_TRACE, "async_seek: %"PRId64"\n", pos);
406 new_logical_pos = pos + c->logical_pos;
407 } else if (whence == SEEK_SET){
408 av_log(h, AV_LOG_TRACE, "async_seek: %"PRId64"\n", pos);
409 new_logical_pos = pos;
410 } else {
411 return AVERROR(EINVAL);
412 }
413 if (new_logical_pos < 0)
414 return AVERROR(EINVAL);
415
416 fifo_size = ring_size(ring);
417 fifo_size_of_read_back = ring_size_of_read_back(ring);
418 if (new_logical_pos == c->logical_pos) {
419 /* current position */
420 return c->logical_pos;
421 } else if ((new_logical_pos >= (c->logical_pos - fifo_size_of_read_back)) &&
422 (new_logical_pos < (c->logical_pos + fifo_size + SHORT_SEEK_THRESHOLD))) {
423 int pos_delta = (int)(new_logical_pos - c->logical_pos);
424 /* fast seek */
425 av_log(h, AV_LOG_TRACE, "async_seek: fask_seek %"PRId64" from %d dist:%d/%d\n",
426 new_logical_pos, (int)c->logical_pos,
427 (int)(new_logical_pos - c->logical_pos), fifo_size);
428
429 if (pos_delta > 0) {
430 // fast seek forwards
431 async_read_internal(h, NULL, pos_delta);
432 } else {
433 // fast seek backwards
434 ring_drain(ring, pos_delta);
435 c->logical_pos = new_logical_pos;
436 }
437
438 return c->logical_pos;
439 } else if (c->logical_size <= 0) {
440 /* can not seek */
441 return AVERROR(EINVAL);
442 } else if (new_logical_pos > c->logical_size) {
443 /* beyond end */
444 return AVERROR(EINVAL);
445 }
446
447 pthread_mutex_lock(&c->mutex);
448
449 c->seek_request = 1;

Callers

nothing calls this directly

Calls 10

av_logFunction · 0.85
ring_sizeFunction · 0.85
ring_size_of_read_backFunction · 0.85
async_read_internalFunction · 0.85
ring_drainFunction · 0.85
async_check_interruptFunction · 0.85
pthread_mutex_lockFunction · 0.50
pthread_cond_signalFunction · 0.50
pthread_cond_waitFunction · 0.50
pthread_mutex_unlockFunction · 0.50

Tested by

no test coverage detected