summaryrefslogtreecommitdiffstats
path: root/pica-client/videodevice.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pica-client/videodevice.cpp')
-rw-r--r--pica-client/videodevice.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/pica-client/videodevice.cpp b/pica-client/videodevice.cpp
index 67094aa..ac9a861 100644
--- a/pica-client/videodevice.cpp
+++ b/pica-client/videodevice.cpp
@@ -615,6 +615,11 @@ QList<VideoCaptureFormat> VideoDevice::CaptureFormats(const QString &device)
return result;
}
+// A reassembled frame never legitimately approaches this; a stream that does
+// is a peer flooding fragments that never carry the last-fragment flag, so the
+// partial frame is dropped and reassembly resynchronizes at the next boundary.
+static const int kMaxAssembledFrameBytes = 4 * 1024 * 1024;
+
VideoFrameAssembler::VideoFrameAssembler()
: m_timestamp(0), m_lastSeq(0)
{
@@ -694,6 +699,19 @@ QByteArray VideoFrameAssembler::addFragment(quint16 seq_num, quint32 timestamp,
m_buffer.clear();
m_buffer.append(data);
+
+ /* Bound the partial frame: a peer that never sets the last-fragment flag
+ * would otherwise grow this without limit. Drop it and resync at the next
+ * frame boundary, exactly as for a lost fragment above.
+ */
+ if (m_buffer.size() > kMaxAssembledFrameBytes)
+ {
+ m_buffer.clear();
+ m_inProgress = false;
+ m_lastWasFrameEnd = false;
+ return QByteArray();
+ }
+
m_timestamp = timestamp;
m_inProgress = true;
m_lastWasFrameEnd = isLast;