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

Function circular_buffer_task_tx

libavformat/udp.c:591–686  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

589}
590
591static void *circular_buffer_task_tx( void *_URLContext)
592{
593 URLContext *h = _URLContext;
594 UDPContext *s = h->priv_data;
595 int64_t target_timestamp = av_gettime_relative();
596 int64_t start_timestamp = av_gettime_relative();
597 int64_t sent_bits = 0;
598 int64_t burst_interval = s->bitrate ? (s->burst_bits * 1000000 / s->bitrate) : 0;
599 int64_t max_delay = s->bitrate ? ((int64_t)h->max_packet_size * 8 * 1000000 / s->bitrate + 1) : 0;
600
601 ff_thread_setname("udp-tx");
602
603 pthread_mutex_lock(&s->mutex);
604
605 if (ff_socket_nonblock(s->udp_fd, 0) < 0) {
606 av_log(h, AV_LOG_ERROR, "Failed to set blocking mode");
607 s->circular_buffer_error = AVERROR(EIO);
608 goto end;
609 }
610
611 for(;;) {
612 int len;
613 const uint8_t *p;
614 uint8_t tmp[4];
615 int64_t timestamp;
616
617 len = av_fifo_can_read(s->tx_fifo);
618
619 while (len<4) {
620 if (s->close_req)
621 goto end;
622 pthread_cond_wait(&s->cond, &s->mutex);
623 len = av_fifo_can_read(s->tx_fifo);
624 }
625
626 av_fifo_read(s->tx_fifo, tmp, 4);
627 len = AV_RL32(tmp);
628
629 av_assert0(len >= 0);
630 av_assert0(len <= sizeof(s->tmp));
631
632 av_fifo_read(s->tx_fifo, s->tmp, len);
633
634 pthread_mutex_unlock(&s->mutex);
635
636 if (s->bitrate) {
637 timestamp = av_gettime_relative();
638 if (timestamp < target_timestamp) {
639 int64_t delay = target_timestamp - timestamp;
640 if (delay > max_delay) {
641 delay = max_delay;
642 start_timestamp = timestamp + delay;
643 sent_bits = 0;
644 }
645 av_usleep(delay);
646 } else {
647 if (timestamp - burst_interval > target_timestamp) {
648 start_timestamp = timestamp - burst_interval;

Callers

nothing calls this directly

Calls 11

av_gettime_relativeFunction · 0.85
ff_thread_setnameFunction · 0.85
ff_socket_nonblockFunction · 0.85
av_logFunction · 0.85
av_fifo_can_readFunction · 0.85
av_fifo_readFunction · 0.85
av_usleepFunction · 0.85
ff_neterrnoFunction · 0.85
pthread_mutex_lockFunction · 0.50
pthread_cond_waitFunction · 0.50
pthread_mutex_unlockFunction · 0.50

Tested by

no test coverage detected