1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
#ifndef RENDERCONTEXT_H
#define RENDERCONTEXT_H
#include "Poco/Task.h"
#include "Poco/StringTokenizer.h"
#include "rotor.h"
#include "graph.h"
#include "Poco/URI.h"
#include "Poco/Channel.h"
#include "Poco/SplitterChannel.h"
#include "Poco/ConsoleChannel.h"
#include "Poco/FormattingChannel.h"
#include "Poco/FileChannel.h"
#include "Poco/Message.h"
#include "Poco/Formatter.h"
#include "Poco/PatternFormatter.h"
#include "Poco/AutoPtr.h"
using Poco::Logger;
using Poco::Channel;
using Poco::SplitterChannel;
using Poco::ConsoleChannel;
using Poco::FormattingChannel;
using Poco::Formatter;
using Poco::PatternFormatter;
using Poco::FileChannel;
using Poco::Message;
using Poco::AutoPtr;
/*------------------------
Render context packages the management of a rotor graph as a web service
-------------------------*/
namespace Rotor {
#define IDLE 0
#define ANALYSING_AUDIO 1
#define AUDIO_READY 2
#define CREATING_PREVIEW 3
#define PREVIEW_READY 4
#define RENDERING 5
#define RENDER_READY 6
#define FAILED 7
#define NOT_FOUND 8
#define CANCELLED 9
#define LOADING_GRAPH 10
#define ANALYSE_AUDIO 1
#define PREVIEW 2
#define RENDER 3
#define LOAD_GRAPH 4
class Session_command {
public:
Session_command(){body="";};
string uid,method,id,body;
vector<string> commands;
};
class Session_task {
public:
Session_task():uid(""),task(0){};
Session_task(const string &_uid,int _task):uid(_uid),task(_task) {};
string uid;
int task;
};
class Render_status {
public:
Render_status():status(0),progress(0.0){};
Render_status(int _status):status(_status),progress(0.0){};
int status;
double progress;
};
class Render_context: public Poco::Task { //Poco task object
//manages a 'patchbay'
//high level interfaces for the wizard
//and low level interface onto the graph
public:
Render_context(const std::string& name): Task(name) {
state=IDLE;
output_framerate=25.0;
start=0;
stop=999999;
xmlIO xml;
if(xml.loadFile("settings.xml") ){
graph_dir=xml.getAttribute("Rotor","graph_dir","",0);
media_dir=xml.getAttribute("Rotor","media_dir","",0);
output_dir=xml.getAttribute("Rotor","output_dir","",0);
}
else cerr<<"Rotor: settings.xml not found, using defaults"<<endl;
output_filename=graph_filename=graph_body="";
AutoPtr<SplitterChannel> splitterChannel(new SplitterChannel());
AutoPtr<Channel> consoleChannel(new ConsoleChannel());
AutoPtr<Channel> fileChannel(new FileChannel("Rotord_session_"+name+".log"));
//AutoPtr<FileChannel> rotatedFileChannel(new FileChannel("Rotord_R.log"));
//rotatedFileChannel->setProperty("rotation", "100");
//rotatedFileChannel->setProperty("archive", "timestamp");
splitterChannel->addChannel(consoleChannel);
splitterChannel->addChannel(fileChannel);
//splitterChannel->addChannel(rotatedFileChannel);
AutoPtr<Formatter> formatter(new PatternFormatter("%d-%m-%Y %H:%M:%S %s: %t"));
AutoPtr<Channel> formattingChannel(new FormattingChannel(formatter, splitterChannel));
Log_name="Context "+name;
graph.set_log_name(Log_name);
Logger& sLog = Logger::create(Log_name, formattingChannel, Message::PRIO_TRACE);
Logger& logger = Logger::get(Log_name);
logger.information("started thread");
};
~Render_context(){};
void runTask();
void add_queue(Session_task item);
void session_command(const Session_command& command,xmlIO& XML,Poco::Net::HTTPResponse::HTTPStatus& status);
void cancel(){
graph.clear();
} //interrupt locking process
Render_status get_render_status(const string &uid){
//graph.mutex.lock();
//cerr<<"render status requested: "<<uid<<" status: "<<renders[uid].status<<endl;
if (renders.find(uid)!=renders.end()){
if (renders[uid].status==RENDERING){
renders[uid].progress=graph.progress;
}
//graph.mutex.unlock();
return renders[uid];
}
//graph.mutex.unlock();
return Render_status(NOT_FOUND);
};
private:
int state;
//thread only does one thing at once
std::deque<Session_task> work_queue;
std::unordered_map<string,Render_status> renders;
std::string output_filename;
std::string graph_dir;
std::string media_dir;
std::string output_dir;
std::string graph_filename;
std::string graph_body;
std::string Log_name;
Poco::Mutex mutex; //lock for access from parent thread
Audio_thumbnailer *audio_thumb;
Graph graph;
double output_framerate;
int start,stop;
};
}
#endif
|