]> git.sesse.net Git - casparcg/commitdiff
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Sun, 23 Oct 2011 15:17:50 +0000 (15:17 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Sun, 23 Oct 2011 15:17:50 +0000 (15:17 +0000)
modules/ffmpeg/producer/frame_muxer.cpp

index d6afa44b33a39f87a7bcb929eee275143c51150b..254a1b1dec05c51b0fa64624c7ad6bb8b3120302 100644 (file)
@@ -125,12 +125,12 @@ display_mode::type get_display_mode(const core::field_mode::type in_mode, double
 struct frame_muxer2::implementation : public Concurrency::agent, boost::noncopyable\r
 {              \r
        ITarget<safe_ptr<core::basic_frame>>&                   target_;\r
-       display_mode::type                                                              display_mode_;\r
+       mutable single_assignment<display_mode::type>   display_mode_;\r
        const double                                                                    in_fps_;\r
        const video_format_desc                                                 format_desc_;\r
        bool                                                                                    auto_transcode_;\r
        \r
-       filter                                                                                  filter_;\r
+       mutable single_assignment<safe_ptr<filter>>             filter_;\r
        const safe_ptr<core::frame_factory>                             frame_factory_;\r
        \r
        call<safe_ptr<AVFrame>>                                                 push_video_;\r
@@ -152,7 +152,6 @@ struct frame_muxer2::implementation : public Concurrency::agent, boost::noncopya
                                   const safe_ptr<core::frame_factory>& frame_factory,\r
                                   const std::wstring& filter)\r
                : target_(target)\r
-               , display_mode_(display_mode::invalid)\r
                , in_fps_(in_fps)\r
                , format_desc_(frame_factory->get_video_format_desc())\r
                , auto_transcode_(env::properties().get("configuration.producers.auto-transcode", false))\r
@@ -161,7 +160,6 @@ struct frame_muxer2::implementation : public Concurrency::agent, boost::noncopya
                , push_audio_(std::bind(&implementation::push_audio, this, std::placeholders::_1))\r
                , video_(std::bind(&implementation::transform_video, this, std::placeholders::_1))\r
                , audio_(std::bind(&implementation::transform_audio, this, std::placeholders::_1))\r
-               , filter_str_(filter)\r
        {\r
                if(video_source)\r
                        video_source->link_target(&push_video_);\r
@@ -247,7 +245,7 @@ struct frame_muxer2::implementation : public Concurrency::agent, boost::noncopya
 \r
                                auto frame = safe_ptr<core::basic_frame>(video);\r
 \r
-                               switch(display_mode_)\r
+                               switch(display_mode_.value())\r
                                {\r
                                case display_mode::simple:                      \r
                                case display_mode::deinterlace:\r
@@ -321,7 +319,7 @@ struct frame_muxer2::implementation : public Concurrency::agent, boost::noncopya
                \r
                try\r
                {\r
-                       if(display_mode_ == display_mode::invalid)\r
+                       if(!display_mode_.has_value())\r
                                initialize_display_mode(*video_frame);\r
                                                \r
                        //if(hints & core::frame_producer::ALPHA_HINT)\r
@@ -331,11 +329,11 @@ struct frame_muxer2::implementation : public Concurrency::agent, boost::noncopya
                        if(video_frame->format == CASPAR_PIX_FMT_LUMA) // CASPAR_PIX_FMT_LUMA is not valid for filter, change it to GRAY8\r
                                video_frame->format = PIX_FMT_GRAY8;\r
 \r
-                       filter_.push(video_frame);\r
+                       filter_.value()->push(video_frame);\r
 \r
                        while(true)\r
                        {\r
-                               auto frame = filter_.poll();\r
+                               auto frame = filter_.value()->poll();\r
                                if(!frame)\r
                                        break;  \r
 \r
@@ -389,6 +387,8 @@ struct frame_muxer2::implementation : public Concurrency::agent, boost::noncopya
 \r
        void initialize_display_mode(AVFrame& frame)\r
        {\r
+               auto display_mode = display_mode::invalid;\r
+\r
                if(auto_transcode_)\r
                {\r
                        auto mode = get_mode(frame);\r
@@ -400,33 +400,35 @@ struct frame_muxer2::implementation : public Concurrency::agent, boost::noncopya
                        if(is_double_rate(filter_str_))\r
                                fps *= 2;\r
 \r
-                       display_mode_ = get_display_mode(mode, fps, format_desc_.field_mode, format_desc_.fps);\r
+                       display_mode = get_display_mode(mode, fps, format_desc_.field_mode, format_desc_.fps);\r
                        \r
-                       if(display_mode_ == display_mode::simple && mode != core::field_mode::progressive && format_desc_.field_mode != core::field_mode::progressive && frame.height != static_cast<int>(format_desc_.height))\r
-                               display_mode_ = display_mode::deinterlace_bob_reinterlace; // The frame will most likely be scaled, we need to deinterlace->reinterlace \r
+                       if(display_mode == display_mode::simple && mode != core::field_mode::progressive && format_desc_.field_mode != core::field_mode::progressive && frame.height != static_cast<int>(format_desc_.height))\r
+                               display_mode = display_mode::deinterlace_bob_reinterlace; // The frame will most likely be scaled, we need to deinterlace->reinterlace  \r
                                \r
-                       if(display_mode_ == display_mode::deinterlace)\r
+                       if(display_mode == display_mode::deinterlace)\r
                                append_filter(filter_str_, L"YADIF=0:-1");\r
-                       else if(display_mode_ == display_mode::deinterlace_bob || display_mode_ == display_mode::deinterlace_bob_reinterlace)\r
+                       else if(display_mode == display_mode::deinterlace_bob || display_mode == display_mode::deinterlace_bob_reinterlace)\r
                                append_filter(filter_str_, L"YADIF=1:-1");\r
                }\r
                else\r
-                       display_mode_ = display_mode::simple;\r
+                       display_mode = display_mode::simple;\r
 \r
-               if(display_mode_ == display_mode::invalid)\r
+               if(display_mode == display_mode::invalid)\r
                {\r
                        CASPAR_LOG(warning) << L"[frame_muxer] Failed to detect display-mode.";\r
-                       display_mode_ = display_mode::simple;\r
+                       display_mode = display_mode::simple;\r
                }\r
                        \r
-               filter_ = filter(filter_str_);\r
+               send(filter_, make_safe<filter>(filter_str_));\r
+\r
+               CASPAR_LOG(info) << "[frame_muxer] " << display_mode::print(display_mode);\r
 \r
-               CASPAR_LOG(info) << "[frame_muxer] " << display_mode::print(display_mode_);\r
+               send(display_mode_, display_mode);\r
        }\r
                                        \r
        int64_t calc_nb_frames(int64_t nb_frames) const\r
        {\r
-               switch(display_mode_) // Take into account transformation in run.\r
+               switch(display_mode_.value()) // Take into account transformation in run.\r
                {\r
                case display_mode::deinterlace_bob_reinterlace:\r
                case display_mode::interlace:   \r
@@ -438,7 +440,7 @@ struct frame_muxer2::implementation : public Concurrency::agent, boost::noncopya
                        break;\r
                }\r
 \r
-               if(is_double_rate(filter_str_)) // Take into account transformations in filter.\r
+               if(is_double_rate(widen(filter_.value()->filter_str()))) // Take into account transformations in filter.\r
                        nb_frames *= 2;\r
 \r
                return nb_frames;\r