Created
February 18, 2014 17:31
-
-
Save rdp/9075597 to your computer and use it in GitHub Desktop.
some pasted notes (too big) to not lose them...don't use this though...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/libavformat/udp.c b/libavformat/udp.c | |
index 3c0d6bf..ee758cc 100644 | |
--- a/libavformat/udp.c | |
+++ b/libavformat/udp.c | |
@@ -40,6 +40,8 @@ | |
#include "os_support.h" | |
#include "url.h" | |
+#undef HAVE_PTHREAD_CANCEL // rdp mine to disable if you have this line commented out, then you have the q | |
+ | |
#if HAVE_PTHREAD_CANCEL | |
#include <pthread.h> | |
#endif | |
@@ -458,6 +460,7 @@ static void *circular_buffer_task( void *_URLContext) | |
in Single Unix. */ | |
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old_cancelstate); | |
len = recv(s->udp_fd, s->tmp+4, sizeof(s->tmp)-4, 0); | |
+ printf("receiving udp packet size %d with q size %d\n", len, av_fifo_space(s->fifo)); | |
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_cancelstate); | |
pthread_mutex_lock(&s->mutex); | |
if (len < 0) { | |
@@ -624,7 +627,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) | |
if (udp_fd < 0) | |
goto fail; | |
- /* Follow the requested reuse option, unless it's multicast in which | |
+ /* Follow the equested reuse option, unless it's multicast in which | |
* case enable reuse unless explicitly disabled. | |
*/ | |
if (s->reuse_socket || (s->is_multicast && !reuse_specified)) { | |
@@ -689,9 +692,15 @@ static int udp_open(URLContext *h, const char *uri, int flags) | |
/* set udp recv buffer size to the largest possible udp packet size to | |
* avoid losing data on OSes that set this too low by default. */ | |
tmp = s->buffer_size; | |
+int rcvBufferSize; | |
+int sockOptSize = sizeof(rcvBufferSize); | |
+getsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &rcvBufferSize, &sockOptSize); | |
+printf("initial socket receive buf %d\n", rcvBufferSize); | |
if (setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp)) < 0) { | |
log_net_error(h, AV_LOG_WARNING, "setsockopt(SO_RECVBUF)"); | |
} | |
+getsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &rcvBufferSize, &sockOptSize); | |
+printf("post socket receive buf %d\n", rcvBufferSize); | |
/* make the socket non-blocking */ | |
ff_socket_nonblock(udp_fd, 1); | |
} | |
@@ -712,7 +721,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) | |
#if HAVE_PTHREAD_CANCEL | |
if (!is_output && s->circular_buffer_size) { | |
int ret; | |
- | |
+ printf("starting circ buf with size %d\n", s->circular_buffer_size); | |
/* start the task going */ | |
s->fifo = av_fifo_alloc(s->circular_buffer_size); | |
ret = pthread_mutex_init(&s->mutex, NULL); | |
@@ -752,6 +761,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) | |
return AVERROR(EIO); | |
} | |
+ | |
static int udp_read(URLContext *h, uint8_t *buf, int size) | |
{ | |
UDPContext *s = h->priv_data; | |
@@ -766,16 +776,25 @@ static int udp_read(URLContext *h, uint8_t *buf, int size) | |
if (avail) { // >=size) { | |
uint8_t tmp[4]; | |
- av_fifo_generic_read(s->fifo, tmp, 4, NULL); | |
- avail= AV_RL32(tmp); | |
+ uint8_t *peek_here = av_fifo_peek2(s->fifo, 0); | |
+ avail= AV_RL32(peek_here); | |
+ //printf("it says its size to give is %d and size requested is %d\n", avail, size); | |
if(avail > size){ | |
- av_log(h, AV_LOG_WARNING, "Part of datagram lost due to insufficient buffer size\n"); | |
- avail= size; | |
+ av_log(h, AV_LOG_DEBUG, "Part of datagram lost due to insufficient buffer size %d > %d, bailing early\n", avail, size); | |
+ avail = size; | |
+ pthread_mutex_unlock(&s->mutex); | |
+ | |
+ return -10040; // yeah, like this is right LOL | |
+ } else { | |
+ //printf("non loss %d < %d\n", avail, size); | |
} | |
+ av_fifo_generic_read(s->fifo, tmp, 4, NULL); // clear counter | |
av_fifo_generic_read(s->fifo, buf, avail, NULL); | |
- av_fifo_drain(s->fifo, AV_RL32(tmp) - avail); | |
+ //printf("draining %d\n", AV_RL32(tmp) - avail); | |
+ av_fifo_drain(s->fifo, AV_RL32(tmp) - avail); // avail minus avail? huh wuh? | |
pthread_mutex_unlock(&s->mutex); | |
+ //printf("returning size read of %d\n", avail); | |
return avail; | |
} else if(s->circular_buffer_error){ | |
int err = s->circular_buffer_error; | |
@@ -806,8 +825,19 @@ static int udp_read(URLContext *h, uint8_t *buf, int size) | |
if (ret < 0) | |
return ret; | |
} | |
- ret = recv(s->udp_fd, buf, size, 0); | |
- | |
+ ret = -1; | |
+ if(size > 1472) { | |
+ ret = recv(s->udp_fd, buf, size, 0); | |
+} else { | |
+ printf("ignoring request for size %d\n", size); | |
+} | |
+ printf("requested *no fifo thread* size %d and received %d\n",size, ret); | |
+ if (ret < 0) { | |
+ printf("returning %d\n", ff_neterrno()); | |
+ log_net_error(NULL, AV_LOG_ERROR, "XXX"); | |
+ } else { | |
+ printf("received size %d\n", ret); | |
+ } | |
return ret < 0 ? ff_neterrno() : ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment