b6b2996b76e1b0f0e403b4be40430a445bc0873c
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 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 first version, plays videos...

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

14) #include "InStreamFile.h"
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

15) #include "ListTracker.h"
16) #include "ListTracker_impl.h"
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

17) #include "Mgrs.h"
Stefan Schuermans implemented halting player...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

19) #include "OutStreamFile.h"
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

20) #include "Player.h"
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

21) #include "PlayerMovie.h"
Stefan Schuermans implemented halting player...

Stefan Schuermans authored 12 years ago

22) #include "StreamRecv.h"
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

23) #include "Time.h"
24) #include "TimeCallee.h"
25) 
26) namespace Blinker {
27) 
28) /**
29)  * @brief constructor
Stefan Schuermans make modules know their name

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

31)  * @param[in] mgrs managers
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

34) Player::Player(const std::string &name, Mgrs &mgrs,
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

37)   m_fileOutStream(dirBase.getFile("outstream"), mgrs.m_streamMgr),
38)   m_fileHaltStream(dirBase.getFile("haltstream"), mgrs.m_streamMgr),
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

39)   m_playlistTracker(*this, dirBase.getSubdir("playlist")),
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

40)   m_curValid(false),
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

41)   m_curEntry(m_playlistTracker.m_list.begin()),
42)   m_curFrame(0),
Stefan Schuermans implemented halting player...

Stefan Schuermans authored 12 years ago

43)   m_curChange(false),
44)   m_halted(false)
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

45) {
46)   // load playlist
Stefan Schuermans implemented halting player...

Stefan Schuermans authored 12 years ago

47)   m_fileHaltStream.setStreamRecv(this);
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

48)   m_playlistTracker.init();
49)   checkCurChanged();
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

50) }
51) 
52) /// virtual destructor
53) Player::~Player()
54) {
Stefan Schuermans cancel time callback reques...

Stefan Schuermans authored 13 years ago

55)   // cancel time callback request
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

56)   m_mgrs.m_callMgr.cancelTimeCall(this);
Stefan Schuermans cancel time callback reques...

Stefan Schuermans authored 13 years ago

57) 
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

58)   // free all movies
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

59)   m_playlistTracker.clear();
Stefan Schuermans implemented halting player...

Stefan Schuermans authored 12 years ago

60)   m_fileHaltStream.setStreamRecv(NULL);
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

61) }
62) 
Stefan Schuermans implemented base class for...

Stefan Schuermans authored 13 years ago

63) /// check for update of configuration
64) void Player::updateConfig()
65) {
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

66)   // output stream name file was modified -> re-get output stream
67)   if (m_fileOutStream.checkModified()) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

68)     m_fileOutStream.update();
69)     sendFrame();
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

70)   }
71) 
Stefan Schuermans implemented halting player...

Stefan Schuermans authored 12 years ago

72)   // halt stream name file was modified -> re-get halt stream
73)   if (m_fileHaltStream.checkModified())
74)     m_fileHaltStream.update();
75) 
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

76)   // playlist update
77)   m_playlistTracker.updateConfig();
78)   checkCurChanged();
Stefan Schuermans implemented base class for...

Stefan Schuermans authored 13 years ago

79) }
80) 
Stefan Schuermans implemented halting player...

Stefan Schuermans authored 12 years ago

81) /**
82)  * @brief set current frame
83)  * @param[in] stream stream name
84)  * @param[in] pFrame current frame (NULL for none)
85)  */
86) void Player::setFrame(const std::string &stream, stBlinkenFrame *pFrame)
87) {
88)   // this is coming from the halt stream, which will halt the player
89)   // whenever a frame is available on this halt stream
90) 
91)   // halt stream came to life -> halt player
92)   if (pFrame && !m_halted) {
93)     m_halted = true;
94)     if (m_curValid) {
95)       // store remaining frame time
96)       m_remainTime = m_nextTime - Time::now();
97)       if (m_remainTime < Time::zero)
98)         m_remainTime = Time::zero;
99)     }
100)     // cancel time call
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

101)     m_mgrs.m_callMgr.cancelTimeCall(this);
Stefan Schuermans implemented halting player...

Stefan Schuermans authored 12 years ago

102)   }
103) 
104)   // halt stream ended -> continue playing
105)   else if (!pFrame && m_halted) {
106)     m_halted = false;
107)     if (m_curValid) {
108)       // determine time for next frame
109)       m_nextTime = Time::now() + m_remainTime;
110)       // schedule time call
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

