Skip to content

Commit

Permalink
Merge remote-tracking branch 'julusian/tv2-2.3' into tv2-2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ianshade committed Jun 9, 2021
2 parents a845213 + 3e29a65 commit 623fe1f
Show file tree
Hide file tree
Showing 15 changed files with 619 additions and 399 deletions.
17 changes: 12 additions & 5 deletions src/core/producer/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,23 @@ struct layer::impl

void resume() { paused_ = false; }

void load(spl::shared_ptr<frame_producer> producer, bool preview, bool auto_play)
void load(spl::shared_ptr<frame_producer> producer, bool preview_producer, bool auto_play)
{
background_ = std::move(producer);
auto_play_ = auto_play;

if (auto_play_ && foreground_ == frame_producer::empty()) {
play();
} else if (preview) {
foreground_ = std::move(background_);
background_ = frame_producer::empty();
paused_ = true;
} else if (preview_producer) {
preview(true);
}
}

void preview(bool force)
{
if (force || background_ != frame_producer::empty()) {
play();
paused_ = true;
}
}

Expand Down Expand Up @@ -160,6 +166,7 @@ void layer::load(spl::shared_ptr<frame_producer> frame_producer, bool preview, b
return impl_->load(std::move(frame_producer), preview, auto_play);
}
void layer::play() { impl_->play(); }
void layer::preview() { impl_->preview(false); }
void layer::pause() { impl_->pause(); }
void layer::resume() { impl_->resume(); }
void layer::stop() { impl_->stop(); }
Expand Down
1 change: 1 addition & 0 deletions src/core/producer/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class layer final

void load(spl::shared_ptr<frame_producer> producer, bool preview, bool auto_play = false);
void play();
void preview();
void pause();
void resume();
void stop();
Expand Down
6 changes: 6 additions & 0 deletions src/core/producer/stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ struct stage::impl : public std::enable_shared_from_this<impl>
{
return executor_.begin_invoke([=] { get_layer(index).load(producer, preview, auto_play); });
}

std::future<void> preview(int index)
{
return executor_.begin_invoke([=] { get_layer(index).preview(); });
}

std::future<void> pause(int index)
{
Expand Down Expand Up @@ -369,6 +374,7 @@ std::future<void> stage::load(int index, const spl::shared_ptr<frame_producer>&
{
return impl_->load(index, producer, preview, auto_play);
}
std::future<void> stage::preview(int index) { return impl_->preview(index); }
std::future<void> stage::pause(int index) { return impl_->pause(index); }
std::future<void> stage::resume(int index) { return impl_->resume(index); }
std::future<void> stage::play(int index) { return impl_->play(index); }
Expand Down
1 change: 1 addition & 0 deletions src/core/producer/stage.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class stage final
std::future<frame_transform> get_current_transform(int index);
std::future<void>
load(int index, const spl::shared_ptr<frame_producer>& producer, bool preview = false, bool auto_play = false);
std::future<void> preview(int index);
std::future<void> pause(int index);
std::future<void> resume(int index);
std::future<void> play(int index);
Expand Down
2 changes: 2 additions & 0 deletions src/protocol/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(SOURCES
util/lock_container.cpp
util/strategy_adapters.cpp
util/http_request.cpp
util/tokenize.cpp

StdAfx.cpp
)
Expand Down Expand Up @@ -62,6 +63,7 @@ set(HEADERS
util/protocol_strategy.h
util/strategy_adapters.h
util/http_request.h
util/tokenize.h

StdAfx.h
)
Expand Down
47 changes: 21 additions & 26 deletions src/protocol/amcp/AMCPCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,57 +82,52 @@ using amcp_command_func = std::function<std::wstring(command_context& args)>;
class AMCPCommand
{
private:
command_context ctx_;
amcp_command_func command_;
int min_num_params_;
std::wstring name_;
std::wstring replyString_;
std::wstring request_id_;
command_context ctx_;
const amcp_command_func command_;
const int min_num_params_;
const std::wstring name_;
const std::wstring request_id_;

public:
AMCPCommand(const command_context& ctx,
AMCPCommand(const command_context& ctx,
const amcp_command_func& command,
int min_num_params,
const std::wstring& name)
const std::wstring& name,
const std::wstring& request_id)
: ctx_(ctx)
, command_(command)
, min_num_params_(min_num_params)
, name_(name)
, request_id_(request_id)
{
}

using ptr_type = std::shared_ptr<AMCPCommand>;

bool Execute()
const std::wstring Execute()
{
SetReplyString(command_(ctx_));
return true;
return command_(ctx_);
}

int minimum_parameters() const { return min_num_params_; }

void SendReply()
void SendReply(std::wstring replyString)
{
if (replyString_.empty())
if (replyString.empty())
return;

ctx_.client->send(std::move(replyString_));
}
if (!request_id_.empty())
replyString = L"RES " + request_id_ + L" " + replyString;

std::vector<std::wstring>& parameters() { return ctx_.parameters; }
ctx_.client->send(std::move(replyString));
}

IO::ClientInfoPtr client() { return ctx_.client; }
const std::vector<std::wstring>& parameters() const { return ctx_.parameters; }

std::wstring print() const { return name_; }
int channel_index() const { return ctx_.channel_index; }

void set_request_id(std::wstring request_id) { request_id_ = std::move(request_id); }
IO::ClientInfoPtr client() const { return ctx_.client; }

void SetReplyString(const std::wstring& str)
{
if (request_id_.empty())
replyString_ = str;
else
replyString_ = L"RES " + request_id_ + L" " + str;
}
const std::wstring& print() const { return name_; }
};
}}} // namespace caspar::protocol::amcp
24 changes: 10 additions & 14 deletions src/protocol/amcp/AMCPCommandQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ void AMCPCommandQueue::AddCommand(AMCPCommand::ptr_type pCurrentCommand)
try {
CASPAR_LOG(error) << "AMCP Command Queue Overflow.";
CASPAR_LOG(error) << "Failed to execute command:" << pCurrentCommand->print();
pCurrentCommand->SetReplyString(L"504 QUEUE OVERFLOW\r\n");
pCurrentCommand->SendReply();
pCurrentCommand->SendReply(L"504 QUEUE OVERFLOW\r\n");
} catch (...) {
CASPAR_LOG_CURRENT_EXCEPTION();
}
Expand All @@ -89,32 +88,29 @@ void AMCPCommandQueue::AddCommand(AMCPCommand::ptr_type pCurrentCommand)

