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
23 #include "consumer/ffmpeg_consumer.h"
\r
24 #include "producer/ffmpeg_producer.h"
\r
26 #include <common/log/log.h>
\r
28 #include <core/consumer/frame_consumer.h>
\r
29 #include <core/producer/frame_producer.h>
\r
31 #include <tbb/recursive_mutex.h>
\r
33 #if defined(_MSC_VER)
\r
34 #pragma warning (disable : 4244)
\r
35 #pragma warning (disable : 4603)
\r
36 #pragma warning (disable : 4996)
\r
41 #define __STDC_CONSTANT_MACROS
\r
42 #define __STDC_LIMIT_MACROS
\r
43 #include <libavformat/avformat.h>
\r
44 #include <libswscale/swscale.h>
\r
45 #include <libavutil/avutil.h>
\r
46 #include <libavfilter/avfilter.h>
\r
51 int ffmpeg_lock_callback(void **mutex, enum AVLockOp op)
\r
56 auto my_mutex = reinterpret_cast<tbb::recursive_mutex*>(*mutex);
\r
60 case AV_LOCK_CREATE:
\r
62 *mutex = new tbb::recursive_mutex();
\r
65 case AV_LOCK_OBTAIN:
\r
71 case AV_LOCK_RELEASE:
\r
74 my_mutex->unlock();
\r
77 case AV_LOCK_DESTROY:
\r
87 static void sanitize(uint8_t *line)
\r
91 if(*line < 0x08 || (*line > 0x0D && *line < 0x20))
\r
97 void log_callback(void* ptr, int level, const char* fmt, va_list vl)
\r
99 static int print_prefix=1;
\r
101 static char prev[1024];
\r
103 static int is_atty;
\r
104 AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
\r
105 if(level > av_log_get_level())
\r
110 if(print_prefix && avc)
\r
112 if (avc->parent_log_context_offset)
\r
114 AVClass** parent= *(AVClass***)(((uint8_t*)ptr) + avc->parent_log_context_offset);
\r
115 if(parent && *parent)
\r
116 std::sprintf(line, "[%s @ %p] ", (*parent)->item_name(parent), parent);
\r
118 std::sprintf(line + strlen(line), "[%s @ %p] ", avc->item_name(ptr), ptr);
\r
121 std::vsprintf(line + strlen(line), fmt, vl);
\r
123 print_prefix = strlen(line) && line[strlen(line)-1] == '\n';
\r
125 //if(print_prefix && !strcmp(line, prev)){
\r
128 // fprintf(stderr, " Last message repeated %d times\r", count);
\r
132 // fprintf(stderr, " Last message repeated %d times\n", count);
\r
135 strcpy(prev, line);
\r
136 sanitize((uint8_t*)line);
\r
138 CASPAR_LOG(trace) << L"[FFMPEG] [" << av_clip(level>>3, 0, 6) << L"] " << line;
\r
140 //colored_fputs(av_clip(level>>3, 0, 6), line);
\r
145 avfilter_register_all();
\r
148 avcodec_register_all();
\r
149 av_lockmgr_register(ffmpeg_lock_callback);
\r
150 av_log_set_callback(log_callback);
\r
152 //core::register_consumer_factory([](const std::vector<std::wstring>& params){return create_ffmpeg_consumer(params);});
\r
153 core::register_producer_factory(create_ffmpeg_producer);
\r
156 void uninit_ffmpeg()
\r
159 av_lockmgr_register(nullptr);
\r
162 std::wstring make_version(unsigned int ver)
\r
164 std::wstringstream str;
\r
165 str << ((ver >> 16) & 0xFF) << L"." << ((ver >> 8) & 0xFF) << L"." << ((ver >> 0) & 0xFF);
\r
169 std::wstring get_avcodec_version()
\r
171 return make_version(avcodec_version());
\r
174 std::wstring get_avformat_version()
\r
176 return make_version(avformat_version());
\r
179 std::wstring get_avutil_version()
\r
181 return make_version(avutil_version());
\r
184 std::wstring get_avfilter_version()
\r
186 return make_version(avfilter_version());
\r
189 std::wstring get_swscale_version()
\r
191 return make_version(swscale_version());
\r