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 }
int64_t CurrentHostCounter(void) { /* 歌方: 1、 卦指: 1、 傍苧: 1、 */ #if defined(TARGET_DARWIN) return( (int64_t)CVGetCurrentHostTime() ); #elif defined(TARGET_WINDOWS) LARGE_INTEGER PerformanceCount; QueryPerformanceCounter(&PerformanceCount); return( (int64_t)PerformanceCount.QuadPart ); #else struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); return( ((int64_t)now.tv_sec * 1000000000L) + now.tv_nsec ); #endif }
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; }
int64_t CurrentHostCounter(void) { #if defined(__APPLE__) return( (int64_t)CVGetCurrentHostTime() ); #elif defined(_LINUX) struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); return( ((int64_t)now.tv_sec * 1000000000L) + now.tv_nsec ); #else LARGE_INTEGER PerformanceCount; QueryPerformanceCounter(&PerformanceCount); return( (int64_t)PerformanceCount.QuadPart ); #endif }
// 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; }
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); }
double QTMovieVisualContext::currentHostTime() { return CVGetCurrentHostTime() / CVGetHostClockFrequency(); }
static int quicktimedrv_record(screenshot_t *screenshot) { if (!video_ready) { return 0; } OSErr theError; // lock buffer theError = CVPixelBufferLockBaseAddress(pixelBuffer, 0); if (theError) { log_debug("quicktime: error locking pixel buffer!"); return -1; } // fill frame unsigned char *buffer = (unsigned char *)CVPixelBufferGetBaseAddress(pixelBuffer); size_t bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer); unsigned int line_size = screenshot->draw_buffer_line_size; int h = screenshot->height; int w = screenshot->width; int xoff = screenshot->x_offset; int yoff = screenshot->y_offset; BYTE *srcBuffer = screenshot->draw_buffer; // move to last line in tgt buffer and to first in source buffer += (video_yoff) * bytesPerRow + video_xoff * 3; srcBuffer += yoff * line_size + xoff; int x, y; for (y = 0; y < h; y++) { int pix = 0; for (x = 0; x < w; x++) { BYTE val = srcBuffer[x]; buffer[pix++] = screenshot->palette->entries[val].red; buffer[pix++] = screenshot->palette->entries[val].green; buffer[pix++] = screenshot->palette->entries[val].blue; } buffer += bytesPerRow; srcBuffer += line_size; } // unlock buffer theError = CVPixelBufferUnlockBaseAddress(pixelBuffer, 0); if (theError) { log_debug("quicktime: error unlocking pixel buffer!"); return -1; } TimeValue64 next = CVGetCurrentHostTime() / divider; TimeValue64 duration = next - timestamp; timestamp = next; // encode frame theError = ICMCompressionSessionEncodeFrame(videoCompressionSession, pixelBuffer, timestamp, duration, kICMValidTime_DisplayTimeStampIsValid | kICMValidTime_DisplayDurationIsValid, NULL, NULL, (void *)NULL); if (theError) { log_debug("quicktime: error encoding frame!"); return -1; } return 0; }
/* Get time in timer units. */ unsigned long vsyncarch_gettime(void) { return (unsigned long)(CVGetCurrentHostTime() / hostToUsFactor); }
TimeT system_time () { return CVGetCurrentHostTime() / CVGetHostClockFrequency(); }