]> git.sesse.net Git - casparcg/blob - protocol/cii/CIIProtocolStrategy.h
[streaming_consumer] Added support for sending recording activity via OSC like in...
[casparcg] / protocol / cii / CIIProtocolStrategy.h
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author: Nicklas P Andersson
20 */
21
22  
23 #pragma once
24
25 #include <core/video_channel.h>
26
27 #include "../util/ProtocolStrategy.h"
28 #include "CIICommand.h"
29
30 #include <core/producer/stage.h>
31 #include <core/producer/cg_proxy.h>
32
33 #include <common/executor.h>
34 #include <common/memory.h>
35
36 #include <string>
37
38 namespace caspar { namespace protocol { namespace cii {
39
40 class CIIProtocolStrategy : public IO::IProtocolStrategy
41 {
42 public:
43         CIIProtocolStrategy(
44                         const std::vector<spl::shared_ptr<core::video_channel>>& channels,
45                         const spl::shared_ptr<core::cg_producer_registry>& cg_registry,
46                         const spl::shared_ptr<const core::frame_producer_registry>& producer_registry);
47
48         void Parse(const std::wstring& message, IO::ClientInfoPtr pClientInfo);
49         std::string GetCodepage() const { return "ISO-8859-1"; }        //ISO 8859-1
50
51         void SetProfile(const std::wstring& profile) {currentProfile_ = profile;}
52
53         spl::shared_ptr<core::video_channel> GetChannel() const { return pChannel_; }
54         spl::shared_ptr<core::cg_producer_registry> get_cg_registry() const { return cg_registry_; }
55         spl::shared_ptr<const core::frame_producer_registry> get_producer_registry() const { return producer_registry_; }
56         core::frame_producer_dependencies get_dependencies() const { return core::frame_producer_dependencies(GetChannel()->frame_factory(), channels_, GetChannel()->video_format_desc(), producer_registry_); }
57
58         void DisplayMediaFile(const std::wstring& filename);
59         void DisplayTemplate(const std::wstring& titleName);
60         void WriteTemplateData(const std::wstring& templateName, const std::wstring& titleName, const std::wstring& xmlData);
61
62 public:
63         struct TitleHolder
64         {
65                 TitleHolder() : titleName(L""), pframe_producer(core::frame_producer::empty())  {}
66                 TitleHolder(const std::wstring& name, spl::shared_ptr<core::frame_producer> pFP) : titleName(name), pframe_producer(pFP) {}
67                 TitleHolder(const TitleHolder& th) : titleName(th.titleName), pframe_producer(th.pframe_producer) {}
68                 TitleHolder& operator=(const TitleHolder& th) 
69                 {
70                         titleName = th.titleName;
71                         pframe_producer = th.pframe_producer;
72
73                         return *this;
74                 }
75                 bool operator==(const TitleHolder& rhs) 
76                 {
77                         return pframe_producer == rhs.pframe_producer;
78                 }
79
80                 std::wstring titleName;
81                 spl::shared_ptr<core::frame_producer> pframe_producer;
82                 friend CIIProtocolStrategy;
83         };
84 private:
85
86         typedef std::list<TitleHolder> TitleList;
87         TitleList titles_;
88         spl::shared_ptr<core::frame_producer> GetPreparedTemplate(const std::wstring& name);
89         void PutPreparedTemplate(const std::wstring& name, const spl::shared_ptr<core::frame_producer>& pframe_producer);
90
91         static const wchar_t TokenDelimiter;
92         static const std::wstring MessageDelimiter;
93
94         void ProcessMessage(const std::wstring& message, IO::ClientInfoPtr pClientInfo);
95         int TokenizeMessage(const std::wstring& message, std::vector<std::wstring>* pTokenVector);
96         CIICommandPtr Create(const std::wstring& name);
97
98         executor executor_;
99         std::wstring currentMessage_;
100
101         std::wstring currentProfile_;
102         spl::shared_ptr<core::video_channel> pChannel_;
103         spl::shared_ptr<core::cg_producer_registry> cg_registry_;
104         spl::shared_ptr<const core::frame_producer_registry> producer_registry_;
105         std::vector<spl::shared_ptr<core::video_channel>> channels_;
106 };
107
108 }}}