2013-11-03 23:53:49 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2014-01-12 20:25:51 +13:00
|
|
|
|
Copyright (C) 2008-2014 ShareX Developers
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
using HelpersLib;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2013-11-16 22:11:39 +13:00
|
|
|
|
namespace ScreenCaptureLib
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-06 23:23:12 +12:00
|
|
|
|
public class AVICache : ImageRecorder
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-04-27 19:07:43 +12:00
|
|
|
|
private AVIWriter aviWriter;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-05-04 06:55:15 +12:00
|
|
|
|
public AVICache(AVIOptions options)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-04 06:55:15 +12:00
|
|
|
|
Options = options;
|
2014-04-27 19:07:43 +12:00
|
|
|
|
|
2014-05-04 06:55:15 +12:00
|
|
|
|
Helpers.CreateDirectoryIfNotExist(Options.OutputPath);
|
|
|
|
|
aviWriter = new AVIWriter(Options);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
imageQueue = new BlockingCollection<Image>();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-06 23:23:12 +12:00
|
|
|
|
protected override void StartConsumerThread()
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
if (!IsWorking)
|
|
|
|
|
{
|
|
|
|
|
IsWorking = true;
|
|
|
|
|
|
|
|
|
|
task = TaskEx.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
position = 0;
|
|
|
|
|
|
|
|
|
|
while (!imageQueue.IsCompleted)
|
|
|
|
|
{
|
|
|
|
|
Image img = null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
img = imageQueue.Take();
|
|
|
|
|
|
|
|
|
|
if (img != null)
|
|
|
|
|
{
|
2014-05-04 08:40:21 +12:00
|
|
|
|
//using (new DebugTimer("Frame saved"))
|
|
|
|
|
aviWriter.AddFrame((Bitmap)img);
|
2014-05-04 06:55:15 +12:00
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
position++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (InvalidOperationException)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if (img != null) img.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
IsWorking = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-06 23:23:12 +12:00
|
|
|
|
public override void Dispose()
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-04-27 19:07:43 +12:00
|
|
|
|
if (aviWriter != null)
|
|
|
|
|
{
|
|
|
|
|
aviWriter.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-06 23:23:12 +12:00
|
|
|
|
base.Dispose();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|