X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fflash%2Fproducer%2Fflash_producer.cpp;h=aa03e29807fa4c7db71db952e7c9828c25b8a921;hb=cd21d5c0a69a732eccd1c4620b9ccd0555f057c3;hp=da4572f7efa547b8de360dec4b9c04a281a4539e;hpb=2f549904ed6da11061fa914fc99f0e0acdd90357;p=casparcg diff --git a/modules/flash/producer/flash_producer.cpp b/modules/flash/producer/flash_producer.cpp index da4572f7e..aa03e2980 100644 --- a/modules/flash/producer/flash_producer.cpp +++ b/modules/flash/producer/flash_producer.cpp @@ -44,10 +44,13 @@ #include #include #include +#include #include -namespace caspar { +#include + +namespace caspar { namespace flash { class bitmap { @@ -93,30 +96,46 @@ struct template_host template_host get_template_host(const core::video_format_desc& desc) { - std::vector template_hosts; - BOOST_FOREACH(auto& xml_mapping, env::properties().get_child("configuration.producers.template-hosts")) + try { - try + std::vector template_hosts; + BOOST_FOREACH(auto& xml_mapping, env::properties().get_child("configuration.producers.template-hosts")) { - template_host template_host; - template_host.field_mode = xml_mapping.second.get("video-mode", narrow(desc.name)); - template_host.filename = xml_mapping.second.get("filename", "cg.fth"); - template_host.width = xml_mapping.second.get("width", desc.width); - template_host.height = xml_mapping.second.get("height", desc.height); - template_hosts.push_back(template_host); + try + { + template_host template_host; + template_host.field_mode = xml_mapping.second.get("video-mode", narrow(desc.name)); + template_host.filename = xml_mapping.second.get("filename", "cg.fth"); + template_host.width = xml_mapping.second.get("width", desc.width); + template_host.height = xml_mapping.second.get("height", desc.height); + template_hosts.push_back(template_host); + } + catch(...){} } - catch(...){} - } - auto template_host_it = boost::find_if(template_hosts, [&](template_host template_host){return template_host.field_mode == narrow(desc.name);}); - if(template_host_it == template_hosts.end()) - template_host_it = boost::find_if(template_hosts, [&](template_host template_host){return template_host.field_mode == "";}); + auto template_host_it = boost::find_if(template_hosts, [&](template_host template_host){return template_host.field_mode == narrow(desc.name);}); + if(template_host_it == template_hosts.end()) + template_host_it = boost::find_if(template_hosts, [&](template_host template_host){return template_host.field_mode == "";}); - if(template_host_it != template_hosts.end()) - return *template_host_it; - + if(template_host_it != template_hosts.end()) + return *template_host_it; + } + catch(...) + { + } + template_host template_host; template_host.filename = "cg.fth"; + + for(auto it = boost::filesystem2::wdirectory_iterator(env::template_folder()); it != boost::filesystem2::wdirectory_iterator(); ++it) + { + if(boost::iequals(it->path().extension(), L"." + desc.name)) + { + template_host.filename = narrow(it->filename()); + break; + } + } + template_host.width = desc.width; template_host.height = desc.height; return template_host; @@ -157,7 +176,7 @@ public: graph_->add_guide("tick-time", 0.5); graph_->set_color("tick-time", diagnostics::color(0.0f, 0.6f, 0.9f)); graph_->set_color("param", diagnostics::color(1.0f, 0.5f, 0.0f)); - graph_->set_color("underflow", diagnostics::color(0.6f, 0.3f, 0.9f)); + graph_->set_color("skip-sync", diagnostics::color(0.8f, 0.3f, 0.2f)); if(FAILED(CComObject::CreateInstance(&ax_))) BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(narrow(print()) + " Failed to create FlashAxContainer")); @@ -216,7 +235,7 @@ public: if(!has_underflow) timer_.tick(frame_time); // This will block the thread. else - graph_->add_tag("underflow"); + graph_->add_tag("skip-sync"); frame_timer_.restart(); @@ -236,6 +255,11 @@ public: return head_; } + bool is_empty() const + { + return ax_->IsEmpty(); + } + double fps() const { return ax_->GetFPS(); @@ -258,6 +282,7 @@ struct flash_producer : public core::frame_producer tbb::concurrent_bounded_queue> frame_buffer_; + mutable tbb::spin_mutex last_frame_mutex_; safe_ptr last_frame_; com_context context_; @@ -275,11 +300,12 @@ public: { if(!boost::filesystem::exists(filename)) BOOST_THROW_EXCEPTION(file_not_found() << boost::errinfo_file_name(narrow(filename))); - + fps_ = 0; - graph_ = diagnostics::create_graph([this]{return print();}); - graph_->set_color("output-buffer-count", diagnostics::color(1.0f, 1.0f, 0.0f)); + graph_ = diagnostics::create_graph(narrow(print())); + graph_->set_color("output-buffer-count", diagnostics::color(1.0f, 1.0f, 0.0f)); + graph_->set_color("underflow", diagnostics::color(0.6f, 0.3f, 0.9f)); frame_buffer_.set_capacity(frame_factory_->get_video_format_desc().fps > 30.0 ? 2 : 1); @@ -298,14 +324,15 @@ public: graph_->set_value("output-buffer-count", static_cast(frame_buffer_.size())/static_cast(frame_buffer_.capacity())); auto frame = core::basic_frame::late(); - if(frame_buffer_.try_pop(frame)) - last_frame_ = frame; + if(!frame_buffer_.try_pop(frame) && context_) + graph_->add_tag("underflow"); return frame; } virtual safe_ptr last_frame() const { + tbb::spin_mutex::scoped_lock lock(last_frame_mutex_); return last_frame_; } @@ -347,6 +374,14 @@ public: render(context_.get()); } + safe_ptr render_frame() + { + auto frame = context_->render_frame(frame_buffer_.size() < frame_buffer_.capacity()); + tbb::spin_mutex::scoped_lock lock(last_frame_mutex_); + last_frame_ = make_safe(frame); + return frame; + } + void render(const flash_renderer* renderer) { context_.begin_invoke([=] @@ -360,24 +395,31 @@ public: if(abs(context_->fps()/2.0 - format_desc.fps) < 2.0) // flash == 2 * format -> interlace { - auto frame1 = context_->render_frame(frame_buffer_.size() < frame_buffer_.capacity()); - auto frame2 = context_->render_frame(frame_buffer_.size() < frame_buffer_.capacity()); + auto frame1 = render_frame(); + auto frame2 = render_frame(); frame_buffer_.push(core::basic_frame::interlace(frame1, frame2, format_desc.field_mode)); } else if(abs(context_->fps()- format_desc.fps/2.0) < 2.0) // format == 2 * flash -> duplicate { - auto frame = context_->render_frame(frame_buffer_.size() < frame_buffer_.capacity()); + auto frame = render_frame(); frame_buffer_.push(frame); frame_buffer_.push(frame); } else //if(abs(renderer_->fps() - format_desc_.fps) < 0.1) // format == flash -> simple { - auto frame = context_->render_frame(frame_buffer_.size() < frame_buffer_.capacity()); + auto frame = render_frame(); frame_buffer_.push(frame); } + if(context_->is_empty()) + { + context_.reset(nullptr); + return; + } + graph_->set_value("output-buffer-count", static_cast(frame_buffer_.size())/static_cast(frame_buffer_.capacity())); - fps_.fetch_and_store(static_cast(context_->fps()*100.0)); + fps_.fetch_and_store(static_cast(context_->fps()*100.0)); + graph_->update_text(narrow(print())); render(renderer); } @@ -391,14 +433,14 @@ public: } }; -safe_ptr create_flash_producer(const safe_ptr& frame_factory, const std::vector& params) +safe_ptr create_producer(const safe_ptr& frame_factory, const std::vector& params) { auto template_host = get_template_host(frame_factory->get_video_format_desc()); return make_safe(frame_factory, env::template_folder() + L"\\" + widen(template_host.filename), template_host.width, template_host.height); } -std::wstring find_flash_template(const std::wstring& template_name) +std::wstring find_template(const std::wstring& template_name) { if(boost::filesystem::exists(template_name + L".ft")) return template_name + L".ft"; @@ -409,4 +451,4 @@ std::wstring find_flash_template(const std::wstring& template_name) return L""; } -} \ No newline at end of file +}} \ No newline at end of file