]> git.sesse.net Git - casparcg/commitdiff
2.0. Refactored API.
authorRonag <Ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Wed, 3 Aug 2011 08:56:51 +0000 (08:56 +0000)
committerRonag <Ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Wed, 3 Aug 2011 08:56:51 +0000 (08:56 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@1044 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

15 files changed:
core/producer/color/color_producer.cpp
core/producer/frame/basic_frame.cpp
core/producer/frame/basic_frame.h
core/producer/frame_producer.cpp
core/producer/frame_producer.h
core/producer/separated/separated_producer.cpp
core/producer/stage.cpp
core/producer/transition/transition_producer.cpp
modules/decklink/producer/decklink_producer.cpp
modules/ffmpeg/producer/ffmpeg_producer.cpp
modules/flash/producer/cg_producer.cpp
modules/flash/producer/cg_producer.h
modules/flash/producer/flash_producer.cpp
modules/image/producer/image_producer.cpp
modules/image/producer/image_scroll_producer.cpp

index 51a7d7e8093899a83a3ea4b691524689b75b15f9..33e70bec67c3de310980c48e1b0380099b56e792 100644 (file)
@@ -42,6 +42,7 @@ public:
        // frame_producer\r
                        \r
        virtual safe_ptr<basic_frame> receive() { return frame_; }      \r
+       virtual safe_ptr<basic_frame> last_frame() const { return frame_; }     \r
        virtual std::wstring print() const { return L"color[" + color_str_ + L"]"; }\r
 };\r
 \r
index 91f78b54fdb80854d1cc230e619fa056de5c99cb..85dd7ccdca0ab4b86c9bd723300a1bc0b70d34d6 100644 (file)
@@ -144,5 +144,12 @@ safe_ptr<basic_frame> basic_frame::fill_and_key(const safe_ptr<basic_frame>& fil
        frames.push_back(fill);\r
        return basic_frame(std::move(frames));\r
 }\r
+\r
+safe_ptr<basic_frame> disable_audio(const safe_ptr<basic_frame>& frame)\r
+{\r
+       basic_frame frame2 = frame;\r
+       frame2.get_audio_transform().set_has_audio(false);\r
+       return std::move(frame2);\r
+}\r
        \r
 }}
\ No newline at end of file
index d6d57d0ea753a9c92b656e6df96e34ce57a97ae8..f4dd0226e067a95932883a6de6ca60efeabeff6f 100644 (file)
@@ -85,6 +85,8 @@ private:
        safe_ptr<implementation> impl_;\r
 };\r
 \r
