1 /* ***** BEGIN LICENSE BLOCK *****
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
25 * ***** END LICENSE BLOCK ***** */
27 #include "videoTransport.h"
31 VideoTransport::VideoTransport(FrameQueue
*fq
) :
34 lastTransportStatus
= Fwd1
;
39 void VideoTransport::setLooping(bool l
)
44 int VideoTransport::getSpeed()
46 TransportControls ts
= transportStatus
;
89 int VideoTransport::getDirection()
91 TransportControls ts
= transportStatus
;
97 if (ts
== Fwd1
|| ts
== Fwd2
|| ts
== Fwd5
|| ts
== Fwd10
|| ts
== Fwd20
98 || ts
== Fwd50
|| ts
== Fwd100
|| ts
== JogFwd
)
102 if (ts
== Rev1
|| ts
== Rev2
|| ts
== Rev5
|| ts
== Rev10
|| ts
== Rev20
103 || ts
== Rev50
|| ts
== Rev100
|| ts
== JogRev
)
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
)
122 //stop at first or last frame if there is no looping - will break at speeds other than 1x
124 if ((looping
== false) && (frame
->isLastFrame
== true
125 || frame
->isFirstFrame
== true)) {
131 //wake the reader thread - done each time as jogging will move the frame number
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
;
224 lastTransportStatus
= Fwd1
; //after 'Stop', unpausing makes us play forwards
228 if (currentStatus
== Stop
|| currentStatus
== Pause
) {
229 newStatus
= JogFwd
; //do jog forward
234 if (currentStatus
== Stop
|| currentStatus
== Pause
) {
235 newStatus
= JogRev
; //do jog backward
240 //when not stopped or paused we can pause, remebering what were doing
241 if (currentStatus
!= Stop
|| currentStatus
== Pause
) {
242 lastTransportStatus
= currentStatus
;
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
)
255 newStatus
= lastTransportStatus
;
259 lastTransportStatus
= currentStatus
;
264 //we can change from any state to a 'shuttle' or play
305 //if we have determined a new transport status, set it
306 if (newStatus
!= Unknown
) {
307 transportStatus
= newStatus
;
309 printf("Changed transport state to %d\n", (int)transportStatus
);