]> git.sesse.net Git - casparcg/commitdiff
2.0. ffmpeg_producer: Do rendering asynchronously.
authorRonag <Ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Sat, 6 Aug 2011 12:19:32 +0000 (12:19 +0000)
committerRonag <Ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Sat, 6 Aug 2011 12:19:32 +0000 (12:19 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@1066 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

modules/ffmpeg/producer/ffmpeg_producer.cpp
modules/ffmpeg/producer/filter/parallel_yadif.cpp
modules/ffmpeg/producer/frame_muxer.cpp

index a56a2626fb1e4407cf519c706754d305768c3ed9..5105081a84d608f1ec724f9b26afef78d1ad5438 100644 (file)
@@ -95,28 +95,43 @@ public:
                for(int n = 0; n < 128 && muxer_.size() < 2; ++n)\r
                        decode_frame();\r
        }\r
+\r
+       ~ffmpeg_producer()\r
+       {\r
+               tasks_.cancel();\r
+               tasks_.wait();\r
+       }\r
        \r
        virtual safe_ptr<core::basic_frame> receive()\r
        {\r
-               // TODO: Do rendering asynchronously.\r
-\r
-               frame_timer_.restart();\r
+               tasks_.wait();\r
 \r
-               for(int n = 0; n < 64 && muxer_.size() < 2; ++n)\r
-                       decode_frame();\r
-\r
-               graph_->update_value("frame-time", static_cast<float>(frame_timer_.elapsed()*format_desc_.fps*0.5));\r
+               auto frame = core::basic_frame::late();\r
                \r
                if(!muxer_.empty())\r
-                       return last_frame_ = muxer_.pop();      \r
+                       frame = last_frame_ = muxer_.pop();     \r
+               else\r
+               {\r
+                       if(input_.eof())\r
+                               frame =  core::basic_frame::eof();\r
+                       else\r
+                       {\r
+                               graph_->add_tag("underflow");   \r
+                               ++nb_frames_;           \r
+                       }\r
+               }\r
 \r
-               if(input_.eof())\r
-                       return core::basic_frame::eof();\r
+               tasks_.run([this]\r
+               {\r
+                       frame_timer_.restart();\r
 \r
-               graph_->add_tag("underflow");   \r
-               ++nb_frames_;           \r
+                       for(int n = 0; n < 64 && muxer_.size() < 2; ++n)\r
+                               decode_frame();\r
 \r
-               return core::basic_frame::late();\r
+                       graph_->update_value("frame-time", static_cast<float>(frame_timer_.elapsed()*format_desc_.fps*0.5));\r
+               });\r
+               \r
+               return frame;\r
        }\r
 \r
        virtual safe_ptr<core::basic_frame> last_frame() const\r
index 3983641e02eb561e4f5db9ec0c3660e044cbc888..70521a1bddc45a89da649924a820ef775e988089 100644 (file)
@@ -7,6 +7,8 @@ extern "C"
        #include <libavfilter/avfilter.h>\r
 }\r
 \r
+#include <tbb/parallel_for.h>\r
+\r
 #include <boost/thread/once.hpp>\r
 \r
 typedef struct {\r
@@ -75,7 +77,6 @@ void RENAME(x)(uint8_t *dst, uint8_t *prev, uint8_t *cur, uint8_t *next, int w,
 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
-\r
 {f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17};\r
 \r
 namespace caspar {\r
@@ -84,14 +85,14 @@ tbb::concurrent_bounded_queue<decltype(org_yadif_filter_line)> parallel_line_fun
 \r
 void init_pool()\r
 {\r
-       for(int n = 0; n < sizeof(fs)/sizeof(decltype(org_yadif_filter_line)); ++n)\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(org_yadif_filter_line)>(func));\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
index c7a86e9f53a18a6d92660b20f4bd3bfc5e382412..b9fc4f597e28775c640dfe4a7d73cf4f56d438d0 100644 (file)
@@ -296,7 +296,6 @@ struct frame_muxer::implementation : boost::noncopyable
                        return;\r
                \r
                auto frame1 = pop_video();\r
-               frame1->commit();\r
                frame1->audio_data() = pop_audio();\r
 \r
                dest.push_back(frame1);         \r
@@ -308,7 +307,6 @@ struct frame_muxer::implementation : boost::noncopyable
                        return;\r
 \r
                auto frame = pop_video();\r
-               frame->commit();\r
 \r
                auto frame1 = make_safe<core::write_frame>(*frame); // make a copy\r
                frame1->audio_data() = pop_audio();\r
@@ -326,7 +324,6 @@ struct frame_muxer::implementation : boost::noncopyable
                        return;\r
                                                \r
                auto frame1 = pop_video();\r
-               frame1->commit();\r
                frame1->audio_data() = pop_audio();\r
                                \r
                video_streams_.front().pop(); // Throw away\r
@@ -340,8 +337,6 @@ struct frame_muxer::implementation : boost::noncopyable
                        return;\r
                \r
                auto frame1 = pop_video();\r
-               frame1->commit();\r
-\r
                frame1->audio_data() = pop_audio();\r
                                \r
                auto frame2 = pop_video();\r