\r
#include <exception>\r
#include <boost/exception/all.hpp>\r
-#include <boost/exception/errinfo_file_name.hpp>\r
+#include <boost/exception/error_info.hpp>\r
#include <boost/throw_exception.hpp>\r
\r
namespace caspar {\r
\r
-typedef boost::error_info<struct tag_arg_name_info, std::string> arg_name_info;\r
-typedef boost::error_info<struct tag_arg_value_info, std::string> arg_value_info;\r
-typedef boost::error_info<struct tag_msg_info, std::string> msg_info;\r
-typedef boost::error_info<struct tag_source_info, std::string> source_info;\r
-typedef boost::error_info<struct tag_inner_info, std::exception_ptr> inner_info;\r
-typedef boost::error_info<struct tag_line_info, int> line_info;\r
+typedef boost::error_info<struct tag_arg_name_info, std::string> arg_name_info;\r
+typedef boost::error_info<struct tag_arg_value_info, std::string> arg_value_info;\r
+typedef boost::error_info<struct tag_msg_info, std::string> msg_info;\r
+typedef boost::error_info<struct tag_errorstr, std::string> errorstr;\r
+typedef boost::error_info<struct tag_source_info, std::string> source_info;\r
+typedef boost::error_info<struct errinfo_nested_exception_, std::exception_ptr> errinfo_nested_exception;\r
\r
struct caspar_exception : virtual boost::exception, virtual std::exception \r
{\r
struct invalid_argument : virtual caspar_exception {};\r
struct null_argument : virtual invalid_argument {};\r
struct out_of_range : virtual invalid_argument {};\r
+struct bad_alloc : virtual caspar_exception {};\r
\r
struct invalid_operation : virtual caspar_exception {};\r
struct operation_failed : virtual caspar_exception {};\r
switch (ErrorCode)\r
{\r
case GL_INVALID_ENUM :\r
- {\r
- Error = "GL_INVALID_ENUM";\r
- Desc = "an unacceptable value has been specified for an enumerated argument";\r
- break;\r
- }\r
+ BOOST_THROW_EXCEPTION(ogl_invalid_enum()\r
+ << msg_info("an unacceptable value has been specified for an enumerated argument")\r
+ << errorstr("GL_INVALID_ENUM"));\r
\r
case GL_INVALID_VALUE :\r
- {\r
- Error = "GL_INVALID_VALUE";\r
- Desc = "a numeric argument is out of range";\r
- break;\r
- }\r
+ BOOST_THROW_EXCEPTION(ogl_invalid_value()\r
+ << msg_info("a numeric argument is out of range")\r
+ << errorstr("GL_INVALID_VALUE"));\r
\r
case GL_INVALID_OPERATION :\r
- {\r
- Error = "GL_INVALID_OPERATION";\r
- Desc = "the specified operation is not allowed in the current state";\r
- break;\r
- }\r
+ BOOST_THROW_EXCEPTION(ogl_invalid_operation()\r
+ << msg_info("the specified operation is not allowed in the current state")\r
+ << errorstr("GL_INVALID_OPERATION"));\r
\r
case GL_STACK_OVERFLOW :\r
- {\r
- Error = "GL_STACK_OVERFLOW";\r
- Desc = "this command would cause a stack overflow";\r
- break;\r
- }\r
+ BOOST_THROW_EXCEPTION(ogl_stack_overflow()\r
+ << msg_info("this command would cause a stack overflow")\r
+ << errorstr("GL_STACK_OVERFLOW"));\r
\r
case GL_STACK_UNDERFLOW :\r
- {\r
- Error = "GL_STACK_UNDERFLOW";\r
- Desc = "this command would cause a stack underflow";\r
- break;\r
- }\r
+ BOOST_THROW_EXCEPTION(ogl_stack_underflow()\r
+ << msg_info("this command would cause a stack underflow")\r
+ << errorstr("GL_STACK_UNDERFLOW"));\r
\r
case GL_OUT_OF_MEMORY :\r
- {\r
- Error = "GL_OUT_OF_MEMORY";\r
- Desc = "there is not enough memory left to execute the command";\r
- break;\r
- }\r
+ BOOST_THROW_EXCEPTION(ogl_stack_underflow()\r
+ << msg_info("there is not enough memory left to execute the command")\r
+ << errorstr("GL_OUT_OF_MEMORY"));\r
\r
case GL_INVALID_FRAMEBUFFER_OPERATION_EXT :\r
- {\r
- Error = "GL_INVALID_FRAMEBUFFER_OPERATION_EXT";\r
- Desc = "the object bound to FRAMEBUFFER_BINDING_EXT is not \"framebuffer complete\"";\r
- break;\r
- }\r
+ BOOST_THROW_EXCEPTION(ogl_stack_underflow()\r
+ << msg_info("the object bound to FRAMEBUFFER_BINDING_EXT is not \"framebuffer complete\"")\r
+ << errorstr("GL_INVALID_FRAMEBUFFER_OPERATION_EXT"));\r
}\r
-\r
- // Log the error\r
- std::stringstream str;\r
- str << "An internal OpenGL call failed in "\r
- << File.substr(File.find_last_of("\\/") + 1).c_str() << " (" << Line << ") : "\r
- << Error.c_str() << ", " << Desc.c_str()\r
- << ", " << expr.c_str()\r
- << std::endl;\r
- BOOST_THROW_EXCEPTION(caspar_exception() <<\r
- msg_info(str.str()));\r
}\r
}\r
\r
{\r
executor_.invoke([&]\r
{\r
- buffer = std::make_shared<device_buffer>(width, height, stride);\r
-\r
- if(glGetError() != GL_NO_ERROR)\r
- BOOST_THROW_EXCEPTION(std::bad_alloc());\r
-\r
- }, high_priority); \r
- executor_.begin_invoke([=]\r
- {\r
- auto buffer = std::make_shared<device_buffer>(width, height, stride);\r
- pool->try_push(buffer);\r
+ try\r
+ {\r
+ buffer = std::make_shared<device_buffer>(width, height, stride);\r
+ }\r
+ catch(...)\r
+ {\r
+ BOOST_THROW_EXCEPTION(bad_alloc()\r
+ << errinfo_nested_exception(std::current_exception()));\r
+ }\r
}, high_priority); \r
}\r
\r
{\r
executor_.invoke([&]\r
{\r
- buffer = std::make_shared<host_buffer>(size, usage);\r
- if(usage == host_buffer::write_only)\r
- buffer->map();\r
- else\r
- buffer->unmap();\r
-\r
- if(glGetError() != GL_NO_ERROR)\r
- BOOST_THROW_EXCEPTION(std::bad_alloc());\r
+ try\r
+ {\r
+ buffer = std::make_shared<host_buffer>(size, usage);\r
+ if(usage == host_buffer::write_only)\r
+ buffer->map();\r
+ else\r
+ buffer->unmap(); \r
+ }\r
+ catch(...)\r
+ {\r
+ BOOST_THROW_EXCEPTION(bad_alloc()\r
+ << errinfo_nested_exception(std::current_exception()));\r
+ }\r
\r
}, high_priority); \r
- executor_.begin_invoke([=]\r
- {\r
- auto buffer = std::make_shared<host_buffer>(size, usage);\r
- if(usage == host_buffer::write_only)\r
- buffer->map();\r
- else\r
- buffer->unmap();\r
- pool->try_push(buffer);\r
- }, high_priority); \r
}\r
\r
return safe_ptr<host_buffer>(buffer.get(), [=](host_buffer*)\r
else\r
buffer->unmap();\r
\r
- if(glGetError() == GL_NO_ERROR)\r
- pool->push(buffer);\r
+ pool->push(buffer);\r
+\r
}, high_priority);\r
});\r
}\r
blue_velvet_initialize();\r
blue_hanc_initialize();\r
}\r
+\r
+safe_ptr<CBlueVelvet4> create_blue(size_t device_index)\r
+{\r
+ if(!BlueVelvetFactory4 || !encode_hanc_frame || !encode_hanc_frame)\r
+ BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Bluefish drivers not found."));\r
+\r
+ auto blue = safe_ptr<CBlueVelvet4>(BlueVelvetFactory4());\r
+ \r
+ if(BLUE_FAIL(blue->device_attach(device_index, FALSE))) \r
+ BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info("Failed to attach device."));\r
+\r
+ return blue;\r
+}\r
+\r
+EVideoMode get_video_mode(CBlueVelvet4& blue, const core::video_format_desc& format_desc)\r
+{\r
+ EVideoMode vid_fmt = VID_FMT_INVALID;\r
+ auto desiredVideoFormat = vid_fmt_from_video_format(format_desc.format);\r
+ int videoModeCount = blue.count_video_mode();\r
+ for(int videoModeIndex = 1; videoModeIndex <= videoModeCount; ++videoModeIndex) \r
+ {\r
+ EVideoMode videoMode = blue.enum_video_mode(videoModeIndex);\r
+ if(videoMode == desiredVideoFormat) \r
+ vid_fmt = videoMode; \r
+ }\r
+ if(vid_fmt == VID_FMT_INVALID)\r
+ BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info("Failed get videomode.") << arg_value_info(narrow(format_desc.name)));\r
+\r
+ return vid_fmt;\r
+}\r
\r
struct bluefish_consumer : boost::noncopyable\r
{\r
- std::wstring model_name_;\r
- const unsigned int device_index_;\r
+ safe_ptr<CBlueVelvet4> blue_;\r
+ const unsigned int device_index_;\r
+ const core::video_format_desc format_desc_;\r
\r
- std::shared_ptr<diagnostics::graph> graph_;\r
- boost::timer frame_timer_;\r
- boost::timer tick_timer_;\r
- boost::timer sync_timer_;\r
+ const std::wstring model_name_;\r
\r
- std::shared_ptr<CBlueVelvet4> blue_;\r
- \r
- const core::video_format_desc format_desc_;\r
+ std::shared_ptr<diagnostics::graph> graph_;\r
+ boost::timer frame_timer_;\r
+ boost::timer tick_timer_;\r
+ boost::timer sync_timer_; \r
\r
- const unsigned long mem_fmt_;\r
- const unsigned long upd_fmt_;\r
- const unsigned long res_fmt_; \r
- unsigned long engine_mode_;\r
- EVideoMode vid_fmt_; \r
+ const EVideoMode vid_fmt_; \r
+ const EMemoryFormat mem_fmt_;\r
+ const EUpdateMethod upd_fmt_;\r
+ const EResoFormat res_fmt_; \r
+ EEngineMode engine_mode_;\r
\r
std::array<blue_dma_buffer_ptr, 4> reserved_frames_; \r
tbb::concurrent_bounded_queue<std::shared_ptr<const core::read_frame>> frame_buffer_;\r
executor executor_;\r
public:\r
bluefish_consumer(const core::video_format_desc& format_desc, unsigned int device_index, bool embedded_audio, size_t buffer_depth) \r
- : model_name_(L"BLUEFISH")\r
- , device_index_(device_index) \r
- , format_desc_(format_desc)\r
+ : blue_(create_blue(device_index))\r
+ , device_index_(device_index)\r
+ , format_desc_(format_desc) \r
+ , model_name_(get_card_desc(blue_->has_video_cardtype()))\r
+ , vid_fmt_(get_video_mode(*blue_, format_desc)) \r
, mem_fmt_(MEM_FMT_ARGB_PC)\r
, upd_fmt_(UPD_FMT_FRAME)\r
, res_fmt_(RES_FMT_NORMAL) \r
, engine_mode_(VIDEO_ENGINE_FRAMESTORE) \r
- , vid_fmt_(VID_FMT_INVALID) \r
, embedded_audio_(embedded_audio)\r
, executor_(print())\r
{\r
executor_.set_capacity(buffer_depth);\r
\r
- if(!BlueVelvetFactory4 || (embedded_audio_ && (!encode_hanc_frame || !encode_hanc_frame)))\r
- BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Bluefish drivers not found."));\r
- \r
- blue_.reset(BlueVelvetFactory4());\r
-\r
- if(BLUE_FAIL(blue_->device_attach(device_index_, FALSE))) \r
- BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info(narrow(print()) + " Failed to attach device."));\r
- \r
- int videoCardType = blue_->has_video_cardtype();\r
- model_name_ = get_card_desc(videoCardType);\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.1f, 0.7f, 0.8f));\r
graph_->add_guide("frame-time", 0.5f); \r
graph_->set_color("frame-time", diagnostics::color(1.0f, 0.0f, 0.0f));\r
- graph_->add_guide("frame-time", 0.5f); \r
graph_->set_color("sync-time", diagnostics::color(0.5f, 1.0f, 0.2f));\r
\r
- //void* pBlueDevice = blue_attach_to_device(1);\r
- //EBlueConnectorPropertySetting video_routing[1];\r
- //auto video_channel = BLUE_VIDEO_OUTPUT_CHANNEL_A;\r
- //video_routing[0].video_channel = video_channel; \r
- //video_routing[0].propType = BLUE_CONNECTOR_PROP_SINGLE_LINK;\r
- //video_routing[0].connector = video_channel == BLUE_VIDEO_OUTPUT_CHANNEL_A ? BLUE_CONNECTOR_SDI_OUTPUT_A : BLUE_CONNECTOR_SDI_OUTPUT_B;\r
- //blue_set_connector_property(pBlueDevice, 1, video_routing);\r
- //blue_detach_from_device(&pBlueDevice);\r
- \r
- auto desiredVideoFormat = vid_fmt_from_video_format(format_desc_.format);\r
- int videoModeCount = blue_->count_video_mode();\r
- for(int videoModeIndex = 1; videoModeIndex <= videoModeCount; ++videoModeIndex) \r
- {\r
- EVideoMode videoMode = blue_->enum_video_mode(videoModeIndex);\r
- if(videoMode == desiredVideoFormat) \r
- vid_fmt_ = videoMode; \r
- }\r
- if(vid_fmt_ == VID_FMT_INVALID)\r
- BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info(narrow(print()) + " Failed to set videomode."));\r
- \r
- // Set default video output video_channel\r
- //if(BLUE_FAIL(set_card_property(blue_, DEFAULT_VIDEO_OUTPUT_CHANNEL, video_channel)))\r
- // CASPAR_LOG(error) << TEXT("BLUECARD ERROR: Failed to set default video_channel. (device ") << device_index_ << TEXT(")");\r
-\r
//Setting output Video mode\r
if(BLUE_FAIL(set_card_property(blue_, VIDEO_MODE, vid_fmt_))) \r
BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info(narrow(print()) + " Failed to set videomode."));\r
if(blue_->GetHDCardType(device_index_) != CRD_HD_INVALID) \r
blue_->Set_DownConverterSignalType(vid_fmt_ == VID_FMT_PAL ? SD_SDI : HD_SDI); \r
\r
- if(BLUE_FAIL(blue_->set_video_engine(engine_mode_)))\r
+ if(BLUE_FAIL(blue_->set_video_engine(*reinterpret_cast<unsigned long*>(&engine_mode_))))\r
BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info(narrow(print()) + " Failed to set video engine."));\r
\r
enable_video_output();\r
executor_.invoke([&]\r
{\r
disable_video_output();\r
-\r
- if(blue_)\r
- blue_->device_detach(); \r
+ blue_->device_detach(); \r
});\r
\r
CASPAR_LOG(info) << print() << L" Shutting down."; \r