2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG.
\r
6 * CasparCG is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * CasparCG is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
\r
22 #include "consumer/ffmpeg_consumer.h"
\r
23 #include "producer/ffmpeg_producer.h"
\r
25 #include <core/consumer/frame_consumer.h>
\r
26 #include <core/producer/frame_producer.h>
\r
28 #include <tbb/mutex.h>
\r
30 #if defined(_MSC_VER)
\r
31 #pragma warning (disable : 4244)
\r
36 #define __STDC_CONSTANT_MACROS
\r
37 #define __STDC_LIMIT_MACROS
\r
38 #include <libavformat/avformat.h>
\r
39 #include <libswscale/swscale.h>
\r
40 #include <libavutil/avutil.h>
\r
41 #include <libavfilter/avfilter.h>
\r
46 int ffmpeg_lock_callback(void **mutex, enum AVLockOp op)
\r
48 static tbb::mutex container_mutex;
\r
49 static std::vector<tbb::mutex> container;
\r
54 auto my_mutex = reinterpret_cast<tbb::mutex*>(*mutex);
\r
58 case AV_LOCK_CREATE:
\r
60 tbb::mutex::scoped_lock lock(container_mutex);
\r
61 container.push_back(tbb::mutex());
\r
62 *mutex = &container.back();
\r
65 case AV_LOCK_OBTAIN:
\r
71 case AV_LOCK_RELEASE:
\r
74 my_mutex->unlock();
\r
77 case AV_LOCK_DESTROY:
\r
79 tbb::mutex::scoped_lock lock(container_mutex);
\r
80 container.erase(std::remove_if(container.begin(), container.end(), [&](const tbb::mutex& m)
\r
82 return &m == my_mutex;
\r
83 }), container.end());
\r
94 av_lockmgr_register(ffmpeg_lock_callback);
\r
96 core::register_consumer_factory([](const std::vector<std::wstring>& params){return create_ffmpeg_consumer(params);});
\r
97 core::register_producer_factory(create_ffmpeg_producer);
\r
100 void uninit_ffmpeg()
\r
102 av_lockmgr_register(nullptr);
\r
105 std::wstring make_version(unsigned int ver)
\r
107 std::wstringstream str;
\r
108 str << ((ver >> 16) & 0xFF) << L"." << ((ver >> 8) & 0xFF) << L"." << ((ver >> 0) & 0xFF);
\r
112 std::wstring get_avcodec_version()
\r
114 return make_version(avcodec_version());
\r
117 std::wstring get_avformat_version()
\r
119 return make_version(avformat_version());
\r
122 std::wstring get_avutil_version()
\r
124 return make_version(avutil_version());
\r
127 std::wstring get_avfilter_version()
\r
129 return make_version(avfilter_version());
\r
132 std::wstring get_swscale_version()
\r
134 return make_version(swscale_version());
\r