CASPAR_LOG(debug) << "Executing command: " << print;

if (pCurrentCommand->Execute())
CASPAR_LOG(debug) << "Executed command (" << timer.elapsed() << "s): " << print;
else
CASPAR_LOG(warning) << "Failed to execute command: " << print;
auto res = pCurrentCommand->Execute();
CASPAR_LOG(debug) << "Executed command (" << timer.elapsed() << "s): " << print;
pCurrentCommand->SendReply(res);
} catch (file_not_found&) {
CASPAR_LOG(error) << " Turn on log level debug for stacktrace.";
pCurrentCommand->SetReplyString(L"404 " + pCurrentCommand->print() + L" FAILED\r\n");
pCurrentCommand->SendReply(L"404 " + pCurrentCommand->print() + L" FAILED\r\n");
} catch (expected_user_error&) {
pCurrentCommand->SetReplyString(L"403 " + pCurrentCommand->print() + L" FAILED\r\n");
pCurrentCommand->SendReply(L"403 " + pCurrentCommand->print() + L" FAILED\r\n");
} catch (user_error&) {
CASPAR_LOG(error) << " Check syntax. Turn on log level debug for stacktrace.";
pCurrentCommand->SetReplyString(L"403 " + pCurrentCommand->print() + L" FAILED\r\n");
pCurrentCommand->SendReply(L"403 " + pCurrentCommand->print() + L" FAILED\r\n");
} catch (std::out_of_range&) {
CASPAR_LOG(error) << L"Missing parameter. Check syntax. Turn on log level debug for stacktrace.";
pCurrentCommand->SetReplyString(L"402 " + pCurrentCommand->print() + L" FAILED\r\n");
pCurrentCommand->SendReply(L"402 " + pCurrentCommand->print() + L" FAILED\r\n");
} catch (boost::bad_lexical_cast&) {
CASPAR_LOG(error) << L"Invalid parameter. Check syntax. Turn on log level debug for stacktrace.";
pCurrentCommand->SetReplyString(L"403 " + pCurrentCommand->print() + L" FAILED\r\n");
pCurrentCommand->SendReply(L"403 " + pCurrentCommand->print() + L" FAILED\r\n");
} catch (...) {
CASPAR_LOG_CURRENT_EXCEPTION();
CASPAR_LOG(error) << "Failed to execute command: " << pCurrentCommand->print();
pCurrentCommand->SetReplyString(L"501 " + pCurrentCommand->print() + L" FAILED\r\n");
pCurrentCommand->SendReply(L"501 " + pCurrentCommand->print() + L" FAILED\r\n");
}

pCurrentCommand->SendReply();

CASPAR_LOG(trace) << "Ready for a new command";
} catch (...) {
CASPAR_LOG_CURRENT_EXCEPTION();
Expand Down
Loading

0 comments on commit 623fe1f

Please sign in to comment.