Unified · Split
| @@ -102,7 +102,8 @@ typedef struct UDPContext { · 101 unmodified lines | ||
| 102 | 102 | |
| 103 | 103 | /* Circular Buffer variables for use in UDP receive code */ |
| 104 | 104 | int circular_buffer_size; |
| 105 | − AVFifo *fifo; | |
| 105 | + AVFifo *rx_fifo; | |
| 106 | + AVFifo *tx_fifo; | |
| 106 | 107 | int circular_buffer_error; |
| 107 | 108 | int64_t bitrate; /* number of bits to send per second */ |
| 108 | 109 | int64_t burst_bits; |
| @@ -531,7 +532,7 @@ static void *circular_buffer_task_rx( void *_URLContext) · 422 unmodified lines | ||
| 531 | 532 | continue; |
| 532 | 533 | memcpy(s->tmp, &pkt_header, sizeof(pkt_header)); |
| 533 | 534 | |
| 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)) { | |
| 535 | 536 | /* No Space left */ |
| 536 | 537 | if (s->overrun_nonfatal) { |
| 537 | 538 | av_log(h, AV_LOG_WARNING, "Circular buffer overrun. " |
| @@ -545,7 +546,7 @@ static void *circular_buffer_task_rx( void *_URLContext) · 7 unmodified lines | ||
| 545 | 546 | goto end; |
| 546 | 547 | } |
| 547 | 548 | } |
| 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)); | |
| 549 | 550 | pthread_cond_signal(&s->cond); |
| 550 | 551 | } |
| 551 | 552 | |
| @@ -581,22 +582,22 @@ static void *circular_buffer_task_tx( void *_URLContext) · 29 unmodified lines | ||
| 581 | 582 | uint8_t tmp[4]; |
| 582 | 583 | int64_t timestamp; |
| 583 | 584 | |
| 584 | − len = av_fifo_can_read(s->fifo); | |
| 585 | + len = av_fifo_can_read(s->tx_fifo); | |
| 585 | 586 | |
| 586 | 587 | while (len<4) { |
| 587 | 588 | if (s->close_req) |
| 588 | 589 | goto end; |
| 589 | 590 | pthread_cond_wait(&s->cond, &s->mutex); |
| 590 | − len = av_fifo_can_read(s->fifo); | |
| 591 | + len = av_fifo_can_read(s->tx_fifo); | |
| 591 | 592 | } |
| 592 | 593 | |
| 593 | − av_fifo_read(s->fifo, tmp, 4); | |
| 594 | + av_fifo_read(s->tx_fifo, tmp, 4); | |
| 594 | 595 | len = AV_RL32(tmp); |
| 595 | 596 | |
| 596 | 597 | av_assert0(len >= 0); |
| 597 | 598 | av_assert0(len <= sizeof(s->tmp)); |
| 598 | 599 | |
| 599 | − av_fifo_read(s->fifo, s->tmp, len); | |
| 600 | + av_fifo_read(s->tx_fifo, s->tmp, len); | |
| 600 | 601 | |
| 601 | 602 | pthread_mutex_unlock(&s->mutex); |
| 602 | 603 | |
| @@ -948,11 +949,15 @@ static int udp_open(URLContext *h, const char *uri, int flags) · 345 unmodified lines | ||
| 948 | 949 | |
| 949 | 950 | if ((!is_output && s->circular_buffer_size) || (is_output && s->bitrate && s->circular_buffer_size)) { |
| 950 | 951 | /* 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) { | |
| 953 | 954 | ret = AVERROR(ENOMEM); |
| 954 | 955 | goto fail; |
| 955 | 956 | } |
| 957 | + if (is_output) | |
| 958 | + s->tx_fifo = fifo; | |
| 959 | + else | |
| 960 | + s->rx_fifo = fifo; | |
| 956 | 961 | ret = pthread_mutex_init(&s->mutex, NULL); |
| 957 | 962 | if (ret != 0) { |
| 958 | 963 | 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 | ||
| 985 | 990 | fail: |
| 986 | 991 | if (udp_fd >= 0) |
| 987 | 992 | closesocket(udp_fd); |
| 988 | − av_fifo_freep2(&s->fifo); | |
| 993 | + av_fifo_freep2(&s->rx_fifo); | |
| 994 | + av_fifo_freep2(&s->tx_fifo); | |
| 989 | 995 | ff_ip_reset_filters(&s->filters); |
| 990 | 996 | return ret; |
| 991 | 997 | } |
| @@ -1007,14 +1013,14 @@ static int udp_read(URLContext *h, uint8_t *buf, int size) · 15 unmodified lines | ||
| 1007 | 1013 | #if HAVE_PTHREAD_CANCEL |
| 1008 | 1014 | int avail, nonblock = h->flags & AVIO_FLAG_NONBLOCK; |
| 1009 | 1015 | |
| 1010 | − if (s->fifo) { | |
| 1016 | + if (s->rx_fifo) { | |
| 1011 | 1017 | pthread_mutex_lock(&s->mutex); |
| 1012 | 1018 | do { |
| 1013 | − avail = av_fifo_can_read(s->fifo); | |
| 1019 | + avail = av_fifo_can_read(s->rx_fifo); | |
| 1014 | 1020 | if (avail) { // >=size) { |
| 1015 | 1021 | UDPQueuedPacketHeader header; |
| 1016 | 1022 | |
| 1017 | − av_fifo_read(s->fifo, &header, sizeof(header)); | |
| 1023 | + av_fifo_read(s->rx_fifo, &header, sizeof(header)); | |
| 1018 | 1024 | |
| 1019 | 1025 | s->last_recv_addr = header.addr; |
| 1020 | 1026 | 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 | ||
| 1025 | 1031 | avail = size; |
| 1026 | 1032 | } |
| 1027 | 1033 | |
| 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); | |
| 1030 | 1036 | pthread_mutex_unlock(&s->mutex); |
| 1031 | 1037 | return avail; |
| 1032 | 1038 | } 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 | ||
| 1073 | 1079 | int ret; |
| 1074 | 1080 | |
| 1075 | 1081 | #if HAVE_PTHREAD_CANCEL |
| 1076 | − if (s->fifo) { | |
| 1082 | + if (s->tx_fifo) { | |
| 1077 | 1083 | uint8_t tmp[4]; |
| 1078 | 1084 | |
| 1079 | 1085 | pthread_mutex_lock(&s->mutex); |
| @@ -1088,14 +1094,14 @@ static int udp_write(URLContext *h, const uint8_t *buf, int size) · 8 unmodified lines | ||
| 1088 | 1094 | return err; |
| 1089 | 1095 | } |
| 1090 | 1096 | |
| 1091 | − if (av_fifo_can_write(s->fifo) < size + 4) { | |
| 1097 | + if (av_fifo_can_write(s->tx_fifo) < size + 4) { | |
| 1092 | 1098 | /* What about a partial packet tx ? */ |
| 1093 | 1099 | pthread_mutex_unlock(&s->mutex); |
| 1094 | 1100 | return AVERROR(ENOMEM); |
| 1095 | 1101 | } |
| 1096 | 1102 | 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 */ | |
| 1099 | 1105 | pthread_cond_signal(&s->cond); |
| 1100 | 1106 | pthread_mutex_unlock(&s->mutex); |
| 1101 | 1107 | return size; |
| @@ -1157,7 +1163,8 @@ static int udp_close(URLContext *h) · 55 unmodified lines | ||
| 1157 | 1163 | } |
| 1158 | 1164 | #endif |
| 1159 | 1165 | closesocket(s->udp_fd); |
| 1160 | − av_fifo_freep2(&s->fifo); | |
| 1166 | + av_fifo_freep2(&s->rx_fifo); | |
| 1167 | + av_fifo_freep2(&s->tx_fifo); | |
| 1161 | 1168 | ff_ip_reset_filters(&s->filters); |
| 1162 | 1169 | return 0; |
| 1163 | 1170 | } |