]> git.sesse.net Git - casparcg/commitdiff
2.0.0.2: bluefish_consumer: Refactored.
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Wed, 1 Jun 2011 10:01:01 +0000 (10:01 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Wed, 1 Jun 2011 10:01:01 +0000 (10:01 +0000)
         ogl: Added exception hierarchy.

git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@834 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

common/concurrency/executor.h
common/exception/exceptions.h
common/gl/gl_check.cpp
common/gl/gl_check.h
core/mixer/gpu/ogl_device.cpp
modules/bluefish/consumer/bluefish_consumer.cpp

index fc8f0107995f5a23c46d2db02f0582d028501570..4409295c8f05459dee88603da047af8ca6f10dfa 100644 (file)
@@ -185,7 +185,11 @@ public:
                {\r
                        try{task_adaptor.value();}\r
                        catch(boost::task_already_started&){}\r
-                       catch(...){CASPAR_LOG_CURRENT_EXCEPTION();}\r
+                       catch(...)\r
+                       {\r
+                               CASPAR_LOG_CURRENT_EXCEPTION();\r
+                               throw;\r
+                       }\r
                });\r
 \r
                if(priority != normal_priority)\r
@@ -208,7 +212,11 @@ public:
                        {\r
                                try{task_adaptor.value();}\r
                                catch(boost::task_already_started&){}\r
-                               catch(...){CASPAR_LOG_CURRENT_EXCEPTION();}\r
+                               catch(...)\r
+                               {\r
+                                       CASPAR_LOG_CURRENT_EXCEPTION();\r
+                                       throw;\r
+                               }\r
                        });\r
                }\r
                \r
index 435141a6916a7d7143e83b0ba63f8c7ab172d8a0..e9b99a33681e2b86d560c28a2829b2860ac692be 100644 (file)
 \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
@@ -47,6 +47,7 @@ struct file_read_error          : virtual io_error {};
 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
index 3d694ff06c30413b8db4b9e0b77f1191751db3be..f82f7403a8ddda404207cf087ef26539c8e1425e 100644 (file)
@@ -51,64 +51,40 @@ void SMFL_GLCheckError(const std::string& expr, const std::string& File, unsigne
                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
index 8663b8c315aad970fd1bbd95b8ccf7d6a46c3fc5..49db7384d38e397d60befd895711daa0a57137c3 100644 (file)
 \r
 #pragma once\r
 \r
+#include "../exception/exceptions.h"\r
+\r
 namespace caspar { namespace gl {\r
-                       \r
+\r
+struct ogl_exception                                                   : virtual caspar_exception{};\r
+struct ogl_invalid_enum                                                        : virtual ogl_exception{};\r
+struct ogl_invalid_value                                               : virtual ogl_exception{};\r
+struct ogl_invalid_operation                                   : virtual ogl_exception{};\r
+struct ogl_stack_overflow                                              : virtual ogl_exception{};\r
+struct ogl_stack_underflow                                             : virtual ogl_exception{};                      \r
+struct ogl_out_of_memory                                               : virtual ogl_exception{};\r
+struct ogl_invalid_framebuffer_operation_ext   : virtual ogl_exception{};\r
+\r
 void SMFL_GLCheckError(const std::string& expr, const std::string& File, unsigned int Line);\r
 \r
 #ifdef _DEBUG\r
index 6fa31aff8c27e629b369250db100039d502415a9..2431d1dabea826e0137998e6c42b4dd94d4f645d 100644 (file)
@@ -66,16 +66,15 @@ safe_ptr<device_buffer> ogl_device::create_device_buffer(size_t width, size_t he
        {\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
@@ -92,25 +91,21 @@ safe_ptr<host_buffer> ogl_device::create_host_buffer(size_t size, host_buffer::u
        {\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
@@ -122,8 +117,8 @@ safe_ptr<host_buffer> ogl_device::create_host_buffer(size_t size, host_buffer::u
                        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
index a4721f92eb7fc5fbc3b02385a78307dd2518695f..c186d73110a3764293fce4afffec67a5afbdc71e 100644 (file)
@@ -82,26 +82,55 @@ void blue_initialize()
        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
@@ -111,62 +140,27 @@ struct bluefish_consumer : boost::noncopyable
        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
@@ -221,7 +215,7 @@ public:
                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
@@ -240,9 +234,7 @@ public:
                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