From 78ed2663ee2497203d6a96bb49d0a09b46bb6259 Mon Sep 17 00:00:00 2001
From: philippegorley <philippe.gorley@savoirfairelinux.com>
Date: Mon, 19 Mar 2018 14:36:21 -0400
Subject: [PATCH] media: update ffmpeg io read callbacks

In newer versions, AVIOContext's read_packet cb no longer considers 0
as being EOF. Changes the read callbacks for SDP and RTP to return
AVERROR_EOF instead of 0.

Change-Id: Ica5bdc95913b4475f1e954a1141700fc88638a59
---
 src/media/audio/audio_rtp_session.cpp    | 10 +++++++++-
 src/media/socket_pair.cpp                |  5 ++++-
 src/media/video/video_receive_thread.cpp |  7 ++++++-
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/media/audio/audio_rtp_session.cpp b/src/media/audio/audio_rtp_session.cpp
index 8ba818ac9d..dd5b8bcc76 100644
--- a/src/media/audio/audio_rtp_session.cpp
+++ b/src/media/audio/audio_rtp_session.cpp
@@ -17,6 +17,9 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
  */
+
+#include "libav_deps.h" // MUST BE INCLUDED FIRST
+
 #include "audio_rtp_session.h"
 
 #include "logger.h"
@@ -340,7 +343,12 @@ AudioReceiveThread::readFunction(void* opaque, uint8_t* buf, int buf_size)
 {
     std::istream& is = static_cast<AudioReceiveThread*>(opaque)->stream_;
     is.read(reinterpret_cast<char*>(buf), buf_size);
-    return is.gcount();
+
+    auto count = is.gcount();
+    if (count != 0)
+        return count;
+    else
+        return AVERROR_EOF;
 }
 
 // This callback is used by libav internally to break out of blocking calls
diff --git a/src/media/socket_pair.cpp b/src/media/socket_pair.cpp
index e710e47085..08263164e7 100644
--- a/src/media/socket_pair.cpp
+++ b/src/media/socket_pair.cpp
@@ -429,7 +429,10 @@ SocketPair::readCallback(uint8_t* buf, int buf_size)
             RING_WARN("decrypt error %d", err);
     }
 
-    return len;
+    if (len != 0)
+        return len;
+    else
+        return AVERROR_EOF;
 }
 
 int
diff --git a/src/media/video/video_receive_thread.cpp b/src/media/video/video_receive_thread.cpp
index 7315589bbf..b6ce1cf908 100644
--- a/src/media/video/video_receive_thread.cpp
+++ b/src/media/video/video_receive_thread.cpp
@@ -151,7 +151,12 @@ int VideoReceiveThread::readFunction(void *opaque, uint8_t *buf, int buf_size)
 {
     std::istream &is = static_cast<VideoReceiveThread*>(opaque)->stream_;
     is.read(reinterpret_cast<char*>(buf), buf_size);
-    return is.gcount();
+
+    auto count = is.gcount();
+    if (count != 0)
+        return count;
+    else
+        return AVERROR_EOF;
 }
 
 void VideoReceiveThread::addIOContext(SocketPair& socketPair)
-- 
GitLab