]> git.sesse.net Git - casparcg/commitdiff
2.1.0: -video_format_desc: Refactored.
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Sun, 11 Dec 2011 19:36:10 +0000 (19:36 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Sun, 11 Dec 2011 19:36:10 +0000 (19:36 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.1.0@1883 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

core/mixer/audio/audio_mixer.cpp
core/video_format.cpp
core/video_format.h
modules/decklink/producer/decklink_producer.cpp
modules/ffmpeg/producer/util/util.cpp
protocol/amcp/AMCPCommandsImpl.cpp
shell/server.cpp

index 80c86d07ea0ebaa94a2d5977e99b3008f9ca590a..186eebb5e5d56a6c601706186925158fbb7084bc 100644 (file)
@@ -76,7 +76,6 @@ struct audio_mixer::implementation
 public:\r
        implementation(const safe_ptr<diagnostics::graph>& graph)\r
                : graph_(graph)\r
-               , format_desc_(video_format_desc::get(video_format::invalid))\r
        {\r
                graph_->set_color("volume", diagnostics::color(1.0f, 0.8f, 0.1f));\r
                transform_stack_.push(core::frame_transform());\r
index 1a15474d661fb83464985c145dc6252f766d032d..61f434147fc5c98c70b790a2c13cd7ee3573a860 100644 (file)
 #include <boost/algorithm/string.hpp>\r
 #include <boost/assign.hpp>\r
 \r
-#define DEFINE_VIDEOFORMATDESC(fmt, w, h, sw, sh, m, scale, duration, audio_samples, name) \\r
-{ \\r
-       (fmt), \\r
-       (w), \\r
-       (h), \\r
-       (sw),\\r
-       (sh),\\r
-       (m), \\r
-       ((double)scale/(double)duration),\\r
-       (scale),\\r
-       (duration),\\r
-       (m == field_mode::progressive ? 1 : 2),\\r
-       ((w)*(h)*4),\\r
-       (name),\\r
-       (48000),\\r
-       (2),\\r
-       (audio_samples)\\r
-}\r
-\r
-\r
 namespace caspar { namespace core {\r
        \r
-const video_format_desc format_descs[video_format::count] =  \r
-{                                                                         \r
-       DEFINE_VIDEOFORMATDESC(video_format::pal                ,720,  576,  1024, 576,  field_mode::upper,                     25,             1,               boost::assign::list_of(3840),                                                  L"PAL"), \r
-       DEFINE_VIDEOFORMATDESC(video_format::ntsc               ,720,  486,  720,  534,  field_mode::lower,                     30000,  1001,    boost::assign::list_of(3204)(3202)(3204)(3202)(3204),  L"NTSC"), \r
-       DEFINE_VIDEOFORMATDESC(video_format::x576p2500  ,720,  576,  720,  576,  field_mode::progressive,       25,             1,               boost::assign::list_of(3840),                                                  L"576p2500"),\r
-       DEFINE_VIDEOFORMATDESC(video_format::x720p2500  ,1280, 720,  1280, 720,  field_mode::progressive,       25,             1,               boost::assign::list_of(3840),                                                  L"720p2500"), \r
-       DEFINE_VIDEOFORMATDESC(video_format::x720p5000  ,1280, 720,  1280, 720,  field_mode::progressive,       50,             1,               boost::assign::list_of(1920),                                                  L"720p5000"), \r
-       DEFINE_VIDEOFORMATDESC(video_format::x720p5994  ,1280, 720,  1280, 720,  field_mode::progressive,       60000,  1001,    boost::assign::list_of(1602)(1601)(1602)(1601)(1602),  L"720p5994"),\r
-       DEFINE_VIDEOFORMATDESC(video_format::x720p6000  ,1280, 720,  1280, 720,  field_mode::progressive,       60,             1,               boost::assign::list_of(1600),                                                  L"720p6000"),\r
-       DEFINE_VIDEOFORMATDESC(video_format::x1080p2397 ,1920, 1080, 1920, 1080, field_mode::progressive,       24000,  1001,    boost::assign::list_of(4004),                                                  L"1080p2398"),\r
-       DEFINE_VIDEOFORMATDESC(video_format::x1080p2400 ,1920, 1080, 1920, 1080, field_mode::progressive,       24,             1,               boost::assign::list_of(4000),                                                  L"1080p2400"),\r
-       DEFINE_VIDEOFORMATDESC(video_format::x1080i5000 ,1920, 1080, 1920, 1080, field_mode::upper,                     25,             1,               boost::assign::list_of(3840),                                                  L"1080i5000"),\r
-       DEFINE_VIDEOFORMATDESC(video_format::x1080i5994 ,1920, 1080, 1920, 1080, field_mode::upper,                     30000,  1001,    boost::assign::list_of(3204)(3202)(3204)(3202)(3204),  L"1080i5994"),\r
-       DEFINE_VIDEOFORMATDESC(video_format::x1080i6000 ,1920, 1080, 1920, 1080, field_mode::upper,                     30,             1,               boost::assign::list_of(3200),                                                  L"1080i6000"),\r
-       DEFINE_VIDEOFORMATDESC(video_format::x1080p2500 ,1920, 1080, 1920, 1080, field_mode::progressive,       25,             1,               boost::assign::list_of(3840),                                                  L"1080p2500"),\r
-       DEFINE_VIDEOFORMATDESC(video_format::x1080p2997 ,1920, 1080, 1920, 1080, field_mode::progressive,       30000,  1001,    boost::assign::list_of(3204)(3202)(3204)(3202)(3204),  L"1080p2997"),\r
-       DEFINE_VIDEOFORMATDESC(video_format::x1080p3000 ,1920, 1080, 1920, 1080, field_mode::progressive,       30,             1,               boost::assign::list_of(3200),                                                  L"1080p3000"),\r
-       DEFINE_VIDEOFORMATDESC(video_format::x1080p5000 ,1920, 1080, 1920, 1080, field_mode::progressive,       50,             1,               boost::assign::list_of(1920),                                                  L"1080p5000"),\r
-       DEFINE_VIDEOFORMATDESC(video_format::invalid    ,0,             0,   0,         0,   field_mode::progressive,   1,              1,               boost::assign::list_of(1),                                                             L"invalid")\r
-};\r
+const std::vector<video_format_desc> format_descs = boost::assign::list_of\r
+       (video_format_desc(video_format::pal,                    720,  576, 1024, 576,  field_mode::upper,                         25,     1, L"PAL",           boost::assign::list_of<int>(3840)))\r
+       (video_format_desc(video_format::ntsc,                   720,  486,  720, 534,  field_mode::lower,                      30000,  1001, L"NTSC",          boost::assign::list_of<int>(3204)(3202)(3204)(3202)(3204)))\r
+       (video_format_desc(video_format::x576p2500,              720,  576,  720, 576,  field_mode::progressive,           25,     1, L"576p2500",      boost::assign::list_of<int>(3840)                                               ))\r
+       (video_format_desc(video_format::x720p2500,             1280,  720, 1280, 720,  field_mode::progressive,           25,     1, L"720p2500",      boost::assign::list_of<int>(3840)                                               )) \r
+       (video_format_desc(video_format::x720p5000,             1280,  720, 1280, 720,  field_mode::progressive,           50,     1, L"720p5000",      boost::assign::list_of<int>(1920)                                               )) \r
+       (video_format_desc(video_format::x720p5994,             1280,  720, 1280, 720,  field_mode::progressive,        60000,  1001, L"720p5994",      boost::assign::list_of<int>(1602)(1601)(1602)(1601)(1602)))\r
+       (video_format_desc(video_format::x720p6000,             1280,  720, 1280, 720,  field_mode::progressive,           60,     1, L"720p6000",      boost::assign::list_of<int>(1600)                                               ))\r
+       (video_format_desc(video_format::x1080p2397,    1920, 1080, 1920, 1080, field_mode::progressive,        24000,  1001, L"1080p2398",     boost::assign::list_of<int>(4004)                                               ))\r
+       (video_format_desc(video_format::x1080p2400,    1920, 1080, 1920, 1080, field_mode::progressive,           24,     1, L"1080p2400",     boost::assign::list_of<int>(4000)                                               ))\r
+       (video_format_desc(video_format::x1080i5000,    1920, 1080, 1920, 1080, field_mode::upper,                         25,     1, L"1080i5000",     boost::assign::list_of<int>(3840)                                               ))\r
+       (video_format_desc(video_format::x1080i5994,    1920, 1080, 1920, 1080, field_mode::upper,                      30000,  1001, L"1080i5994",     boost::assign::list_of<int>(3204)(3202)(3204)(3202)(3204)))\r
+       (video_format_desc(video_format::x1080i6000,    1920, 1080, 1920, 1080, field_mode::upper,                         30,     1, L"1080i6000",     boost::assign::list_of<int>(3200)                                               ))\r
+       (video_format_desc(video_format::x1080p2500,    1920, 1080, 1920, 1080, field_mode::progressive,           25,     1, L"1080p2500",     boost::assign::list_of<int>(3840)                                               ))\r
+       (video_format_desc(video_format::x1080p2997,    1920, 1080, 1920, 1080, field_mode::progressive,        30000,  1001, L"1080p2997",     boost::assign::list_of<int>(3204)(3202)(3204)(3202)(3204)))\r
+       (video_format_desc(video_format::x1080p3000,    1920, 1080, 1920, 1080, field_mode::progressive,           30,     1, L"1080p3000",     boost::assign::list_of<int>(3200)                                               ))\r
+       (video_format_desc(video_format::x1080p5000,    1920, 1080, 1920, 1080, field_mode::progressive,           50,     1, L"1080p5000",     boost::assign::list_of<int>(1920)                                               ))\r
+       (video_format_desc(video_format::invalid,                  0,    0,    0,        0, field_mode::progressive,        1,     1, L"invalid",       boost::assign::list_of<int>(1)                                                  ));\r
 \r
-const video_format_desc& video_format_desc::get(video_format::type format)     \r
+video_format_desc::video_format_desc(video_format::type format,\r
+                                       int width,\r
+                                       int height,\r
+                                       int square_width,\r
+                                       int square_height,\r
+                                       field_mode::type field_mode,\r
+                                       int time_scale,\r
+                                       int duration,\r
+                                       const std::wstring& name,\r
+                                       const std::vector<int>& audio_cadence)\r
+       : format(format)\r
+       , width(width)\r
+       , height(height)\r
+       , square_width(square_width)\r
+       , square_height(square_height)\r
+       , field_mode(field_mode)\r
+       , fps((double)time_scale/(double)duration)\r
+       , time_scale(time_scale)\r
+       , duration(duration)\r
+       , field_count(field_mode == field_mode::progressive ? 1 : 2)\r
+       , size(width*height*4)\r
+       , name(name)\r
+       , audio_sample_rate(48000)\r
+       , audio_channels(2)\r
+       , audio_cadence(audio_cadence)\r
 {\r
-       return format_descs[format];\r
 }\r
 \r
-const video_format_desc& video_format_desc::get(const std::wstring& name)      \r
+video_format_desc::video_format_desc(video_format::type format)\r
 {\r
-       for(int n = 0; n < video_format::invalid; ++n)\r
+       *this = format_descs[format];\r
+}\r
+\r
+video_format_desc::video_format_desc(const std::wstring& name)\r
+{      \r
+       *this = video_format_desc(video_format::invalid);\r
+       for(auto it = std::begin(format_descs); it != std::end(format_descs)-1; ++it)\r
        {\r
-               if(boost::iequals(format_descs[n].name, name))\r
-                       return format_descs[n];\r
+               if(boost::iequals(it->name, name))\r
+               {\r
+                       *this = *it;\r
+                       break;\r
+               }\r
        }\r
-       return format_descs[video_format::invalid];\r
 }\r
 \r
+video_format_desc& video_format_desc::operator=(const video_format_desc& other)\r
+{\r
+       format                          = other.format;                 \r
+       width                           = other.width;\r
+       height                          = other.height;\r
+       square_width            = other.square_width;\r
+       square_height           = other.square_height;\r
+       field_mode                      = other.field_mode;\r
+       fps                                     = other.fps;\r
+       time_scale                      = other.time_scale;\r
+       duration                        = other.duration;\r
+       field_count                     = other.field_count;\r
+       size                            = other.size;\r
+       name                            = other.name;\r
+       audio_sample_rate       = other.audio_sample_rate;\r
+       audio_channels          = other.audio_channels;\r
+       audio_cadence           = other.audio_cadence;\r
+\r
+       return *this;\r
+}\r
+\r
+bool operator==(const video_format_desc& lhs, const video_format_desc& rhs)\r
+{                                                                                      \r
+       return lhs.format == rhs.format;\r
+}\r
+\r
+bool operator!=(const video_format_desc& lhs, const video_format_desc& rhs)\r
+{\r
+       return !(lhs == rhs);\r
+}\r
+\r
+std::wostream& operator<<(std::wostream& out, const video_format_desc& format_desc)\r
+{\r
+       out << format_desc.name.c_str();\r
+       return out;\r
+}\r
+\r
+\r
 }}\r
 \r
index 0152e70f78be497cdba947207d2feed22ac563cb..75bf4c2055cc7dc7e22d6a428524b5d0691b8f58 100644 (file)
@@ -97,24 +97,26 @@ struct video_format_desc sealed
        int                                     audio_channels;\r
        std::vector<int>        audio_cadence;\r
 \r
-       static const video_format_desc& get(video_format::type format);\r
-       static const video_format_desc& get(const std::wstring& name);\r
-       \r
-       bool operator==(const video_format_desc& lhs)\r
-       {\r
-               return format == lhs.format;\r
-       }\r
+       video_format_desc(video_format::type format,\r
+                                         int width,\r
+                                         int height,\r
+                                         int square_width,\r
+                                         int square_height,\r
+                                         field_mode::type field_mode,\r
+                                         int time_scale,\r
+                                         int duration,\r
+                                         const std::wstring& name,\r
+                                         const std::vector<int>& audio_cadence);\r
 \r
-       bool operator!=(const video_format_desc& lhs)\r
-       {\r
-               return !(*this == lhs);\r
-       }\r
+       video_format_desc& operator=(const video_format_desc& other);\r
+       \r
+       video_format_desc(video_format::type format = video_format::invalid);\r
+       video_format_desc(const std::wstring& name);\r
 };\r
 \r
-inline std::wostream& operator<<(std::wostream& out, const video_format_desc& format_desc)\r
-{\r
-       out << format_desc.name.c_str();\r
-       return out;\r
-}\r
+bool operator==(const video_format_desc& rhs, const video_format_desc& lhs);\r
+bool operator!=(const video_format_desc& rhs, const video_format_desc& lhs);\r
+\r
+std::wostream& operator<<(std::wostream& out, const video_format_desc& format_desc);\r
 \r
 }}
