-/*\r
-* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
-*\r
-* This file is part of CasparCG (www.casparcg.com).\r
-*\r
-* CasparCG is free software: you can redistribute it and/or modify\r
-* it under the terms of the GNU General Public License as published by\r
-* the Free Software Foundation, either version 3 of the License, or\r
-* (at your option) any later version.\r
-*\r
-* CasparCG is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
-*\r
-* Author: Robert Nagy, ronag89@gmail.com\r
-*/\r
-\r
-#include "../stdafx.h"\r
-\r
-#include "tbb_avcodec.h"\r
-\r
-#include <common/assert.h>\r
-#include <common/log.h>\r
-#include <common/env.h>\r
-\r
-#include <tbb/atomic.h>\r
-#include <tbb/parallel_for.h>\r
-#include <tbb/tbb_thread.h>\r
-\r
-#if defined(_MSC_VER)\r
-#pragma warning (push)\r
-#pragma warning (disable : 4244)\r
-#endif\r
-extern "C" \r
-{\r
- #define __STDC_CONSTANT_MACROS\r
- #define __STDC_LIMIT_MACROS\r
- #include <libavformat/avformat.h>\r
-}\r
-#if defined(_MSC_VER)\r
-#pragma warning (pop)\r
-#endif\r
-\r
-namespace caspar {\r
- \r
-static const int MAX_THREADS = 16; // See mpegvideo.h\r
-\r
-int thread_execute(AVCodecContext* s, int (*func)(AVCodecContext *c2, void *arg2), void* arg, int* ret, int count, int size)\r
-{\r
- tbb::parallel_for(0, count, 1, [&](int i)\r
- {\r
- int r = func(s, (char*)arg + i*size);\r
- if(ret) \r
- ret[i] = r;\r
- });\r
-\r
- return 0;\r
-}\r
-\r
-int thread_execute2(AVCodecContext* s, int (*func)(AVCodecContext* c2, void* arg2, int, int), void* arg, int* ret, int count)\r
-{ \r
- std::array<std::vector<int>, 16> jobs;\r
- \r
- for(int n = 0; n < count; ++n) \r
- jobs[(n*MAX_THREADS) / count].push_back(n); \r
- \r
- tbb::parallel_for(0, MAX_THREADS, [&](int n) \r
- {
- BOOST_FOREACH(auto k, jobs[n])
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* This file is part of CasparCG (www.casparcg.com).
+*
+* CasparCG 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 3 of the License, or
+* (at your option) any later version.
+*
+* CasparCG 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 CasparCG. If not, see <http://www.gnu.org/licenses/>.
+*
+* Author: Robert Nagy, ronag89@gmail.com
+*/
+
+#include "../StdAfx.h"
+
+#include "tbb_avcodec.h"
+
+#include <common/assert.h>
+#include <common/except.h>
+#include <common/log.h>
+#include <common/env.h>
+
+#include <tbb/atomic.h>
+#include <tbb/parallel_for.h>
+#include <tbb/tbb_thread.h>
+
+#if defined(_MSC_VER)
+#pragma warning (push)
+#pragma warning (disable : 4244)
+#endif
+extern "C"
+{
+ #define __STDC_CONSTANT_MACROS
+ #define __STDC_LIMIT_MACROS
+ #include <libavformat/avformat.h>
+}
+#if defined(_MSC_VER)
+#pragma warning (pop)
+#endif
+
+namespace caspar {
+
+static const int MAX_THREADS = 16; // See mpegvideo.h
+
+int thread_execute(AVCodecContext* s, int (*func)(AVCodecContext *c2, void *arg2), void* arg, int* ret, int count, int size)
+{
+ tbb::parallel_for(0, count, 1, [&](int i)
+ {
+ int r = func(s, (char*)arg + i*size);
+ if(ret)
+ ret[i] = r;
+ });
+
+ return 0;
+}
+
+int thread_execute2(AVCodecContext* s, int (*func)(AVCodecContext* c2, void* arg2, int, int), void* arg, int* ret, int count)
+{
+ // TODO: Micro-optimize...
+
+ std::array<std::vector<int>, 16> jobs;
+
+ for(int n = 0; n < count; ++n)
+ jobs[(n*MAX_THREADS) / count].push_back(n);
+
+ tbb::parallel_for(0, MAX_THREADS, [&](int n)
+ {
+ for (auto k : jobs[n])