mirror of https://github.com/Genymobile/scrcpy
Wrap tick API
This avoids to use the SDL timer API directly, and will allow to handle generic ticks (possibly negative).buffering.10
parent
5524f378c8
commit
ec871dd3f5
@ -0,0 +1,16 @@
|
||||
#include "tick.h"
|
||||
|
||||
#include <SDL2/SDL_timer.h>
|
||||
|
||||
sc_tick
|
||||
sc_tick_now(void) {
|
||||
// SDL_GetTicks() resolution is in milliseconds, but sc_tick are expressed
|
||||
// in microseconds to store PTS without precision loss.
|
||||
//
|
||||
// As an alternative, SDL_GetPerformanceCounter() and
|
||||
// SDL_GetPerformanceFrequency() could be used, but:
|
||||
// - the conversions (avoiding overflow) are expansive, since the
|
||||
// frequency is not known at compile time;
|
||||
// - in practice, we don't need more precision for now.
|
||||
return (sc_tick) SDL_GetTicks() * 1000;
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
#ifndef SC_TICK_H
|
||||
#define SC_TICK_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int64_t sc_tick;
|
||||
#define SC_TICK_FREQ 1000000 // microsecond
|
||||
|
||||
// To be adapted if SC_TICK_FREQ changes
|
||||
#define SC_TICK_TO_US(tick) (tick)
|
||||
#define SC_TICK_TO_MS(tick) ((tick) / 1000)
|
||||
#define SC_TICK_TO_SEC(tick) ((tick) / 1000000)
|
||||
#define SC_TICK_FROM_US(us) (us)
|
||||
#define SC_TICK_FROM_MS(ms) ((ms) * 1000)
|
||||
#define SC_TICK_FROM_SEC(sec) ((sec) * 1000000)
|
||||
|
||||
sc_tick
|
||||
sc_tick_now(void);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue