[mmap] partial revert of 8cef8db4 to disable using mmap file reader
[videoplayer.git] / videoTransport.cpp
blob65d0b20adaded8c9e27faeddbd181826e478655e
1 /* ***** BEGIN LICENSE BLOCK *****
3 * The MIT License
5 * Copyright (c) 2008 BBC Research
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
25 * ***** END LICENSE BLOCK ***** */
27 #include "videoTransport.h"
29 #define DEBUG 0
31 VideoTransport::VideoTransport(FrameQueue *fq) :
32 frameQueue(fq)
34 lastTransportStatus = Fwd1;
35 looping=true;
36 transportFwd1();
39 void VideoTransport::setLooping(bool l)
41 looping = l;
44 int VideoTransport::getSpeed()
46 TransportControls ts = transportStatus;
48 int speed = 1;
50 switch (ts) {
52 case Fwd2:
53 case Rev2:
54 speed = 2;
55 break;
57 case Fwd5:
58 case Rev5:
59 speed = 5;
60 break;
62 case Fwd10:
63 case Rev10:
64 speed = 10;
65 break;
67 case Fwd20:
68 case Rev20:
69 speed = 20;
70 break;
72 case Fwd50:
73 case Rev50:
74 speed = 50;
75 break;
77 case Fwd100:
78 case Rev100:
79 speed = 100;
80 break;
82 default:
83 break;
86 return speed;
89 int VideoTransport::getDirection()
91 TransportControls ts = transportStatus;
93 //stopped or paused
94 int direction = 0;
96 //any forward speed
97 if (ts == Fwd1 || ts == Fwd2 || ts == Fwd5 || ts == Fwd10 || ts == Fwd20
98 || ts == Fwd50 || ts == Fwd100 || ts == JogFwd)
99 direction = 1;
101 //any reverse speed
102 if (ts == Rev1 || ts == Rev2 || ts == Rev5 || ts == Rev10 || ts == Rev20
103 || ts == Rev50 || ts == Rev100 || ts == JogRev)
104 direction = -1;
106 return direction;
109 VideoData *VideoTransport::getNextFrame()
111 int currentSpeed = getSpeed();
112 int currentDirection = getDirection();
114 TransportControls ts = transportStatus;
116 VideoData *frame = frameQueue->getNextFrame(currentSpeed, currentDirection);
118 //stop after each jog
119 if (ts == JogFwd || ts == JogRev)
120 transportStop();
122 //stop at first or last frame if there is no looping - will break at speeds other than 1x
123 if (frame) {
124 if ((looping == false) && (frame->isLastFrame == true
125 || frame->isFirstFrame == true)) {
126 transportStop();
127 emit(endOfFile());
131 //wake the reader thread - done each time as jogging will move the frame number
132 frameQueue->wake();
134 return frame;
137 void VideoTransport::transportFwd100()
139 transportController(Fwd100);
141 void VideoTransport::transportFwd50()
143 transportController(Fwd50);
145 void VideoTransport::transportFwd20()
147 transportController(Fwd20);
149 void VideoTransport::transportFwd10()
151 transportController(Fwd10);
153 void VideoTransport::transportFwd5()
155 transportController(Fwd5);
157 void VideoTransport::transportFwd2()
159 transportController(Fwd2);
161 void VideoTransport::transportFwd1()
163 transportController(Fwd1);
165 void VideoTransport::transportStop()
167 transportController(Stop);
169 void VideoTransport::transportRev1()
171 transportController(Rev1);
173 void VideoTransport::transportRev2()
175 transportController(Rev2);
177 void VideoTransport::transportRev5()
179 transportController(Rev5);
181 void VideoTransport::transportRev10()
183 transportController(Rev10);
185 void VideoTransport::transportRev20()
187 transportController(Rev20);
189 void VideoTransport::transportRev50()
191 transportController(Rev50);
193 void VideoTransport::transportRev100()
195 transportController(Rev100);
197 void VideoTransport::transportJogFwd()
199 transportController(JogFwd);
201 void VideoTransport::transportJogRev()
203 transportController(JogRev);
205 void VideoTransport::transportPlayPause()
207 transportController(PlayPause);
209 void VideoTransport::transportPause()
211 transportController(Pause);
214 void VideoTransport::transportController(TransportControls in)
216 TransportControls newStatus = Unknown;
217 TransportControls currentStatus;
219 currentStatus = transportStatus;
221 switch (in) {
222 case Stop:
223 newStatus = Stop;
224 lastTransportStatus = Fwd1; //after 'Stop', unpausing makes us play forwards
225 break;
227 case JogFwd:
228 if (currentStatus == Stop || currentStatus == Pause) {
229 newStatus = JogFwd; //do jog forward
231 break;
233 case JogRev:
234 if (currentStatus == Stop || currentStatus == Pause) {
235 newStatus = JogRev; //do jog backward
237 break;
239 case Pause:
240 //when not stopped or paused we can pause, remebering what were doing
241 if (currentStatus != Stop || currentStatus == Pause) {
242 lastTransportStatus = currentStatus;
243 newStatus = Pause;
245 break;
247 case PlayPause:
248 //PlayPause toggles between stop and playing, and paused and playing. It
249 //remembers the direction and speed were going
250 if (currentStatus == Stop || currentStatus == Pause) {
252 if (lastTransportStatus == Stop)
253 newStatus = Fwd1;
254 else
255 newStatus = lastTransportStatus;
258 else {
259 lastTransportStatus = currentStatus;
260 newStatus = Pause;
262 break;
264 //we can change from any state to a 'shuttle' or play
265 case Fwd100:
266 case Rev100:
267 newStatus = in;
268 break;
270 case Fwd50:
271 case Rev50:
272 newStatus = in;
273 break;
275 case Fwd20:
276 case Rev20:
277 newStatus = in;
278 break;
280 case Fwd10:
281 case Rev10:
282 newStatus = in;
283 break;
285 case Fwd5:
286 case Rev5:
287 newStatus = in;
288 break;
290 case Fwd2:
291 case Rev2:
292 newStatus = in;
293 break;
295 case Fwd1:
296 case Rev1:
297 newStatus = in;
298 break;
300 default:
301 //oh-no!
302 break;
305 //if we have determined a new transport status, set it
306 if (newStatus != Unknown) {
307 transportStatus = newStatus;
308 if (DEBUG)
309 printf("Changed transport state to %d\n", (int)transportStatus);