+safe_ptr<basic_frame> disable_audio(const safe_ptr<basic_frame>& frame);\r
+\r
 inline bool is_concrete_frame(const safe_ptr<basic_frame>& frame)\r
 {\r
        return frame != basic_frame::empty() && frame != basic_frame::eof() && frame != basic_frame::late();\r
index 4f7b729df4054b854696e3b30c5555026f5db077..43bea338702a03af40ded13cd733e8547d32760e 100644 (file)
@@ -33,13 +33,12 @@ namespace caspar { namespace core {
        \r
 std::vector<const producer_factory_t> g_factories;\r
 \r
-frame_producer::frame_producer() : last_frame_(core::basic_frame::empty()){}\r
-\r
 const safe_ptr<frame_producer>& frame_producer::empty() // nothrow\r
 {\r
        struct empty_frame_producer : public frame_producer\r
        {\r
                virtual safe_ptr<basic_frame> receive(){return basic_frame::empty();}\r
+               virtual safe_ptr<basic_frame> last_frame() const{return basic_frame::empty();}\r
                virtual void set_frame_factory(const safe_ptr<frame_factory>&){}\r
                virtual std::wstring print() const { return L"empty";}\r
        };\r
@@ -47,22 +46,6 @@ const safe_ptr<frame_producer>& frame_producer::empty() // nothrow
        return producer;\r
 }      \r
 \r
-safe_ptr<basic_frame> frame_producer::receive_save_last()\r
-{\r
-       auto frame = receive();\r
-       if(frame != core::basic_frame::late())\r
-       {\r
-               last_frame_ = make_safe<basic_frame>(frame);\r
-               last_frame_->get_audio_transform().set_has_audio(false);\r
-       }       \r
-       return frame;\r
-}\r
-\r
-safe_ptr<basic_frame> receive(const safe_ptr<frame_producer>& producer)\r
-{\r
-       return producer->receive_save_last();\r
-}\r
-\r
 safe_ptr<basic_frame> receive_and_follow(safe_ptr<frame_producer>& producer)\r
 {      \r
        if(producer == frame_producer::empty())\r
@@ -71,7 +54,7 @@ safe_ptr<basic_frame> receive_and_follow(safe_ptr<frame_producer>& producer)
        auto frame = basic_frame::eof();\r
        try\r
        {\r
-               frame = receive(producer);\r
+               frame = producer->receive();\r
        }\r
        catch(...)\r
        {\r
index cbc099d93e4bc83803487a6ac3a43d6b5f2c775b..dbdd824d78b990e171dc62065c43a9c565adf0a0 100644 (file)
@@ -36,7 +36,6 @@ class basic_frame;
 class frame_producer : boost::noncopyable\r
 {\r
 public:\r
-       frame_producer();\r
        virtual ~frame_producer(){}     \r
 \r
        virtual std::wstring print() const = 0; // nothrow\r
@@ -47,22 +46,13 @@ public:
        virtual void set_leading_producer(const safe_ptr<frame_producer>&) {}  // nothrow\r
                \r
        virtual int64_t nb_frames() const {return 0;}\r
-\r
-       virtual safe_ptr<core::basic_frame> last_frame() const {return last_frame_;}\r
-\r
-       static const safe_ptr<frame_producer>& empty(); // nothrow\r
        \r
-private:\r
-       friend safe_ptr<basic_frame> receive(const safe_ptr<frame_producer>& producer);\r
-\r
        virtual safe_ptr<basic_frame> receive() = 0;\r
+       virtual safe_ptr<core::basic_frame> last_frame() const = 0;\r
 \r
-       safe_ptr<basic_frame> receive_save_last();\r
-\r
-       safe_ptr<core::basic_frame> last_frame_;\r
+       static const safe_ptr<frame_producer>& empty(); // nothrow\r
 };\r
 \r
-safe_ptr<basic_frame> receive(const safe_ptr<frame_producer>& producer);\r
 safe_ptr<basic_frame> receive_and_follow(safe_ptr<frame_producer>& producer);\r
 \r
 typedef std::function<safe_ptr<core::frame_producer>(const safe_ptr<frame_factory>&, const std::vector<std::wstring>&)> producer_factory_t;\r
index 3cccf40f628cb5f681500ec390130dfa7181cf88..5d3df3643111ac6ad62a4b7b45de858bd7ab4fd2 100644 (file)
@@ -33,12 +33,14 @@ struct separated_producer : public frame_producer
        safe_ptr<frame_producer>        key_producer_;\r
        safe_ptr<basic_frame>           fill_;\r
        safe_ptr<basic_frame>           key_;\r
+       safe_ptr<basic_frame>           last_frame_;\r
                \r
        explicit separated_producer(const safe_ptr<frame_producer>& fill, const safe_ptr<frame_producer>& key) \r
                : fill_producer_(fill)\r
                , key_producer_(key)\r
                , fill_(core::basic_frame::late())\r
-               , key_(core::basic_frame::late()){}\r
+               , key_(core::basic_frame::late())\r
+               , last_frame_(core::basic_frame::empty()){}\r
        \r
        // frame_producer\r
        \r
@@ -69,7 +71,12 @@ struct separated_producer : public frame_producer
                fill_ = basic_frame::late();\r
                key_ = basic_frame::late();\r
 \r
-               return frame;\r
+               return last_frame_ = frame;\r
+       }\r
+\r
+       virtual safe_ptr<core::basic_frame> last_frame() const\r
+       {\r
+               return last_frame_;\r
        }\r
 \r
        virtual std::wstring print() const\r
index 056e85d63c70c9dc97190321c90f723c65425024..aa6c92e2262c882b16d76e78fccb46491dfbd177 100644 (file)
@@ -64,7 +64,8 @@ public:
                destroy_context_.begin_invoke(std::bind(&destroy_producer, std::move(producer_)));\r
        }\r
 \r
-       virtual safe_ptr<basic_frame>           receive()                                                                                                               {return core::receive(producer_);}\r
+       virtual safe_ptr<basic_frame>           receive()                                                                                                               {return producer_->receive();}\r
+       virtual safe_ptr<basic_frame>           last_frame() const                                                                                              {return producer_->last_frame();}\r
        virtual std::wstring                            print() const                                                                                                   {return producer_->print();}\r
        virtual void                                            param(const std::wstring& str)                                                                  {producer_->param(str);}\r
        virtual safe_ptr<frame_producer>        get_following_producer() const                                                                  {return producer_->get_following_producer();}\r
index 495ab7886e7f4b9a7d77a4587461b1c2d8c6b8e4..43f2c76b1004f561710940bbfb470ae6b8512046 100644 (file)
@@ -38,13 +38,20 @@ struct transition_producer : public frame_producer
        \r
        safe_ptr<frame_producer>        dest_producer_;\r
        safe_ptr<frame_producer>        source_producer_;\r
+       safe_ptr<frame_producer>        org_dest_producer_;\r
+       safe_ptr<frame_producer>        org_source_producer_;\r
+\r
+       safe_ptr<basic_frame>           last_frame_;\r
                \r
        explicit transition_producer(const video_mode::type& mode, const safe_ptr<frame_producer>& dest, const transition_info& info) \r
                : mode_(mode)\r
                , current_frame_(0)\r
                , info_(info)\r
                , dest_producer_(dest)\r
-               , source_producer_(frame_producer::empty()){}\r
+               , org_dest_producer_(dest)\r
+               , source_producer_(frame_producer::empty())\r
+               , org_source_producer_(frame_producer::empty())\r
+               , last_frame_(basic_frame::empty()){}\r
        \r
        // frame_producer\r
 \r
@@ -55,7 +62,8 @@ struct transition_producer : public frame_producer
        \r
        virtual void set_leading_producer(const safe_ptr<frame_producer>& producer)\r
        {\r
-               source_producer_ = producer;\r
+               source_producer_         = producer;\r
+               org_source_producer_ = producer;\r
        }\r
 \r
        virtual safe_ptr<basic_frame> receive()\r
@@ -82,7 +90,12 @@ struct transition_producer : public frame_producer
                        }\r
                );\r
 \r
-               return compose(dest, source);\r
+               return last_frame_ = compose(dest, source);\r
+       }\r
+\r
+       virtual safe_ptr<core::basic_frame> last_frame() const\r
+       {\r
+               return last_frame_;\r
        }\r
 \r
        virtual int64_t nb_frames() const \r
