From 521f0c5769e4cc41fa0270c827089106e53dad2d Mon Sep 17 00:00:00 2001 From: ronag Date: Thu, 12 Jan 2012 17:03:14 +0000 Subject: [PATCH] git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.1.0@2116 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d --- core/producer/stage.cpp | 16 +++++- core/producer/stage.h | 9 ++- protocol/amcp/AMCPCommandsImpl.cpp | 90 ++++++++++++++---------------- 3 files changed, 64 insertions(+), 51 deletions(-) diff --git a/core/producer/stage.cpp b/core/producer/stage.cpp index 475e2bdc3..24c9df565 100644 --- a/core/producer/stage.cpp +++ b/core/producer/stage.cpp @@ -170,8 +170,21 @@ public: CASPAR_LOG_CURRENT_EXCEPTION(); } } + + void apply_transforms(const std::vector>& transforms) + { + executor_.begin_invoke([=] + { + BOOST_FOREACH(auto& transform, transforms) + { + auto src = transforms_[std::get<0>(transform)].fetch(); + auto dst = std::get<1>(transform)(src); + transforms_[std::get<0>(transform)] = tweened_transform(src, dst, std::get<2>(transform), std::get<3>(transform)); + } + }, high_priority); + } - void apply_transform(int index, const std::function& transform, unsigned int mix_duration, const std::wstring& tween) + void apply_transform(int index, const stage::transform_func_t& transform, unsigned int mix_duration, const std::wstring& tween) { executor_.begin_invoke([=] { @@ -339,6 +352,7 @@ public: }; stage::stage(const safe_ptr& target, const safe_ptr& graph, const struct video_format_desc& format_desc) : impl_(new impl(target, graph, format_desc)){} +void stage::apply_transforms(const std::vector& transforms){impl_->apply_transforms(transforms);} void stage::apply_transform(int index, const std::function& transform, unsigned int mix_duration, const std::wstring& tween){impl_->apply_transform(index, transform, mix_duration, tween);} void stage::clear_transforms(int index){impl_->clear_transforms(index);} void stage::clear_transforms(){impl_->clear_transforms();} diff --git a/core/producer/stage.h b/core/producer/stage.h index f5ddc1101..a435279f0 100644 --- a/core/producer/stage.h +++ b/core/producer/stage.h @@ -31,6 +31,8 @@ #include #include +#include +#include FORWARD2(caspar, diagnostics, class graph); FORWARD1(boost, template class unique_future); @@ -41,13 +43,16 @@ class stage sealed { CASPAR_NO_COPY(stage); public: - typedef target>, std::shared_ptr>> target_t; + typedef std::function transform_func_t; + typedef std::tuple transform_tuple_t; + typedef target>, std::shared_ptr>> target_t; stage(const safe_ptr& target, const safe_ptr& graph, const struct video_format_desc& format_desc); // stage - void apply_transform(int index, const std::function& transform, unsigned int mix_duration = 0, const std::wstring& tween = L"linear"); + void apply_transforms(const std::vector& transforms); + void apply_transform(int index, const transform_func_t& transform, unsigned int mix_duration = 0, const std::wstring& tween = L"linear"); void clear_transforms(int index); void clear_transforms(); diff --git a/protocol/amcp/AMCPCommandsImpl.cpp b/protocol/amcp/AMCPCommandsImpl.cpp index 62404dfc2..e7ca0db94 100644 --- a/protocol/amcp/AMCPCommandsImpl.cpp +++ b/protocol/amcp/AMCPCommandsImpl.cpp @@ -69,6 +69,8 @@ #include #include +#include + /* Return codes 100 [action] Information om att något har hänt @@ -317,22 +319,27 @@ bool CallCommand::DoExecute() } } +tbb::concurrent_unordered_map> deferred_transforms; + bool MixerCommand::DoExecute() { //Perform loading of the clip try { + bool defer = _parameters.back() == L"DEFER"; + if(defer) + _parameters.pop_back(); + + std::vector transforms; + if(_parameters[0] == L"KEYER" || _parameters[0] == L"IS_KEY") { bool value = boost::lexical_cast(_parameters.at(1)); - auto transform = [=](frame_transform transform) -> frame_transform + transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform { transform.is_key = value; return transform; - }; - - int layer = GetLayerIndex(); - GetChannel()->stage()->apply_transform(GetLayerIndex(), transform); + }, 0, L"linear")); } else if(_parameters[0] == L"OPACITY") { @@ -341,14 +348,11 @@ bool MixerCommand::DoExecute() double value = boost::lexical_cast(_parameters.at(1)); - auto transform = [=](frame_transform transform) -> frame_transform + transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform { transform.opacity = value; return transform; - }; - - int layer = GetLayerIndex(); - GetChannel()->stage()->apply_transform(GetLayerIndex(), transform, duration, tween); + }, duration, tween)); } else if(_parameters[0] == L"FILL" || _parameters[0] == L"FILL_RECT") { @@ -359,7 +363,7 @@ bool MixerCommand::DoExecute() double x_s = boost::lexical_cast(_parameters.at(3)); double y_s = boost::lexical_cast(_parameters.at(4)); - auto transform = [=](frame_transform transform) mutable -> frame_transform + transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) mutable -> frame_transform { transform.fill_translation[0] = x; transform.fill_translation[1] = y; @@ -370,10 +374,7 @@ bool MixerCommand::DoExecute() transform.clip_scale[0] = x_s; transform.clip_scale[1] = y_s; return transform; - }; - - int layer = GetLayerIndex(); - GetChannel()->stage()->apply_transform(GetLayerIndex(), transform, duration, tween); + }, duration, tween)); } else if(_parameters[0] == L"CLIP" || _parameters[0] == L"CLIP_RECT") { @@ -384,17 +385,14 @@ bool MixerCommand::DoExecute() double x_s = boost::lexical_cast(_parameters.at(3)); double y_s = boost::lexical_cast(_parameters.at(4)); - auto transform = [=](frame_transform transform) -> frame_transform + transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform { transform.clip_translation[0] = x; transform.clip_translation[1] = y; transform.clip_scale[0] = x_s; transform.clip_scale[1] = y_s; return transform; - }; - - int layer = GetLayerIndex(); - GetChannel()->stage()->apply_transform(GetLayerIndex(), transform, duration, tween); + }, duration, tween)); } else if(_parameters[0] == L"GRID") { @@ -407,7 +405,7 @@ bool MixerCommand::DoExecute() for(int y = 0; y < n; ++y) { int index = x+y*n+1; - auto transform = [=](frame_transform transform) -> frame_transform + transforms.push_back(stage::transform_tuple_t(index, [=](frame_transform transform) -> frame_transform { transform.fill_translation[0] = x*delta; transform.fill_translation[1] = y*delta; @@ -418,8 +416,7 @@ bool MixerCommand::DoExecute() transform.clip_scale[0] = delta; transform.clip_scale[1] = delta; return transform; - }; - GetChannel()->stage()->apply_transform(index, transform, duration, tween); + }, duration, tween)); } } } @@ -434,42 +431,33 @@ bool MixerCommand::DoExecute() auto value = boost::lexical_cast(_parameters.at(1)); int duration = _parameters.size() > 2 ? boost::lexical_cast(_parameters[2]) : 0; std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear"; - auto transform = [=](frame_transform transform) -> frame_transform + auto transform = stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform { transform.brightness = value; return transform; - }; - - int layer = GetLayerIndex(); - GetChannel()->stage()->apply_transform(GetLayerIndex(), transform, duration, tween); + }, duration, tween); } else if(_parameters[0] == L"SATURATION") { auto value = boost::lexical_cast(_parameters.at(1)); int duration = _parameters.size() > 2 ? boost::lexical_cast(_parameters[2]) : 0; std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear"; - auto transform = [=](frame_transform transform) -> frame_transform + auto transform = stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform { transform.saturation = value; return transform; - }; - - int layer = GetLayerIndex(); - GetChannel()->stage()->apply_transform(GetLayerIndex(), transform, duration, tween); + }, duration, tween); } else if(_parameters[0] == L"CONTRAST") { auto value = boost::lexical_cast(_parameters.at(1)); int duration = _parameters.size() > 2 ? boost::lexical_cast(_parameters[2]) : 0; std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear"; - auto transform = [=](frame_transform transform) -> frame_transform + auto transform = stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform { transform.contrast = value; return transform; - }; - - int layer = GetLayerIndex(); - GetChannel()->stage()->apply_transform(GetLayerIndex(), transform, duration, tween); + }, duration, tween); } else if(_parameters[0] == L"LEVELS") { @@ -482,14 +470,11 @@ bool MixerCommand::DoExecute() int duration = _parameters.size() > 6 ? boost::lexical_cast(_parameters[6]) : 0; std::wstring tween = _parameters.size() > 7 ? _parameters[7] : L"linear"; - auto transform = [=](frame_transform transform) -> frame_transform + auto transform = stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform { transform.levels = value; return transform; - }; - - int layer = GetLayerIndex(); - GetChannel()->stage()->apply_transform(GetLayerIndex(), transform, duration, tween); + }, duration, tween); } else if(_parameters[0] == L"VOLUME") { @@ -497,14 +482,11 @@ bool MixerCommand::DoExecute() std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear"; double value = boost::lexical_cast(_parameters[1]); - auto transform = [=](frame_transform transform) -> frame_transform + auto transform = stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform { transform.volume = value; return transform; - }; - - int layer = GetLayerIndex(); - GetChannel()->stage()->apply_transform(GetLayerIndex(), transform, duration, tween); + }, duration, tween); } else if(_parameters[0] == L"CLEAR") { @@ -514,11 +496,23 @@ bool MixerCommand::DoExecute() else GetChannel()->stage()->clear_transforms(layer); } + else if(_parameters[0] == L"COMMIT") + { + transforms = std::move(deferred_transforms[GetChannelIndex()]); + } else { SetReplyString(TEXT("404 MIXER ERROR\r\n")); return false; } + + if(defer) + { + auto& defer_tranforms = deferred_transforms[GetChannelIndex()]; + defer_tranforms.insert(defer_tranforms.end(), transforms.begin(), transforms.end()); + } + else + GetChannel()->stage()->apply_transforms(transforms); SetReplyString(TEXT("202 MIXER OK\r\n")); -- 2.39.2