baf52dacd8003c3ac6d43bfef7073aae9e871e3b
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 put all managers in one str...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

27)  * @param[in] dirBase base directory
28)  */
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

29) Scaler::Scaler(Mgrs &mgrs,
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

30)                  const Directory &dirBase):
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

123)   m_fileOutStream.setFrame(pProcFrame);