baf52dacd8003c3ac6d43bfef7073aae9e871e3b
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 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 <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 put all managers in one str...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

33) Player::Player(Mgrs &mgrs,
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

175)     // movie not yet finished -> done
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

185) 
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

196)   }
197) }
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

198) 
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

199) /// send current frame to output stream
200) void Player::sendFrame()
201) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

202)   // frame avalable -> send it
203)   if (m_curValid) {
204)     stBlinkenFrame *pFrame =
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

207)   }
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

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