From 6415afd14d29ae1c663e5cf62b6bc3c7476f214b Mon Sep 17 00:00:00 2001
From: smallishzulu <alikizil@gmail.com>
Date: Mon, 14 Nov 2016 13:03:20 +0200
Subject: [PATCH 1/2] Fix UDP MPEGTS Overflow Exit Case

---
 libavformat/udp.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavformat/udp.c b/libavformat/udp.c
index 3835f98..b850ac9 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -1098,7 +1098,13 @@ static int udp_write(URLContext *h, const uint8_t *buf, int size)
         if(av_fifo_space(s->fifo) < size + 4) {
             /* What about a partial packet tx ? */
             pthread_mutex_unlock(&s->mutex);
-            return AVERROR(ENOMEM);
+	    if (s->overrun_nonfatal) {
+		av_log(h, AV_LOG_WARNING, "Circular buffer overrun. "
+			"Surviving due to overrun_nonfatal option\n");
+		return 0;
+	    } else {
+            	return AVERROR(ENOMEM);
+	    }
         }
         AV_WL32(tmp, size);
         av_fifo_generic_write(s->fifo, tmp, 4, NULL); /* size of packet */
-- 
1.9.1