111)       m_mgrs.m_callMgr.requestTimeCall(this, m_nextTime);
Stefan Schuermans implemented halting player...

Stefan Schuermans authored 12 years ago

112)     }
113)   }
114) 
115)   (void)stream; // unused
116) }
117) 
Stefan Schuermans fixed comment typo

Stefan Schuermans authored 12 years ago

118) /// callback when requested time reached
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

119) void Player::timeCall()
120) {
Stefan Schuermans implemented halting player...

Stefan Schuermans authored 12 years ago

121)   // leave if halted
122)   if (m_halted)
123)     return;
124) 
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

125)   // leave if time is not yet ready to next frame
126)   if (Time::now() < m_nextTime) {
127)     // request call at time for next frame
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

128)     m_mgrs.m_callMgr.requestTimeCall(this, m_nextTime);
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

129)     return;
130)   }
131) 
132)   // go to next frame
133)   ++m_curFrame;
134) 
135)   // process new current frame
136)   procFrame();
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

137) }
138) 
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

139) /// check if current movie changed and react
140) void Player::checkCurChanged()
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

141) {
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

142)   // current movie changed
143)   if (m_curChange) {
144)     m_curChange = false;
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

145) 
146)     // go to begin of new current movie and start playing now
147)     m_curFrame = 0;
Stefan Schuermans implemented halting player...

Stefan Schuermans authored 12 years ago

148)     m_remainTime = Time::zero;
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

149)     m_nextTime = Time::now();
150)     procFrame();
151) 
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

152)   } // if (m_curChange)
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

153) }
154) 
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

155) /// process current frame
156) void Player::procFrame()
157) {
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

158)   // movie finished -> next movie
159)   //   use while loops to handle empty movies / empty playlist
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

160)   m_curValid = true;
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

161)   bool wrapped = false;
162)   while (true) {
163)     // playlist finished -> re-start from beginning
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

164)     while (m_curEntry == m_playlistTracker.m_list.end()) {
165)       m_curEntry = m_playlistTracker.m_list.begin();
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

166)       m_curFrame = 0;
167)       // detect empty playlist or playlist with only empty movies
168)       if (wrapped) {
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

169)         m_curValid = false;
170)         break;
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

171)       }
172)       wrapped = true;
173)     }
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

174)     if (!m_curValid)
175)       break;
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

176)     // movie not yet finished -> done
Stefan Schuermans fix bug in player module: c...

Stefan Schuermans authored 12 years ago

177)     if (m_curEntry->m_pObj->m_pMovie &&
178)         m_curFrame < BlinkenMovieGetFrameCnt(m_curEntry->m_pObj->m_pMovie))
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

179)       break;
180)     // movie finished -> next movie
181)     ++m_curEntry;
182)     m_curFrame = 0;
183)   }
184) 
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

185)   // send new frame to stream
186)   sendFrame();
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

187) 
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

188)   // if a frame is there
189)   if (m_curValid) {
Stefan Schuermans implemented halting player...

Stefan Schuermans authored 12 years ago

190)     // get frame time and calculate absolute time for next frame
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

191)     stBlinkenFrame *pFrame =
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

192)       BlinkenMovieGetFrame(m_curEntry->m_pObj->m_pMovie, m_curFrame);
Stefan Schuermans implemented halting player...

Stefan Schuermans authored 12 years ago

193)     m_remainTime.fromMs(BlinkenFrameGetDuration(pFrame));
194)     m_nextTime += m_remainTime;
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

195)     // request call at time for next frame
Stefan Schuermans implemented halting player...

Stefan Schuermans authored 12 years ago

196)     if (!m_halted)
Stefan Schuermans put all managers in one str...

Stefan Schuermans authored 12 years ago

197)       m_mgrs.m_callMgr.requestTimeCall(this, m_nextTime);
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

198)   }
199) }
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

200) 
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

201) /// send current frame to output stream
202) void Player::sendFrame()
203) {
Stefan Schuermans typo

Stefan Schuermans authored 12 years ago

204)   // frame available -> send it
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

205)   if (m_curValid) {
206)     stBlinkenFrame *pFrame =
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

207)       BlinkenMovieGetFrame(m_curEntry->m_pObj->m_pMovie, m_curFrame);
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

208)     m_fileOutStream.setFrame(pFrame);
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

209)   }
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

210)   // no frame available -> send this information
211)   else
212)     m_fileOutStream.setFrame(NULL);