X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=core%2Fvideo_format.cpp;h=b58e1f199a968d9bcb565a5600ee87211ea6fc85;hb=6fcaa28bd5c747e88368e15cb0d18c14e3449a00;hp=2118fda336c86b4eb08958a6bdadec80fb5b2771;hpb=d100d17e81ed61c7638b681989cfdab5276430db;p=casparcg diff --git a/core/video_format.cpp b/core/video_format.cpp index 2118fda33..b58e1f199 100644 --- a/core/video_format.cpp +++ b/core/video_format.cpp @@ -1,82 +1,138 @@ -/* -* copyright (c) 2010 Sveriges Television AB -* -* This file is part of CasparCG. -* -* CasparCG is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* CasparCG is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. - -* You should have received a copy of the GNU General Public License -* along with CasparCG. If not, see . -* -*/ - -#include "StdAfx.h" - -#include "video_format.h" - -#include - -#include - -#define DEFINE_VIDEOFORMATDESC(fmt, w, h, m, scale, duration, name) \ -{ \ - (fmt), \ - (w), \ - (h), \ - (m), \ - ((double)scale/(double)duration),\ - (scale),\ - (duration),\ - (m == video_mode::progressive ? 1 : 2),\ - ((w)*(h)*4),\ - (name)\ -} - -namespace caspar { namespace core { - -const video_format_desc format_descs[video_format::count] = -{ - DEFINE_VIDEOFORMATDESC(video_format::pal ,720, 576, video_mode::upper, 25, 1, TEXT("pal") ), - DEFINE_VIDEOFORMATDESC(video_format::ntsc ,720, 486, video_mode::lower, 30000, 1001, TEXT("ntsc") ), - DEFINE_VIDEOFORMATDESC(video_format::x576p2500 ,720, 576, video_mode::progressive, 25, 1, TEXT("576p2500")), - DEFINE_VIDEOFORMATDESC(video_format::x720p2500 ,1280, 720, video_mode::progressive, 25, 1, TEXT("720p2500")), - DEFINE_VIDEOFORMATDESC(video_format::x720p5000 ,1280, 720, video_mode::progressive, 50, 1, TEXT("720p5000")), - DEFINE_VIDEOFORMATDESC(video_format::x720p5994 ,1280, 720, video_mode::progressive, 60000, 1001, TEXT("720p5994")), - DEFINE_VIDEOFORMATDESC(video_format::x720p6000 ,1280, 720, video_mode::progressive, 60, 1, TEXT("720p6000")), - DEFINE_VIDEOFORMATDESC(video_format::x1080p2397 ,1920, 1080, video_mode::progressive, 24000, 1001, TEXT("1080p2398")), - DEFINE_VIDEOFORMATDESC(video_format::x1080p2400 ,1920, 1080, video_mode::progressive, 24, 1, TEXT("1080p2400")), - DEFINE_VIDEOFORMATDESC(video_format::x1080i5000 ,1920, 1080, video_mode::upper, 25, 1, TEXT("1080i5000")), - DEFINE_VIDEOFORMATDESC(video_format::x1080i5994 ,1920, 1080, video_mode::upper, 60000, 1001, TEXT("1080i5994")), - DEFINE_VIDEOFORMATDESC(video_format::x1080i6000 ,1920, 1080, video_mode::upper, 60, 1, TEXT("1080i6000")), - DEFINE_VIDEOFORMATDESC(video_format::x1080p2500 ,1920, 1080, video_mode::progressive, 25, 1, TEXT("1080p2500")), - DEFINE_VIDEOFORMATDESC(video_format::x1080p2997 ,1920, 1080, video_mode::progressive, 30000, 1001, TEXT("1080p2997")), - DEFINE_VIDEOFORMATDESC(video_format::x1080p3000 ,1920, 1080, video_mode::progressive, 30, 1, TEXT("1080p3000")), - DEFINE_VIDEOFORMATDESC(video_format::x1080p5000 ,1920, 1080, video_mode::progressive, 50, 1, TEXT("1080p5000")), - DEFINE_VIDEOFORMATDESC(video_format::invalid ,0, 0, video_mode::invalid, 0, 1, TEXT("invalid")) -}; - -const video_format_desc& video_format_desc::get(video_format::type format) -{ - return format_descs[format]; -} - -const video_format_desc& video_format_desc::get(const std::wstring& name) -{ - for(int n = 0; n < video_format::invalid; ++n) - { - if(boost::iequals(format_descs[n].name, name)) - return format_descs[n]; - } - return format_descs[video_format::invalid]; -} - -}} - +/* +* Copyright (c) 2011 Sveriges Television AB +* +* This file is part of CasparCG (www.casparcg.com). +* +* CasparCG is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* CasparCG is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with CasparCG. If not, see . +* +* Author: Robert Nagy, ronag89@gmail.com +*/ + +#include "StdAfx.h" + +#include "video_format.h" + +#include + +namespace caspar { namespace core { + + const std::vector format_descs = { + { video_format::pal, 720, 576, 1024, 576, field_mode::upper, 25000, 1000, L"PAL", { 1920 } }, + { video_format::ntsc, 720, 486, 720, 540, field_mode::lower, 30000, 1001, L"NTSC", { 1602, 1601, 1602, 1601, 1602 } }, + { video_format::x576p2500, 720, 576, 1024, 576, field_mode::progressive, 25000, 1000, L"576p2500", { 1920 } }, + { video_format::x720p2398, 1280, 720, 1280, 720, field_mode::progressive, 24000, 1001, L"720p2398", { 2002 } }, + { video_format::x720p2400, 1280, 720, 1280, 720, field_mode::progressive, 24000, 1000, L"720p2400", { 2000 } }, + { video_format::x720p2500, 1280, 720, 1280, 720, field_mode::progressive, 25000, 1000, L"720p2500", { 1920 } }, + { video_format::x720p5000, 1280, 720, 1280, 720, field_mode::progressive, 50000, 1000, L"720p5000", { 960 } }, + { video_format::x720p2997, 1280, 720, 1280, 720, field_mode::progressive, 30000, 1001, L"720p2997", { 1602, 1601, 1602, 1601, 1602 } }, + { video_format::x720p5994, 1280, 720, 1280, 720, field_mode::progressive, 60000, 1001, L"720p5994", { 801, 800, 801, 801, 801 } }, + { video_format::x720p3000, 1280, 720, 1280, 720, field_mode::progressive, 30000, 1000, L"720p3000", { 1600 } }, + { video_format::x720p6000, 1280, 720, 1280, 720, field_mode::progressive, 60000, 1000, L"720p6000", { 800 } }, + { video_format::x1080p2398, 1920, 1080, 1920, 1080, field_mode::progressive, 24000, 1001, L"1080p2398", { 2002 } }, + { video_format::x1080p2400, 1920, 1080, 1920, 1080, field_mode::progressive, 24000, 1000, L"1080p2400", { 2000 } }, + { video_format::x1080i5000, 1920, 1080, 1920, 1080, field_mode::upper, 25000, 1000, L"1080i5000", { 1920 } }, + { video_format::x1080i5994, 1920, 1080, 1920, 1080, field_mode::upper, 30000, 1001, L"1080i5994", { 1602, 1601, 1602, 1601, 1602 } }, + { video_format::x1080i6000, 1920, 1080, 1920, 1080, field_mode::upper, 30000, 1000, L"1080i6000", { 1600 } }, + { video_format::x1080p2500, 1920, 1080, 1920, 1080, field_mode::progressive, 25000, 1000, L"1080p2500", { 1920 } }, + { video_format::x1080p2997, 1920, 1080, 1920, 1080, field_mode::progressive, 30000, 1001, L"1080p2997", { 1602, 1601, 1602, 1601, 1602 } }, + { video_format::x1080p3000, 1920, 1080, 1920, 1080, field_mode::progressive, 30000, 1000, L"1080p3000", { 1600 } }, + { video_format::x1080p5000, 1920, 1080, 1920, 1080, field_mode::progressive, 50000, 1000, L"1080p5000", { 960 } }, + { video_format::x1080p5994, 1920, 1080, 1920, 1080, field_mode::progressive, 60000, 1001, L"1080p5994", { 801, 800, 801, 801, 801 } }, + { video_format::x1080p6000, 1920, 1080, 1920, 1080, field_mode::progressive, 60000, 1000, L"1080p6000", { 800 } }, + { video_format::x1556p2398, 2048, 1556, 2048, 1556, field_mode::progressive, 24000, 1001, L"1556p2398", { 2002 } }, + { video_format::x1556p2400, 2048, 1556, 2048, 1556, field_mode::progressive, 24000, 1000, L"1556p2400", { 2000 } }, + { video_format::x1556p2500, 2048, 1556, 2048, 1556, field_mode::progressive, 25000, 1000, L"1556p2500", { 1920 } }, + { video_format::dci1080p2398, 2048, 1080, 2048, 1080, field_mode::progressive, 24000, 1001, L"dci1080p2398", { 2002 } }, + { video_format::dci1080p2400, 2048, 1080, 2048, 1080, field_mode::progressive, 24000, 1000, L"dci1080p2400", { 2000 } }, + { video_format::dci1080p2500, 2048, 1080, 2048, 1080, field_mode::progressive, 25000, 1000, L"dci1080p2500", { 1920 } }, + { video_format::x2160p2398, 3840, 2160, 3840, 2160, field_mode::progressive, 24000, 1001, L"2160p2398", { 2002 } }, + { video_format::x2160p2400, 3840, 2160, 3840, 2160, field_mode::progressive, 24000, 1000, L"2160p2400", { 2000 } }, + { video_format::x2160p2500, 3840, 2160, 3840, 2160, field_mode::progressive, 25000, 1000, L"2160p2500", { 1920 } }, + { video_format::x2160p2997, 3840, 2160, 3840, 2160, field_mode::progressive, 30000, 1001, L"2160p2997", { 1602, 1601, 1602, 1601, 1602 } }, + { video_format::x2160p3000, 3840, 2160, 3840, 2160, field_mode::progressive, 30000, 1000, L"2160p3000", { 1600 } }, + { video_format::dci2160p2398, 4096, 2160, 4096, 2160, field_mode::progressive, 24000, 1001, L"dci2160p2398", { 2002 } }, + { video_format::dci2160p2400, 4096, 2160, 4096, 2160, field_mode::progressive, 24000, 1000, L"dci2160p2400", { 2000 } }, + { video_format::dci2160p2500, 4096, 2160, 4096, 2160, field_mode::progressive, 25000, 1000, L"dci2160p2500", { 1920 } }, + { video_format::invalid, 0, 0, 0, 0, field_mode::progressive, 1, 1, L"invalid", { 1 } } + }; + +video_format_desc::video_format_desc( + video_format format, + int width, + int height, + int square_width, + int square_height, + core::field_mode field_mode, + int time_scale, + int duration, + const std::wstring& name, + const std::vector& audio_cadence) + : format(format) + , width(width) + , height(height) + , square_width(square_width) + , square_height(square_height) + , field_mode(field_mode) + , fps(static_cast(time_scale) / static_cast(duration)) + , time_scale(time_scale) + , duration(duration) + , field_count(field_mode == core::field_mode::progressive ? 1 : 2) + , size(width*height*4) + , name(name) + , audio_sample_rate(48000) + , audio_cadence(audio_cadence) +{ +} + +video_format_desc::video_format_desc(video_format format) + : format(video_format::invalid) + , field_mode(core::field_mode::empty) +{ + *this = format_descs.at(static_cast(format)); +} + +video_format_desc::video_format_desc(const std::wstring& name) + : format(video_format::invalid) + , field_mode(core::field_mode::empty) +{ + *this = video_format_desc(video_format::invalid); + for(auto it = std::begin(format_descs); it != std::end(format_descs)-1; ++it) + { + if(boost::iequals(it->name, name)) + { + *this = *it; + break; + } + } +} + +bool operator==(const video_format_desc& lhs, const video_format_desc& rhs) +{ + return lhs.format == rhs.format; +} + +bool operator!=(const video_format_desc& lhs, const video_format_desc& rhs) +{ + return !(lhs == rhs); +} + +std::wostream& operator<<(std::wostream& out, const video_format_desc& format_desc) +{ + out << format_desc.name.c_str(); + return out; +} + + +}} +