X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=protocol%2Famcp%2FAMCPCommandsImpl.cpp;h=5eedd32f13a8d1fcb72b9c5666903bd4badf9a99;hb=3cfeb882a742d67080e60b2686421b4d862e9e9c;hp=0b06c546fccc577b5ce8c7affbcaf41306e0b1f2;hpb=f0ee6c6addebce6dfbe10ab969463ba448726fd8;p=casparcg diff --git a/protocol/amcp/AMCPCommandsImpl.cpp b/protocol/amcp/AMCPCommandsImpl.cpp index 0b06c546f..5eedd32f1 100644 --- a/protocol/amcp/AMCPCommandsImpl.cpp +++ b/protocol/amcp/AMCPCommandsImpl.cpp @@ -20,21 +20,29 @@ #include "../StdAfx.h" +#if defined(_MSC_VER) +#pragma warning (push, 1) // TODO: Legacy code, just disable warnings +#endif + #include "AMCPCommandsImpl.h" #include "AMCPProtocolStrategy.h" -#include "../media.h" - #include +#include + #include #include -#include #include -#include +#include +#include +#include +#include +#include -#include -#include +#include +#include +#include #include #include @@ -46,10 +54,7 @@ #include #include #include - -#if defined(_MSC_VER) -#pragma warning (push, 1) // TODO: Legacy code, just disable warnings -#endif +#include /* Return codes @@ -86,10 +91,13 @@ std::wstring ListMedia() { std::wstring clipttype = TEXT(" N/A "); std::wstring extension = boost::to_upper_copy(itr->path().extension()); - if(extension == TEXT(".TGA") || extension == TEXT(".COL")) + if(extension == TEXT(".TGA") || extension == TEXT(".COL") || extension == L".PNG" || extension == L".JPEG" || extension == L".JPG" || + extension == L"GIF" || extension == L"BMP") clipttype = TEXT(" STILL "); else if(extension == TEXT(".SWF") || extension == TEXT(".DV") || extension == TEXT(".MOV") || extension == TEXT(".MPG") || - extension == TEXT(".AVI") || extension == TEXT(".FLV") || extension == TEXT(".F4V") || extension == TEXT(".MP4")) + extension == TEXT(".AVI") || extension == TEXT(".FLV") || extension == TEXT(".F4V") || extension == TEXT(".MP4") || + extension == L".M2V" || extension == L".H264" || extension == L".MKV" || extension == L".WMV" || extension == L".DIVX" || + extension == L".XVID" || extension == L".OGG") clipttype = TEXT(" MOVIE "); else if(extension == TEXT(".WAV") || extension == TEXT(".MP3")) clipttype = TEXT(" STILL "); @@ -107,12 +115,16 @@ std::wstring ListMedia() auto sizeStr = boost::lexical_cast(boost::filesystem::file_size(itr->path())); sizeStr.erase(std::remove_if(sizeStr.begin(), sizeStr.end(), is_not_digit), sizeStr.end()); auto sizeWStr = std::wstring(sizeStr.begin(), sizeStr.end()); + + auto str = relativePath.replace_extension(TEXT("")).external_file_string(); + if(str[0] == '\\' || str[0] == '/') + str = std::wstring(str.begin() + 1, str.end()); - replyString << TEXT("\"") << relativePath.replace_extension(TEXT("")) + replyString << TEXT("\"") << str << TEXT("\" ") << clipttype << TEXT(" ") << sizeStr << TEXT(" ") << writeTimeWStr - << TEXT("\r\n"); + << TEXT("\r\n"); } } } @@ -137,14 +149,22 @@ std::wstring ListTemplates() sizeStr.erase(std::remove_if(sizeStr.begin(), sizeStr.end(), [](char c){ return std::isdigit(c) == 0;}), sizeStr.end()); auto sizeWStr = std::wstring(sizeStr.begin(), sizeStr.end()); - - replyString << TEXT("\"") << relativePath.replace_extension(TEXT("")) + + std::wstring dir = relativePath.parent_path().external_directory_string(); + std::wstring file = boost::to_upper_copy(relativePath.filename()); + relativePath = boost::filesystem::wpath(dir + L"/" + file); + + auto str = relativePath.replace_extension(TEXT("")).external_file_string(); + if(str[0] == '\\' || str[0] == '/') + str = std::wstring(str.begin() + 1, str.end()); + + replyString << TEXT("\"") << str << TEXT("\" ") << sizeWStr << TEXT(" ") << writeTimeWStr << TEXT("\r\n"); } } - return boost::to_upper_copy(replyString.str()); + return replyString.str(); } namespace amcp { @@ -164,100 +184,234 @@ void AMCPCommand::SendReply() void AMCPCommand::Clear() { - pChannel_->producer().clear(); + pChannel_->stage()->clear(); pClientInfo_.reset(); channelIndex_ = 0; _parameters.clear(); } +bool ParamCommand::DoExecute() +{ + //Perform loading of the clip + try + { + auto what = _parameters.at(2); + if(what == L"B") + GetChannel()->stage()->background(GetLayerIndex()).get()->param(_parameters.at(3)); + else if(what == L"F") + GetChannel()->stage()->foreground(GetLayerIndex()).get()->param(_parameters.at(3)); + + CASPAR_LOG(info) << "Executed param: " << _parameters[0] << TEXT(" successfully"); + + SetReplyString(TEXT("202 PARAM OK\r\n")); + + return true; + } + catch(...) + { + CASPAR_LOG_CURRENT_EXCEPTION(); + SetReplyString(TEXT("502 PARAM FAILED\r\n")); + return false; + } +} + bool MixerCommand::DoExecute() { //Perform loading of the clip try { - if(_parameters[0] == L"VIDEO") + if(_parameters[0] == L"KEYER") { - if(_parameters[1] == L"OPACITY") + bool value = lexical_cast_or_default(_parameters.at(1), false); + auto transform = [=](frame_transform transform) -> frame_transform { - double value = boost::lexical_cast(_parameters.at(2)); - auto transform = GetChannel()->mixer().get_image_transform(GetLayerIndex()); - transform.set_opacity(value); - GetChannel()->mixer().set_image_transform(GetLayerIndex(), std::move(transform)); - } - else if(_parameters[1] == L"GAIN") + transform.is_key = value; + return transform; + }; + + int layer = GetLayerIndex(); + GetChannel()->mixer()->apply_frame_transform(GetLayerIndex(), transform); + } + else if(_parameters[0] == L"OPACITY") + { + int duration = _parameters.size() > 2 ? lexical_cast_or_default(_parameters[2], 0) : 0; + std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear"; + + double value = boost::lexical_cast(_parameters.at(1)); + + auto transform = [=](frame_transform transform) -> frame_transform { - double value = boost::lexical_cast(_parameters.at(2)); - auto transform = GetChannel()->mixer().get_image_transform(GetLayerIndex()); - transform.set_gain(value); - GetChannel()->mixer().set_image_transform(GetLayerIndex(), std::move(transform)); - } - else if(_parameters[1] == L"FIX_RECT") + transform.opacity = value; + return transform; + }; + + int layer = GetLayerIndex(); + GetChannel()->mixer()->apply_frame_transform(GetLayerIndex(), transform, duration, tween); + } + else if(_parameters[0] == L"FILL") + { + int duration = _parameters.size() > 5 ? lexical_cast_or_default(_parameters[5], 0) : 0; + std::wstring tween = _parameters.size() > 6 ? _parameters[6] : L"linear"; + double x = boost::lexical_cast(_parameters.at(1)); + double y = boost::lexical_cast(_parameters.at(2)); + 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 { - double x = boost::lexical_cast(_parameters.at(2)); - double y = boost::lexical_cast(_parameters.at(3)); - double x_s = boost::lexical_cast(_parameters.at(4)); - double y_s = boost::lexical_cast(_parameters.at(5)); - auto transform = GetChannel()->mixer().get_image_transform(GetLayerIndex()); - transform.set_image_translation(x, y); - transform.set_image_scale(x_s, y_s); - transform.set_mask_translation(x, y); - transform.set_mask_scale(x_s, y_s); - GetChannel()->mixer().set_image_transform(GetLayerIndex(), std::move(transform)); - } - else if(_parameters[1] == L"CLIP_RECT") + transform.fill_translation[0] = x; + transform.fill_translation[1] = y; + transform.fill_scale[0] = x_s; + transform.fill_scale[1] = y_s; + 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()->mixer()->apply_frame_transform(GetLayerIndex(), transform, duration, tween); + } + else if(_parameters[0] == L"CLIP") + { + int duration = _parameters.size() > 5 ? lexical_cast_or_default(_parameters[5], 0) : 0; + std::wstring tween = _parameters.size() > 6 ? _parameters[6] : L"linear"; + double x = boost::lexical_cast(_parameters.at(1)); + double y = boost::lexical_cast(_parameters.at(2)); + 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 { - double x = boost::lexical_cast(_parameters.at(2)); - double y = boost::lexical_cast(_parameters.at(3)); - double x_s = boost::lexical_cast(_parameters.at(4)); - double y_s = boost::lexical_cast(_parameters.at(5)); - auto transform = GetChannel()->mixer().get_image_transform(GetLayerIndex()); - transform.set_image_translation(0.0, 0.0); - transform.set_image_scale(1.0, 1.0); - transform.set_mask_translation(x, y); - transform.set_mask_scale(x_s, y_s); - GetChannel()->mixer().set_image_transform(GetLayerIndex(), std::move(transform)); - } - else if(_parameters[1] == L"GRID") + 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()->mixer()->apply_frame_transform(GetLayerIndex(), transform, duration, tween); + } + else if(_parameters[0] == L"GRID") + { + int duration = _parameters.size() > 2 ? lexical_cast_or_default(_parameters[2], 0) : 0; + std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear"; + int n = boost::lexical_cast(_parameters.at(1)); + double delta = 1.0/static_cast(n); + for(int x = 0; x < n; ++x) { - int n = boost::lexical_cast(_parameters.at(2)); - double delta = 1.0/static_cast(n); - for(int x = 0; x < n; ++x) + for(int y = 0; y < n; ++y) { - for(int y = 0; y < n; ++y) - { - int index = x+y*n; - auto transform = GetChannel()->mixer().get_image_transform(index); - transform.set_image_translation(x*delta, y*delta); - transform.set_image_scale(delta, delta); - transform.set_mask_translation(x*delta, y*delta); - transform.set_mask_scale(delta, delta); - GetChannel()->mixer().set_image_transform(index, std::move(transform)); - } + int index = x+y*n+1; + auto transform = [=](frame_transform transform) -> frame_transform + { + transform.fill_translation[0] = x*delta; + transform.fill_translation[1] = y*delta; + transform.fill_scale[0] = delta; + transform.fill_scale[1] = delta; + transform.clip_translation[0] = x*delta; + transform.clip_translation[1] = y*delta; + transform.clip_scale[0] = delta; + transform.clip_scale[1] = delta; + return transform; + }; + GetChannel()->mixer()->apply_frame_transform(index, transform, duration, tween); } } - else if(_parameters[1] == L"RESET") + } + else if(_parameters[0] == L"BLEND") + { + auto blend_str = _parameters.at(1); + int layer = GetLayerIndex(); + GetChannel()->mixer()->set_blend_mode(GetLayerIndex(), get_blend_mode(blend_str)); + } + else if(_parameters[0] == L"BRIGHTNESS") + { + auto value = boost::lexical_cast(_parameters.at(1)); + int duration = _parameters.size() > 2 ? lexical_cast_or_default(_parameters[2], 0) : 0; + std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear"; + auto transform = [=](frame_transform transform) -> frame_transform { - GetChannel()->mixer().set_image_transform(GetLayerIndex(), image_transform()); - } + transform.brightness = value; + return transform; + }; + + int layer = GetLayerIndex(); + GetChannel()->mixer()->apply_frame_transform(GetLayerIndex(), transform, duration, tween); } - else if(_parameters[0] == L"AUDIO") + else if(_parameters[0] == L"SATURATION") { - if(_parameters[1] == L"GAIN") + auto value = boost::lexical_cast(_parameters.at(1)); + int duration = _parameters.size() > 2 ? lexical_cast_or_default(_parameters[2], 0) : 0; + std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear"; + auto transform = [=](frame_transform transform) -> frame_transform { - double value = boost::lexical_cast(_parameters[2]); - auto transform = GetChannel()->mixer().get_audio_transform(GetLayerIndex()); - transform.set_gain(value); - GetChannel()->mixer().set_audio_transform(GetLayerIndex(), std::move(transform)); - } - else if(_parameters[1] == L"RESET") + transform.saturation = value; + return transform; + }; + + int layer = GetLayerIndex(); + GetChannel()->mixer()->apply_frame_transform(GetLayerIndex(), transform, duration, tween); + } + else if(_parameters[0] == L"CONTRAST") + { + auto value = boost::lexical_cast(_parameters.at(1)); + int duration = _parameters.size() > 2 ? lexical_cast_or_default(_parameters[2], 0) : 0; + std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear"; + auto transform = [=](frame_transform transform) -> frame_transform { - GetChannel()->mixer().set_audio_transform(GetLayerIndex(), audio_transform()); - } + transform.contrast = value; + return transform; + }; + + int layer = GetLayerIndex(); + GetChannel()->mixer()->apply_frame_transform(GetLayerIndex(), transform, duration, tween); + } + else if(_parameters[0] == L"LEVELS") + { + levels value; + value.min_input = boost::lexical_cast(_parameters.at(1)); + value.max_input = boost::lexical_cast(_parameters.at(2)); + value.gamma = boost::lexical_cast(_parameters.at(3)); + value.min_output = boost::lexical_cast(_parameters.at(4)); + value.max_output = boost::lexical_cast(_parameters.at(5)); + int duration = _parameters.size() > 6 ? lexical_cast_or_default(_parameters[6], 0) : 0; + std::wstring tween = _parameters.size() > 7 ? _parameters[7] : L"linear"; + + auto transform = [=](frame_transform transform) -> frame_transform + { + transform.levels = value; + return transform; + }; + + int layer = GetLayerIndex(); + GetChannel()->mixer()->apply_frame_transform(GetLayerIndex(), transform, duration, tween); + } + else if(_parameters[0] == L"VOLUME") + { + int duration = _parameters.size() > 2 ? lexical_cast_or_default(_parameters[2], 0) : 0; + std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear"; + double value = boost::lexical_cast(_parameters[1]); + + auto transform = [=](frame_transform transform) -> frame_transform + { + transform.volume = value; + return transform; + }; + + int layer = GetLayerIndex(); + GetChannel()->mixer()->apply_frame_transform(GetLayerIndex(), transform, duration, tween); } - else if(_parameters[0] == L"RESET") + else if(_parameters[0] == L"CLEAR") { - GetChannel()->mixer().set_image_transform(GetLayerIndex(), image_transform()); - GetChannel()->mixer().set_audio_transform(GetLayerIndex(), audio_transform()); + GetChannel()->mixer()->clear_transforms(); + } + else + { + SetReplyString(TEXT("404 MIXER ERROR\r\n")); + return false; } SetReplyString(TEXT("202 MIXER OK\r\n")); @@ -294,13 +448,13 @@ bool SwapCommand::DoExecute() int l1 = GetLayerIndex(); int l2 = boost::lexical_cast(strs.at(1)); - ch1->producer().swap_layer(l1, l2, ch2->producer()); + ch1->stage()->swap_layer(l1, l2, *ch2->stage()); } else { auto ch1 = GetChannel(); auto ch2 = GetChannels().at(boost::lexical_cast(_parameters[0])-1); - ch1->producer().swap(ch2->producer()); + ch1->stage()->swap(*ch2->stage()); } CASPAR_LOG(info) << "Swapped successfully"; @@ -328,7 +482,7 @@ bool AddCommand::DoExecute() //Perform loading of the clip try { - GetChannel()->consumer().add(GetLayerIndex(), create_consumer(_parameters)); + GetChannel()->output()->add(GetLayerIndex(), create_consumer(_parameters)); CASPAR_LOG(info) << "Added " << _parameters[0] << TEXT(" successfully"); @@ -355,9 +509,7 @@ bool RemoveCommand::DoExecute() //Perform loading of the clip try { - GetChannel()->consumer().remove(GetLayerIndex()); - - CASPAR_LOG(info) << "Removed " << TEXT(" successfully"); + GetChannel()->output()->remove(GetLayerIndex()); SetReplyString(TEXT("202 REMOVE OK\r\n")); @@ -383,8 +535,8 @@ bool LoadCommand::DoExecute() try { _parameters[0] = _parameters[0]; - auto pFP = create_producer(_parameters); - GetChannel()->producer().preview(GetLayerIndex(), pFP); + auto pFP = create_producer(GetChannel()->mixer(), _parameters); + GetChannel()->stage()->load(GetLayerIndex(), pFP, true); CASPAR_LOG(info) << "Loaded " << _parameters[0] << TEXT(" successfully"); @@ -406,65 +558,99 @@ bool LoadCommand::DoExecute() } } + + +//std::function channel_cg_add_command::parse(const std::wstring& message, const std::vector& channels) +//{ +// static boost::wregex expr(L"^CG\\s(?\\d+)-?(?\\d+)?\\sADD\\s(?\\d+)\\s(?