From 960d40f8b213d6e85270f52625760510ba7dc791 Mon Sep 17 00:00:00 2001 From: casey langen Date: Sun, 6 Jan 2019 11:37:13 -0800 Subject: [PATCH] Don't allow waiting for or caching streams with indeterminate/infinite durations when transcoding. --- src/plugins/server/Transcoder.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/plugins/server/Transcoder.cpp b/src/plugins/server/Transcoder.cpp index 3f854a95d..35322c618 100644 --- a/src/plugins/server/Transcoder.cpp +++ b/src/plugins/server/Transcoder.cpp @@ -157,15 +157,28 @@ IDataStream* Transcoder::TranscodeOnDemand( prefs::transcoder_cache_count.c_str(), defaults::transcoder_cache_count); + TranscodingDataStream* transcoder = nullptr; + if (cacheCount > 0) { PruneTranscodeCache(context); - return new TranscodingDataStream( + transcoder = new TranscodingDataStream( context, uri, tempFilename, expectedFilename, bitrate, format); + + /* if the stream has an indeterminite length, close it down and + re-open it without caching options; we don't want to fill up + the storage disk */ + if (transcoder->Length() < 0) { + transcoder->Release(); + delete transcoder; + transcoder = new TranscodingDataStream(context, uri, bitrate, format); + } } else { - return new TranscodingDataStream(context, uri, bitrate, format); + transcoder = new TranscodingDataStream(context, uri, bitrate, format); } + + return transcoder; } IDataStream* Transcoder::TranscodeAndWait( @@ -187,6 +200,14 @@ IDataStream* Transcoder::TranscodeAndWait( TranscodingDataStream* transcoder = new TranscodingDataStream( context, uri, tempFilename, expectedFilename, bitrate, format); + /* transcoders with a negative length have an indeterminate duration, so + we disallow waiting for them because they may never finish */ + if (transcoder->Length() < 0) { + transcoder->Release(); + delete transcoder; + return nullptr; + } + char buffer[8192]; while (!transcoder->Eof()) { transcoder->Read(buffer, sizeof(buffer));