~ubuntu-branches/ubuntu/intrepid/gpac/intrepid-proposed

« back to all changes in this revision

Viewing changes to src/utils/wce/os_divers.c

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2007-01-24 23:34:57 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070124233457-zzlls8afkt0nyakj
Tags: 0.4.2~rc2-0ubuntu1
* New upstream release
  * Most notably MP4 tagging support via MP4Box -itags
* debian/patches/01_64bits.dpatch: dropped; included upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *                      GPAC - Multimedia Framework C SDK
3
 
 *
4
 
 *                      Copyright (c) Jean Le Feuvre 2000-2005
5
 
 *                                      All rights reserved
6
 
 *
7
 
 *  This file is part of GPAC / common tools sub-project
8
 
 *
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)
12
 
 *  any later version.
13
 
 *   
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.
18
 
 *   
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. 
22
 
 *
23
 
 */
24
 
 
25
 
 
26
 
#include <gpac/tools.h>
27
 
 
28
 
#include <winsock.h>
29
 
 
30
 
void gf_sleep(u32 millisecs)
31
 
{
32
 
        Sleep(millisecs);
33
 
}
34
 
 
35
 
#define TIME_WRAP               (~(DWORD)0)
36
 
 
37
 
static u32 clock_init = 0;
38
 
 
39
 
static LARGE_INTEGER frequency;
40
 
static LARGE_INTEGER init_counter;
41
 
 
42
 
 
43
 
static u32 (*CE_GetSysClock)();
44
 
 
45
 
u32 gf_sys_clock()
46
 
{
47
 
        return CE_GetSysClock();
48
 
}
49
 
 
50
 
u32 CE_GetSysClockHIGHRES()
51
 
{
52
 
        LARGE_INTEGER now;
53
 
        u64 res;
54
 
        QueryPerformanceCounter(&now);
55
 
 
56
 
        now.QuadPart -= init_counter.QuadPart;
57
 
        res = now.QuadPart * 1000 / frequency.QuadPart;
58
 
        return (u32) res;
59
 
}
60
 
 
61
 
u32 CE_GetSysClockNORMAL()
62
 
{
63
 
        return GetTickCount();
64
 
}
65
 
 
66
 
 
67
 
void gf_sys_clock_start()
68
 
{
69
 
        if (!clock_init) {
70
 
                if (QueryPerformanceFrequency(&frequency) && 0) {
71
 
                        QueryPerformanceCounter(&init_counter);
72
 
                        CE_GetSysClock = CE_GetSysClockHIGHRES;
73
 
                } else {
74
 
                        CE_GetSysClock = CE_GetSysClockNORMAL;
75
 
                }
76
 
        }
77
 
        clock_init += 1;
78
 
}
79
 
 
80
 
void gf_sys_clock_stop()
81
 
{
82
 
}
83
 
 
84
 
#ifndef gettimeofday
85
 
 
86
 
/*
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 
90
 
*/
91
 
#define TIMESPEC_TO_FILETIME_OFFSET (((LONGLONG)27111902 << 32) + (LONGLONG)3577643008)
92
 
 
93
 
s32 gettimeofday(struct timeval *tp, void *tz)
94
 
{
95
 
        FILETIME ft;
96
 
        SYSTEMTIME st;
97
 
        s32 val;
98
 
 
99
 
        GetSystemTime(&st);
100
 
    SystemTimeToFileTime(&st, &ft);
101
 
 
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);
105
 
        tp->tv_usec = val;
106
 
        return 0;
107
 
}
108
 
#endif
109
 
 
110
 
void gf_utc_time_since_1970(u32 *sec, u32 *msec)
111
 
{
112
 
        struct timeval tv;
113
 
        gettimeofday(&tv, NULL);
114
 
        *sec = tv.tv_sec;
115
 
        *msec = tv.tv_usec/1000;
116
 
}
117
 
 
118
 
 
119
 
void gf_delete_file(char *fileName)
120
 
{
121
 
        TCHAR swzName[MAX_PATH];
122
 
        CE_CharToWide(fileName, swzName);
123
 
        DeleteFile(swzName);
124
 
}
125
 
 
126
 
 
127
 
FILE *gf_temp_file_new()
128
 
