Unified · Split
| @@ -102,7 +102,8 @@ typedef struct UDPContext { · 101 unmodified lines | |||
| 102 | 102 | ||
| 103 | /* Circular Buffer variables for use in UDP receive code */ | 103 | /* Circular Buffer variables for use in UDP receive code */ |
| 104 | int circular_buffer_size; | 104 | int circular_buffer_size; |
| 105 | AVFifo *fifo; | 105 | AVFifo *rx_fifo; |
| 106 | AVFifo *tx_fifo; | ||
| 106 | int circular_buffer_error; | 107 | int circular_buffer_error; |
| 107 | int64_t bitrate; /* number of bits to send per second */ | 108 | int64_t bitrate; /* number of bits to send per second */ |
| 108 | int64_t burst_bits; | 109 | int64_t burst_bits; |
| @@ -531,7 +532,7 @@ static void *circular_buffer_task_rx( void *_URLContext) · 422 unmodified lines | |||
| 531 | continue; | 532 | continue; |
| 532 | memcpy(s->tmp, &pkt_header, sizeof(pkt_header)); | 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 | /* No Space left */ | 536 | /* No Space left */ |
| 536 | if (s->overrun_nonfatal) { | 537 | if (s->overrun_nonfatal) { |
| 537 | av_log(h, AV_LOG_WARNING, "Circular buffer overrun. " | 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 | goto end; | 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 | pthread_cond_signal(&s->cond); | 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 | uint8_t tmp[4]; | 582 | uint8_t tmp[4]; |
| 582 | int64_t timestamp; | 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 | while (len<4) { | 587 | while (len<4) { |
| 587 | if (s->close_req) | 588 | if (s->close_req) |
| 588 | goto end; | 589 | goto end; |
| 589 | pthread_cond_wait(&s->cond, &s->mutex); | 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 | len = AV_RL32(tmp); | 595 | len = AV_RL32(tmp); |
| 595 | 596 | ||
| 596 | av_assert0(len >= 0); | 597 | av_assert0(len >= 0); |
| 597 | av_assert0(len <= sizeof(s->tmp)); | 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 | pthread_mutex_unlock(&s->mutex); | 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 | if ((!is_output && s->circular_buffer_size) || (is_output && s->bitrate && s->circular_buffer_size)) { | 950 | if ((!is_output && s->circular_buffer_size) || (is_output && s->bitrate && s->circular_buffer_size)) { |
| 950 | /* start the task going */ | 951 | /* start the task going */ |
| 951 | s->fifo = av_fifo_alloc2(s->circular_buffer_size, 1, 0); | 952 | AVFifo *fifo = av_fifo_alloc2(s->circular_buffer_size, 1, 0); |
| 952 | if (!s->fifo) { | 953 | if (!fifo) { |
| 953 | ret = AVERROR(ENOMEM); | 954 | ret = AVERROR(ENOMEM); |
| 954 | goto fail; | 955 | goto fail; |
| 955 | } | 956 | } |
| 957 | if (is_output) | ||
| 958 | s->tx_fifo = fifo; | ||
| 959 | else | ||
| 960 | s->rx_fifo = fifo; | ||
| 956 | ret = pthread_mutex_init(&s->mutex, NULL); | 961 | ret = pthread_mutex_init(&s->mutex, NULL); |
| 957 | if (ret != 0) { | 962 | if (ret != 0) { |
| 958 | av_log(h, AV_LOG_ERROR, "pthread_mutex_init failed : %s\n", strerror(ret)); | 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 | fail: | 990 | fail: |
| 986 | if (udp_fd >= 0) | 991 | if (udp_fd >= 0) |
| 987 | closesocket(udp_fd); | 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 | ff_ip_reset_filters(&s->filters); | 995 | ff_ip_reset_filters(&s->filters); |
| 990 | return ret; | 996 | return ret; |
| 991 | } | 997 | } |
| @@ -1007,14 +1013,14 @@ static int udp_read(URLContext *h, uint8_t *buf, int size) · 15 unmodified lines | |||
| 1007 | #if HAVE_PTHREAD_CANCEL | 1013 | #if HAVE_PTHREAD_CANCEL |
| 1008 | int avail, nonblock = h->flags & AVIO_FLAG_NONBLOCK; | 1014 | int avail, nonblock = h->flags & AVIO_FLAG_NONBLOCK; |
| 1009 | 1015 | ||
| 1010 | if (s->fifo) { | 1016 | if (s->rx_fifo) { |
| 1011 | pthread_mutex_lock(&s->mutex); | 1017 | pthread_mutex_lock(&s->mutex); |
| 1012 | do { | 1018 | do { |
| 1013 | avail = av_fifo_can_read(s->fifo); | 1019 | avail = av_fifo_can_read(s->rx_fifo); |
| 1014 | if (avail) { // >=size) { | 1020 | if (avail) { // >=size) { |
| 1015 | UDPQueuedPacketHeader header; | 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 | s->last_recv_addr = header.addr; | 1025 | s->last_recv_addr = header.addr; |
| 1020 | s->last_recv_addr_len = header.addr_len; | 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 | avail = size; | 1031 | avail = size; |
| 1026 | } | 1032 | } |
| 1027 | 1033 | ||
| 1028 | av_fifo_read(s->fifo, buf, avail); | 1034 | av_fifo_read(s->rx_fifo, buf, avail); |
| 1029 | av_fifo_drain2(s->fifo, header.pkt_size - avail); | 1035 | av_fifo_drain2(s->rx_fifo, header.pkt_size - avail); |
| 1030 | pthread_mutex_unlock(&s->mutex); | 1036 | pthread_mutex_unlock(&s->mutex); |
| 1031 | return avail; | 1037 | return avail; |
| 1032 | } else if(s->circular_buffer_error){ | 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 | int ret; | 1079 | int ret; |
| 1074 | 1080 | ||
| 1075 | #if HAVE_PTHREAD_CANCEL | 1081 | #if HAVE_PTHREAD_CANCEL |
| 1076 | if (s->fifo) { | 1082 | if (s->tx_fifo) { |
| 1077 | uint8_t tmp[4]; | 1083 | uint8_t tmp[4]; |
| 1078 | 1084 | ||
| 1079 | pthread_mutex_lock(&s->mutex); | 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 | return err; | 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 | /* What about a partial packet tx ? */ | 1098 | /* What about a partial packet tx ? */ |
| 1093 | pthread_mutex_unlock(&s->mutex); | 1099 | pthread_mutex_unlock(&s->mutex); |
| 1094 | return AVERROR(ENOMEM); | 1100 | return AVERROR(ENOMEM); |
| 1095 | } | 1101 | } |
| 1096 | AV_WL32(tmp, size); | 1102 | AV_WL32(tmp, size); |
| 1097 | av_fifo_write(s->fifo, tmp, 4); /* size of packet */ | 1103 | av_fifo_write(s->tx_fifo, tmp, 4); /* size of packet */ |
| 1098 | av_fifo_write(s->fifo, buf, size); /* the data */ | 1104 | av_fifo_write(s->tx_fifo, buf, size); /* the data */ |
| 1099 | pthread_cond_signal(&s->cond); | 1105 | pthread_cond_signal(&s->cond); |
| 1100 | pthread_mutex_unlock(&s->mutex); | 1106 | pthread_mutex_unlock(&s->mutex); |
| 1101 | return size; | 1107 | return size; |
| @@ -1157,7 +1163,8 @@ static int udp_close(URLContext *h) · 55 unmodified lines | |||
| 1157 | } | 1163 | } |
| 1158 | #endif | 1164 | #endif |
| 1159 | closesocket(s->udp_fd); | 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 | ff_ip_reset_filters(&s->filters); | 1168 | ff_ip_reset_filters(&s->filters); |
| 1162 | return 0; | 1169 | return 0; |
| 1163 | } | 1170 | } |