]> git.sesse.net Git - casparcg/blobdiff - modules/ffmpeg/producer/frame_muxer.cpp
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
[casparcg] / modules / ffmpeg / producer / frame_muxer.cpp
index 5402e8e29ac2054e888c26e123c39020f512afa8..89c51a68bc5ff1264f8c0a15cea0c7a592d35c49 100644 (file)
@@ -86,6 +86,20 @@ display_mode::type get_display_mode(const core::video_mode::type in_mode, double
 {              \r
        static const auto epsilon = 2.0;\r
 \r
+       if(in_fps < 20.0 || in_fps > 80.0)\r
+       {\r
+               //if(out_mode != core::video_mode::progressive && in_mode == core::video_mode::progressive)\r
+               //      return display_mode::interlace;\r
+               \r
+               if(out_mode == core::video_mode::progressive && in_mode != core::video_mode::progressive)\r
+               {\r
+                       if(in_fps < 35.0)\r
+                               return display_mode::deinterlace;\r
+                       else\r
+                               return display_mode::deinterlace_bob;\r
+               }\r
+       }\r
+\r
        if(std::abs(in_fps - out_fps) < epsilon)\r
        {\r
                if(in_mode != core::video_mode::progressive && out_mode == core::video_mode::progressive)\r
@@ -127,7 +141,7 @@ struct frame_muxer::implementation : boost::noncopyable
        display_mode::type                                                              display_mode_;\r
        const double                                                                    in_fps_;\r
        const video_format_desc                                                 format_desc_;\r
-       bool                                                                                    auto_mode_;\r
+       bool                                                                                    auto_transcode_;\r
 \r
        size_t                                                                                  audio_sample_count_;\r
        size_t                                                                                  video_frame_count_;\r
@@ -144,7 +158,7 @@ struct frame_muxer::implementation : boost::noncopyable
                , display_mode_(display_mode::invalid)\r
                , in_fps_(in_fps)\r
                , format_desc_(frame_factory->get_video_format_desc())\r
-               , auto_mode_(env::properties().get("configuration.producers.auto-transcode", false))\r
+               , auto_transcode_(env::properties().get("configuration.producers.auto-transcode", false))\r
                , audio_sample_count_(0)\r
                , video_frame_count_(0)\r
                , frame_factory_(frame_factory)\r
@@ -171,7 +185,7 @@ struct frame_muxer::implementation : boost::noncopyable
 \r
                if(display_mode_ == display_mode::invalid)\r
                {\r
-                       if(auto_mode_)\r
+                       if(auto_transcode_)\r
                        {\r
                                auto in_mode = get_mode(*video_frame);\r
                                display_mode_ = get_display_mode(in_mode, in_fps_, format_desc_.mode, format_desc_.fps);\r
@@ -195,12 +209,19 @@ struct frame_muxer::implementation : boost::noncopyable
 \r
                        CASPAR_LOG(info) << "[frame_muxer] " << display_mode::print(display_mode_);\r
                }\r
+\r
                                \r
                if(hints & core::frame_producer::ALPHA_HINT)\r
-                       try_make_gray(make_safe(video_frame));\r
+                       video_frame->format = make_alpha_format(video_frame->format);\r
+               \r
+               auto format = video_frame->format;\r
+               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
                BOOST_FOREACH(auto& av_frame, filter_.execute(video_frame))\r
                {\r
+                       av_frame->format = format;\r
+\r
                        auto frame = make_write_frame(this, av_frame, frame_factory_, hints);\r
 \r
                        // Fix field-order if needed\r
@@ -212,6 +233,9 @@ struct frame_muxer::implementation : boost::noncopyable
                        video_streams_.back().push(frame);\r
                        ++video_frame_count_;\r
                }\r
+\r
+               if(video_streams_.back().size() > 8)\r
+                       BOOST_THROW_EXCEPTION(invalid_operation() << source_info("frame_muxer") << msg_info("audio-stream overflow. This can be caused by incorrect frame-rate. Check clip meta-data."));\r
        }\r
 \r
        void push(const std::shared_ptr<std::vector<int16_t>>& audio_samples)\r
@@ -227,6 +251,9 @@ struct frame_muxer::implementation : boost::noncopyable
                audio_sample_count_ += audio_samples->size();\r
 \r
                boost::range::push_back(audio_streams_.back(), *audio_samples);\r
+\r
+               if(audio_streams_.back().size() > 8*format_desc_.audio_samples_per_frame)\r
+                       BOOST_THROW_EXCEPTION(invalid_operation() << source_info("frame_muxer") << msg_info("audio-stream overflow. This can be caused by incorrect frame-rate. Check clip meta-data."));\r
        }\r
 \r
        safe_ptr<basic_frame> pop()\r
@@ -261,31 +288,43 @@ struct frame_muxer::implementation : boost::noncopyable
 \r
                return samples;\r
        }\r
-\r
+       \r
        bool video_ready() const\r
-       {\r
-               return video_frames() > 1 && video_streams_.size() >= audio_streams_.size();\r
+       {               \r
+               return video_streams_.size() > 1 || (video_streams_.size() >= audio_streams_.size() && video_ready2());\r
        }\r
        \r
        bool audio_ready() const\r
        {\r
-               return audio_chunks() > 1 && audio_streams_.size() >= video_streams_.size();\r
+               return audio_streams_.size() > 1 || (audio_streams_.size() >= video_streams_.size() && audio_ready2());\r
        }\r
 \r
-       size_t video_frames() const\r
-       {\r
-               return video_streams_.back().size();\r
+       bool video_ready2() const\r
+       {               \r
+               switch(display_mode_)\r
+               {\r
+               case display_mode::deinterlace_bob_reinterlace:                                 \r
+               case display_mode::interlace:                                   \r
+                       return video_streams_.front().size() >= 2;\r
+               default:                                                                                \r
+                       return !video_streams_.front().empty();\r
+               }\r
        }\r
-\r
-       size_t audio_chunks() const\r
+       \r
+       bool audio_ready2() const\r
        {\r
-               return audio_streams_.back().size() / format_desc_.audio_samples_per_frame;\r
+               switch(display_mode_)\r
+               {\r
+               case display_mode::duplicate:                                   \r
+                       return audio_streams_.front().size()/2 >= format_desc_.audio_samples_per_frame;\r
+               default:                                                                                \r
+                       return audio_streams_.front().size() >= format_desc_.audio_samples_per_frame;\r
+               }\r
        }\r
-       \r
+               \r
        void commit()\r
        {\r
-               if(video_streams_.size() > 1 && audio_streams_.size() > 1 &&\r
-                       (video_streams_.front().empty() || audio_streams_.front().empty()))\r
+               if(video_streams_.size() > 1 && audio_streams_.size() > 1 && (!video_ready2() || !audio_ready2()))\r
                {\r
                        if(!video_streams_.front().empty() || !audio_streams_.front().empty())\r
                                CASPAR_LOG(debug) << "Truncating: " << video_streams_.front().size() << L" video-frames, " << audio_streams_.front().size() << L" audio-samples.";\r
@@ -294,7 +333,7 @@ struct frame_muxer::implementation : boost::noncopyable
                        audio_streams_.pop_front();\r
                }\r
 \r
-               if(video_streams_.front().empty() || audio_streams_.front().size() < format_desc_.audio_samples_per_frame)\r
+               if(!video_ready2() || !audio_ready2())\r
                        return;\r
                \r
                switch(display_mode_)\r
@@ -309,12 +348,9 @@ struct frame_muxer::implementation : boost::noncopyable
                default:                                                                                BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("invalid display-mode"));\r
                }\r
        }\r
-\r
+       \r
        void simple(std::deque<safe_ptr<basic_frame>>& dest)\r
-       {\r
-               if(video_streams_.front().empty() || audio_streams_.front().size() < format_desc_.audio_samples_per_frame)\r
-                       return;\r
-               \r
+       {               \r
                auto frame1 = pop_video();\r
                frame1->audio_data() = pop_audio();\r
 \r
@@ -323,9 +359,6 @@ struct frame_muxer::implementation : boost::noncopyable
 \r
        void duplicate(std::deque<safe_ptr<basic_frame>>& dest)\r
        {               \r
-               if(video_streams_.front().empty() || audio_streams_.front().size()/2 < format_desc_.audio_samples_per_frame)\r
-                       return;\r
-\r
                auto frame = pop_video();\r
 \r
                auto frame1 = make_safe<core::write_frame>(*frame); // make a copy\r
@@ -339,10 +372,7 @@ struct frame_muxer::implementation : boost::noncopyable
        }\r
 \r
        void half(std::deque<safe_ptr<basic_frame>>& dest)\r
-       {       \r
-               if(video_streams_.front().size() < 2 || audio_streams_.front().size() < format_desc_.audio_samples_per_frame)\r
-                       return;\r
-                                               \r
+       {                                                       \r
                auto frame1 = pop_video();\r
                frame1->audio_data() = pop_audio();\r
                                \r
@@ -352,10 +382,7 @@ struct frame_muxer::implementation : boost::noncopyable
        }\r
        \r
        void interlace(std::deque<safe_ptr<basic_frame>>& dest)\r
-       {               \r
-               if(video_streams_.front().size() < 2 || audio_streams_.front().size() < format_desc_.audio_samples_per_frame)\r
-                       return;\r
-               \r
+       {                               \r
                auto frame1 = pop_video();\r
                frame1->audio_data() = pop_audio();\r
                                \r