Stefan Schuermans commited on 2011-11-19 21:52:49
Showing 8 changed files, with 370 additions and 0 deletions.
... | ... |
@@ -87,6 +87,7 @@ |
87 | 87 |
<li><a href="canvas.html">Canvas</a></li> |
88 | 88 |
<li><a href="player.html">Player</a></li> |
89 | 89 |
<li><a href="printer.html">Printer</a></li> |
90 |
+ <li><a href="resizer.html">Resizer</a></li> |
|
90 | 91 |
<li><a href="udp4sender.html">UDP4 Sender</a></li> |
91 | 92 |
</ul> |
92 | 93 |
</p> |
... | ... |
@@ -0,0 +1,40 @@ |
1 |
+<html> |
|
2 |
+ <head> |
|
3 |
+ <title>Blinker - Resizer</title> |
|
4 |
+ </head> |
|
5 |
+ <body> |
|
6 |
+ <h1>Blinker - Resizer</h1> |
|
7 |
+ <p> |
|
8 |
+ The resizer module resizes the frame format of a stream. |
|
9 |
+ It receives a single input stream and passes it on with a resized format. |
|
10 |
+ </p> |
|
11 |
+ <h2>Configuration</h2> |
|
12 |
+ <p> |
|
13 |
+ The configuration of the resizer module with name <code>NAME</code> |
|
14 |
+ is located in the <code>resizers/NAME</code> subdirectory. |
|
15 |
+ </p> |
|
16 |
+ <h3>Input Stream</h3> |
|
17 |
+ <p> |
|
18 |
+ The file <code>instream</code> contains the name of the stream to |
|
19 |
+ receive. |
|
20 |
+ The frames received from this stream are resized and passed to the |
|
21 |
+ output stream. |
|
22 |
+ </p> |
|
23 |
+ <h3>Format</h3> |
|
24 |
+ <p> |
|
25 |
+ The file <code>format</code> describes the format of the output stream, |
|
26 |
+ i.e. its dimensions, the number of channels and the color depth on |
|
27 |
+ each channel. |
|
28 |
+ The file must contain a string |
|
29 |
+ <code><width>x<height>-<channels>/<colors></code>, |
|
30 |
+ e.g. <code>18x8-1/256</code> for 18 pixels width, 8 pixels height |
|
31 |
+ in 256 grayscales. |
|
32 |
+ </p> |
|
33 |
+ <h3>Output Stream</h3> |
|
34 |
+ <p> |
|
35 |
+ The file <code>outstream</code> contains the name of the stream to |
|
36 |
+ send the resized frames to. |
|
37 |
+ </p> |
|
38 |
+ </body> |
|
39 |
+</html> |
|
40 |
+ |
... | ... |
@@ -0,0 +1 @@ |
1 |
+36x16-1/256 |
... | ... |
@@ -0,0 +1 @@ |
1 |
+dot |
... | ... |
@@ -0,0 +1 @@ |
1 |
+bigdot |
... | ... |
@@ -0,0 +1,217 @@ |
1 |
+/* Blinker |
|
2 |
+ Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org> |
|
3 |
+ Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html |
|
4 |
+ a blinkenarea.org project */ |
|
5 |
+ |
|
6 |
+#include <iostream> |
|
7 |
+#include <stdlib.h> |
|
8 |
+#include <string> |
|
9 |
+ |
|
10 |
+#include <BlinkenLib/BlinkenFrame.h> |
|
11 |
+ |
|
12 |
+#include "CallMgr.h" |
|
13 |
+#include "Directory.h" |
|
14 |
+#include "File.h" |
|
15 |
+#include "Format.h" |
|
16 |
+#include "Module.h" |
|
17 |
+#include "Resizer.h" |
|
18 |
+#include "SettingFile.h" |
|
19 |
+#include "StreamMgr.h" |
|
20 |
+#include "StreamRecv.h" |
|
21 |
+ |
|
22 |
+namespace Blinker { |
|
23 |
+ |
|
24 |
+/** |
|
25 |
+ * @brief constructor |
|
26 |
+ * @param[in] callMgr callback manager |
|
27 |
+ * @param[in] streamMgr stream manager |
|
28 |
+ * @param[in] dirBase base directory |
|
29 |
+ */ |
|
30 |
+Resizer::Resizer(CallMgr &callMgr, StreamMgr &streamMgr, |
|
31 |
+ const Directory &dirBase): |
|
32 |
+ Module(callMgr, streamMgr, dirBase), |
|
33 |
+ m_fileInStream(dirBase.getFile("instream")), |
|
34 |
+ m_fileFormat(dirBase.getFile("format")), |
|
35 |
+ m_fileOutStream(dirBase.getFile("outstream")), |
|
36 |
+ m_pInStream(NULL), |
|
37 |
+ m_haveFormat(false), |
|
38 |
+ m_pOutStream(NULL) |
|
39 |
+{ |
|
40 |
+ // set up |
|
41 |
+ getInStream(); |
|
42 |
+ getFormat(); |
|
43 |
+ getOutStream(); |
|
44 |
+} |
|
45 |
+ |
|
46 |
+/// virtual destructor |
|
47 |
+Resizer::~Resizer() |
|
48 |
+{ |
|
49 |
+ // clean up |
|
50 |
+ releaseInStream(); |
|
51 |
+ releaseOutStream(); |
|
52 |
+} |
|
53 |
+ |
|
54 |
+/// check for update of configuration |
|
55 |
+void Resizer::updateConfig() |
|
56 |
+{ |
|
57 |
+ // stream name or format file was modified -> re-get stream or format |
|
58 |
+ if (m_fileInStream.checkModified()) { |
|
59 |
+ releaseInStream(); |
|
60 |
+ getInStream(); |
|
61 |
+ } |
|
62 |
+ if (m_fileFormat.checkModified()) { |
|
63 |
+ getFormat(); |
|
64 |
+ } |
|
65 |
+ if (m_fileOutStream.checkModified()) { |
|
66 |
+ releaseOutStream(); |
|
67 |
+ getOutStream(); |
|
68 |
+ } |
|
69 |
+} |
|
70 |
+ |
|
71 |
+/** |
|
72 |
+ * @brief set current frame |
|
73 |
+ * @param[in] stream stream name |
|
74 |
+ * @param[in] pFrame current frame |
|
75 |
+ */ |
|
76 |
+void Resizer::setFrame(const std::string &stream, stBlinkenFrame *pFrame) |
|
77 |
+{ |
|
78 |
+ procFrame(pFrame); |
|
79 |
+ (void)stream; // unused |
|
80 |
+} |
|
81 |
+ |
|
82 |
+/** |
|
83 |
+ * @brief set current frame to none |
|
84 |
+ * @param[in] stream stream name |
|
85 |
+ */ |
|
86 |
+void Resizer::setNoFrame(const std::string &stream) |
|
87 |
+{ |
|
88 |
+ procNoFrame(); |
|
89 |
+ (void)stream; // unused |
|
90 |
+} |
|
91 |
+ |
|
92 |
+/// get input stream and attach to it |
|
93 |
+void Resizer::getInStream() |
|
94 |
+{ |
|
95 |
+ // get input stream |
|
96 |
+ m_fileInStream.getStr(m_nameInStream); |
|
97 |
+ m_pInStream = &m_streamMgr.refStream(m_nameInStream); |
|
98 |
+ |
|
99 |
+ // attach to input stream |
|
100 |
+ if (m_pInStream) |
|
101 |
+ m_pInStream->attach(this); |
|
102 |
+} |
|
103 |
+ |
|
104 |
+/// detach from input stream and release it |
|
105 |
+void Resizer::releaseInStream() |
|
106 |
+{ |
|
107 |
+ // detach from input stream |
|
108 |
+ if (m_pInStream) |
|
109 |
+ m_pInStream->detach(this); |
|
110 |
+ |
|
111 |
+ // unreference stream |
|
112 |
+ m_pInStream = NULL; |
|
113 |
+ m_streamMgr.unrefStream(m_nameInStream); |
|
114 |
+} |
|
115 |
+ |
|
116 |
+/// (re-)get format to resize to |
|
117 |
+void Resizer::getFormat() |
|
118 |
+{ |
|
119 |
+ std::string strFormat; |
|
120 |
+ |
|
121 |
+ // read format from format file |
|
122 |
+ m_haveFormat = m_fileFormat.getStr(strFormat) && m_format.fromStr(strFormat); |
|
123 |
+ |
|
124 |
+ // send current frame to output stream |
|
125 |
+ sendFrame(); |
|
126 |
+} |
|
127 |
+ |
|
128 |
+/// get output stream |
|
129 |
+void Resizer::getOutStream() |
|
130 |
+{ |
|
131 |
+ // get output stream |
|
132 |
+ m_fileOutStream.getStr(m_nameOutStream); |
|
133 |
+ m_pOutStream = &m_streamMgr.refStream(m_nameOutStream); |
|
134 |
+ |
|
135 |
+ // send current frame to output stream |
|
136 |
+ sendFrame(); |
|
137 |
+} |
|
138 |
+ |
|
139 |
+/// release output stream |
|
140 |
+void Resizer::releaseOutStream() |
|
141 |
+{ |
|
142 |
+ // send no frame information |
|
143 |
+ if (m_pOutStream) |
|
144 |
+ m_pOutStream->setNoFrame(); |
|
145 |
+ |
|
146 |
+ // unreference stream |
|
147 |
+ m_pOutStream = NULL; |
|
148 |
+ m_streamMgr.unrefStream(m_nameOutStream); |
|
149 |
+} |
|
150 |
+ |
|
151 |
+/// send current frame to output stream |
|
152 |
+void Resizer::sendFrame() |
|
153 |
+{ |
|
154 |
+ stBlinkenFrame *pFrame; |
|
155 |
+ |
|
156 |
+ // get current frame from input stream and process it |
|
157 |
+ if (m_pInStream && m_pInStream->getCurFrame(pFrame)) |
|
158 |
+ procFrame(pFrame); |
|
159 |
+ else |
|
160 |
+ procNoFrame(); |
|
161 |
+} |
|
162 |
+ |
|
163 |
+/** |
|
164 |
+ * @brief process frame |
|
165 |
+ * @param[in] pFrame frame to process |
|
166 |
+ */ |
|
167 |
+void Resizer::procFrame(stBlinkenFrame *pFrame) |
|
168 |
+{ |
|
169 |
+ stBlinkenFrame *pProcFrame; |
|
170 |
+ |
|
171 |
+ // no output stream -> nothing to do |
|
172 |
+ if (!m_pOutStream) |
|
173 |
+ return; |
|
174 |
+ |
|
175 |
+ // no format -> pass "no frame" |
|
176 |
+ if (!m_haveFormat) { |
|
177 |
+ m_pOutStream->setNoFrame(); |
|
178 |
+ return; |
|
179 |
+ } |
|
180 |
+ |
|
181 |
+ // format matches -> pass frame directly |
|
182 |
+ if ((unsigned int)BlinkenFrameGetWidth(pFrame) == m_format.m_width && |
|
183 |
+ (unsigned int)BlinkenFrameGetHeight(pFrame) == m_format.m_height && |
|
184 |
+ (unsigned int)BlinkenFrameGetChannels(pFrame) == m_format.m_channels && |
|
185 |
+ (unsigned int)BlinkenFrameGetMaxval(pFrame) == m_format.m_maxval) { |
|
186 |
+ m_pOutStream->setFrame(pFrame); |
|
187 |
+ return; |
|
188 |
+ } |
|
189 |
+ |
|
190 |
+ // clone frame |
|
191 |
+ pProcFrame = BlinkenFrameClone(pFrame); |
|
192 |
+ if (!pProcFrame){ |
|
193 |
+ m_pOutStream->setNoFrame(); |
|
194 |
+ return; |
|
195 |
+ } |
|
196 |
+ |
|
197 |
+ // resize frame |
|
198 |
+ BlinkenFrameResize(pProcFrame, m_format.m_height, m_format.m_width, |
|
199 |
+ m_format.m_channels, m_format.m_maxval); |
|
200 |
+ |
|
201 |
+ // pass process frame to output stream |
|
202 |
+ m_pOutStream->setFrame(pProcFrame); |
|
203 |
+ |
|
204 |
+ // free cloned frame |
|
205 |
+ BlinkenFrameFree(pProcFrame); |
|
206 |
+} |
|
207 |
+ |
|
208 |
+/// process "no frame" |
|
209 |
+void Resizer::procNoFrame() |
|
210 |
+{ |
|
211 |
+ // pass "no frame" to output stream |
|
212 |
+ if (m_pOutStream) |
|
213 |
+ m_pOutStream->setNoFrame(); |
|
214 |
+} |
|
215 |
+ |
|
216 |
+} // namespace Blinker |
|
217 |
+ |
... | ... |
@@ -0,0 +1,106 @@ |
1 |
+/* Blinker |
|
2 |
+ Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org> |
|
3 |
+ Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html |
|
4 |
+ a blinkenarea.org project */ |
|
5 |
+ |
|
6 |
+#ifndef RESIZER_H |
|
7 |
+#define RESIZER_H |
|
8 |
+ |
|
9 |
+#include <string> |
|
10 |
+ |
|
11 |
+#include <BlinkenLib/BlinkenFrame.h> |
|
12 |
+ |
|
13 |
+#include "CallMgr.h" |
|
14 |
+#include "Directory.h" |
|
15 |
+#include "File.h" |
|
16 |
+#include "Format.h" |
|
17 |
+#include "Module.h" |
|
18 |
+#include "SettingFile.h" |
|
19 |
+#include "StreamMgr.h" |
|
20 |
+#include "StreamRecv.h" |
|
21 |
+ |
|
22 |
+namespace Blinker { |
|
23 |
+ |
|
24 |
+/// a stream resizer |
|
25 |
+class Resizer: public Module, public StreamRecv |
|
26 |
+{ |
|
27 |
+public: |
|
28 |
+ /** |
|
29 |
+ * @brief constructor |
|
30 |
+ * @param[in] callMgr callback manager |
|
31 |
+ * @param[in] streamMgr stream manager |
|
32 |
+ * @param[in] dirBase base directory |
|
33 |
+ */ |
|
34 |
+ Resizer(CallMgr &callMgr, StreamMgr &streamMgr, const Directory &dirBase); |
|
35 |
+ |
|
36 |
+ /// virtual destructor |
|
37 |
+ virtual ~Resizer(); |
|
38 |
+ |
|
39 |
+private: |
|
40 |
+ /// copy constructor disabled |
|
41 |
+ Resizer(const Resizer &that); |
|
42 |
+ |
|
43 |
+ /// assignment operator disabled |
|
44 |
+ const Resizer & operator=(const Resizer &that); |
|
45 |
+ |
|
46 |
+public: |
|
47 |
+ /// check for update of configuration |
|
48 |
+ virtual void updateConfig(); |
|
49 |
+ |
|
50 |
+ /** |
|
51 |
+ * @brief set current frame |
|
52 |
+ * @param[in] stream stream name |
|
53 |
+ * @param[in] pFrame current frame |
|
54 |
+ */ |
|
55 |
+ virtual void setFrame(const std::string &stream, stBlinkenFrame *pFrame); |
|
56 |
+ |
|
57 |
+ /** |
|
58 |
+ * @brief set current frame to none |
|
59 |
+ * @param[in] stream stream name |
|
60 |
+ */ |
|
61 |
+ virtual void setNoFrame(const std::string &stream); |
|
62 |
+ |
|
63 |
+protected: |
|
64 |
+ /// get input stream and attach to it |
|
65 |
+ void getInStream(); |
|
66 |
+ |
|
67 |
+ /// detach from input stream and release it |
|
68 |
+ void releaseInStream(); |
|
69 |
+ |
|
70 |
+ /// (re-)get format to resize to |
|
71 |
+ void getFormat(); |
|
72 |
+ |
|
73 |
+ /// get output stream |
|
74 |
+ void getOutStream(); |
|
75 |
+ |
|
76 |
+ /// release output stream |
|
77 |
+ void releaseOutStream(); |
|
78 |
+ |
|
79 |
+ /// send current frame to output stream |
|
80 |
+ void sendFrame(); |
|
81 |
+ |
|
82 |
+ /** |
|
83 |
+ * @brief process frame |
|
84 |
+ * @param[in] pFrame frame to process |
|
85 |
+ */ |
|
86 |
+ void procFrame(stBlinkenFrame *pFrame); |
|
87 |
+ |
|
88 |
+ /// process "no frame" |
|
89 |
+ void procNoFrame(); |
|
90 |
+ |
|
91 |
+protected: |
|
92 |
+ SettingFile m_fileInStream; ///< input stream name file |
|
93 |
+ SettingFile m_fileFormat; ///< format file |
|
94 |
+ SettingFile m_fileOutStream; ///< output stream name file |
|
95 |
+ std::string m_nameInStream; ///< name of input stream |
|
96 |
+ Stream *m_pInStream; ///< input stream |
|
97 |
+ bool m_haveFormat; ///< if the format to resize to is available |
|
98 |
+ Format m_format; ///< format to resize to |
|
99 |
+ std::string m_nameOutStream; ///< name of output stream |
|
100 |
+ Stream *m_pOutStream; ///< output stream |
|
101 |
+}; // class Resizer |
|
102 |
+ |
|
103 |
+} // namespace Blinker |
|
104 |
+ |
|
105 |
+#endif // #ifndef RESIZER_H |
|
106 |
+ |
... | ... |
@@ -12,6 +12,7 @@ |
12 | 12 |
#include "ModuleMgr.h" |
13 | 13 |
#include "Player.h" |
14 | 14 |
#include "Printer.h" |
15 |
+#include "Resizer.h" |
|
15 | 16 |
#include "StreamMgr.h" |
16 | 17 |
#include "Udp4Sender.h" |
17 | 18 |
|
... | ... |
@@ -30,6 +31,8 @@ void run(const std::string &dirConfig) |
30 | 31 |
dirCfg.getSubdir("players")); |
31 | 32 |
ModuleMgr<Printer> printerMgr(callMgr, streamMgr, |
32 | 33 |
dirCfg.getSubdir("printers")); |
34 |
+ ModuleMgr<Resizer> resizerMgr(callMgr, streamMgr, |
|
35 |
+ dirCfg.getSubdir("resizers")); |
|
33 | 36 |
ModuleMgr<Udp4Sender> udp4Mgr(callMgr, streamMgr, |
34 | 37 |
dirCfg.getSubdir("udp4senders")); |
35 | 38 |
|
36 | 39 |