2
* GPAC - Multimedia Framework C SDK
4
* Copyright (c) Jean Le Feuvre 2000-2005
7
* This file is part of GPAC / common tools sub-project
9
* GPAC is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; either version 2, or (at your option)
14
* GPAC is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU Lesser General Public License for more details.
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with this library; see the file COPYING. If not, write to
21
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26
#include <gpac/tools.h>
30
void gf_sleep(u32 millisecs)
35
#define TIME_WRAP (~(DWORD)0)
37
static u32 clock_init = 0;
39
static LARGE_INTEGER frequency;
40
static LARGE_INTEGER init_counter;
43
static u32 (*CE_GetSysClock)();
47
return CE_GetSysClock();
50
u32 CE_GetSysClockHIGHRES()
54
QueryPerformanceCounter(&now);
56
now.QuadPart -= init_counter.QuadPart;
57
res = now.QuadPart * 1000 / frequency.QuadPart;
61
u32 CE_GetSysClockNORMAL()
63
return GetTickCount();
67
void gf_sys_clock_start()
70
if (QueryPerformanceFrequency(&frequency) && 0) {
71
QueryPerformanceCounter(&init_counter);
72
CE_GetSysClock = CE_GetSysClockHIGHRES;
74
CE_GetSysClock = CE_GetSysClockNORMAL;
80
void gf_sys_clock_stop()
87
Conversion code for WinCE from pthreads WinCE
88
(FILETIME in Win32 is from jan 1, 1601)
89
time between jan 1, 1601 and jan 1, 1970 in units of 100 nanoseconds
91
#define TIMESPEC_TO_FILETIME_OFFSET (((LONGLONG)27111902 << 32) + (LONGLONG)3577643008)
93
s32 gettimeofday(struct timeval *tp, void *tz)
100
SystemTimeToFileTime(&st, &ft);
102
val = (s32) ((*(LONGLONG *) &ft - TIMESPEC_TO_FILETIME_OFFSET) / 10000000);
103
tp->tv_sec = (u32) val;
104
val = (s32 ) ((*(LONGLONG *) &ft - TIMESPEC_TO_FILETIME_OFFSET - ((LONGLONG) val * (LONGLONG) 10000000)) * 100);
110
void gf_utc_time_since_1970(u32 *sec, u32 *msec)
113
gettimeofday(&tv, NULL);
115
*msec = tv.tv_usec/1000;
119
void gf_delete_file(char *fileName)
121
TCHAR swzName[MAX_PATH];
122
CE_CharToWide(fileName, swzName);
127
FILE *gf_temp_file_new()
129
TCHAR pTemp[MAX_PATH+1];
130
if (GetTempFileName(TEXT("."), TEXT("A8_"), 0, pTemp))
131
return _wfopen(pTemp, TEXT("w+b"));
136
void CE_Assert(u32 valid)
139
MessageBox(NULL, _T("ASSERT FAILED"), _T("Fatal Error"), MB_OK);
144
void gf_rand_init(Bool Reset)
149
srand( (u32) GetTickCount() );
160
void gf_get_user_name(char *buf, u32 buf_size)
162
strcpy(buf, "mpeg4-user");
167
void CE_WideToChar(unsigned short *w_str, char *str)
169
WideCharToMultiByte(CP_ACP, 0, w_str, -1, str, GF_MAX_PATH, NULL, NULL);
172
void CE_CharToWide(char *str, unsigned short *w_str)
174
MultiByteToWideChar(CP_ACP, 0, str, -1, w_str, GF_MAX_PATH);
179
/*enumerate directories*/
180
GF_Err gf_enum_directory(const char *dir, Bool enum_directory, Bool (*enum_dir_item)(void *cbck, char *item_name, char *item_path), void *cbck)
182
unsigned char _path[GF_MAX_PATH];
183
unsigned short path[GF_MAX_PATH];
184
unsigned char file[GF_MAX_PATH], filepath[GF_MAX_PATH];
185
WIN32_FIND_DATA FindData;
188
if (!dir) return GF_BAD_PARAM;
189
if (dir[strlen(dir) - 1] != GF_PATH_SEPARATOR) {
190
sprintf(_path, "%s*", dir);
192
sprintf(_path, "%s%c*", dir);
194
CE_CharToWide(_path, path);
196
SearchH= FindFirstFile(path, &FindData);
197
if (SearchH == INVALID_HANDLE_VALUE) return GF_IO_ERR;
199
_path[strlen(_path)-1] = 0;
201
while (SearchH != INVALID_HANDLE_VALUE) {
202
if (!wcscmp(FindData.cFileName, _T(".") )) goto next;
203
if (!wcscmp(FindData.cFileName, _T("..") )) goto next;
205
if (!enum_directory && (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) goto next;
206
if (enum_directory && !(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) goto next;
208
CE_WideToChar(FindData.cFileName, file);
209
strcpy(filepath, _path);
210
strcat(filepath, file);
211
if (enum_dir_item(cbck, file, filepath)) {
217
if (!FindNextFile(SearchH, &FindData)) {
225
char * my_str_upr(char *str)
228
for (i=0; i<strlen(str); i++) {
229
str[i] = toupper(str[i]);
233
char * my_str_lwr(char *str)
236
for (i=0; i<strlen(str); i++) {
237
str[i] = tolower(str[i]);
243
u64 gf_f64_tell(FILE *f)
245
return (u64) ftell(f);
248
u64 gf_f64_seek(FILE *f, s64 pos, s32 whence)
250
return (u64) fseek(f, (s32) pos, whence);
253
FILE *gf_f64_open(const char *file_name, const char *mode)
255
return fopen(file_name, mode);