{
129
 
        TCHAR pTemp[MAX_PATH+1];
130
 
        if (GetTempFileName(TEXT("."), TEXT("A8_"), 0, pTemp))
131
 
                return _wfopen(pTemp, TEXT("w+b"));
132
 
 
133
 
        return NULL;
134
 
}
135
 
 
136
 
void CE_Assert(u32 valid)
137
 
{
138
 
        if (!valid) {
139
 
                MessageBox(NULL, _T("ASSERT FAILED"), _T("Fatal Error"), MB_OK);
140
 
        }
141
 
}
142
 
 
143
 
 
144
 
void gf_rand_init(Bool Reset)
145
 
{
146
 
        if (Reset) {
147
 
                srand(1);
148
 
        } else {
149
 
                srand( (u32) GetTickCount() );
150
 
        }
151
 
}
152
 
 
153
 
u32 gf_rand()
154
 
{
155
 
        return rand();
156
 
}
157
 
 
158
 
 
159
 
 
160
 
void gf_get_user_name(char *buf, u32 buf_size)
161
 
{
162
 
        strcpy(buf, "mpeg4-user");
163
 
 
164
 
}
165
 
 
166
 
 
167
 
void CE_WideToChar(unsigned short *w_str, char *str)
168
 
{
169
 
        WideCharToMultiByte(CP_ACP, 0, w_str, -1, str, GF_MAX_PATH, NULL, NULL);
170
 
}
171
 
 
172
 
void CE_CharToWide(char *str, unsigned short *w_str)
173
 
{
174
 
        MultiByteToWideChar(CP_ACP, 0, str, -1, w_str, GF_MAX_PATH);
175
 
}
176
 
 
177
 
 
178
 
 
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)
181
 
{
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;
186
 
        HANDLE SearchH;
187
 
 
188
 
        if (!dir) return GF_BAD_PARAM;
189
 
        if (dir[strlen(dir) - 1] != GF_PATH_SEPARATOR) {
190
 
                sprintf(_path, "%s*", dir);
191
 
        } else {
192
 
                sprintf(_path, "%s%c*", dir);
193
 
        }
194
 
        CE_CharToWide(_path, path);
195
 
 
196
 
        SearchH= FindFirstFile(path, &FindData);
197
 
        if (SearchH == INVALID_HANDLE_VALUE) return GF_IO_ERR;
198
 
 
199
 
        _path[strlen(_path)-1] = 0;
200
 
 
201
 
        while (SearchH != INVALID_HANDLE_VALUE) {
202
 
                if (!wcscmp(FindData.cFileName, _T(".") )) goto next;
203
 
                if (!wcscmp(FindData.cFileName, _T("..") )) goto next;
204
 
 
205
 
                if (!enum_directory && (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) goto next;
206
 
                if (enum_directory && !(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) goto next;
207
 
 
208
 
                CE_WideToChar(FindData.cFileName, file);
209
 
                strcpy(filepath, _path);
210
 
                strcat(filepath, file);
211
 
                if (enum_dir_item(cbck, file, filepath)) {
212
 
                        FindClose(SearchH);
213
 
                        break;
214
 
                }
215
 
 
216
 
next:
217
 
                if (!FindNextFile(SearchH, &FindData)) {
218
 
                        FindClose(SearchH);
219
 
                        break;
220
 
                }
221
 
        }
222
 
        return GF_OK;
223
 
}
224
 
 
225
 
char * my_str_upr(char *str)
226
 
{
227
 
        u32 i;
228
 
        for (i=0; i<strlen(str); i++) {
229
 
                str[i] = toupper(str[i]);
230
 
        }
231
 
        return str;
232
 
}
233
 
char * my_str_lwr(char *str)
234
 
{
235
 
        u32 i;
236
 
        for (i=0; i<strlen(str); i++) {
237
 
                str[i] = tolower(str[i]);
238
 
        }
239
 
        return str;
240
 
}
241
 
 
242
 
 
243
 
u64 gf_f64_tell(FILE *f)
244
 
{
245
 
        return (u64) ftell(f);
246
 
}
247
 
 
248
 
u64 gf_f64_seek(FILE *f, s64 pos, s32 whence)
249
 
{
250
 
        return (u64) fseek(f, (s32) pos, whence);
251
 
}
252
 
 
253
 
FILE *gf_f64_open(const char *file_name, const char *mode)
254
 
{
255
 
        return fopen(file_name, mode);
256
 
}