@@ -92,7 +105,7 @@ struct transition_producer : public frame_producer
 \r
        virtual std::wstring print() const\r
        {\r
-               return L"transition";\r
+               return L"transition[" + org_source_producer_->print() + L"|" + org_dest_producer_->print() + L"]";\r
        }\r
        \r
        // transition_producer\r
index f48cfea4302db798554c1c8f905b14247c36f3be..56e3c9ca5ce9cffa0461320322e1b84b1b5a1392 100644 (file)
@@ -239,18 +239,25 @@ public:
        \r
 class decklink_producer_proxy : public core::frame_producer\r
 {              \r
+       safe_ptr<core::basic_frame>     last_frame_;\r
        com_context<decklink_producer> context_;\r
 public:\r
 \r
        explicit decklink_producer_proxy(const safe_ptr<core::frame_factory>& frame_factory, const core::video_format_desc& format_desc, size_t device_index, const std::wstring& filter_str = L"")\r
                : context_(L"decklink_producer[" + boost::lexical_cast<std::wstring>(device_index) + L"]")\r
+               , last_frame_(core::basic_frame::empty())\r
        {\r
                context_.reset([&]{return new decklink_producer(format_desc, device_index, frame_factory, filter_str);}); \r
        }\r
                                \r
        virtual safe_ptr<core::basic_frame> receive()\r
        {\r
-               return context_->get_frame();\r
+               return last_frame_ = context_->get_frame();\r
+       }\r
+\r
+       virtual safe_ptr<core::basic_frame> last_frame() const\r
+       {\r
+               return disable_audio(last_frame_);\r
        }\r
        \r
        std::wstring print() const\r
index ab7acc01a966a66da707e8c853612f5c025ff5ab..f08e1096623b883d39c9c840050d9d3e4ae87f26 100644 (file)
@@ -71,6 +71,8 @@ struct ffmpeg_producer : public core::frame_producer
        int64_t                                                                                 nb_frames_;\r
        bool                                                                                    loop_;\r
 \r
+       safe_ptr<core::basic_frame>                                             last_frame_;\r
+\r
 public:\r
        explicit ffmpeg_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filename, const std::wstring& filter, bool loop, int start, int length) \r
                : filename_(filename)\r
