History

avformat/udp: separate rx and tx fifo

Timo Rothenpieler committed 1 year ago

Commit 585cae11 parent af04a271 file · +27 −20Browse files

Unified · Split

libavformat/udp.c+27−20
@@ -102,7 +102,8 @@ typedef struct UDPContext { · 101 unmodified lines
102102
103103 /* Circular Buffer variables for use in UDP receive code */
104104 int circular_buffer_size;
105− AVFifo *fifo;
105+ AVFifo *rx_fifo;
106+ AVFifo *tx_fifo;
106107 int circular_buffer_error;
107108 int64_t bitrate; /* number of bits to send per second */
108109 int64_t burst_bits;
@@ -531,7 +532,7 @@ static void *circular_buffer_task_rx( void *_URLContext) · 422 unmodified lines
531532 continue;
532533 memcpy(s->tmp, &pkt_header, sizeof(pkt_header));
533534
534− if (av_fifo_can_write(s->fifo) < pkt_header.pkt_size + sizeof(pkt_header)) {
535+ if (av_fifo_can_write(s->rx_fifo) < pkt_header.pkt_size + sizeof(pkt_header)) {
535536 /* No Space left */
536537 if (s->overrun_nonfatal) {
537538 av_log(h, AV_LOG_WARNING, "Circular buffer overrun. "
@@ -545,7 +546,7 @@ static void *circular_buffer_task_rx( void *_URLContext) · 7 unmodified lines
545546 goto end;
546547 }
547548 }
548− av_fifo_write(s->fifo, s->tmp, pkt_header.pkt_size + sizeof(pkt_header));
549+ av_fifo_write(s->rx_fifo, s->tmp, pkt_header.pkt_size + sizeof(pkt_header));
549550 pthread_cond_signal(&s->cond);
550551 }
551552
@@ -581,22 +582,22 @@ static void *circular_buffer_task_tx( void *_URLContext) · 29 unmodified lines
581582 uint8_t tmp[4];
582583 int64_t timestamp;
583584
584− len = av_fifo_can_read(s->fifo);
585+ len = av_fifo_can_read(s->tx_fifo);
585586
586587 while (len<4) {
587588 if (s->close_req)
588589 goto end;
589590 pthread_cond_wait(&s->cond, &s->mutex);
590− len = av_fifo_can_read(s->fifo);
591+ len = av_fifo_can_read(s->tx_fifo);
591592 }
592593
593− av_fifo_read(s->fifo, tmp, 4);
594+ av_fifo_read(s->tx_fifo, tmp, 4);
594595 len = AV_RL32(tmp);
595596
596597 av_assert0(len >= 0);
597598 av_assert0(len <= sizeof(s->tmp));
598599
599− av_fifo_read(s->fifo, s->tmp, len);
600+ av_fifo_read(s->tx_fifo, s->tmp, len);
600601
601602 pthread_mutex_unlock(&s->mutex);
602603
@@ -948,11 +949,15 @@ static int udp_open(URLContext *h, const char *uri, int flags) · 345 unmodified lines
948949
949950 if ((!is_output && s->circular_buffer_size) || (is_output && s->bitrate && s->circular_buffer_size)) {
950951 /* start the task going */
951− s->fifo = av_fifo_alloc2(s->circular_buffer_size, 1, 0);
952− if (!s->fifo) {
952+ AVFifo *fifo = av_fifo_alloc2(s->circular_buffer_size, 1, 0);
953+ if (!fifo) {
953954 ret = AVERROR(ENOMEM);
954955 goto fail;
955956 }
957+ if (is_output)
958+ s->tx_fifo = fifo;
959+ else
960+ s->rx_fifo = fifo;
956961 ret = pthread_mutex_init(&s->mutex, NULL);
957962 if (ret != 0) {
958963 av_log(h, AV_LOG_ERROR, "pthread_mutex_init failed : %s\n", strerror(ret));
@@ -985,7 +990,8 @@ static int udp_open(URLContext *h, const char *uri, int flags) · 26 unmodified lines
985990 fail:
986991 if (udp_fd >= 0)
987992 closesocket(udp_fd);
988− av_fifo_freep2(&s->fifo);
993+ av_fifo_freep2(&s->rx_fifo);
994+ av_fifo_freep2(&s->tx_fifo);
989995 ff_ip_reset_filters(&s->filters);
990996 return ret;
991997 }
@@ -1007,14 +1013,14 @@ static int udp_read(URLContext *h, uint8_t *buf, int size) · 15 unmodified lines
10071013 #if HAVE_PTHREAD_CANCEL
10081014 int avail, nonblock = h->flags & AVIO_FLAG_NONBLOCK;
10091015
1010− if (s->fifo) {
1016+ if (s->rx_fifo) {
10111017 pthread_mutex_lock(&s->mutex);
10121018 do {
1013− avail = av_fifo_can_read(s->fifo);
1019+ avail = av_fifo_can_read(s->rx_fifo);
10141020 if (avail) { // >=size) {
10151021 UDPQueuedPacketHeader header;
10161022
1017− av_fifo_read(s->fifo, &header, sizeof(header));
1023+ av_fifo_read(s->rx_fifo, &header, sizeof(header));
10181024
10191025 s->last_recv_addr = header.addr;
10201026 s->last_recv_addr_len = header.addr_len;
@@ -1025,8 +1031,8 @@ static int udp_read(URLContext *h, uint8_t *buf, int size) · 4 unmodified lines
10251031 avail = size;
10261032 }
10271033
1028− av_fifo_read(s->fifo, buf, avail);
1029− av_fifo_drain2(s->fifo, header.pkt_size - avail);
1034+ av_fifo_read(s->rx_fifo, buf, avail);
1035+ av_fifo_drain2(s->rx_fifo, header.pkt_size - avail);
10301036 pthread_mutex_unlock(&s->mutex);
10311037 return avail;
10321038 } else if(s->circular_buffer_error){
@@ -1073,7 +1079,7 @@ static int udp_write(URLContext *h, const uint8_t *buf, int size) · 40 unmodified lines
10731079 int ret;
10741080
10751081 #if HAVE_PTHREAD_CANCEL
1076− if (s->fifo) {
1082+ if (s->tx_fifo) {
10771083 uint8_t tmp[4];
10781084
10791085 pthread_mutex_lock(&s->mutex);
@@ -1088,14 +1094,14 @@ static int udp_write(URLContext *h, const uint8_t *buf, int size) · 8 unmodified lines
10881094 return err;
10891095 }
10901096
1091− if (av_fifo_can_write(s->fifo) < size + 4) {
1097+ if (av_fifo_can_write(s->tx_fifo) < size + 4) {
10921098 /* What about a partial packet tx ? */
10931099 pthread_mutex_unlock(&s->mutex);
10941100 return AVERROR(ENOMEM);
10951101 }
10961102 AV_WL32(tmp, size);
1097− av_fifo_write(s->fifo, tmp, 4); /* size of packet */
1098− av_fifo_write(s->fifo, buf, size); /* the data */
1103+ av_fifo_write(s->tx_fifo, tmp, 4); /* size of packet */
1104+ av_fifo_write(s->tx_fifo, buf, size); /* the data */
10991105 pthread_cond_signal(&s->cond);
11001106 pthread_mutex_unlock(&s->mutex);
11011107 return size;
@@ -1157,7 +1163,8 @@ static int udp_close(URLContext *h) · 55 unmodified lines
11571163 }
11581164 #endif
11591165 closesocket(s->udp_fd);
1160− av_fifo_freep2(&s->fifo);
1166+ av_fifo_freep2(&s->rx_fifo);
1167+ av_fifo_freep2(&s->tx_fifo);
11611168 ff_ip_reset_filters(&s->filters);
11621169 return 0;
11631170 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t