Stefan Schuermans commited on 2011-11-19 22:04:34
Showing 8 changed files, with 366 additions and 0 deletions.
... | ... |
@@ -88,6 +88,7 @@ |
88 | 88 |
<li><a href="player.html">Player</a></li> |
89 | 89 |
<li><a href="printer.html">Printer</a></li> |
90 | 90 |
<li><a href="resizer.html">Resizer</a></li> |
91 |
+ <li><a href="scaler.html">Scaler</a></li> |
|
91 | 92 |
<li><a href="udp4sender.html">UDP4 Sender</a></li> |
92 | 93 |
</ul> |
93 | 94 |
</p> |
... | ... |
@@ -0,0 +1,39 @@ |
1 |
+<html> |
|
2 |
+ <head> |
|
3 |
+ <title>Blinker - Scaler</title> |
|
4 |
+ </head> |
|
5 |
+ <body> |
|
6 |
+ <h1>Blinker - Scaler</h1> |
|
7 |
+ <p> |
|
8 |
+ The scaler module scales the frames of a stream. |
|
9 |
+ It receives a single input stream and passes it on with a |
|
10 |
+ different size. |
|
11 |
+ </p> |
|
12 |
+ <h2>Configuration</h2> |
|
13 |
+ <p> |
|
14 |
+ The configuration of the scaler module with name <code>NAME</code> |
|
15 |
+ is located in the <code>scalers/NAME</code> subdirectory. |
|
16 |
+ </p> |
|
17 |
+ <h3>Input Stream</h3> |
|
18 |
+ <p> |
|
19 |
+ The file <code>instream</code> contains the name of the stream to |
|
20 |
+ receive. |
|
21 |
+ The frames received from this stream are scaled and passed to the |
|
22 |
+ output stream. |
|
23 |
+ </p> |
|
24 |
+ <h3>Size</h3> |
|
25 |
+ <p> |
|
26 |
+ The file <code>size</code> describes the size of the output stream, |
|
27 |
+ i.e. its dimensions. |
|
28 |
+ The file must contain a string |
|
29 |
+ <code><width>x<height></code>, |
|
30 |
+ e.g. <code>18x8</code> for 18 pixels width, 8 pixels height. |
|
31 |
+ </p> |
|
32 |
+ <h3>Output Stream</h3> |
|
33 |
+ <p> |
|
34 |
+ The file <code>outstream</code> contains the name of the stream to |
|
35 |
+ send the scaled frames to. |
|
36 |
+ </p> |
|
37 |
+ </body> |
|
38 |
+</html> |
|
39 |
+ |
... | ... |
@@ -0,0 +1 @@ |
1 |
+dash |
... | ... |
@@ -0,0 +1 @@ |
1 |
+bigdash |
... | ... |
@@ -0,0 +1 @@ |
1 |
+36x16 |
... | ... |
@@ -0,0 +1,214 @@ |
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 "Module.h" |
|
16 |
+#include "Scaler.h" |
|
17 |
+#include "SettingFile.h" |
|
18 |
+#include "Size.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 |
+Scaler::Scaler(CallMgr &callMgr, StreamMgr &streamMgr, |
|
31 |
+ const Directory &dirBase): |
|
32 |
+ Module(callMgr, streamMgr, dirBase), |
|
33 |
+ m_fileInStream(dirBase.getFile("instream")), |
|
34 |
+ m_fileSize(dirBase.getFile("size")), |
|
35 |
+ m_fileOutStream(dirBase.getFile("outstream")), |
|
36 |
+ m_pInStream(NULL), |
|
37 |
+ m_haveSize(false), |
|
38 |
+ m_pOutStream(NULL) |
|
39 |
+{ |
|
40 |
+ // set up |
|
41 |
+ getInStream(); |
|
42 |
+ getSize(); |
|
43 |
+ getOutStream(); |
|
44 |
+} |
|
45 |
+ |
|
46 |
+/// virtual destructor |
|
47 |
+Scaler::~Scaler() |
|
48 |
+{ |
|
49 |
+ // clean up |
|
50 |
+ releaseInStream(); |
|
51 |
+ releaseOutStream(); |
|
52 |
+} |
|
53 |
+ |
|
54 |
+/// check for update of configuration |
|
55 |
+void Scaler::updateConfig() |
|
56 |
+{ |
|
57 |
+ // stream name or size file was modified -> re-get stream or size |
|
58 |
+ if (m_fileInStream.checkModified()) { |
|
59 |
+ releaseInStream(); |
|
60 |
+ getInStream(); |
|
61 |
+ } |
|
62 |
+ if (m_fileSize.checkModified()) { |
|
63 |
+ getSize(); |
|
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 Scaler::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 Scaler::setNoFrame(const std::string &stream) |
|
87 |
+{ |
|
88 |
+ procNoFrame(); |
|
89 |
+ (void)stream; // unused |
|
90 |
+} |
|
91 |
+ |
|
92 |
+/// get input stream and attach to it |
|
93 |
+void Scaler::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 Scaler::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 size to scale to |
|
117 |
+void Scaler::getSize() |
|
118 |
+{ |
|
119 |
+ std::string strSize; |
|
120 |
+ |
|
121 |
+ // read size from size file |
|
122 |
+ m_haveSize = m_fileSize.getStr(strSize) && m_size.fromStr(strSize); |
|
123 |
+ |
|
124 |
+ // send current frame to output stream |
|
125 |
+ sendFrame(); |
|
126 |
+} |
|
127 |
+ |
|
128 |
+/// get output stream |
|
129 |
+void Scaler::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 Scaler::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 Scaler::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 Scaler::procFrame(stBlinkenFrame *pFrame) |
|
168 |
+{ |
|
169 |
+ stBlinkenFrame *pProcFrame; |
|
170 |
+ |
|
171 |
+ // no output stream -> nothing to do |
|
172 |
+ if (!m_pOutStream) |
|
173 |
+ return; |
|
174 |
+ |
|
175 |
+ // no size -> pass "no frame" |
|
176 |
+ if (!m_haveSize) { |
|
177 |
+ m_pOutStream->setNoFrame(); |
|
178 |
+ return; |
|
179 |
+ } |
|
180 |
+ |
|
181 |
+ // size matches -> pass frame directly |
|
182 |
+ if ((unsigned int)BlinkenFrameGetWidth(pFrame) == m_size.m_width && |
|
183 |
+ (unsigned int)BlinkenFrameGetHeight(pFrame) == m_size.m_height) { |
|
184 |
+ m_pOutStream->setFrame(pFrame); |
|
185 |
+ return; |
|
186 |
+ } |
|
187 |
+ |
|
188 |
+ // clone frame |
|
189 |
+ pProcFrame = BlinkenFrameClone(pFrame); |
|
190 |
+ if (!pProcFrame){ |
|
191 |
+ m_pOutStream->setNoFrame(); |
|
192 |
+ return; |
|
193 |
+ } |
|
194 |
+ |
|
195 |
+ // scale frame |
|
196 |
+ BlinkenFrameScale(pProcFrame, m_size.m_height, m_size.m_width); |
|
197 |
+ |
|
198 |
+ // pass process frame to output stream |
|
199 |
+ m_pOutStream->setFrame(pProcFrame); |
|
200 |
+ |
|
201 |
+ // free cloned frame |
|
202 |
+ BlinkenFrameFree(pProcFrame); |
|
203 |
+} |
|
204 |
+ |
|
205 |
+/// process "no frame" |
|
206 |
+void Scaler::procNoFrame() |
|
207 |
+{ |
|
208 |
+ // pass "no frame" to output stream |
|
209 |
+ if (m_pOutStream) |
|
210 |
+ m_pOutStream->setNoFrame(); |
|
211 |
+} |
|
212 |
+ |
|
213 |
+} // namespace Blinker |
|
214 |
+ |
... | ... |
@@ -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 SCALER_H |
|
7 |
+#define SCALER_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 "Module.h" |
|
17 |
+#include "SettingFile.h" |
|
18 |
+#include "Size.h" |
|
19 |
+#include "StreamMgr.h" |
|
20 |
+#include "StreamRecv.h" |
|
21 |
+ |
|
22 |
+namespace Blinker { |
|
23 |
+ |
|
24 |
+/// a stream scaler |
|
25 |
+class Scaler: 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 |
+ Scaler(CallMgr &callMgr, StreamMgr &streamMgr, const Directory &dirBase); |
|
35 |
+ |
|
36 |
+ /// virtual destructor |
|
37 |
+ virtual ~Scaler(); |
|
38 |
+ |
|
39 |
+private: |
|
40 |
+ /// copy constructor disabled |
|
41 |
+ Scaler(const Scaler &that); |
|
42 |
+ |
|
43 |
+ /// assignment operator disabled |
|
44 |
+ const Scaler & operator=(const Scaler &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 size to scale to |
|
71 |
+ void getSize(); |
|
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_fileSize; ///< size 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_haveSize; ///< if the size to scale to is available |
|
98 |
+ Size m_size; ///< size to scale to |
|
99 |
+ std::string m_nameOutStream; ///< name of output stream |
|
100 |
+ Stream *m_pOutStream; ///< output stream |
|
101 |
+}; // class Scaler |
|
102 |
+ |
|
103 |
+} // namespace Blinker |
|
104 |
+ |
|
105 |
+#endif // #ifndef SCALER_H |
|
106 |
+ |
... | ... |
@@ -13,6 +13,7 @@ |
13 | 13 |
#include "Player.h" |
14 | 14 |
#include "Printer.h" |
15 | 15 |
#include "Resizer.h" |
16 |
+#include "Scaler.h" |
|
16 | 17 |
#include "StreamMgr.h" |
17 | 18 |
#include "Udp4Sender.h" |
18 | 19 |
|
... | ... |
@@ -33,6 +34,8 @@ void run(const std::string &dirConfig) |
33 | 34 |
dirCfg.getSubdir("printers")); |
34 | 35 |
ModuleMgr<Resizer> resizerMgr(callMgr, streamMgr, |
35 | 36 |
dirCfg.getSubdir("resizers")); |
37 |
+ ModuleMgr<Scaler> scalersMgr(callMgr, streamMgr, |
|
38 |
+ dirCfg.getSubdir("scalers")); |
|
36 | 39 |
ModuleMgr<Udp4Sender> udp4Mgr(callMgr, streamMgr, |
37 | 40 |
dirCfg.getSubdir("udp4senders")); |
38 | 41 |
|
39 | 42 |