\r
#include "frame_producer.h"\r
#include "frame/basic_frame.h"\r
-#include "frame/audio_transform.h"\r
+#include "frame/frame_transform.h"\r
\r
#include "color/color_producer.h"\r
#include "separated/separated_producer.h"\r
\r
#include <common/memory/safe_ptr.h>\r
+#include <common/concurrency/executor.h>\r
#include <common/exception/exceptions.h>\r
+#include <common/utility/move_on_copy.h>\r
\r
namespace caspar { namespace core {\r
\r
std::vector<const producer_factory_t> g_factories;\r
+ \r
+class destroy_producer_proxy : public frame_producer\r
+{\r
+ safe_ptr<frame_producer> producer_;\r
+ executor& destroy_context_;\r
+public:\r
+ destroy_producer_proxy(executor& destroy_context, const safe_ptr<frame_producer>& producer) \r
+ : producer_(producer)\r
+ , destroy_context_(destroy_context){}\r
+\r
+ ~destroy_producer_proxy()\r
+ { \r
+ if(destroy_context_.size() > 4)\r
+ CASPAR_LOG(error) << L" Potential destroyer deadlock.";\r
+\r
+ // Hacks to bypass compiler bugs.\r
+ auto mov_producer = make_move_on_copy<safe_ptr<frame_producer>>(std::move(producer_));\r
+ auto empty_producer = frame_producer::empty();\r
+ destroy_context_.begin_invoke([=]\r
+ { \r
+ //if(!mov_producer.value.unique())\r
+ // CASPAR_LOG(debug) << mov_producer.value->print() << L" Not destroyed on safe asynchronous destruction thread.";\r
+ //else\r
+ // CASPAR_LOG(debug) << mov_producer.value->print() << L" Destroying on safe asynchronous destruction thread.";\r
+ \r
+ mov_producer.value = empty_producer;\r
+ });\r
+ }\r
\r
-const safe_ptr<frame_producer>& frame_producer::empty() // nothrow\r
+ virtual safe_ptr<basic_frame> receive(int hints) {return producer_->receive(hints);}\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
+ virtual void set_leading_producer(const safe_ptr<frame_producer>& producer) {producer_->set_leading_producer(producer);}\r
+ virtual int64_t nb_frames() const {return producer_->nb_frames();}\r
+};\r
+\r
+safe_ptr<core::frame_producer> create_destroy_producer_proxy(executor& destroy_context, const safe_ptr<frame_producer>& producer)\r
+{\r
+ return make_safe<destroy_producer_proxy>(destroy_context, producer);\r
+}\r
+\r
+class last_frame_producer : public frame_producer\r
{\r
- struct empty_frame_producer : public frame_producer\r
+ const std::wstring print_;\r
+ const safe_ptr<basic_frame> frame_;\r
+ const int64_t nb_frames_;\r
+public:\r
+ last_frame_producer(const safe_ptr<frame_producer>& producer) \r
+ : print_(producer->print())\r
+ , frame_(producer->last_frame() != basic_frame::eof() ? producer->last_frame() : basic_frame::empty())\r
+ , nb_frames_(producer->nb_frames())\r
{\r
- virtual safe_ptr<basic_frame> receive(int){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 int64_t nb_frames() const {return 0;}\r
- virtual std::wstring print() const { return L"empty";}\r
- };\r
+ }\r
+ \r
+ virtual safe_ptr<basic_frame> receive(int){return frame_;}\r
+ virtual safe_ptr<core::basic_frame> last_frame() const{return frame_;}\r
+ virtual std::wstring print() const{return L"dummy[" + print_ + L"]";}\r
+ virtual int64_t nb_frames() const {return nb_frames_;} \r
+};\r
+\r
+struct empty_frame_producer : public frame_producer\r
+{\r
+ virtual safe_ptr<basic_frame> receive(int){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 int64_t nb_frames() const {return 0;}\r
+ virtual std::wstring print() const { return L"empty";}\r
+};\r
+\r
+const safe_ptr<frame_producer>& frame_producer::empty() // nothrow\r
+{\r
static safe_ptr<frame_producer> producer = make_safe<empty_frame_producer>();\r
return producer;\r
} \r
{\r
CASPAR_LOG(info) << producer->print() << " End Of File.";\r
auto following = producer->get_following_producer();\r
- following->set_leading_producer(producer);\r
- producer = std::move(following); \r
- \r
- if(producer == frame_producer::empty())\r
- return basic_frame::eof();\r
+ if(following != frame_producer::empty())\r
+ {\r
+ following->set_leading_producer(producer);\r
+ producer = std::move(following);\r
+ }\r
+ else\r
+ producer = make_safe<last_frame_producer>(producer);\r
\r
return receive_and_follow(producer, hints);\r
}\r