osdep.h 5.27 KB
Newer Older
1
/*****************************************************************************
Loren Merritt's avatar
Loren Merritt committed
2
 * osdep.h: h264 encoder
3
 *****************************************************************************
4
5
6
7
 * Copyright (C) 2007-2008 x264 project
 *
 * Authors: Loren Merritt <lorenm@u.washington.edu>
 *          Laurent Aimar <fenrir@via.ecp.fr>
8
9
10
11
12
13
14
15
16
17
18
19
20
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
22
23
 *****************************************************************************/

24
25
#ifndef X264_OSDEP_H
#define X264_OSDEP_H
26

27
28
29
30
#define _LARGEFILE_SOURCE 1
#define _FILE_OFFSET_BITS 64
#include <stdio.h>

31
32
33
34
35
36
#ifdef HAVE_STDINT_H
#include <stdint.h>
#else
#include <inttypes.h>
#endif

37
#ifdef _WIN32
38
39
#include <io.h>    // _setmode()
#include <fcntl.h> // _O_BINARY
40
41
42
#endif

#ifdef _MSC_VER
43
#define inline __inline
44
#define strcasecmp stricmp
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#define strncasecmp strnicmp
#define snprintf _snprintf
#define fseek _fseeki64
#define ftell _ftelli64
#define isfinite _finite
#define _CRT_SECURE_NO_DEPRECATE
#define X264_VERSION "" // no configure script for msvc
#endif

#ifdef SYS_OPENBSD
#define isfinite finite
#endif
#if defined(_MSC_VER) || defined(SYS_SunOS) || defined(SYS_MACOSX)
#define sqrtf sqrt
#endif
60
#ifdef _WIN32
Loren Merritt's avatar
Loren Merritt committed
61
62
63
64
#define rename(src,dst) (unlink(dst), rename(src,dst)) // POSIX says that rename() removes the destination, but win32 doesn't.
#ifndef strtok_r
#define strtok_r(str,delim,save) strtok(str,delim)
#endif
65
66
67
#endif

#ifdef _MSC_VER
Loren Merritt's avatar
Loren Merritt committed
68
#define DECLARE_ALIGNED( var, n ) __declspec(align(n)) var
69
#else
Loren Merritt's avatar
Loren Merritt committed
70
#define DECLARE_ALIGNED( var, n ) var __attribute__((aligned(n)))
71
#endif
Loren Merritt's avatar
Loren Merritt committed
72
73
74
#define DECLARE_ALIGNED_16( var ) DECLARE_ALIGNED( var, 16 )
#define DECLARE_ALIGNED_8( var )  DECLARE_ALIGNED( var, 8 )
#define DECLARE_ALIGNED_4( var )  DECLARE_ALIGNED( var, 4 )
75
76
77

#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
#define UNUSED __attribute__((unused))
78
#define ALWAYS_INLINE __attribute__((always_inline)) inline
79
#define NOINLINE __attribute__((noinline))
80
81
#else
#define UNUSED
82
#define ALWAYS_INLINE inline
83
#define NOINLINE
84
85
86
#endif

/* threads */
87
#if defined(SYS_BEOS)
88
#include <kernel/OS.h>
89
90
91
92
93
#define x264_pthread_t               thread_id
#define x264_pthread_create(t,u,f,d) { *(t)=spawn_thread(f,"",10,d); \
                                       resume_thread(*(t)); }
#define x264_pthread_join(t,s)       { long tmp; \
                                       wait_for_thread(t,(s)?(long*)(s):&tmp); }
94
#ifndef usleep
95
#define usleep(t)                    snooze(t)
96
97
98
99
100
#endif
#define HAVE_PTHREAD 1

#elif defined(HAVE_PTHREAD)
#include <pthread.h>
101
102
#define USE_REAL_PTHREAD

103
#else
104
105
106
#define x264_pthread_t               int
#define x264_pthread_create(t,u,f,d)
#define x264_pthread_join(t,s)
107
108
#endif //SYS_*

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifdef USE_REAL_PTHREAD
#define x264_pthread_t               pthread_t
#define x264_pthread_create          pthread_create
#define x264_pthread_join            pthread_join
#define x264_pthread_mutex_t         pthread_mutex_t
#define x264_pthread_mutex_init      pthread_mutex_init
#define x264_pthread_mutex_destroy   pthread_mutex_destroy
#define x264_pthread_mutex_lock      pthread_mutex_lock
#define x264_pthread_mutex_unlock    pthread_mutex_unlock
#define x264_pthread_cond_t          pthread_cond_t
#define x264_pthread_cond_init       pthread_cond_init
#define x264_pthread_cond_destroy    pthread_cond_destroy
#define x264_pthread_cond_broadcast  pthread_cond_broadcast
#define x264_pthread_cond_wait       pthread_cond_wait
#else
#define x264_pthread_mutex_t         int
#define x264_pthread_mutex_init(m,f)
#define x264_pthread_mutex_destroy(m)
#define x264_pthread_mutex_lock(m)
#define x264_pthread_mutex_unlock(m)
#define x264_pthread_cond_t          int
#define x264_pthread_cond_init(c,f)
#define x264_pthread_cond_destroy(c)
#define x264_pthread_cond_broadcast(c)
Gabriel Bouvigne's avatar
Gabriel Bouvigne committed
133
#define x264_pthread_cond_wait(c,m)
134
135
#endif

Fiona Glaser's avatar
Fiona Glaser committed
136
#define WORD_SIZE sizeof(void*)
137

138
139
140
141
142
143
#if !defined(_WIN64) && !defined(__LP64__)
#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
#define BROKEN_STACK_ALIGNMENT /* define it if stack is not mod16 */
#endif
#endif

Fiona Glaser's avatar
Fiona Glaser committed
144
145
#ifdef WORDS_BIGENDIAN
#define endian_fix(x) (x)
146
#define endian_fix32(x) (x)
Fiona Glaser's avatar
Fiona Glaser committed
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#elif defined(__GNUC__) && defined(HAVE_MMX)
static ALWAYS_INLINE uint32_t endian_fix32( uint32_t x )
{
    asm("bswap %0":"+r"(x));
    return x;
}
static ALWAYS_INLINE intptr_t endian_fix( intptr_t x )
{
    asm("bswap %0":"+r"(x));
    return x;
}
#else
static ALWAYS_INLINE uint32_t endian_fix32( uint32_t x )
{
    return (x<<24) + ((x<<8)&0xff0000) + ((x>>8)&0xff00) + (x>>24);
}
static ALWAYS_INLINE intptr_t endian_fix( intptr_t x )
{
    if( WORD_SIZE == 8 )
        return endian_fix32(x>>32) + ((uint64_t)endian_fix32(x)<<32);
    else
        return endian_fix32(x);
}
#endif

172
#endif /* X264_OSDEP_H */