static void
new_frame_cb (EggTimeline *timeline,
              gint frame_num,
              TestState *state)
{
  gint current_frame = egg_timeline_get_current_frame (timeline);

  if (current_frame == TEST_TIMELINE_FRAME_COUNT)
    {
      g_print ("new-frame signal recieved (end of timeline)\n");
      g_print ("Rewinding timeline\n");
      egg_timeline_rewind (timeline);
      state->rewind_count++;
    }
  else
    {
      if (current_frame == 0)
        {
          g_print ("new-frame signal recieved (start of timeline)\n");
        }
      else
        {
          g_print ("new-frame signal recieved (mid frame)\n");
        }

      if (state->rewind_count >= 2)
        {
          g_print ("Sleeping for 1 second\n");
          g_usleep (1000000);
        }
    }
}
static void
new_frame_cb (EggTimeline *timeline,
              gint frame_num,
	      TestState *state)
{
  GTimeVal current_time;
  gint current_frame;
  glong msec_diff;
  gint loop_overflow = 0;
  static gint step = 1;
  
  g_get_current_time (&current_time);

  current_frame = egg_timeline_get_current_frame (state->timeline);
  
  msec_diff = (current_time.tv_sec - state->start_time.tv_sec) * 1000;
  msec_diff += (current_time.tv_usec - state->start_time.tv_usec)/1000;
  
  /* If we expect to have interpolated past the end of the timeline
   * we keep track of the overflow so we can determine when
   * the next timeout will happen. We then clip expected_frames
   * to TEST_TIMELINE_FRAME_COUNT since egg-timeline
   * semantics guaranty this frame is always signaled before
   * looping */
  if (state->expected_frame > TEST_TIMELINE_FRAME_COUNT)
    {
	loop_overflow = state->expected_frame - TEST_TIMELINE_FRAME_COUNT;
	state->expected_frame = TEST_TIMELINE_FRAME_COUNT;
    }

  if (current_frame >= (state->expected_frame-TEST_ERROR_TOLERANCE)
      && current_frame <= (state->expected_frame+TEST_ERROR_TOLERANCE))
    {
      g_print ("\nelapsed milliseconds=%-5li expected frame=%-4i actual frame=%-4i (OK)\n",
              msec_diff,
              state->expected_frame,
              current_frame);
    }
  else
    {
      g_print ("\nelapsed milliseconds=%-5li expected frame=%-4i actual frame=%-4i (FAILED)\n",
              msec_diff,
              state->expected_frame,
              current_frame);
      state->passed = FALSE;
    }
    
  if (step>0)
    {
      state->expected_frame = current_frame + (TEST_TIMELINE_FPS / 4);
      g_print ("Sleeping for 250ms so next frame should be (%i + %i) = %i\n",
             current_frame, (TEST_TIMELINE_FPS / 4), state->expected_frame);
      g_usleep (250000);
    }
  else
    {
      state->expected_frame = current_frame + TEST_TIMELINE_FPS;
      g_print ("Sleeping for 1sec so next frame should be (%i + %i) = %i\n",
             current_frame, TEST_TIMELINE_FPS, state->expected_frame);
      g_usleep (1000000);
    }
  
  if (current_frame >= TEST_TIMELINE_FRAME_COUNT)
    {
      state->expected_frame += loop_overflow;
      state->expected_frame -= TEST_TIMELINE_FRAME_COUNT;
      g_print ("End of timeline reached: Wrapping expected frame too %i\n",
	       state->expected_frame);
    }

  state->new_frame_counter++;
  step = -step;
}