diff --git a/libavformat/udp.c b/libavformat/udp.c
index 3835f98..a5a30bf 100644
|
a
|
b
|
static void *circular_buffer_task_tx( void *_URLContext)
|
| 575 | 575 | |
| 576 | 576 | for(;;) { |
| 577 | 577 | int len; |
| | 578 | int buffer_needs; |
| 578 | 579 | const uint8_t *p; |
| 579 | 580 | uint8_t tmp[4]; |
| 580 | 581 | int64_t timestamp; |
| 581 | 582 | |
| 582 | 583 | len=av_fifo_size(s->fifo); |
| 583 | 584 | |
| 584 | | while (len<4) { |
| | 585 | if (len < 4 && !s->close_req){ |
| | 586 | buffer_needs = s->circular_buffer_size / 2; |
| | 587 | av_log(h, AV_LOG_WARNING, "Fifo empty, prefill up to atleast half of buffer:%i\n", buffer_needs); |
| | 588 | } else { |
| | 589 | buffer_needs = 4; |
| | 590 | } |
| | 591 | |
| | 592 | while (len < buffer_needs) { |
| 585 | 593 | if (s->close_req) |
| 586 | 594 | goto end; |
| 587 | 595 | if (pthread_cond_wait(&s->cond, &s->mutex) < 0) { |
| … |
… |
static void *circular_buffer_task_tx( void *_URLContext)
|
| 589 | 597 | } |
| 590 | 598 | len=av_fifo_size(s->fifo); |
| 591 | 599 | } |
| | 600 | |
| | 601 | if (buffer_needs > 4) { |
| | 602 | target_timestamp = av_gettime_relative(); |
| | 603 | start_timestamp = av_gettime_relative(); |
| | 604 | } |
| 592 | 605 | |
| 593 | 606 | av_fifo_generic_read(s->fifo, tmp, 4, NULL); |
| 594 | 607 | len=AV_RL32(tmp); |
| 595 | | |
| 596 | 608 | av_assert0(len >= 0); |
| 597 | 609 | av_assert0(len <= sizeof(s->tmp)); |
| 598 | | |
| 599 | 610 | av_fifo_generic_read(s->fifo, s->tmp, len, NULL); |
| 600 | 611 | |
| 601 | 612 | pthread_mutex_unlock(&s->mutex); |
| … |
… |
static int udp_write(URLContext *h, const uint8_t *buf, int size)
|
| 1097 | 1108 | |
| 1098 | 1109 | if(av_fifo_space(s->fifo) < size + 4) { |
| 1099 | 1110 | /* What about a partial packet tx ? */ |
| 1100 | | pthread_mutex_unlock(&s->mutex); |
| 1101 | | return AVERROR(ENOMEM); |
| | 1111 | /* No Space left */ |
| | 1112 | pthread_mutex_unlock(&s->mutex); |
| | 1113 | if (s->overrun_nonfatal) { |
| | 1114 | av_log(h, AV_LOG_WARNING, "Circular buffer overrun. " |
| | 1115 | "Surviving due to overrun_nonfatal option\n"); |
| | 1116 | return 0; |
| | 1117 | } else { |
| | 1118 | return AVERROR(ENOMEM); |
| | 1119 | } |
| 1102 | 1120 | } |
| 1103 | 1121 | AV_WL32(tmp, size); |
| 1104 | 1122 | av_fifo_generic_write(s->fifo, tmp, 4, NULL); /* size of packet */ |
diff --git a/libavformat/udp.c b/libavformat/udp.c
index 3835f98..38b7a2e 100644
|
a
|
b
|
static void *circular_buffer_task_tx( void *_URLContext)
|
| 581 | 581 | |
| 582 | 582 | len=av_fifo_size(s->fifo); |
| 583 | 583 | |
| 584 | | while (len<4) { |
| 585 | | if (s->close_req) |
| 586 | | goto end; |
| 587 | | if (pthread_cond_wait(&s->cond, &s->mutex) < 0) { |
| 588 | | goto end; |
| 589 | | } |
| 590 | | len=av_fifo_size(s->fifo); |
| | 584 | if ( len < 4 ) { |
| | 585 | while (len < s->circular_buffer_size / 2) { |
| | 586 | if (s->close_req) |
| | 587 | goto end; |
| | 588 | if (pthread_cond_wait(&s->cond, &s->mutex) < 0) { |
| | 589 | goto end; |
| | 590 | } |
| | 591 | len=av_fifo_size(s->fifo); |
| | 592 | } |
| | 593 | target_timestamp = av_gettime_relative(); |
| | 594 | start_timestamp = av_gettime_relative(); |
| 591 | 595 | } |
| 592 | | |
| | 596 | |
| 593 | 597 | av_fifo_generic_read(s->fifo, tmp, 4, NULL); |
| 594 | 598 | len=AV_RL32(tmp); |
| 595 | | |
| 596 | 599 | av_assert0(len >= 0); |
| 597 | 600 | av_assert0(len <= sizeof(s->tmp)); |
| 598 | | |
| 599 | 601 | av_fifo_generic_read(s->fifo, s->tmp, len, NULL); |
| 600 | 602 | |
| 601 | 603 | pthread_mutex_unlock(&s->mutex); |
| … |
… |
static int udp_write(URLContext *h, const uint8_t *buf, int size)
|
| 1097 | 1099 | |
| 1098 | 1100 | if(av_fifo_space(s->fifo) < size + 4) { |
| 1099 | 1101 | /* What about a partial packet tx ? */ |
| 1100 | | pthread_mutex_unlock(&s->mutex); |
| 1101 | | return AVERROR(ENOMEM); |
| | 1102 | /* No Space left */ |
| | 1103 | pthread_mutex_unlock(&s->mutex); |
| | 1104 | if (s->overrun_nonfatal) { |
| | 1105 | av_log(h, AV_LOG_WARNING, "Circular buffer overrun. " |
| | 1106 | "Surviving due to overrun_nonfatal option\n"); |
| | 1107 | return 0; |
| | 1108 | } else { |
| | 1109 | return AVERROR(ENOMEM); |
| | 1110 | } |
| 1102 | 1111 | } |
| 1103 | 1112 | AV_WL32(tmp, size); |
| 1104 | 1113 | av_fifo_generic_write(s->fifo, tmp, 4, NULL); /* size of packet */ |