\r
#include <core/mixer/read_frame.h>\r
\r
-#include <common/concurrency/com_context.h>\r
#include <common/diagnostics/graph.h>\r
#include <common/exception/exceptions.h>\r
#include <common/memory/memcpy.h>\r
#include <boost/circular_buffer.hpp>\r
#include <boost/timer.hpp>\r
\r
-namespace caspar { \r
+#include <agents.h>\r
+#include <concrt_extras.h>\r
+\r
+namespace caspar { namespace decklink { \r
\r
struct configuration\r
{\r
bool internal_key;\r
bool low_latency;\r
bool key_only;\r
- size_t buffer_depth;\r
\r
configuration()\r
: device_index(1)\r
, embedded_audio(false)\r
, internal_key(false)\r
, low_latency(false)\r
- , key_only(false)\r
- , buffer_depth(core::consumer_buffer_depth()){}\r
+ , key_only(false){}\r
+\r
+ size_t preroll_count() const\r
+ {\r
+ size_t count = 0;\r
+ count += low_latency ? 2 : 3;\r
+ count += embedded_audio ? 1 : 0;\r
+ return count;\r
+ }\r
};\r
\r
class decklink_frame : public IDeckLinkVideoFrame\r
CComQIPtr<IDeckLinkConfiguration> configuration_;\r
CComQIPtr<IDeckLinkKeyer> keyer_;\r
\r
- tbb::spin_mutex exception_mutex_;\r
- std::exception_ptr exception_;\r
+ Concurrency::overwrite_buffer<std::exception_ptr> exception_;\r
\r
tbb::atomic<bool> is_running_;\r
\r
tbb::concurrent_bounded_queue<std::shared_ptr<core::read_frame>> video_frame_buffer_;\r
tbb::concurrent_bounded_queue<std::shared_ptr<core::read_frame>> audio_frame_buffer_;\r
\r
- std::shared_ptr<diagnostics::graph> graph_;\r
+ safe_ptr<diagnostics::graph> graph_;\r
boost::timer tick_timer_;\r
\r
public:\r
, keyer_(decklink_)\r
, model_name_(get_model_name(decklink_))\r
, format_desc_(format_desc)\r
- , buffer_size_(config.embedded_audio ? config.buffer_depth + 1 : config.buffer_depth) // Minimum buffer-size 3.\r
+ , buffer_size_(config.preroll_count())\r
, frames_scheduled_(0)\r
, audio_scheduled_(0)\r
, preroll_count_(0)\r
video_frame_buffer_.set_capacity(1);\r
audio_frame_buffer_.set_capacity(1);\r
\r
- graph_ = diagnostics::create_graph(narrow(print()));\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("late-frame", diagnostics::color(0.6f, 0.3f, 0.3f));\r
graph_->set_color("dropped-frame", diagnostics::color(0.3f, 0.6f, 0.3f));\r
graph_->set_color("flushed-frame", diagnostics::color(0.4f, 0.3f, 0.8f));\r
+ graph_->set_text(print());\r
+ diagnostics::register_graph(graph_);\r
\r
enable_video(get_display_mode(output_, format_desc_.format, bmdFormat8BitBGRA, bmdVideoOutputFlagDefault));\r
\r
\r
std::shared_ptr<core::read_frame> frame; \r
video_frame_buffer_.pop(frame); \r
- schedule_next_video(make_safe(frame)); \r
+ schedule_next_video(make_safe_ptr(frame)); \r
}\r
catch(...)\r
{\r
- tbb::spin_mutex::scoped_lock lock(exception_mutex_);\r
- exception_ = std::current_exception();\r
+ Concurrency::send(exception_, std::current_exception());\r
return E_FAIL;\r
}\r
\r
{\r
std::shared_ptr<core::read_frame> frame;\r
audio_frame_buffer_.pop(frame);\r
- schedule_next_audio(make_safe(frame)); \r
+ schedule_next_audio(make_safe_ptr(frame)); \r
}\r
}\r
catch(...)\r
{\r
- tbb::spin_mutex::scoped_lock lock(exception_mutex_);\r
- exception_ = std::current_exception();\r
+ Concurrency::send(exception_, std::current_exception());\r
return E_FAIL;\r
}\r
\r
\r
void send(const safe_ptr<core::read_frame>& frame)\r
{\r
- {\r
- tbb::spin_mutex::scoped_lock lock(exception_mutex_);\r
- if(exception_ != nullptr)\r
- std::rethrow_exception(exception_);\r
- }\r
+ if(exception_.has_value())\r
+ std::rethrow_exception(exception_.value());\r
\r
if(!is_running_)\r
BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(narrow(print()) + " Is not running."));\r
\r
+ Concurrency::scoped_oversubcription_token oversubscribe; \r
if(config_.embedded_audio)\r
audio_frame_buffer_.push(frame); \r
video_frame_buffer_.push(frame); \r
\r
struct decklink_consumer_proxy : public core::frame_consumer\r
{\r
- const configuration config_;\r
- com_context<decklink_consumer> context_;\r
- core::video_format_desc format_desc_;\r
+ const configuration config_;\r
+ std::unique_ptr<decklink_consumer> context_;\r
+ core::video_format_desc format_desc_;\r
public:\r
\r
decklink_consumer_proxy(const configuration& config)\r
: config_(config)\r
- , context_(L"decklink_consumer[" + boost::lexical_cast<std::wstring>(config.device_index) + L"]")\r
{\r
}\r
\r
\r
virtual void initialize(const core::video_format_desc& format_desc)\r
{\r
+ Concurrency::scoped_oversubcription_token oversubscribe;\r
format_desc_ = format_desc;\r
- context_.reset([&]{return new decklink_consumer(config_, format_desc_);}); \r
+ struct co_init\r
+ {\r
+ co_init(){CoInitialize(nullptr);}\r
+ ~co_init(){CoUninitialize();}\r
+ } init; \r
+ context_ = nullptr;\r
+ context_.reset(new decklink_consumer(config_, format_desc_)); \r
\r
CASPAR_LOG(info) << print() << L" Successfully Initialized."; \r
}\r
}\r
}; \r
\r
-safe_ptr<core::frame_consumer> create_decklink_consumer(const std::vector<std::wstring>& params) \r
+safe_ptr<core::frame_consumer> create_consumer(const std::vector<std::wstring>& params) \r
{\r
if(params.size() < 1 || params[0] != L"DECKLINK")\r
return core::frame_consumer::empty();\r
return make_safe<decklink_consumer_proxy>(config);\r
}\r
\r
-safe_ptr<core::frame_consumer> create_decklink_consumer(const boost::property_tree::ptree& ptree) \r
+safe_ptr<core::frame_consumer> create_consumer(const boost::property_tree::ptree& ptree) \r
{\r
configuration config;\r
\r
return make_safe<decklink_consumer_proxy>(config);\r
}\r
\r
-}\r
+}}\r
\r
/*\r
##############################################################################\r