1a209d467a4bce9c08e380b6847f228d624aa951
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

1) /* Blinker
Stefan Schuermans update copyright years

Stefan Schuermans authored 10 years ago

2)    Copyright 2011-2014 Stefan Schuermans <stefan@blinkenarea.org>
Stefan Schuermans implemented scaler module

Stefan Schuermans authored 12 years ago

3)    Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
4)    a blinkenarea.org project */
5) 
6) #include <stdlib.h>
7) #include <string>
8) 
9) #include <BlinkenLib/BlinkenFrame.h>
10) 
11) #include "Directory.h"
12) #include "File.h"
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

25)  * @param[in] name module name
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 make modules know their name

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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) 
Stefan Schuermans implement frame rate limiter

Stefan Schuermans authored 10 years ago

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

Stefan Schuermans authored 12 years ago

123)   m_fileOutStream.setFrame(pProcFrame);