]> git.sesse.net Git - casparcg/commitdiff
ffmpeg: Cleanup and bug fixes.
authorRobert Nagy <ronag@live.com>
Mon, 16 Dec 2013 18:46:25 +0000 (19:46 +0100)
committerRobert Nagy <ronag@live.com>
Mon, 16 Dec 2013 18:46:25 +0000 (19:46 +0100)
modules/ffmpeg/ffmpeg.vcxproj
modules/ffmpeg/ffmpeg.vcxproj.filters
modules/ffmpeg/producer/filter/filter.cpp
modules/ffmpeg/producer/filter/parallel_yadif.cpp [deleted file]
modules/ffmpeg/producer/filter/parallel_yadif.h [deleted file]
modules/ffmpeg/producer/filter/scalable_yadif/scalable_yadif.cpp [deleted file]
modules/ffmpeg/producer/filter/scalable_yadif/scalable_yadif.h [deleted file]

index 63980cd0bf754c96cf1a929737ec5b3ff247a9a5..303f39ae51eab07761bcdb9cc666fa38bd6b09b2 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>\r
+<?xml version="1.0" encoding="utf-8"?>\r
 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
   <ItemGroup Label="ProjectConfigurations">\r
     <ProjectConfiguration Include="Profile|Win32">\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
     </ClCompile>\r
-    <ClCompile Include="producer\filter\parallel_yadif.cpp">\r
-      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
-      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
-      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
-      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
-    </ClCompile>\r
     <ClCompile Include="producer\input\input.cpp">\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
     <ClInclude Include="producer\audio\audio_resampler.h" />\r
     <ClInclude Include="producer\ffmpeg_producer.h" />\r
     <ClInclude Include="producer\filter\filter.h" />\r
-    <ClInclude Include="producer\filter\parallel_yadif.h" />\r
     <ClInclude Include="producer\input\input.h" />\r
     <ClInclude Include="producer\muxer\display_mode.h" />\r
     <ClInclude Include="producer\muxer\frame_muxer.h" />\r
index 540b4acefcf057a4f02fa106c1431dd111f4850b..2c75f48d3e2b088375ef901c5b7a8cee4abbc676 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>\r
+<?xml version="1.0" encoding="utf-8"?>\r
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
   <ItemGroup>\r
     <Filter Include="source">\r
@@ -46,9 +46,6 @@
     <ClCompile Include="producer\filter\filter.cpp">\r
       <Filter>source\producer\filter</Filter>\r
     </ClCompile>\r
-    <ClCompile Include="producer\filter\parallel_yadif.cpp">\r
-      <Filter>source\producer\filter</Filter>\r
-    </ClCompile>\r
     <ClCompile Include="producer\audio\audio_resampler.cpp">\r
       <Filter>source\producer\audio</Filter>\r
     </ClCompile>\r
@@ -97,9 +94,6 @@
     <ClInclude Include="producer\filter\filter.h">\r
       <Filter>source\producer\filter</Filter>\r
     </ClInclude>\r
-    <ClInclude Include="producer\filter\parallel_yadif.h">\r
-      <Filter>source\producer\filter</Filter>\r
-    </ClInclude>\r
     <ClInclude Include="producer\audio\audio_resampler.h">\r
       <Filter>source\producer\audio</Filter>\r
     </ClInclude>\r
index 38ec37404fce8042ba3b3dba45cb2674ffe2ad13..5c608e978615762b88f12cf7f5c695313a1f5ecb 100644 (file)
@@ -23,8 +23,6 @@
 \r
 #include "filter.h"\r
 \r
-#include "parallel_yadif.h"\r
-\r
 #include "../../ffmpeg_error.h"\r
 \r
 #include <common/exception/exceptions.h>\r