@@ -84,6 +86,7 @@ public:
                , start_(start)\r
                , nb_frames_(video_decoder_.nb_frames() - start)\r
                , loop_(loop)\r
+               , last_frame_(core::basic_frame::empty())\r
        {\r
                graph_->add_guide("frame-time", 0.5);\r
                graph_->set_color("frame-time", diagnostics::color(1.0f, 0.0f, 0.0f));\r
@@ -119,7 +122,12 @@ public:
                else            \r
                        frame = muxer_.pop();           \r
                \r
-               return frame;\r
+               return last_frame_ = frame;\r
+       }\r
+\r
+       virtual safe_ptr<core::basic_frame> last_frame() const\r
+       {\r
+               return disable_audio(last_frame_);\r
        }\r
 \r
        void decode_frame()\r
index 33c6f45a7328b06b0424341154df9ad95e610cff..9a1ca66161c0f44f4f8db2ad85255f9c4eaec703 100644 (file)
@@ -93,10 +93,15 @@ public:
                flash_producer_->param(str);\r
        }\r
 \r
-       safe_ptr<core::basic_frame> receive()\r
+       virtual safe_ptr<core::basic_frame> receive()\r
        {\r
-               return core::receive(flash_producer_);\r
+               return flash_producer_->receive();\r
        }\r
