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

« back to all changes in this revision

Viewing changes to src/utils/w32/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
 
#include <gpac/tools.h>
26
 
 
27
 
#include <time.h>
28
 
#include <sys/timeb.h>
29
 
#include <io.h>
30
 
#include <windows.h>
31
 
 
32
 
 
33
 
void gf_sleep(u32 ms)
34
 
{
35
 
        Sleep(ms);
36
 
}
37
 
 
38
 
static u32 clock_init = 0;
39
 
 
40
 
/*TODO: add queryperformancetimer stuff for win32*/
41
 
void gf_sys_clock_start()
42
 
{
43
 
        if (!clock_init) timeBeginPeriod(1);
44
 
        clock_init += 1;
45
 
}
46
 
 
47
 
void gf_sys_clock_stop()
48
 
{
49
 
        if (clock_init > 0) {
50
 
                clock_init --;
51
 
                if (!clock_init) timeEndPeriod(1);
52
 
        }
53
 
}
54
 
 
55
 
u32 gf_sys_clock()
56
 
{
57
 
        return timeGetTime();
58
 
}
59
 
 
60
 
void gf_delete_file(char *fileName)
61
 
{
62
 
        DeleteFile(fileName);
63
 
}
64
 
 
65
 
 
66
 
 
67
 
void gf_rand_init(Bool Reset)
68
 
{
69
 
        if (Reset) {
70
 
                srand(1);
71
 
        } else {
72
 
                srand( (u32) time(NULL) );
73
 
        }
74
 
}
75
 
 
76
 
u32 gf_rand()
77
 
{
78
 
        return rand();
79
 
}
80
 
 
81
 
 
82
 
#ifndef GPAC_READ_ONLY
83
 
FILE *gf_temp_file_new()
84
 
{
85
 
        return tmpfile();
86
 
}
87
 
#endif
88
 
 
89
 
 
90
 
void gf_utc_time_since_1970(u32 *sec, u32 *msec)
91
 
{
92
 
        struct _timeb   tb;
93
 
        _ftime( &tb );
94
 
        *sec = tb.time;
95
 
        *msec = tb.millitm;
96
 
 
97
 
}
98
 
 
99
 
void gf_get_user_name(char *buf, u32 buf_size)
100
 
{
101
 
        strcpy(buf, "mpeg4-user");
102
 
 
103
 
#if 0
104
 
 
105
 
        s32 len;
106
 
        char *t;
107
 
 
108
 
        strcpy(buf, "");
109
 
        len = 1024;
110
 
        GetUserName(buf, &len);
111
 
        if (!len) {
112
 
                t = getenv("USER");
113
 
                if (t) strcpy(buf, t);
114
 
        }
115
 
#endif
116
 
}
117
 
 
118
 
 
119
 
/*enumerate directories*/
120
 
GF_Err gf_enum_directory(const char *dir, Bool enum_directory, gf_enum_dir_item enum_dir_fct, void *cbck)
121
 
{
122
 
        unsigned char path[GF_MAX_PATH], item_path[GF_MAX_PATH];
123
 
        WIN32_FIND_DATA FindData;
124
 
        HANDLE SearchH;
125
 
 
126
 
        if (!dir || !enum_dir_fct) return GF_BAD_PARAM;
127
 
        if (dir[strlen(dir) - 1] == GF_PATH_SEPARATOR) {
128
 
                sprintf(path, "%s*", dir);
129
 
        } else {
130
 
                sprintf(path, "%s%c*", dir, GF_PATH_SEPARATOR);
131
 
        }
132
 
 
133
 
        SearchH= FindFirstFile(path, &FindData);
134
 
        if (SearchH == INVALID_HANDLE_VALUE) return GF_IO_ERR;
135
 
 
136
 
        path[strlen(path)-1] = 0;
137
 
 
138
 
        while (SearchH != INVALID_HANDLE_VALUE) {
139
 
                if (!strcmp(FindData.cFileName, ".")) goto next;
140
 
                if (!strcmp(FindData.cFileName, "..")) goto next;
141
 
 
142
 
                if (!enum_directory && (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) goto next;
143
 
                if (enum_directory && !(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) goto next;
144
 
 
145
 
                strcpy(item_path, path);
146
 
                strcat(item_path, FindData.cFileName);
147
 
                if (enum_dir_fct(cbck, FindData.cFileName, item_path)) {
148
 
                        FindClose(SearchH);
149
 
                        break;
150
 
                }
151
 
 
152
 
next:
153
 
                if (!FindNextFile(SearchH, &FindData)) {
154
 
                        FindClose(SearchH);
155
 
                        break;
156
 
                }
157
 
        }
158
 
        return GF_OK;
159
 
}
160
 
 
161
 
 
162
 
u64 gf_f64_tell(FILE *fp)
163
 
{
164
 
        fpos_t pos;
165
 
        if (fgetpos(fp, &pos))
166
 
                return (u64) -1;
167
 
        else
168
 
                return ((u64) pos);
169
 
}
170
 
 
171
 
u64 gf_f64_seek(FILE *fp, s64 offset, s32 whence)
172
 
{
173
 
        fpos_t pos;
174
 
        if (whence == SEEK_CUR) {
175
 
                fgetpos(fp, &pos);
176
 
                pos += (fpos_t) offset;
177
 
        } 
178
 
        else if (whence == SEEK_END) 
179
 
                pos = (fpos_t) (_filelengthi64(fileno(fp)) + offset);
180
 
        else if (whence == SEEK_SET)
181
 
                pos = (fpos_t) offset;
182
 
        return fsetpos(fp, &pos);
183
 
}
184
 
 
185
 
FILE *gf_f64_open(const char *file_name, const char *mode)
186
 
{
187
 
        return fopen(file_name, mode);
188
 
}