69ac12fcb8ee5ac55fadc04d3a96a3a7c2d0038a
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

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 "Directory.h"
13) #include "File.h"
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

14) #include "InStreamFile.h"
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

15) #include "Mgrs.h"
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

16) #include "Module.h"
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

17) #include "OutStreamFile.h"
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

18) #include "Scaler.h"
19) #include "Size.h"
20) #include "StreamRecv.h"
21) 
22) namespace Blinker {
23) 
24) /**
25)  * @brief constructor
Stefan Schuermans make modules know their name

Stefan Schuermans authored 12 years ago

26)  * @param[in] name module name
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

27)  * @param[in] mgrs managers
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

28)  * @param[in] dirBase base directory
29)  */
Stefan Schuermans make modules know their name

Stefan Schuermans authored 12 years ago

30) Scaler::Scaler(const std::string &name, Mgrs &mgrs,
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

31)                  const Directory &dirBase):
Stefan Schuermans make modules know their name

Stefan Schuermans authored 12 years ago

32)   Module(name, mgrs, dirBase),
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

33)   m_fileInStream(dirBase.getFile("instream"), mgrs.m_streamMgr),
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

34)   m_fileSize(dirBase.getFile("size")),
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

35)   m_fileOutStream(dirBase.getFile("outstream"), mgrs.m_streamMgr)
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

36) {
37)   // set up
38)   getSize();
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

39)   m_fileInStream.setStreamRecv(this);
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

40) }
41) 
42) /// virtual destructor
43) Scaler::~Scaler()
44) {
45)   // clean up
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

46)   m_fileInStream.setStreamRecv(NULL);
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

47) }
48) 
49) /// check for update of configuration
50) void Scaler::updateConfig()
51) {
52)   // stream name or size file was modified -> re-get stream or size
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

53)   if (m_fileInStream.checkModified())
54)     m_fileInStream.update();
55)   if (m_fileSize.checkModified())
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

56)     getSize();
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

57)   if (m_fileOutStream.checkModified())
58)     m_fileOutStream.update();
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

59) }
60) 
61) /**
62)  * @brief set current frame
63)  * @param[in] stream stream name
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

64)  * @param[in] pFrame current frame (NULL for none)
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

65)  */
66) void Scaler::setFrame(const std::string &stream, stBlinkenFrame *pFrame)
67) {
68)   procFrame(pFrame);
69)   (void)stream; // unused
70) }
71) 
72) /// (re-)get size to scale to
73) void Scaler::getSize()
74) {
75)   // read size from size file
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

76)   m_fileSize.update();
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

77) 
78)   // send current frame to output stream
79)   sendFrame();
80) }
81) 
82) /// send current frame to output stream
83) void Scaler::sendFrame()
84) {
85)   // get current frame from input stream and process it
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

86)   procFrame(m_fileInStream.getCurFrame());
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

87) }
88) 
89) /**
90)  * @brief process frame
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

91)  * @param[in] pFrame frame to process (NULL for none)
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

92)  */
93) void Scaler::procFrame(stBlinkenFrame *pFrame)
94) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

95)   int width, height;
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

96)   stBlinkenFrame *pProcFrame;
97) 
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

98)   // no frame or no size -> pass "no frame"
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

99)   if (!pFrame || !m_fileSize.m_valid) {
100)     m_fileOutStream.setFrame(NULL);
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

101)     return;
102)   }
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

103)   width = m_fileSize.m_obj.m_width;
104)   height = m_fileSize.m_obj.m_height;
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

105) 
106)   // size matches -> pass frame directly
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

107)   if (BlinkenFrameGetWidth(pFrame) == width &&
108)       BlinkenFrameGetHeight(pFrame) == height ) {
109)     m_fileOutStream.setFrame(pFrame);
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

110)     return;
111)   }
112) 
113)   // clone frame
114)   pProcFrame = BlinkenFrameClone(pFrame);
Stefan Schuermans merged frame processing wit...

Stefan Schuermans authored 12 years ago

115)   if (!pProcFrame) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

116)     m_fileOutStream.setFrame(NULL);
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

117)     return;
118)   }
119) 
120)   // scale frame
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

121)   BlinkenFrameScale(pProcFrame, height, width);
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

122) 
123)   // pass process frame to output stream
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

124)   m_fileOutStream.setFrame(pProcFrame);