99ee20ed7723d5787a5be3a61e9aa177f611b040
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 "CallMgr.h"
13) #include "Directory.h"
14) #include "File.h"
Stefan Schuermans implemented halting player...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

16) #include "ListTracker.h"
17) #include "ListTracker_impl.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 first version, plays videos...

Stefan Schuermans authored 13 years ago

22) #include "StreamMgr.h"
Stefan Schuermans implemented halting player...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

24) #include "Time.h"
25) #include "TimeCallee.h"
26) 
27) namespace Blinker {
28) 
29) /**
30)  * @brief constructor
31)  * @param[in] callMgr callback manager
32)  * @param[in] streamMgr stream manager
33)  * @param[in] dirBase base directory
34)  */
35) Player::Player(CallMgr &callMgr, StreamMgr &streamMgr,
36)                const Directory &dirBase):
Stefan Schuermans implemented base class for...

Stefan Schuermans authored 13 years ago

37)   Module(callMgr, streamMgr, dirBase),
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

38)   m_fileOutStream(dirBase.getFile("outstream"), streamMgr),
Stefan Schuermans implemented halting player...

Stefan Schuermans authored 12 years ago

39)   m_fileHaltStream(dirBase.getFile("haltstream"), streamMgr),
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

56)   // cancel time callback request
57)   m_callMgr.cancelTimeCall(this);
58) 
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

82) /**
83)  * @brief set current frame
84)  * @param[in] stream stream name
85)  * @param[in] pFrame current frame (NULL for none)
86)  */
87) void Player::setFrame(const std::string &stream, stBlinkenFrame *pFrame)
88) {
89)   // this is coming from the halt stream, which will halt the player
90)   // whenever a frame is available on this halt stream
91) 
92)   // halt stream came to life -> halt player
93)   if (pFrame && !m_halted) {
94)     m_halted = true;
95)     if (m_curValid) {
96)       // store remaining frame time
97)       m_remainTime = m_nextTime - Time::now();
98)       if (m_remainTime < Time::zero)
99)         m_remainTime = Time::zero;
100)     }
101)     // cancel time call
102)     m_callMgr.cancelTimeCall(this);
103)   }
104) 
105)   // halt stream ended -> continue playing
106)   else if (!pFrame && m_halted) {
107)     m_halted = false;
108)     if (m_curValid) {
109)       // determine time for next frame
110)       m_nextTime = Time::now() + m_remainTime;
111)       // schedule time call
112)       m_callMgr.requestTimeCall(this, m_nextTime);
113)     }
114)   }
115) 
116)   (void)stream; // unused
117) }
118) 
Stefan Schuermans fixed comment typo

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

126)   // leave if time is not yet ready to next frame
127)   if (Time::now() < m_nextTime) {
128)     // request call at time for next frame
129)     m_callMgr.requestTimeCall(this, m_nextTime);
130)     return;
131)   }
132) 
133)   // go to next frame
134)   ++m_curFrame;
135) 
136)   // process new current frame
137)   procFrame();
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

178)     if (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)
197)       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 implemented specialized set...

Stefan Schuermans authored 12 years ago

204)   // frame avalable -> send it
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);