#include <agents_extras.h>\r
#include <concrt_extras.h>\r
\r
+using namespace Concurrency;\r
+\r
namespace caspar { namespace flash {\r
\r
class bitmap\r
\r
class flash_renderer\r
{ \r
- const std::wstring filename_;\r
+ const std::wstring filename_;\r
\r
- const safe_ptr<core::frame_factory> frame_factory_;\r
- \r
- CComObject<caspar::flash::FlashAxContainer>* ax_;\r
- safe_ptr<core::basic_frame> head_;\r
- bitmap bmp_;\r
- \r
- safe_ptr<diagnostics::graph> graph_;\r
- boost::timer frame_timer_;\r
- boost::timer tick_timer_;\r
+ const safe_ptr<core::frame_factory> frame_factory_;\r
+ safe_ptr<diagnostics::graph> graph_;\r
\r
- high_prec_timer timer_;\r
+ high_prec_timer timer_;\r
+ safe_ptr<core::basic_frame> head_;\r
+ bitmap bmp_;\r
\r
- const size_t width_;\r
- const size_t height_;\r
+ const size_t width_;\r
+ const size_t height_;\r
+ \r
+ boost::timer frame_timer_;\r
+ boost::timer tick_timer_;\r
+\r
+ CComObject<caspar::flash::FlashAxContainer>* ax_;\r
\r
public:\r
flash_renderer(const safe_ptr<diagnostics::graph>& graph, const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filename, int width, int height) \r
graph_->set_color("frame-time", diagnostics::color(0.1f, 1.0f, 0.1f));\r
graph_->add_guide("tick-time", 0.5);\r
graph_->set_color("tick-time", diagnostics::color(0.0f, 0.6f, 0.9f));\r
- graph_->set_color("param", diagnostics::color(1.0f, 0.5f, 0.0f)); \r
- graph_->set_color("skip-sync", diagnostics::color(0.8f, 0.3f, 0.2f)); \r
+ graph_->set_color("param", diagnostics::color(1.0f, 0.5f, 0.0f)); \r
\r
if(FAILED(CComObject<caspar::flash::FlashAxContainer>::CreateInstance(&ax_)))\r
BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(narrow(print()) + " Failed to create FlashAxContainer"));\r
graph_->add_tag("param");\r
}\r
\r
- safe_ptr<core::basic_frame> render_frame(bool has_underflow)\r
+ safe_ptr<core::basic_frame> operator()()\r
{\r
const float frame_time = 1.0f/ax_->GetFPS();\r
\r
if(ax_->IsEmpty())\r
return core::basic_frame::empty(); \r
\r
- if(!has_underflow) \r
- {\r
- Concurrency::scoped_oversubcription_token oversubscribe;\r
- timer_.tick(frame_time); // This will block the thread.\r
- //Concurrency::wait(std::max<int>(0, frame_time-3));\r
- }\r
- else\r
- graph_->add_tag("skip-sync");\r
+ Concurrency::scoped_oversubcription_token oversubscribe;\r
+ timer_.tick(frame_time); // This will block the thread.\r
+ //Concurrency::wait(std::max<int>(0, frame_time-3));\r
\r
frame_timer_.restart();\r
\r
\r
struct flash_producer : public Concurrency::agent, public core::frame_producer\r
{ \r
- Concurrency::unbounded_buffer<std::wstring> params_;\r
- Concurrency::bounded_buffer<safe_ptr<core::basic_frame>> frames_;\r
+ unbounded_buffer<std::wstring> params_;\r
+ bounded_buffer<safe_ptr<core::basic_frame>> frames_;\r
\r
tbb::atomic<bool> is_running_;\r
\r
const int width_;\r
const int height_;\r
\r
- mutable Concurrency::overwrite_buffer<safe_ptr<core::basic_frame>> last_frame_;\r
+ mutable overwrite_buffer<safe_ptr<core::basic_frame>> last_frame_;\r
\r
safe_ptr<diagnostics::graph> graph_;\r
\r
, filename_(filename) \r
, width_(width > 0 ? width : frame_factory->get_video_format_desc().width)\r
, height_(height > 0 ? height : frame_factory->get_video_format_desc().height)\r
- , graph_(diagnostics::create_graph("", false))\r
+ , graph_(diagnostics::create_graph("flash", false))\r
{ \r
if(!boost::filesystem::exists(filename))\r
BOOST_THROW_EXCEPTION(file_not_found() << boost::errinfo_file_name(narrow(filename))); \r
{\r
is_running_ = false;\r
auto frame = core::basic_frame::empty();\r
- while(Concurrency::try_receive(frames_, frame)){}\r
+ while(try_receive(frames_, frame)){}\r
agent::wait(this);\r
}\r
\r
\r
if(abs(renderer.fps()/2.0 - format_desc.fps) < 2.0) // flash == 2 * format -> interlace\r
{\r
- auto frame1 = renderer.render_frame(false);\r
- auto frame2 = renderer.render_frame(false);\r
- Concurrency::send(last_frame_, frame2);\r
- Concurrency::send(frames_, core::basic_frame::interlace(frame1, frame2, format_desc.field_mode));\r
+ auto frame1 = renderer();\r
+ auto frame2 = renderer();\r
+ send(last_frame_, frame2);\r
+ send(frames_, core::basic_frame::interlace(frame1, frame2, format_desc.field_mode));\r
}\r
else if(abs(renderer.fps()- format_desc.fps/2.0) < 2.0) // format == 2 * flash -> duplicate\r
{\r
- auto frame = renderer.render_frame(false);\r
- Concurrency::send(last_frame_, frame);\r
- Concurrency::send(frames_, frame);\r
- Concurrency::send(frames_, frame);\r
+ auto frame = renderer();\r
+ send(last_frame_, frame);\r
+ send(frames_, frame);\r
+ send(frames_, frame);\r
}\r
else //if(abs(renderer_->fps() - format_desc_.fps) < 0.1) // format == flash -> simple\r
{\r
- auto frame = renderer.render_frame(false);\r
- Concurrency::send(last_frame_, frame);\r
- Concurrency::send(frames_, frame);\r
+ auto frame = renderer();\r
+ send(last_frame_, frame);\r
+ send(frames_, frame);\r
}\r
\r
fps_ = static_cast<int>(renderer.fps()*100.0);\r
\r
try\r
{\r
- frame = Concurrency::receive(frames_, 5);\r
+ frame = Concurrency::receive(frames_, 10);\r
}\r
- catch(Concurrency::operation_timed_out&)\r
+ catch(operation_timed_out&)\r
{ \r
graph_->add_tag("underflow");\r
}\r
agent::wait(this);\r
start();\r
}\r
- Concurrency::asend(params_, param);\r
+ asend(params_, param);\r
}\r
\r
virtual std::wstring print() const\r