]> git.sesse.net Git - casparcg/blobdiff - modules/ffmpeg/producer/ffmpeg_producer.cpp
2.0. Updated namespaces.
[casparcg] / modules / ffmpeg / producer / ffmpeg_producer.cpp
index d20cbaca4f0a73f4d0280d3e121e1720b8ccdbd1..480e95b8d0d3739eb4db855e35613adc428ca9fc 100644 (file)
@@ -46,7 +46,7 @@
 \r
 #include <tbb/parallel_invoke.h>\r
 \r
-namespace caspar {\r
+namespace caspar { namespace ffmpeg {\r
                                \r
 struct ffmpeg_producer : public core::frame_producer\r
 {\r
@@ -99,8 +99,22 @@ public:
                graph_->set_color("frame-time", diagnostics::color(0.1f, 1.0f, 0.1f));\r
                graph_->set_color("underflow", diagnostics::color(0.6f, 0.3f, 0.9f));   \r
                \r
-               for(int n = 0; n < 32 && muxer_.empty(); ++n)\r
-                       decode_frame(0);\r
+               // Do some pre-work in order to not block rendering thread for initialization and allocations.\r
+\r
+               push_packets();\r
+               auto video_frames = video_decoder_.poll();\r
+               if(!video_frames.empty())\r
+               {\r
+                       auto& video_frame = video_frames.front();\r
+                       auto  desc                = get_pixel_format_desc(static_cast<PixelFormat>(video_frame->format), video_frame->width, video_frame->height);\r
+                       if(desc.pix_fmt == core::pixel_format::invalid)\r
+                               get_pixel_format_desc(PIX_FMT_BGRA, video_frame->width, video_frame->height);\r
+                       \r
+                       for(int n = 0; n < 3; ++n)\r
+                               frame_factory->create_frame(this, desc);\r
+               }\r
+               BOOST_FOREACH(auto& video, video_frames)                        \r
+                       muxer_.push(video, 0);  \r
        }\r
                        \r
        virtual safe_ptr<core::basic_frame> receive(int hints)\r
@@ -132,7 +146,7 @@ public:
                return disable_audio(last_frame_);\r
        }\r
 \r
-       void decode_frame(int hints)\r
+       void push_packets()\r
        {\r
                for(int n = 0; n < 16 && ((!muxer_.video_ready() && !video_decoder_.ready()) || (!muxer_.audio_ready() && !audio_decoder_.ready())); ++n) \r
                {\r
@@ -143,6 +157,11 @@ public:
                                audio_decoder_.push(pkt);\r
                        }\r
                }\r
+       }\r
+\r
+       void decode_frame(int hints)\r
+       {\r
+               push_packets();\r
                \r
                tbb::parallel_invoke(\r
                [&]\r
@@ -197,12 +216,12 @@ public:
        {\r
                return L"ffmpeg[" + boost::filesystem::wpath(filename_).filename() + L"|" \r
                                                  + boost::lexical_cast<std::wstring>(width_) + L"x" + boost::lexical_cast<std::wstring>(height_)\r
-                                                 + (is_progressive_ ? L"p" : L"i")  + boost::lexical_cast<std::wstring>(fps_)\r
+                                                 + (is_progressive_ ? L"p" : L"i")  + boost::lexical_cast<std::wstring>(is_progressive_ ? fps_ : 2.0 * fps_)\r
                                                  + L"]";\r
        }\r
 };\r
 \r
-safe_ptr<core::frame_producer> create_ffmpeg_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::vector<std::wstring>& params)\r
+safe_ptr<core::frame_producer> create_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::vector<std::wstring>& params)\r
 {              \r
        static const std::vector<std::wstring> extensions = boost::assign::list_of\r
                (L"mpg")(L"mpeg")(L"m2v")(L"m4v")(L"mp3")(L"mp4")(L"mpga")\r
@@ -240,4 +259,4 @@ safe_ptr<core::frame_producer> create_ffmpeg_producer(const safe_ptr<core::frame
        return make_safe<ffmpeg_producer>(frame_factory, path, filter_str, loop, start, length);\r
 }\r
 \r
-}
\ No newline at end of file
+}}
\ No newline at end of file