From ac44751d58b23888cd0e95ffeffbf8409b06e783 Mon Sep 17 00:00:00 2001 From: Ronag Date: Sun, 14 Aug 2011 00:57:52 +0000 Subject: [PATCH] 2.0. Applied tk3 patch, STATUS command for layer status querying. git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@1165 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d --- core/producer/layer.cpp | 15 ++++++++++++++ core/producer/layer.h | 14 +++++++++++++ core/producer/stage.cpp | 11 +++++++++- core/producer/stage.h | 5 ++++- protocol/amcp/AMCPCommandsImpl.cpp | 28 ++++++++++++++++++++++++++ protocol/amcp/AMCPCommandsImpl.h | 6 ++++++ protocol/amcp/AMCPProtocolStrategy.cpp | 1 + 7 files changed, 78 insertions(+), 2 deletions(-) diff --git a/core/producer/layer.cpp b/core/producer/layer.cpp index 9ba6acaa5..9010954f4 100644 --- a/core/producer/layer.cpp +++ b/core/producer/layer.cpp @@ -120,6 +120,18 @@ public: } } + layer_status status() const + { + layer_status status; + status.foreground = foreground_->print(); + status.background = background_->print(); + status.is_paused = is_paused_; + status.total_frames = foreground_->nb_frames(); + status.current_frame = frame_number_; + + return status; + } + bool empty() const { return background_ == core::frame_producer::empty() && foreground_ == core::frame_producer::empty(); @@ -148,6 +160,9 @@ void layer::load(const safe_ptr& frame_producer, bool preview, i void layer::play(){impl_->play();} void layer::pause(){impl_->pause();} void layer::stop(){impl_->stop();} +bool layer::is_paused() const{return impl_->is_paused_;} +int64_t layer::frame_number() const{return impl_->frame_number_;} +layer_status layer::status() const {return impl_->status();} safe_ptr layer::receive() {return impl_->receive();} safe_ptr layer::foreground() const { return impl_->foreground_;} safe_ptr layer::background() const { return impl_->background_;} diff --git a/core/producer/layer.h b/core/producer/layer.h index eb976d5d7..e7991d1f3 100644 --- a/core/producer/layer.h +++ b/core/producer/layer.h @@ -29,6 +29,15 @@ namespace caspar { namespace core { struct frame_producer; class basic_frame; +struct layer_status +{ + std::wstring foreground; + std::wstring background; + bool is_paused; + int64_t total_frames; + int64_t current_frame; +}; + class layer : boost::noncopyable { public: @@ -46,6 +55,11 @@ public: void stop(); // nothrow void param(const std::wstring& param); + bool is_paused() const; + int64_t frame_number() const; + + layer_status status() const; + bool empty() const; safe_ptr foreground() const; // nothrow diff --git a/core/producer/stage.cpp b/core/producer/stage.cpp index 1c5d99014..d222b39d7 100644 --- a/core/producer/stage.cpp +++ b/core/producer/stage.cpp @@ -39,7 +39,7 @@ #include namespace caspar { namespace core { - + void destroy_producer(safe_ptr& producer) { if(!producer.unique()) @@ -194,6 +194,14 @@ public: channel_.execution().invoke([&]{other.impl_->channel_.execution().invoke(func, high_priority);}); } + + layer_status get_status(int index) + { + return channel_.execution().invoke([&] + { + return layers_[index].status(); + }, high_priority ); + } boost::unique_future> foreground(int index) { @@ -222,6 +230,7 @@ void stage::clear(int index){impl_->clear(index);} void stage::clear(){impl_->clear();} void stage::swap_layer(int index, size_t other_index){impl_->swap_layer(index, other_index);} void stage::swap_layer(int index, size_t other_index, stage& other){impl_->swap_layer(index, other_index, other);} +layer_status stage::get_status(int index){return impl_->get_status(index);} boost::unique_future> stage::foreground(size_t index) {return impl_->foreground(index);} boost::unique_future> stage::background(size_t index) {return impl_->background(index);} std::map> stage::execute(){return impl_->execute();} diff --git a/core/producer/stage.h b/core/producer/stage.h index 1217dc2c6..b13e71257 100644 --- a/core/producer/stage.h +++ b/core/producer/stage.h @@ -30,7 +30,8 @@ namespace caspar { namespace core { struct video_format_desc; -class video_channel_context;; +class video_channel_context; +struct layer_status; class stage : boost::noncopyable { @@ -49,6 +50,8 @@ public: void clear(); void swap_layer(int index, size_t other_index); void swap_layer(int index, size_t other_index, stage& other); + + layer_status get_status(int index); boost::unique_future> foreground(size_t index); boost::unique_future> background(size_t index); diff --git a/protocol/amcp/AMCPCommandsImpl.cpp b/protocol/amcp/AMCPCommandsImpl.cpp index 726e4bdfd..49d0b41e1 100644 --- a/protocol/amcp/AMCPCommandsImpl.cpp +++ b/protocol/amcp/AMCPCommandsImpl.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include @@ -798,6 +800,32 @@ bool PrintCommand::DoExecute() return true; } +bool StatusCommand::DoExecute() +{ + if (GetLayerIndex() > -1) + { + auto status = GetChannel()->stage()->get_status(GetLayerIndex()); + std::wstringstream status_text; + status_text + << L"202 STATUS OK\r\n" + << L"FOREGROUND:" << status.foreground << L"\r\n" + << L"BACKGROUND:" << status.background << L"\r\n" + << L"STATUS:" << (status.is_paused ? L"PAUSED" : L"PLAYING") << L"\r\n" + << L"TOTAL FRAMES:" << (status.total_frames == std::numeric_limits::max() ? 0 : status.total_frames) << L"\r\n" + << L"CURRENT FRAME:" << status.current_frame << L"\r\n"; + + SetReplyString(status_text.str()); + return true; + } + else + { + //NOTE: Possible to extend soo that "channel" status is returned when no layer is specified. + + SetReplyString(TEXT("403 LAYER MUST BE SPECIFIED\r\n")); + return false; + } +} + bool LogCommand::DoExecute() { if(_parameters.at(0) == L"LEVEL") diff --git a/protocol/amcp/AMCPCommandsImpl.h b/protocol/amcp/AMCPCommandsImpl.h index 3f50f34a7..ef5f53bda 100644 --- a/protocol/amcp/AMCPCommandsImpl.h +++ b/protocol/amcp/AMCPCommandsImpl.h @@ -102,6 +102,12 @@ class PrintCommand : public AMCPCommandBase bool DoExecute(); }; +class StatusCommand : public AMCPCommandBase +{ + std::wstring print() const { return L"StatusCommand";} + bool DoExecute(); +}; + class LogCommand : public AMCPCommandBase { std::wstring print() const { return L"LogCommand";} diff --git a/protocol/amcp/AMCPProtocolStrategy.cpp b/protocol/amcp/AMCPProtocolStrategy.cpp index 937922f22..fdd685875 100644 --- a/protocol/amcp/AMCPProtocolStrategy.cpp +++ b/protocol/amcp/AMCPProtocolStrategy.cpp @@ -322,6 +322,7 @@ AMCPCommandPtr AMCPProtocolStrategy::CommandFactory(const std::wstring& str) else if(s == TEXT("STOP")) return std::make_shared(); else if(s == TEXT("CLEAR")) return std::make_shared(); else if(s == TEXT("PRINT")) return std::make_shared(); + else if(s == TEXT("STATUS")) return std::make_shared(); else if(s == TEXT("LOG")) return std::make_shared(); else if(s == TEXT("CG")) return std::make_shared(); else if(s == TEXT("DATA")) return std::make_shared(); -- 2.39.2