Exemplo n.º 1
0
unsigned int CTimeUtils::GetTimeMS()
{
  // best replacement for windows timeGetTime/GetTickCount
  // 1st call sets start_mstime, subsequent are the diff
  // between start_mstime and now_mstime to match SDL_GetTick behavior
  // of previous usage. We might want to change this as CTimeUtils::GetTimeMS is 
  // time (ms) since system startup. 
#if defined(_WIN32)
  return timeGetTime();
#elif defined(_LINUX)
#if defined(__APPLE__)
  static uint64_t start_time = 0;
  uint64_t now_time;
  now_time = CVGetCurrentHostTime() * 1000 / CVGetHostClockFrequency();
  if (start_time == 0)
    start_time = now_time;
  return(now_time - start_time);
#else
  static uint64_t start_mstime = 0;
  uint64_t now_mstime;
  struct timespec ts;

  clock_gettime(CLOCK_MONOTONIC, &ts);
  now_mstime = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
  if (start_mstime == 0)
  {
    start_mstime = now_mstime;
  }
  
  return(now_mstime - start_mstime);
#endif
#endif
}
Exemplo n.º 2
0
// Called by the Core Video Display Link whenever it's appropriate to render a frame.
static CVReturn DisplayLinkCallBack(CVDisplayLinkRef displayLink, const CVTimeStamp* inNow, const CVTimeStamp* inOutputTime, CVOptionFlags flagsIn, CVOptionFlags* flagsOut, void* displayLinkContext)
{
  // Create an autorelease pool (necessary to call into non-Obj-C code from Obj-C code)
  void* pool = Cocoa_Create_AutoReleasePool();
  
  CVideoSyncOsx *VideoSyncOsx = reinterpret_cast<CVideoSyncOsx*>(displayLinkContext);

  if (inOutputTime->flags & kCVTimeStampHostTimeValid)
    VideoSyncOsx->VblankHandler(inOutputTime->hostTime, CVGetHostClockFrequency());
  else
    VideoSyncOsx->VblankHandler(CVGetCurrentHostTime(), CVGetHostClockFrequency());
  
  // Destroy the autorelease pool
  Cocoa_Destroy_AutoReleasePool(pool);
  
  return kCVReturnSuccess;
}
Exemplo n.º 3
0
/* Number of timer units per second. */
signed long vsyncarch_frequency(void)
{
    /* how to convert host time to us */
    hostToUsFactor = (unsigned long)(CVGetHostClockFrequency() / 1000000UL);
    
    /* Microseconds resolution. */
    return 1000000L;
}
Exemplo n.º 4
0
static int quicktimedrv_save(screenshot_t *screenshot, const char *filename)
{
    // align and center video
    video_width = screenshot->width;
    video_height = screenshot->height;
    video_width = (video_width + 15) & ~15;
    video_height = (video_height + 15) & ~15;
    video_xoff = (video_width - screenshot->width) >> 1;
    video_yoff = (video_height - screenshot->height) >> 1;

    // create cfstring from filename
    CFStringRef path = CFStringCreateWithCString(NULL, filename, kCFStringEncodingUTF8);
    if (path == NULL) {
        log_debug("quicktime: error creating CFString!");
        return -1;
    }

    // create data reference
    Handle dataRef;
    OSType dataRefType;
    OSErr theError = QTNewDataReferenceFromFullPathCFString(
        path, kQTNativeDefaultPathStyle, 0, &dataRef, &dataRefType);
    if (theError) {
        log_debug("quicktime: error creating data reference for '%s'", filename);
        return -1;
    }

    // Create a movie for this file (data ref)
    theError = CreateMovieStorage(
        dataRef, dataRefType, 'TVOD', smCurrentScript, createMovieFileDeleteCurFile,
        &dataHandler, &movie);
    if (theError) {
        log_debug("quicktime: error creating movie storage for '%s'", filename);
        return -1;
    }

    // dispose of the data reference handle - we no longer need it
    DisposeHandle(dataRef);

    // define time scale and host clock divider
    divider = (TimeScale)CVGetHostClockFrequency() / timeScale;

    // setup video
    if (setup_video() != noErr) {
        return -1;
    }

    // setup audio
    if (audio_codec != -1) {
        soundmovie_start(&quicktime_soundmovie_funcs);
    }

    // set initial time stamp
    timestamp = CVGetCurrentHostTime() / divider;
    return 0;
}
Exemplo n.º 5
0
int64_t CurrentHostFrequency(void)
{
#if defined(TARGET_DARWIN)
  return( (int64_t)CVGetHostClockFrequency() );
#elif defined(TARGET_WINDOWS)
  LARGE_INTEGER Frequency;
  QueryPerformanceFrequency(&Frequency);
  return( (int64_t)Frequency.QuadPart );
#else
  return( (int64_t)1000000000L );
#endif
}
Exemplo n.º 6
0
int64_t CurrentHostFrequency(void)
{
#if defined(__APPLE__)
  // needed for 10.5.8 on ppc
  return( (int64_t)CVGetHostClockFrequency() );
#elif defined(_LINUX)
  return( (int64_t)1000000000L );
#else
  LARGE_INTEGER Frequency;
  QueryPerformanceFrequency(&Frequency);
  return( (int64_t)Frequency.QuadPart );
#endif
}
Exemplo n.º 7
0
  unsigned int SystemClockMillis()
  {
    uint64_t now_time;
    static uint64_t start_time = 0;
    static bool start_time_set = false;
#if defined(TARGET_DARWIN)
    now_time = CVGetCurrentHostTime() *  1000 / CVGetHostClockFrequency();
#elif defined(TARGET_WINDOWS)
    now_time = (uint64_t)timeGetTime();
#else
    struct timespec ts = {};
    clock_gettime(CLOCK_MONOTONIC, &ts);
    now_time = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
#endif
    if (!start_time_set)
    {
      start_time = now_time;
      start_time_set = true;
    }
    return (unsigned int)(now_time - start_time);
  }
Exemplo n.º 8
0
static void
gst_mio_video_src_init (GstMIOVideoSrc * self, GstMIOVideoSrcClass * gclass)
{
  GstBaseSrc *base_src = GST_BASE_SRC_CAST (self);
  guint64 host_freq;

  gst_base_src_set_live (base_src, TRUE);
  gst_base_src_set_format (base_src, GST_FORMAT_TIME);

  host_freq = gst_gdouble_to_guint64 (CVGetHostClockFrequency ());
  if (host_freq <= GST_SECOND) {
    self->cv_ratio_n = GST_SECOND / host_freq;
    self->cv_ratio_d = 1;
  } else {
    self->cv_ratio_n = 1;
    self->cv_ratio_d = host_freq / GST_SECOND;
  }

  self->queue = g_queue_new ();
  self->qlock = g_mutex_new ();
  self->qcond = g_cond_new ();
}
double QTMovieVisualContext::currentHostTime()
{
    return CVGetCurrentHostTime() / CVGetHostClockFrequency();
}
Exemplo n.º 10
0
		TimeT system_time () {
			return CVGetCurrentHostTime() / CVGetHostClockFrequency();
		}