+\r
+       virtual safe_ptr<core::basic_frame> last_frame() const\r
+       {\r
+               return flash_producer_->last_frame();\r
+       }                       \r
                        \r
        std::wstring print() const\r
        {\r
@@ -134,6 +139,7 @@ safe_ptr<core::frame_producer> create_ct_producer(const safe_ptr<core::frame_fac
 cg_producer::cg_producer(const safe_ptr<core::frame_producer>& frame_producer) : impl_(new implementation(frame_producer)){}\r
 cg_producer::cg_producer(cg_producer&& other) : impl_(std::move(other.impl_)){}\r
 safe_ptr<core::basic_frame> cg_producer::receive(){return impl_->receive();}\r
+safe_ptr<core::basic_frame> cg_producer::last_frame() const{return impl_->last_frame();}\r
 void cg_producer::add(int layer, const std::wstring& template_name,  bool play_on_load, const std::wstring& startFromLabel, const std::wstring& data){impl_->add(layer, template_name, play_on_load, startFromLabel, data);}\r
 void cg_producer::remove(int layer){impl_->remove(layer);}\r
 void cg_producer::play(int layer){impl_->play(layer);}\r
index 6180562b0f3d17730f7cee867d5d67ec2810856e..2f13e9092032dc1cf8aed9d6400c7b61ebb8d317 100644 (file)
@@ -38,6 +38,7 @@ public:
        \r
        // frame_producer\r
        virtual safe_ptr<core::basic_frame> receive();\r
+       virtual safe_ptr<core::basic_frame> last_frame() const;\r
        virtual std::wstring print() const;\r
 \r
        //cg_producer\r
index 75fca1989dc9e3aa7c05ba2efbdab851e504c1e1..8f6864f1e56dc08c16085141acab07d4ca61c2cc 100644 (file)
@@ -224,6 +224,8 @@ struct flash_producer : public core::frame_producer
        std::shared_ptr<diagnostics::graph> graph_;\r
 \r
        tbb::concurrent_bounded_queue<safe_ptr<core::basic_frame>> frame_buffer_;\r
+\r
+       safe_ptr<core::basic_frame>     last_frame_;\r
                                \r
        com_context<flash_renderer> context_;           \r
 public:\r
@@ -231,6 +233,7 @@ public:
                : filename_(filename)           \r
                , frame_factory_(frame_factory)\r
                , context_(L"flash_producer")\r
+               , last_frame_(core::basic_frame::empty())\r
        {       \r
                if(!boost::filesystem::exists(filename))\r
                        BOOST_THROW_EXCEPTION(file_not_found() << boost::errinfo_file_name(narrow(filename)));  \r
@@ -258,8 +261,13 @@ public:
 \r
                auto frame = core::basic_frame::late();\r
                frame_buffer_.try_pop(frame);           \r
-               return frame;\r
+               return last_frame_ = frame;\r
        }\r
+\r
+       virtual safe_ptr<core::basic_frame> last_frame() const\r
+       {\r
+               return last_frame_;\r
+       }               \r
        \r
        virtual void param(const std::wstring& param) \r
        {       \r
index 09dbd929a326f35c0f5bec117d6ddce995c9fa06..5c6b4427ae7137802d797309910ae4cbf447169c 100644 (file)
@@ -58,6 +58,11 @@ struct image_producer : public core::frame_producer
 \r
        virtual safe_ptr<core::basic_frame> receive(){return frame_;}\r
                \r
+       virtual safe_ptr<core::basic_frame> last_frame() const\r
+       {\r
+               return frame_;\r
+       }\r
+\r
        virtual std::wstring print() const\r
        {\r
                return L"image_producer[" + filename_ + L"]";\r
index c3b441e0ce30c285e460775a3b30d6406754cb0e..1a92877f4b9d23e79313b4a2c767e68f43206135 100644 (file)
@@ -53,12 +53,15 @@ struct image_scroll_producer : public core::frame_producer
        int                                                                                     speed_;\r
 \r
        std::array<double, 2>                                           start_offset_;\r
+\r
+       safe_ptr<core::basic_frame>                                     last_frame_;\r
        \r
        explicit image_scroll_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filename, int speed) \r
                : filename_(filename)\r
                , delta_(0)\r
                , format_desc_(frame_factory->get_video_format_desc())\r
                , speed_(speed)\r
+               , last_frame_(core::basic_frame::empty())\r
        {\r
                start_offset_.assign(0.0);\r
 \r
@@ -145,7 +148,7 @@ struct image_scroll_producer : public core::frame_producer
 \r
        virtual safe_ptr<core::basic_frame> receive()\r
        {               \r
-               delta_ = 1;//+= speed_;\r
+               delta_ += speed_;\r
 \r
                if(frames_.empty())\r
                        return core::basic_frame::eof();\r
@@ -167,7 +170,12 @@ struct image_scroll_producer : public core::frame_producer
                                frames_[n]->get_image_transform().set_fill_translation(start_offset_[0] -0.5*(n+1) + delta_ * 0.5/static_cast<double>(format_desc_.height), start_offset_[1]);\r
                }\r
 \r
-               return core::basic_frame(frames_);\r
+               return last_frame_ = core::basic_frame(frames_);\r
+       }\r
+\r
+       virtual safe_ptr<core::basic_frame> last_frame() const\r
+       {\r
+               return last_frame_;\r
        }\r
                \r
        virtual std::wstring print() const\r