+ window_begin = 0;
+ window_end = 0;
+ last_mtc_frame = 0;
+ last_mtc_timestamp = 0;
+
+ average_speed = 0;
+ have_first_speed_accumulator = false;
+ speed_accumulator_cnt = 0;
+
+ pic->reset();
+}
+
+void
+MTC_Slave::reset_window (nframes64_t root)
+{
+
+ /* if we're waiting for the master to catch us after seeking ahead, keep the window
+ of acceptable MTC frames wide open. otherwise, shrink it down to just 2 video frames
+ ahead of the window root (taking direction into account).
+ */
+
+ DEBUG_TRACE (DEBUG::MTC, string_compose ("trying to reset MTC window with state = %1\n", enum_2_string (port->input()->mtc_running())));
+
+ switch (port->input()->mtc_running()) {
+ case MTC_Forward:
+ DEBUG_TRACE (DEBUG::MTC, "set MTC window while running forward\n");
+ window_begin = root;
+ if (session.slave_state() == Session::Running) {
+ window_end = root + (session.frames_per_timecode_frame() * frame_tolerance);
+ } else {
+ window_end = root + seekahead_distance ();
+ }
+ break;
+
+ case MTC_Backward:
+ DEBUG_TRACE (DEBUG::MTC, "set MTC window while running backward\n");
+ if (session.slave_state() == Session::Running) {
+ nframes_t d = session.frames_per_timecode_frame() * frame_tolerance;
+ if (root > d) {
+ window_begin = root - d;
+ window_end = root;
+ } else {
+ window_begin = 0;
+ }
+ } else {
+ nframes_t d = seekahead_distance ();
+ if (root > d) {
+ window_begin = root - d;
+ } else {
+ window_begin = 0;
+ }
+ }
+ window_end = root;
+ break;
+
+ default:
+ DEBUG_TRACE (DEBUG::MTC, "not touching MTC window - MTC_Stopped\n");
+ /* do nothing */
+ break;
+ }
+
+ DEBUG_TRACE (DEBUG::MTC, string_compose ("legal MTC window now %1 .. %2\n", window_begin, window_end));
+}
+
+nframes64_t
+MTC_Slave::seekahead_distance () const
+{
+ /* 1 second */
+ return session.frame_rate();
+}
+
+bool
+MTC_Slave::outside_window (nframes64_t pos) const
+{
+ return ((pos < window_begin) || (pos > window_end));