@@ -64,58 +62,9 @@ extern "C"
 \r
 namespace caspar { namespace ffmpeg {\r
        \r
-//static int query_formats_444(AVFilterContext *ctx)\r
-//{\r
-//    static const int pix_fmts[] = {PIX_FMT_YUV444P, PIX_FMT_NONE};\r
-//    avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));\r
-//    return 0;\r
-//}\r
-//\r
-//static int query_formats_422(AVFilterContext *ctx)\r
-//{\r
-//    static const int pix_fmts[] = {PIX_FMT_YUV422P, PIX_FMT_NONE};\r
-//    avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));\r
-//    return 0;\r
-//}\r
-//\r
-//static int query_formats_420(AVFilterContext *ctx)\r
-//{\r
-//    static const int pix_fmts[] = {PIX_FMT_YUV420P, PIX_FMT_NONE};\r
-//    avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));\r
-//    return 0;\r
-//}\r
-//\r
-//static int query_formats_420a(AVFilterContext *ctx)\r
-//{\r
-//    static const int pix_fmts[] = {PIX_FMT_YUVA420P, PIX_FMT_NONE};\r
-//    avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));\r
-//    return 0;\r
-//}\r
-//\r
-//static int query_formats_411(AVFilterContext *ctx)\r
-//{\r
-//    static const int pix_fmts[] = {PIX_FMT_YUV411P, PIX_FMT_NONE};\r
-//    avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));\r
-//    return 0;\r
-//}\r
-//\r
-//static int query_formats_410(AVFilterContext *ctx)\r
-//{\r
-//    static const int pix_fmts[] = {PIX_FMT_YUV410P, PIX_FMT_NONE};\r
-//    avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));\r
-//    return 0;\r
-//}\r
-\r
 struct filter::implementation\r
 {\r
-       std::wstring                                    filters_;\r
-       //std::shared_ptr<AVFilterGraph>        graph_; \r
-       //AVFilterContext*                              buffersink_ctx_;\r
-       //AVFilterContext*                              buffersrc_ctx_;\r
-       //std::shared_ptr<void>                 parallel_yadif_ctx_;\r
-       std::vector<PixelFormat>                pix_fmts_;\r
-       //std::queue<safe_ptr<AVFrame>> bypass_;\r
-\r
+       std::string                                         filtergraph_;\r
        std::shared_ptr<AVFilterGraph>  video_graph_;   \r
     AVFilterContext*                           video_graph_in_;  \r
     AVFilterContext*                           video_graph_out_; \r
@@ -129,10 +78,11 @@ struct filter::implementation
                AVPixelFormat in_pix_fmt,\r
                std::vector<AVPixelFormat> out_pix_fmts,\r
                const std::string& filtergraph) \r
+               : filtergraph_(boost::to_lower_copy(filtergraph))\r
        {\r
                if(out_pix_fmts.empty())\r
                {\r
-                       pix_fmts_ = boost::assign::list_of\r
+                       out_pix_fmts = boost::assign::list_of\r
                                (AV_PIX_FMT_YUVA420P)\r
                                (AV_PIX_FMT_YUV444P)\r
                                (AV_PIX_FMT_YUV422P)\r
@@ -157,14 +107,6 @@ struct filter::implementation
                video_graph_->nb_threads  = boost::thread::hardware_concurrency();\r
                video_graph_->thread_type = AVFILTER_THREAD_SLICE;\r
 \r
-               //const auto sample_aspect_ratio = \r
-               //      boost::rational<int>(\r
-               //              in_video_format_.square_width, \r
-               //              in_video_format_.square_height) /\r
-               //      boost::rational<int>(\r
-               //              in_video_format_.width, \r
-               //              in_video_format_.height);\r
-               \r
                const auto vsrc_options = (boost::format("video_size=%1%x%2%:pix_fmt=%3%:time_base=%4%/%5%:pixel_aspect=%6%/%7%:frame_rate=%8%/%9%")\r
                        % in_width % in_height\r
                        % in_pix_fmt\r
@@ -176,7 +118,7 @@ struct filter::implementation
                FF(avfilter_graph_create_filter(\r
                        &filt_vsrc,\r
                        avfilter_get_by_name("buffer"), \r
-                       "ffmpeg_consumer_buffer",\r
+                       "filter_buffer",\r
                        vsrc_options.c_str(), \r
                        nullptr, \r
                        video_graph_.get()));\r
@@ -185,7 +127,7 @@ struct filter::implementation
                FF(avfilter_graph_create_filter(\r
                        &filt_vsink,\r
                        avfilter_get_by_name("buffersink"), \r
-                       "ffmpeg_consumer_buffersink",\r
+                       "filter_buffersink",\r
                        nullptr, \r
                        nullptr, \r
                        video_graph_.get()));\r
@@ -204,7 +146,7 @@ struct filter::implementation
                        \r
                configure_filtergraph(\r
                        *video_graph_, \r
-                       filtergraph,\r
+                       filtergraph_,\r
                        *filt_vsrc,\r
                        *filt_vsink);\r
 \r
@@ -301,184 +243,6 @@ struct filter::implementation
 \r
                return filt_frame;\r
        }\r
-\r
-//     void push(const std::shared_ptr<AVFrame>& frame)\r
-//     {               \r
-//             if(!frame)\r
-//                     return;\r
-//\r
-//             if(frame->data[0] == nullptr || frame->width < 1)\r
-//                     BOOST_THROW_EXCEPTION(invalid_argument());\r
-//\r
-//             if(filters_.empty())\r
-//             {\r
-//                     bypass_.push(make_safe_ptr(frame));\r
-//                     return;\r
-//             }\r
-//             \r
-//             try\r
-//             {\r
-//                     if(!graph_)\r
-//                     {\r
-//                             try\r
-//                             {\r
-//                                     graph_.reset(avfilter_graph_alloc(), [](AVFilterGraph* p){avfilter_graph_free(&p);});\r
-//                                                             \r
-//                                     // Input\r
-//                                     std::stringstream args;\r
-//                                     args << frame->width << ":" << frame->height << ":" << frame->format << ":" << 0 << ":" << 0 << ":" << 0 << ":" << 0; // don't care about pts and aspect_ratio\r
-//                                     THROW_ON_ERROR2(avfilter_graph_create_filter(&buffersrc_ctx_, avfilter_get_by_name("buffer"), "src", args.str().c_str(), NULL, graph_.get()), "[filter]");\r
-//                                     \r
-//#if FF_API_OLD_VSINK_API\r
-//                                     THROW_ON_ERROR2(avfilter_graph_create_filter(&buffersink_ctx_, avfilter_get_by_name("buffersink"), "out", NULL, pix_fmts_.data(), graph_.get()), "[filter]");\r
-//#else\r
-//                                     safe_ptr<AVBufferSinkParams> buffersink_params(av_buffersink_params_alloc(), av_free);\r
-//                                     buffersink_params->pixel_fmts = pix_fmts_.data();\r
-//                                     THROW_ON_ERROR2(avfilter_graph_create_filter(&buffersink_ctx_, avfilter_get_by_name("buffersink"), "out", NULL, buffersink_params.get(), graph_.get()), "[filter]");\r
-//#endif\r
-//                                     AVFilterInOut* inputs  = avfilter_inout_alloc();\r
-//                                     AVFilterInOut* outputs = avfilter_inout_alloc();\r
-//                                                             \r
-//                                     outputs->name                   = av_strdup("in");\r
-//                                     outputs->filter_ctx             = buffersrc_ctx_;\r
-//                                     outputs->pad_idx                = 0;\r
-//                                     outputs->next                   = nullptr;\r
-//\r
-//                                     inputs->name                    = av_strdup("out");\r
-//                                     inputs->filter_ctx              = buffersink_ctx_;\r
-//                                     inputs->pad_idx                 = 0;\r
-//                                     inputs->next                    = nullptr;\r
-//                     \r
-//                                     std::string filters = boost::to_lower_copy(narrow(filters_));\r
-//                                     THROW_ON_ERROR2(avfilter_graph_parse(graph_.get(), filters.c_str(), &inputs, &outputs, NULL), "[filter]");\r
-//                     \r
-//                                     auto yadif_filter = boost::adaptors::filtered([&](AVFilterContext* p){return strstr(p->name, "yadif") != 0;});\r
-//\r
-//                                     BOOST_FOREACH(auto filter_ctx, boost::make_iterator_range(graph_->filters, graph_->filters + graph_->filter_count) | yadif_filter)\r
-//                                     {\r
-//                                             // Don't trust that libavfilter chooses optimal format.\r
-//                                             filter_ctx->filter->query_formats = [&]() -> int (*)(AVFilterContext*)\r
-//                                             {\r
-//                                                     switch(frame->format)\r
-//                                                     {\r
-//                                                     case PIX_FMT_YUV444P16: \r
-//                                                     case PIX_FMT_YUV444P10: \r
-//                                                     case PIX_FMT_YUV444P9:          \r
-//                                                     case PIX_FMT_YUV444P:   \r
-//                                                     case PIX_FMT_BGR24:             \r
-//                                                     case PIX_FMT_RGB24:     \r
-//                                                             return query_formats_444;\r
-//                                                     case PIX_FMT_YUV422P16: \r
-//                                                     case PIX_FMT_YUV422P10: \r
-//                                                     case PIX_FMT_YUV422P9:  \r
-//                                                     case PIX_FMT_YUV422P:   \r
-//                                                     case PIX_FMT_UYVY422:   \r
-//                                                     case PIX_FMT_YUYV422:   \r
-//                                                             return query_formats_422;\r
-//                                                     case PIX_FMT_YUV420P16: \r
-//                                                     case PIX_FMT_YUV420P10: \r
-//                                                     case PIX_FMT_YUV420P9:  \r
-//                                                     case PIX_FMT_YUV420P:   \r
-//                                                             return query_formats_420;\r
-//                                                     case PIX_FMT_YUVA420P:  \r
-//                                                     case PIX_FMT_BGRA:              \r
-//                                                     case PIX_FMT_RGBA:              \r
-//                                                     case PIX_FMT_ABGR:              \r
-//                                                     case PIX_FMT_ARGB:              \r
-//                                                             return query_formats_420a;\r
-//                                                     case PIX_FMT_UYYVYY411: \r
-//                                                     case PIX_FMT_YUV411P:   \r
-//                                                             return query_formats_411;\r
-//                                                     case PIX_FMT_YUV410P:   \r
-//                                                             return query_formats_410;\r
-//                                                     default:                                \r
-//                                                             return filter_ctx->filter->query_formats;\r
-//                                                     }\r
-//                                             }();\r
-//                                     }\r
-//                                     \r
-//                                     THROW_ON_ERROR2(avfilter_graph_config(graph_.get(), NULL), "[filter]"); \r
-//                                     \r
-//                                     BOOST_FOREACH(auto filter_ctx, boost::make_iterator_range(graph_->filters, graph_->filters + graph_->filter_count) | yadif_filter)                                              \r
-//                                             parallel_yadif_ctx_ = make_parallel_yadif(filter_ctx);                                          \r
-//                             }\r
-//                             catch(...)\r
-//                             {\r
-//                                     graph_ = nullptr;\r
-//                                     throw;\r
-//                             }\r
-//                     }\r
-//             \r
-//                     THROW_ON_ERROR2(av_vsrc_buffer_add_frame(buffersrc_ctx_, frame.get(), 0), "[filter]");\r
-//             }\r
-//             catch(ffmpeg_error&)\r
-//             {\r
-//                     throw;\r
-//             }\r
-//             catch(...)\r
-//             {\r
-//                     BOOST_THROW_EXCEPTION(ffmpeg_error() << boost::errinfo_nested_exception(boost::current_exception()));\r
-//             }\r
-//     }\r
-//\r
-//     std::shared_ptr<AVFrame> poll()\r
-//     {\r
-//             if(filters_.empty())\r
-//             {\r
-//                     if(bypass_.empty())\r
-//                             return nullptr;\r
-//                     auto frame = bypass_.front();\r
-//                     bypass_.pop();\r
-//                     return frame;\r
-//             }\r
-//\r
-//             if(!graph_)\r
-//                     return nullptr;\r
-//             \r
-//             try\r
-//             {\r
-//                     if(avfilter_poll_frame(buffersink_ctx_->inputs[0])) \r
-//                     {\r
-//                             AVFilterBufferRef *picref;\r
-//                             THROW_ON_ERROR2(av_buffersink_get_buffer_ref(buffersink_ctx_, &picref, 0), "[filter]");\r
-//\r
-//                             if (!picref) \r
-//                                     return nullptr;\r
-//                             \r
-//                             safe_ptr<AVFrame> frame(avcodec_alloc_frame(), [=](AVFrame* p)\r
-//                             {\r
-//                                     av_free(p);\r
-//                                     avfilter_unref_buffer(picref);\r
-//                             });\r
-//\r
-//                             avcodec_get_frame_defaults(frame.get());        \r
-//\r
-//                             memcpy(frame->data,     picref->data,     sizeof(frame->data));\r
-//                             memcpy(frame->linesize, picref->linesize, sizeof(frame->linesize));\r
-//                             frame->format                           = picref->format;\r
-//                             frame->width                            = picref->video->w;\r
-//                             frame->height                           = picref->video->h;\r
-//                             frame->pkt_pos                          = picref->pos;\r
-//                             frame->interlaced_frame         = picref->video->interlaced;\r
-//                             frame->top_field_first          = picref->video->top_field_first;\r
-//                             frame->key_frame                        = picref->video->key_frame;\r
-//                             frame->pict_type                        = picref->video->pict_type;\r
-//                             frame->sample_aspect_ratio      = picref->video->sample_aspect_ratio;\r
-//                                     \r
-//                             return frame;                           \r
-//                     }\r
-//\r
-//                     return nullptr;\r
-//             }\r
-//             catch(ffmpeg_error&)\r
-//             {\r
-//                     throw;\r
-//             }\r
-//             catch(...)\r
-//             {\r
-//                     BOOST_THROW_EXCEPTION(ffmpeg_error() << boost::errinfo_nested_exception(boost::current_exception()));\r
-//             }\r
-//     }\r
 };\r
 \r
 filter::filter(\r
@@ -503,7 +267,7 @@ filter::filter(filter&& other) : impl_(std::move(other.impl_)){}
 filter& filter::operator=(filter&& other){impl_ = std::move(other.impl_); return *this;}\r
 void filter::push(const std::shared_ptr<AVFrame>& frame){impl_->push(frame);}\r
 std::shared_ptr<AVFrame> filter::poll(){return impl_->poll();}\r
-std::wstring filter::filter_str() const{return impl_->filters_;}\r
+std::wstring filter::filter_str() const{return widen(impl_->filtergraph_);}\r
 std::vector<safe_ptr<AVFrame>> filter::poll_all()\r
 {      \r
        std::vector<safe_ptr<AVFrame>> frames;\r
diff --git a/modules/ffmpeg/producer/filter/parallel_yadif.cpp b/modules/ffmpeg/producer/filter/parallel_yadif.cpp
deleted file mode 100644 (file)
index 915f82b..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-/*\r
-* Copyright 2013 Sveriges Television AB http://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 "parallel_yadif.h"\r
-\r
-#include <common/log/log.h>\r
-\r
-#if defined(_MSC_VER)\r
-#pragma warning (push)\r
-#pragma warning (disable : 4244)\r
-#endif\r
-extern "C" \r
-{\r
-       #include <libavfilter/avfilter.h>\r
-}\r
-#if defined(_MSC_VER)\r
-#pragma warning (pop)\r
-#endif\r
-\r
-#include <tbb/parallel_for.h>\r
-#include <tbb/concurrent_queue.h>\r
-\r
-#include <boost/thread/once.hpp>\r
-\r
-typedef struct {\r
-    int mode;\r
-    int parity;\r
-    int frame_pending;\r
-    int auto_enable;\r
-    AVFilterBufferRef *cur;\r
-    AVFilterBufferRef *next;\r
-    AVFilterBufferRef *prev;\r
-    AVFilterBufferRef *out;\r
-    void (*filter_line)(uint8_t *dst,\r
-                        uint8_t *prev, uint8_t *cur, uint8_t *next,\r
-                        int w, int prefs, int mrefs, int parity, int mode);\r
-    //const AVPixFmtDescriptor *csp;\r
-} YADIFContext;\r
-\r
-struct parallel_yadif_context\r
-{\r
-       struct arg\r
-       {\r
-               uint8_t *dst;\r
-               uint8_t *prev;\r
-               uint8_t *cur; \r
-               uint8_t *next; \r
-               int w; \r
-               int prefs; \r
-               int mrefs;\r
-               int parity;\r
-               int mode;\r
-       };\r
-\r
-       arg     args[1080];\r
-       int     index;\r
-       int last_index;\r
-\r
-       parallel_yadif_context() : index(0){}\r
-};\r
-\r
-void (*org_yadif_filter_line)(uint8_t *dst, uint8_t *prev, uint8_t *cur, uint8_t *next, int w, int prefs, int mrefs, int parity, int mode) = 0;\r
-\r
-void parallel_yadif_filter_line(parallel_yadif_context& ctx, uint8_t *dst, uint8_t *prev, uint8_t *cur, uint8_t *next, int w, int prefs, int mrefs, int parity, int mode)\r
-{\r
-       parallel_yadif_context::arg arg = {dst, prev, cur, next, w, prefs, mrefs, parity, mode};\r
-       ctx.args[ctx.index++] = arg;\r
-       \r
-       if(ctx.index == ctx.last_index)\r
-       {               \r
-               tbb::parallel_for(tbb::blocked_range<size_t>(0, ctx.index), [=](const tbb::blocked_range<size_t>& r)\r
-               {\r
-                       for(auto n = r.begin(); n != r.end(); ++n)\r
-                               org_yadif_filter_line(ctx.args[n].dst, ctx.args[n].prev, ctx.args[n].cur, ctx.args[n].next, ctx.args[n].w, ctx.args[n].prefs, ctx.args[n].mrefs, ctx.args[n].parity, ctx.args[n].mode);\r
-               });\r
-               ctx.index = 0;\r
-       }\r
-}\r
-\r
-namespace caspar { namespace ffmpeg {\r
-       \r
-tbb::concurrent_bounded_queue<decltype(org_yadif_filter_line)> parallel_line_func_pool;\r
-std::array<parallel_yadif_context, 18> ctxs;\r
-\r
-#define RENAME(a) f ## a\r
-\r
-#define ff(x) \\r
-void RENAME(x)(uint8_t *dst, uint8_t *prev, uint8_t *cur, uint8_t *next, int w, int prefs, int mrefs, int parity, int mode) \\r
-{\\r
-       parallel_yadif_filter_line(ctxs[x], dst, prev, cur, next, w, prefs, mrefs, parity, mode);\\r
-}\r
-\r
-ff(0); ff(1); ff(2); ff(3); ff(4); ff(5); ff(6); ff(7); ff(8); ff(9); ff(10); ff(11); ff(12); ff(13); ff(14); ff(15); ff(16); ff(17);\r
-\r
-void (*fs[])(uint8_t *dst, uint8_t *prev, uint8_t *cur, uint8_t *next, int w, int prefs, int mrefs, int parity, int mode) = \r
-{f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17};\r
-\r
-\r
-void init_pool()\r
-{\r
-       for(int n = 0; n < sizeof(fs)/sizeof(fs[0]); ++n)\r
-               parallel_line_func_pool.push(fs[n]);\r
-}\r
-\r
-void return_parallel_yadif(void* func)\r
-{\r
-       if(func != nullptr)\r
-               parallel_line_func_pool.push(reinterpret_cast<decltype(fs[0])>(func));\r
-}\r
-\r
-std::shared_ptr<void> make_parallel_yadif(AVFilterContext* ctx)\r
-{\r
-       static boost::once_flag flag = BOOST_ONCE_INIT;\r
-       boost::call_once(&init_pool, flag);\r
-\r
-       YADIFContext* yadif = (YADIFContext*)ctx->priv;\r
-       org_yadif_filter_line = yadif->filter_line; // Data race is not a problem.\r
-       \r
-       decltype(org_yadif_filter_line) func = nullptr;\r
-       if(!parallel_line_func_pool.try_pop(func))      \r
-               CASPAR_LOG(warning) << "Not enough scalable-yadif context instances. Running non-scalable";\r
-       else\r
-       {\r
-               int index = 0;\r
-               while(index < sizeof(fs)/sizeof(fs[0]) && fs[index] != func)\r
-                       ++index;\r
-\r
-               ctxs[index].last_index = 0;\r
-               for (int y = 0; y < ctx->inputs[0]->h; y++)\r
-               {\r
-            if ((y ^ yadif->parity) & 1)\r
-                               ++ctxs[index].last_index;\r
-               }\r
-\r
-               yadif->filter_line = func;\r
-       }\r
-\r
-       return std::shared_ptr<void>(func, return_parallel_yadif);\r
-}\r
-\r
-}}
\ No newline at end of file
diff --git a/modules/ffmpeg/producer/filter/parallel_yadif.h b/modules/ffmpeg/producer/filter/parallel_yadif.h
deleted file mode 100644 (file)
index 8d0f605..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*\r
-* Copyright 2013 Sveriges Television AB http://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
-#pragma once\r
-\r
-#include <memory>\r
-\r
-struct AVFilterContext;\r
-\r
-namespace caspar { namespace ffmpeg {\r
-       \r
-std::shared_ptr<void> make_parallel_yadif(AVFilterContext* ctx);\r
-\r
-}}
\ No newline at end of file
diff --git a/modules/ffmpeg/producer/filter/scalable_yadif/scalable_yadif.cpp b/modules/ffmpeg/producer/filter/scalable_yadif/scalable_yadif.cpp
deleted file mode 100644 (file)
index aa35e0a..0000000
+++ /dev/null
@@ -1,429 +0,0 @@
-#include "../../../StdAfx.h"\r
-\r
-#include "scalable_yadif.h"\r
-\r
-\r
-/*
- * Copyright (C) 2006-2010 Michael Niedermayer <michaelni@gmx.at>
- *               2010      James Darnley <james.darnley@gmail.com>
- *
- * FFmpeg 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.
- *
- * FFmpeg 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 FFmpeg; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-\r
-#pragma warning(push, 0)
-
-
-#undef NDEBUG
-#include <assert.h>
-
-typedef struct {
-    /**
-     * 0: send 1 frame for each frame
-     * 1: send 1 frame for each field
-     * 2: like 0 but skips spatial interlacing check
-     * 3: like 1 but skips spatial interlacing check
-     */
-    int mode;
-
-    /**
-     *  0: bottom field first
-     *  1: top field first
-     * -1: auto-detection
-     */
-    int parity;
-
-    int frame_pending;
-
-    /**
-     *  0: deinterlace all frames
-     *  1: only deinterlace frames marked as interlaced
-     */
-    int auto_enable;
-
-    AVFilterBufferRef *cur;
-    AVFilterBufferRef *next;
-    AVFilterBufferRef *prev;
-    AVFilterBufferRef *out;
-    void (*filter_line)(uint8_t *dst,
-                        uint8_t *prev, uint8_t *cur, uint8_t *next,
-                        int w, int prefs, int mrefs, int parity, int mode);
-
-    const AVPixFmtDescriptor *csp;
-} YADIFContext;
-
-#define CHECK(j)\
-    {   int score = FFABS(cur[mrefs-1+(j)] - cur[prefs-1-(j)])\
-                  + FFABS(cur[mrefs  +(j)] - cur[prefs  -(j)])\
-                  + FFABS(cur[mrefs+1+(j)] - cur[prefs+1-(j)]);\
-        if (score < spatial_score) {\
-            spatial_score= score;\
-            spatial_pred= (cur[mrefs  +(j)] + cur[prefs  -(j)])>>1;\
-
-#define FILTER \
-    for (x = 0;  x < w; x++) { \
-        int c = cur[mrefs]; \
-        int d = (prev2[0] + next2[0])>>1; \
-        int e = cur[prefs]; \
-        int temporal_diff0 = FFABS(prev2[0] - next2[0]); \
-        int temporal_diff1 =(FFABS(prev[mrefs] - c) + FFABS(prev[prefs] - e) )>>1; \
-        int temporal_diff2 =(FFABS(next[mrefs] - c) + FFABS(next[prefs] - e) )>>1; \
-        int diff = FFMAX3(temporal_diff0>>1, temporal_diff1, temporal_diff2); \
-        int spatial_pred = (c+e)>>1; \
-        int spatial_score = FFABS(cur[mrefs-1] - cur[prefs-1]) + FFABS(c-e) \
-                          + FFABS(cur[mrefs+1] - cur[prefs+1]) - 1; \
- \
-        CHECK(-1) CHECK(-2) }} }} \
-        CHECK( 1) CHECK( 2) }} }} \
- \
-        if (mode < 2) { \
-            int b = (prev2[2*mrefs] + next2[2*mrefs])>>1; \
-            int f = (prev2[2*prefs] + next2[2*prefs])>>1; \
-            int max = FFMAX3(d-e, d-c, FFMIN(b-c, f-e)); \
-            int min = FFMIN3(d-e, d-c, FFMAX(b-c, f-e)); \
- \
-            diff = FFMAX3(diff, min, -max); \
-        } \
- \
-        if (spatial_pred > d + diff) \
-           spatial_pred = d + diff; \
-        else if (spatial_pred < d - diff) \
-           spatial_pred = d - diff; \
- \
-        dst[0] = spatial_pred; \
- \
-        dst++; \
-        cur++; \
-        prev++; \
-        next++; \
-        prev2++; \
-        next2++; \
-    }
-
-void filter_line_c(uint8_t *dst,
-                          uint8_t *prev, uint8_t *cur, uint8_t *next,
-                          int w, int prefs, int mrefs, int parity, int mode)
-{
-    int x;
-    uint8_t *prev2 = parity ? prev : cur ;
-    uint8_t *next2 = parity ? cur  : next;
-
-    FILTER
-}
-
-void filter_line_c_16bit(uint16_t *dst,
-                                uint16_t *prev, uint16_t *cur, uint16_t *next,
-                                int w, int prefs, int mrefs, int parity, int mode)
-{
-    int x;
-    uint16_t *prev2 = parity ? prev : cur ;
-    uint16_t *next2 = parity ? cur  : next;
-    mrefs /= 2;
-    prefs /= 2;
-
-    FILTER
-}
-
-void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic,
-                   int parity, int tff)
-{
-    YADIFContext *yadif = (YADIFContext*)ctx->priv;
-    int y, i;
-
-    for (i = 0; i < yadif->csp->nb_components; i++) {
-        int w = dstpic->video->w;
-        int h = dstpic->video->h;
-        int refs = yadif->cur->linesize[i];
-        int df = (yadif->csp->comp[i].depth_minus1+1) / 8;
-
-        if (i) {
-        /* Why is this not part of the per-plane description thing? */
-            w >>= yadif->csp->log2_chroma_w;
-            h >>= yadif->csp->log2_chroma_h;
-        }
-
-        for (y = 0; y < h; y++) {
-            if ((y ^ parity) & 1) {
-                uint8_t *prev = &yadif->prev->data[i][y*refs];
-                uint8_t *cur  = &yadif->cur ->data[i][y*refs];
-                uint8_t *next = &yadif->next->data[i][y*refs];
-                uint8_t *dst  = &dstpic->data[i][y*dstpic->linesize[i]];
-                int     mode  = y==1 || y+2==h ? 2 : yadif->mode;
-                yadif->filter_line(dst, prev, cur, next, w, y+1<h ? refs : -refs, y ? -refs : refs, parity ^ tff, mode);
-            } else {
-                memcpy(&dstpic->data[i][y*dstpic->linesize[i]],
-                       &yadif->cur->data[i][y*refs], w*df);
-            }
-        }
-    }
-    //__asm__ volatile("emms \n\t" : : : "memory");
-}
-
-AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms, int w, int h)
-{
-    AVFilterBufferRef *picref;
-    int width = FFALIGN(w, 32);
-    int height= FFALIGN(h+2, 32);
-    int i;
-
-    picref = avfilter_default_get_video_buffer(link, perms, width, height);
-
-    picref->video->w = w;
-    picref->video->h = h;
-
-    for (i = 0; i < 3; i++)
-        picref->data[i] += picref->linesize[i];
-
-    return picref;
-}
-
-void return_frame(AVFilterContext *ctx, int is_second)
-{
-    YADIFContext *yadif = (YADIFContext*)ctx->priv;
-    AVFilterLink *link= ctx->outputs[0];
-    int tff;
-
-    if (yadif->parity == -1) {
-        tff = yadif->cur->video->interlaced ?
-            yadif->cur->video->top_field_first : 1;
-    } else {
-        tff = yadif->parity^1;
-    }
-
-    if (is_second)
-        yadif->out = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE |
-                                               AV_PERM_REUSE, link->w, link->h);
-
-    if (!yadif->csp)
-        yadif->csp = &av_pix_fmt_descriptors[link->format];
-    if (yadif->csp->comp[0].depth_minus1 == 15)
-        yadif->filter_line = (decltype(yadif->filter_line))filter_line_c_16bit;
-
-    filter(ctx, yadif->out, tff ^ !is_second, tff);
-
-    if (is_second) {
-        if (yadif->next->pts != AV_NOPTS_VALUE &&
-            yadif->cur->pts != AV_NOPTS_VALUE) {
-            yadif->out->pts =
-                (yadif->next->pts&yadif->cur->pts) +
-                ((yadif->next->pts^yadif->cur->pts)>>1);
-        } else {
-            yadif->out->pts = AV_NOPTS_VALUE;
-        }
-        avfilter_start_frame(ctx->outputs[0], yadif->out);
-    }
-    avfilter_draw_slice(ctx->outputs[0], 0, link->h, 1);
-    avfilter_end_frame(ctx->outputs[0]);
-
-    yadif->frame_pending = (yadif->mode&1) && !is_second;
-}
-
-void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
-{
-    AVFilterContext *ctx = link->dst;
-    YADIFContext *yadif = (YADIFContext*)ctx->priv;
-
-    if (yadif->frame_pending)
-        return_frame(ctx, 1);
-
-    if (yadif->prev)
-        avfilter_unref_buffer(yadif->prev);
-    yadif->prev = yadif->cur;
-    yadif->cur  = yadif->next;
-    yadif->next = picref;
-
-    if (!yadif->cur)
-        return;
-
-    if (yadif->auto_enable && !yadif->cur->video->interlaced) {
-        yadif->out  = avfilter_ref_buffer(yadif->cur, AV_PERM_READ);
-        avfilter_unref_buffer(yadif->prev);
-        yadif->prev = NULL;
-        avfilter_start_frame(ctx->outputs[0], yadif->out);
-        return;
-    }
-
-    if (!yadif->prev)
-        yadif->prev = avfilter_ref_buffer(yadif->cur, AV_PERM_READ);
-
-    yadif->out = avfilter_get_video_buffer(ctx->outputs[0], AV_PERM_WRITE | AV_PERM_PRESERVE |
-                                       AV_PERM_REUSE, link->w, link->h);
-
-    avfilter_copy_buffer_ref_props(yadif->out, yadif->cur);
-    yadif->out->video->interlaced = 0;
-    avfilter_start_frame(ctx->outputs[0], yadif->out);
-}
-
-void end_frame(AVFilterLink *link)
-{
-    AVFilterContext *ctx = link->dst;
-    YADIFContext *yadif = (YADIFContext*)ctx->priv;
-
-    if (!yadif->out)
-        return;
-
-    if (yadif->auto_enable && !yadif->cur->video->interlaced) {
-        avfilter_draw_slice(ctx->outputs[0], 0, link->h, 1);
-        avfilter_end_frame(ctx->outputs[0]);
-        return;
-    }
-
-    return_frame(ctx, 0);
-}
-
-int request_frame(AVFilterLink *link)
-{
-    AVFilterContext *ctx = link->src;
-    YADIFContext *yadif = (YADIFContext*)ctx->priv;
-
-    if (yadif->frame_pending) {
-        return_frame(ctx, 1);
-        return 0;
-    }
-
-    do {
-        int ret;
-               ret = avfilter_request_frame(link->src->inputs[0]);
-        if (ret)
-            return ret;
-    } while (!yadif->cur);
-
-    return 0;
-}
-
-int poll_frame(AVFilterLink *link)
-{
-    YADIFContext *yadif = (YADIFContext*)link->src->priv;
-    int ret, val;
-
-    if (yadif->frame_pending)
-        return 1;
-
-    val = avfilter_poll_frame(link->src->inputs[0]);
-
-    if (val==1 && !yadif->next) { //FIXME change API to not requre this red tape
-        if ((ret = avfilter_request_frame(link->src->inputs[0])) < 0)
-            return ret;
-        val = avfilter_poll_frame(link->src->inputs[0]);
-    }
-    assert(yadif->next || !val);
-
-    if (yadif->auto_enable && yadif->next && !yadif->next->video->interlaced)
-        return val;
-
-    return val * ((yadif->mode&1)+1);
-}
-
-void uninit(AVFilterContext *ctx)
-{
-    YADIFContext *yadif = (YADIFContext*)ctx->priv;
-
-    if (yadif->prev) avfilter_unref_buffer(yadif->prev);
-    if (yadif->cur ) avfilter_unref_buffer(yadif->cur );
-    if (yadif->next) avfilter_unref_buffer(yadif->next);
-}
-
-int query_formats(AVFilterContext *ctx)
-{
-    static const enum PixelFormat pix_fmts[] = {
-        PIX_FMT_YUV420P,
-        PIX_FMT_YUV422P,
-        PIX_FMT_YUV444P,
-        PIX_FMT_YUV410P,
-        PIX_FMT_YUV411P,
-        PIX_FMT_GRAY8,
-        PIX_FMT_YUVJ420P,
-        PIX_FMT_YUVJ422P,
-        PIX_FMT_YUVJ444P,
-        AV_NE( PIX_FMT_GRAY16BE, PIX_FMT_GRAY16LE ),
-        PIX_FMT_YUV440P,
-        PIX_FMT_YUVJ440P,
-        AV_NE( PIX_FMT_YUV420P16BE, PIX_FMT_YUV420P16LE ),
-        AV_NE( PIX_FMT_YUV422P16BE, PIX_FMT_YUV422P16LE ),
-        AV_NE( PIX_FMT_YUV444P16BE, PIX_FMT_YUV444P16LE ),
-        PIX_FMT_NONE
-    };
-
-    avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list((const int*)pix_fmts));
-
-    return 0;
-}
-
-int init(AVFilterContext *ctx, const char *args, void *opaque)
-{
-    YADIFContext *yadif = (YADIFContext*)ctx->priv;
-    av_unused int cpu_flags = av_get_cpu_flags();
-
-    yadif->mode = 0;
-    yadif->parity = -1;
-    yadif->auto_enable = 0;
-    yadif->csp = NULL;
-
-    if (args) sscanf(args, "%d:%d:%d", &yadif->mode, &yadif->parity, &yadif->auto_enable);
-
-       \r
-       auto module = LoadLibrary(L"avfilter-2.dll");\r
-       static std::shared_ptr<void> lib(module, FreeLibrary);\r
-    yadif->filter_line = (decltype(yadif->filter_line))(GetProcAddress(module, "ff_yadif_filter_line_ssse3"));
-
-    //yadif->filter_line = filter_line_c;
-    //if (HAVE_SSSE3 && cpu_flags & AV_CPU_FLAG_SSSE3)
-    //    yadif->filter_line = ff_yadif_filter_line_ssse3;
-    //else if (HAVE_SSE && cpu_flags & AV_CPU_FLAG_SSE2)
-    //    yadif->filter_line = ff_yadif_filter_line_sse2;
-    //else if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX)
-    //    yadif->filter_line = ff_yadif_filter_line_mmx;
-
-    av_log(ctx, AV_LOG_INFO, "mode:%d parity:%d auto_enable:%d\n", yadif->mode, yadif->parity, yadif->auto_enable);
-
-    return 0;
-}
-
-void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
-
-void register_scalable_yadif()
-{
-       static AVFilter avfilter_vf_syadif;
-    avfilter_vf_syadif.name          = "syadif";
-    avfilter_vf_syadif .description   = "Deinterlace the input image";
-
-    avfilter_vf_syadif.priv_size     = sizeof(YADIFContext);
-    avfilter_vf_syadif.init          = init;
-    avfilter_vf_syadif.uninit        = uninit;
-    avfilter_vf_syadif.query_formats = query_formats;
-
-       static AVFilterPad inputs[2];
-
-       inputs[0].name                          = "default";         
-       inputs[0].type                          = AVMEDIA_TYPE_VIDEO,
-    inputs[0].start_frame              = start_frame;
-    inputs[0].get_video_buffer = get_video_buffer;
-    inputs[0].draw_slice               = null_draw_slice;
-    inputs[0].end_frame                        = end_frame;
-       inputs[1].name                          = nullptr;
-       
-       avfilter_vf_syadif.inputs = inputs;
-
-       static AVFilterPad outputs[2];
-
-       outputs[0].name                         = "default";
-       outputs[0].type                         = AVMEDIA_TYPE_VIDEO;
-       outputs[0].poll_frame           = poll_frame;
-       outputs[0].request_frame        = request_frame;
-       outputs[1].name                         = nullptr;
-       
-       avfilter_vf_syadif.outputs = outputs;
-       
-       avfilter_register(&avfilter_vf_syadif);
-};
diff --git a/modules/ffmpeg/producer/filter/scalable_yadif/scalable_yadif.h b/modules/ffmpeg/producer/filter/scalable_yadif/scalable_yadif.h
deleted file mode 100644 (file)
index e734057..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#pragma once\r
-\r
-extern "C" \r
-{\r
-       #define __STDC_CONSTANT_MACROS\r
-       #define __STDC_LIMIT_MACROS
-       #include <libavutil/cpu.h>
-       #include <libavutil/common.h>
-       #include <libavutil/pixdesc.h>
-       #include <libavfilter/avfilter.h>\r
-}\r
-\r
-int init(AVFilterContext *ctx, const char *args, void *opaque);\r
-void uninit(AVFilterContext *ctx);\r
-int query_formats(AVFilterContext *ctx);\r
-int poll_frame(AVFilterLink *link);\r
-int request_frame(AVFilterLink *link);\r
-void start_frame(AVFilterLink *link, AVFilterBufferRef *picref);\r
-void end_frame(AVFilterLink *link);\r
-void return_frame(AVFilterContext *ctx, int is_second);\r
-AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms, int w, int h);\r
-\r
-void register_scalable_yadif();
\ No newline at end of file