5b311bf422079c7c413879108e167ab19e66c5f6
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 base class for...

Stefan Schuermans authored 13 years ago

15) #include "Module.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 specialized set...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

20) #include "PlayerMovie.h"
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

36)   m_fileOutStream(dirBase.getFile("outstream"), streamMgr),
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

39)   m_curEntry(m_playlistTracker.m_list.begin()),
40)   m_curFrame(0),
41)   m_curChange(false)
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

42) {
43)   // load playlist
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

44)   m_playlistTracker.init();
45)   checkCurChanged();
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

46) }
47) 
48) /// virtual destructor
49) Player::~Player()
50) {
Stefan Schuermans cancel time callback reques...

Stefan Schuermans authored 13 years ago

51)   // cancel time callback request
52)   m_callMgr.cancelTimeCall(this);
53) 
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

55)   m_playlistTracker.clear();
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

56) }
57) 
Stefan Schuermans implemented base class for...

Stefan Schuermans authored 13 years ago

58) /// check for update of configuration
59) void Player::updateConfig()
60) {
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

63)     m_fileOutStream.update();
64)     sendFrame();
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

65)   }
66) 
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

67)   // playlist update
68)   m_playlistTracker.updateConfig();
69)   checkCurChanged();
Stefan Schuermans implemented base class for...

Stefan Schuermans authored 13 years ago

70) }
71) 
Stefan Schuermans fixed comment typo

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

73) void Player::timeCall()
74) {
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

75)   // leave if time is not yet ready to next frame
76)   if (Time::now() < m_nextTime) {
77)     // request call at time for next frame
78)     m_callMgr.requestTimeCall(this, m_nextTime);
79)     return;
80)   }
81) 
82)   // go to next frame
83)   ++m_curFrame;
84) 
85)   // process new current frame
86)   procFrame();
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

87) }
88) 
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

92)   // current movie changed
93)   if (m_curChange) {
94)     m_curChange = false;
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

95) 
96)     // go to begin of new current movie and start playing now
97)     m_curFrame = 0;
98)     m_nextTime = Time::now();
99)     procFrame();
100) 
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

102) }
103) 
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

104) /// process current frame
105) void Player::procFrame()
106) {
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

115)       m_curFrame = 0;
116)       // detect empty playlist or playlist with only empty movies
117)       if (wrapped) {
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

118)         m_curValid = false;
119)         break;
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

120)       }
121)       wrapped = true;
122)     }
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

123)     if (!m_curValid)
124)       break;
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

127)       break;
128)     // movie finished -> next movie
129)     ++m_curEntry;
130)     m_curFrame = 0;
131)   }
132) 
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

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

Stefan Schuermans authored 13 years ago

135) 
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

136)   // if a frame is there
137)   if (m_curValid) {
138)     // calculate time for next frame
139)     stBlinkenFrame *pFrame =
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

140)       BlinkenMovieGetFrame(m_curEntry->m_pObj->m_pMovie, m_curFrame);
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

141)     Time duration;
142)     duration.fromMs(BlinkenFrameGetDuration(pFrame));
143)     m_nextTime += duration;
144)     // request call at time for next frame
145)     m_callMgr.requestTimeCall(this, m_nextTime);
146)   }
147) }
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

148) 
Stefan Schuermans implemented automatic check...

Stefan Schuermans authored 13 years ago

149) /// send current frame to output stream
150) void Player::sendFrame()
151) {
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

152)   // frame avalable -> send it
153)   if (m_curValid) {
154)     stBlinkenFrame *pFrame =
Stefan Schuermans converted player module to...

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 12 years ago

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

Stefan Schuermans authored 13 years ago

157)   }
Stefan Schuermans implemented specialized set...

Stefan Schuermans authored 12 years ago

158)   // no frame available -> send this information
159)   else
160)     m_fileOutStream.setFrame(NULL);