\ No newline at end of file
index 8e20f008909a9e1c3f0dcaff6f7f162e4f24e80c..3351c7a7fbb1f2501c40124f38ccd3a0c616bc6e 100644 (file)
@@ -329,7 +329,7 @@ safe_ptr<core::frame_producer> create_producer(const safe_ptr<core::frame_factor
        auto device_index       = get_param(L"DEVICE", params, 1);\r
        auto filter_str         = get_param(L"FILTER", params);         \r
        auto length                     = get_param(L"LENGTH", params, std::numeric_limits<uint32_t>::max());   \r
-       auto format_desc        = core::video_format_desc::get(get_param(L"FORMAT", params, L"INVALID"));\r
+       auto format_desc        = core::video_format_desc(get_param(L"FORMAT", params, L"INVALID"));\r
        \r
        boost::replace_all(filter_str, L"DEINTERLACE", L"YADIF=0:-1");\r
        boost::replace_all(filter_str, L"DEINTERLACE_BOB", L"YADIF=1:-1");\r
index f15f69a7e46f2528dbfeb445d258069568ce5e3a..1d5d1f324f8079ee9a1ffaa56fd6e656a216bcd9 100644 (file)
@@ -368,7 +368,7 @@ double read_fps(AVFormatContext& context, double fail_value)
                double closest_fps = 0.0;\r
                for(int n = 0; n < core::video_format::count; ++n)\r
                {\r
-                       auto format = core::video_format_desc::get(static_cast<core::video_format::type>(n));\r
+                       auto format = core::video_format_desc(static_cast<core::video_format::type>(n));\r
 \r
                        double diff1 = std::abs(format.fps - fps);\r
                        double diff2 = std::abs(closest_fps - fps);\r
index ce680d992fe7a63c5a5debdd3f2d5007de2c5bfc..983124cc68c9917aa470c1529410c500b693666f 100644 (file)
@@ -1499,7 +1499,7 @@ bool SetCommand::DoExecute()
 \r
        if(name == TEXT("MODE"))\r
        {\r
-               auto format_desc = core::video_format_desc::get(value);\r
+               auto format_desc = core::video_format_desc(value);\r
                if(format_desc.format != core::video_format::invalid)\r
                {\r
                        GetChannel()->set_video_format_desc(format_desc);\r
index 28970419e1ec09a5c52e97c52ef021a89eb42ff8..a5d3f20f7f3705369108924c623c015772d82701 100644 (file)
@@ -111,7 +111,7 @@ struct server::implementation : boost::noncopyable
                using boost::property_tree::wptree;\r
                BOOST_FOREACH(auto& xml_channel, pt.get_child(L"configuration.channels"))\r
                {               \r
-                       auto format_desc = video_format_desc::get(xml_channel.second.get(L"video-mode", L"PAL"));               \r
+                       auto format_desc = video_format_desc(xml_channel.second.get(L"video-mode", L"PAL"));            \r
                        if(format_desc.format == video_format::invalid)\r
                                BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Invalid video-mode."));\r
                        \r