From: Loren Merritt Date: Tue, 17 Jul 2007 11:11:19 +0000 (+0000) Subject: move os/compiler specific defines to their own header X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=85f2fc3252f0fae8031fa9e942577d121cb75cd1;p=libx264 move os/compiler specific defines to their own header git-svn-id: svn://svn.videolan.org/x264/trunk@666 df754926-b1dd-0310-bc7b-ec298dee348c --- diff --git a/common/cabac.c b/common/cabac.c index 2996d33c..695b411d 100644 --- a/common/cabac.c +++ b/common/cabac.c @@ -21,9 +21,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#include -#include - #include "common.h" diff --git a/common/common.c b/common/common.c index e771dc07..f699d128 100644 --- a/common/common.c +++ b/common/common.c @@ -21,8 +21,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#include -#include #include #ifdef HAVE_MALLOC_H diff --git a/common/common.h b/common/common.h index 0b8f8f79..7e147ef5 100644 --- a/common/common.h +++ b/common/common.h @@ -24,67 +24,6 @@ #ifndef _COMMON_H #define _COMMON_H 1 -#ifdef HAVE_STDINT_H -#include -#else -#include -#endif -#include -#include -#include - -#ifdef _MSC_VER -#define inline __inline -#define strncasecmp(s1, s2, n) strnicmp(s1, s2, n) -#define snprintf _snprintf -#define X264_VERSION "" // no configure script for msvc -#endif - -#ifdef _MSC_VER -#define DECLARE_ALIGNED( type, var, n ) __declspec(align(n)) type var -#else -#define DECLARE_ALIGNED( type, var, n ) type var __attribute__((aligned(n))) -#endif - -/* threads */ -#if defined(__WIN32__) && defined(HAVE_PTHREAD) -#include -#define USE_CONDITION_VAR - -#elif defined(SYS_BEOS) -#include -#define pthread_t thread_id -#define pthread_create(t,u,f,d) { *(t)=spawn_thread(f,"",10,d); \ - resume_thread(*(t)); } -#define pthread_join(t,s) { long tmp; \ - wait_for_thread(t,(s)?(long*)(s):&tmp); } -#ifndef usleep -#define usleep(t) snooze(t) -#endif -#define HAVE_PTHREAD 1 - -#elif defined(HAVE_PTHREAD) -#include -#define USE_CONDITION_VAR -#else -#define pthread_t int -#define pthread_create(t,u,f,d) -#define pthread_join(t,s) -#endif //SYS_* - -#ifndef USE_CONDITION_VAR -#define pthread_mutex_t int -#define pthread_mutex_init(m,f) -#define pthread_mutex_destroy(m) -#define pthread_mutex_lock(m) -#define pthread_mutex_unlock(m) -#define pthread_cond_t int -#define pthread_cond_init(c,f) -#define pthread_cond_destroy(c) -#define pthread_cond_broadcast(c) -#define pthread_cond_wait(c,m) usleep(100) -#endif - /**************************************************************************** * Macros ****************************************************************************/ @@ -101,12 +40,6 @@ #define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F)) #endif -#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) -#define UNUSED __attribute__((unused)) -#else -#define UNUSED -#endif - #define CHECKED_MALLOC( var, size )\ {\ var = x264_malloc( size );\ @@ -129,6 +62,11 @@ /**************************************************************************** * Includes ****************************************************************************/ +#include +#include +#include +#include +#include "osdep.h" #include "x264.h" #include "bs.h" #include "set.h" diff --git a/common/cpu.c b/common/cpu.c index 1668a6fa..45484b83 100644 --- a/common/cpu.c +++ b/common/cpu.c @@ -33,8 +33,6 @@ #include #endif -#include - #include "common.h" #ifdef HAVE_MMX diff --git a/common/csp.c b/common/csp.c index baf6de00..68132911 100644 --- a/common/csp.c +++ b/common/csp.c @@ -21,9 +21,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#include -#include - #include "common.h" static inline void plane_copy_vflip( x264_mc_functions_t *mc, diff --git a/common/frame.c b/common/frame.c index 99529d0a..f16fe17d 100644 --- a/common/frame.c +++ b/common/frame.c @@ -21,12 +21,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#include -#include -#ifndef _MSC_VER -#include -#endif - #include "common.h" #define PADH 32 diff --git a/common/macroblock.c b/common/macroblock.c index 3ecda66c..6bd2c83b 100644 --- a/common/macroblock.c +++ b/common/macroblock.c @@ -21,9 +21,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#include -#include - #include "common.h" int x264_mb_predict_intra4x4_mode( x264_t *h, int idx ) diff --git a/common/mc.c b/common/mc.c index 9a498caa..6d3a226b 100644 --- a/common/mc.c +++ b/common/mc.c @@ -21,9 +21,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#include -#include - #include "common.h" #include "clip1.h" diff --git a/common/mdate.c b/common/mdate.c index c57becbd..a856ac10 100644 --- a/common/mdate.c +++ b/common/mdate.c @@ -21,12 +21,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#ifdef HAVE_STDINT_H -#include -#else -#include -#endif - #if !(defined(_MSC_VER) || defined(__MINGW32__)) #include #else @@ -35,6 +29,8 @@ #endif #include +#include "osdep.h" + int64_t x264_mdate( void ) { #if !(defined(_MSC_VER) || defined(__MINGW32__)) diff --git a/common/osdep.h b/common/osdep.h new file mode 100644 index 00000000..7edfa5cb --- /dev/null +++ b/common/osdep.h @@ -0,0 +1,108 @@ +/***************************************************************************** + * common.h: h264 encoder + ***************************************************************************** + * Copyright (C) 2007 x264 project + * + * 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 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + *****************************************************************************/ + +#ifndef _OSDEP_H +#define _OSDEP_H + +#ifdef HAVE_STDINT_H +#include +#else +#include +#endif + +#define _LARGEFILE_SOURCE 1 +#define _FILE_OFFSET_BITS 64 +#include + +#ifdef _MSC_VER +#include // _setmode() +#include // _O_BINARY +#define inline __inline +#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 +#ifdef __WIN32__ // POSIX says that rename() removes the destination, but win32 doesn't. +#define rename(src,dst) (unlink(dst), rename(src,dst)) +#endif + +#ifdef _MSC_VER +#define DECLARE_ALIGNED( type, var, n ) __declspec(align(n)) type var +#else +#define DECLARE_ALIGNED( type, var, n ) type var __attribute__((aligned(n))) +#endif + +#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) +#define UNUSED __attribute__((unused)) +#else +#define UNUSED +#endif + +/* threads */ +#if defined(__WIN32__) && defined(HAVE_PTHREAD) +#include +#define USE_CONDITION_VAR + +#elif defined(SYS_BEOS) +#include +#define pthread_t thread_id +#define pthread_create(t,u,f,d) { *(t)=spawn_thread(f,"",10,d); \ + resume_thread(*(t)); } +#define pthread_join(t,s) { long tmp; \ + wait_for_thread(t,(s)?(long*)(s):&tmp); } +#ifndef usleep +#define usleep(t) snooze(t) +#endif +#define HAVE_PTHREAD 1 + +#elif defined(HAVE_PTHREAD) +#include +#define USE_CONDITION_VAR +#else +#define pthread_t int +#define pthread_create(t,u,f,d) +#define pthread_join(t,s) +#endif //SYS_* + +#ifndef USE_CONDITION_VAR +#define pthread_mutex_t int +#define pthread_mutex_init(m,f) +#define pthread_mutex_destroy(m) +#define pthread_mutex_lock(m) +#define pthread_mutex_unlock(m) +#define pthread_cond_t int +#define pthread_cond_init(c,f) +#define pthread_cond_destroy(c) +#define pthread_cond_broadcast(c) +#define pthread_cond_wait(c,m) usleep(100) +#endif + +#endif //_OSDEP_H diff --git a/common/pixel.c b/common/pixel.c index 1ccfb6e8..39fb210e 100644 --- a/common/pixel.c +++ b/common/pixel.c @@ -21,8 +21,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#include - #include "common.h" #include "clip1.h" diff --git a/common/set.c b/common/set.c index 8a6886f7..e49de9b0 100644 --- a/common/set.c +++ b/common/set.c @@ -21,8 +21,6 @@ *****************************************************************************/ #include "common.h" -#include -#include #define SHIFT(x,s) ((s)<0 ? (x)<<-(s) : (s)==0 ? (x) : ((x)+(1<<((s)-1)))>>(s)) #define DIV(n,d) (((n) + ((d)>>1)) / (d)) diff --git a/common/visualize.c b/common/visualize.c index 8bd02d86..a5f90290 100644 --- a/common/visualize.c +++ b/common/visualize.c @@ -39,14 +39,6 @@ * pink blocks with a diagonal line are predicted using the planar function. */ -#ifdef HAVE_STDINT_H -#include -#else -#include -#endif -#include /* NULL */ -#include /* getchar */ - #include "common.h" #include "visualize.h" #include "display.h" diff --git a/encoder/analyse.c b/encoder/analyse.c index b4795638..1e1db9ea 100644 --- a/encoder/analyse.c +++ b/encoder/analyse.c @@ -22,8 +22,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#include -#include #include #include #ifndef _MSC_VER diff --git a/encoder/cabac.c b/encoder/cabac.c index dc7f6596..f5ece2bc 100644 --- a/encoder/cabac.c +++ b/encoder/cabac.c @@ -21,9 +21,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#include -#include - #include "common/common.h" #include "macroblock.h" diff --git a/encoder/cavlc.c b/encoder/cavlc.c index 52aec281..6ac15b19 100644 --- a/encoder/cavlc.c +++ b/encoder/cavlc.c @@ -21,9 +21,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#include -#include - #include "common/common.h" #include "common/vlc.h" #include "macroblock.h" diff --git a/encoder/encoder.c b/encoder/encoder.c index 8917ae1a..a48ed1e7 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -21,8 +21,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#include -#include #include #include "common/common.h" diff --git a/encoder/macroblock.c b/encoder/macroblock.c index ec7e9b80..c0967fe0 100644 --- a/encoder/macroblock.c +++ b/encoder/macroblock.c @@ -21,9 +21,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#include -#include - #include "common/common.h" #include "macroblock.h" diff --git a/encoder/me.c b/encoder/me.c index ffd18140..eb9d1246 100644 --- a/encoder/me.c +++ b/encoder/me.c @@ -22,9 +22,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#include -#include - #include "common/common.h" #include "me.h" diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index 9b92dbeb..20425a77 100644 --- a/encoder/ratecontrol.c +++ b/encoder/ratecontrol.c @@ -25,8 +25,6 @@ #define _ISOC99_SOURCE #undef NDEBUG // always check asserts, the speed effect is far too small to disable them -#include -#include #include #include #include @@ -35,19 +33,6 @@ #include "common/cpu.h" #include "ratecontrol.h" -#if defined(SYS_OPENBSD) -#define isfinite finite -#endif -#if defined(_MSC_VER) -#define isfinite _finite -#endif -#if defined(_MSC_VER) || defined(SYS_SunOS) || defined(SYS_MACOSX) -#define sqrtf sqrt -#endif -#ifdef WIN32 // POSIX says that rename() removes the destination, but win32 doesn't. -#define rename(src,dst) (unlink(dst), rename(src,dst)) -#endif - typedef struct { int pict_type; diff --git a/encoder/set.c b/encoder/set.c index 200840b5..04fe8261 100644 --- a/encoder/set.c +++ b/encoder/set.c @@ -21,8 +21,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#include -#include #include #include "common/common.h" diff --git a/encoder/slicetype.c b/encoder/slicetype.c index d3e1194e..bfe44e57 100644 --- a/encoder/slicetype.c +++ b/encoder/slicetype.c @@ -20,7 +20,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#include #include #include diff --git a/matroska.c b/matroska.c index fb7e4d0c..917acebc 100644 --- a/matroska.c +++ b/matroska.c @@ -21,19 +21,9 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#define _LARGEFILE_SOURCE -#define _FILE_OFFSET_BITS 64 - -#include #include #include - -#ifdef HAVE_STDINT_H -#include -#else -#include -#endif - +#include "common/osdep.h" #include "matroska.h" #define CLSIZE 1048576 diff --git a/muxers.c b/muxers.c index 6a7f76e2..46315367 100644 --- a/muxers.c +++ b/muxers.c @@ -18,11 +18,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#define _LARGEFILE_SOURCE -#define _FILE_OFFSET_BITS 64 - -#include -#include #include #include "common/common.h" @@ -257,7 +252,7 @@ int get_frame_total_y4m( hnd_t handle ) { y4m_input_t *h = handle; int i_frame_total = 0; - off_t init_pos = ftell(h->fh); + uint64_t init_pos = ftell(h->fh); if( !fseek( h->fh, 0, SEEK_END ) ) { diff --git a/muxers.h b/muxers.h index 7ce84afb..eef40cd4 100644 --- a/muxers.h +++ b/muxers.h @@ -13,19 +13,15 @@ int get_frame_total_y4m( hnd_t handle ); int read_frame_y4m( x264_picture_t *p_pic, hnd_t handle, int i_frame ); int close_file_y4m( hnd_t handle ); -#ifdef AVIS_INPUT int open_file_avis( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param ); int get_frame_total_avis( hnd_t handle ); int read_frame_avis( x264_picture_t *p_pic, hnd_t handle, int i_frame ); int close_file_avis( hnd_t handle ); -#endif -#ifdef HAVE_PTHREAD int open_file_thread( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param ); int get_frame_total_thread( hnd_t handle ); int read_frame_thread( x264_picture_t *p_pic, hnd_t handle, int i_frame ); int close_file_thread( hnd_t handle ); -#endif int open_file_bsf( char *psz_filename, hnd_t *p_handle ); int set_param_bsf( hnd_t handle, x264_param_t *p_param ); @@ -33,13 +29,11 @@ int write_nalu_bsf( hnd_t handle, uint8_t *p_nal, int i_size ); int set_eop_bsf( hnd_t handle, x264_picture_t *p_picture ); int close_file_bsf( hnd_t handle ); -#ifdef MP4_OUTPUT int open_file_mp4( char *psz_filename, hnd_t *p_handle ); int set_param_mp4( hnd_t handle, x264_param_t *p_param ); int write_nalu_mp4( hnd_t handle, uint8_t *p_nal, int i_size ); int set_eop_mp4( hnd_t handle, x264_picture_t *p_picture ); int close_file_mp4( hnd_t handle ); -#endif int open_file_mkv( char *psz_filename, hnd_t *p_handle ); int set_param_mkv( hnd_t handle, x264_param_t *p_param ); diff --git a/tools/checkasm.c b/tools/checkasm.c index 8e77fbb7..07c9210f 100644 --- a/tools/checkasm.c +++ b/tools/checkasm.c @@ -1,6 +1,4 @@ -#include #include -#include #include #include "common/common.h" diff --git a/x264.c b/x264.c index d864b513..73877c9a 100644 --- a/x264.c +++ b/x264.c @@ -21,31 +21,21 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -#define _LARGEFILE_SOURCE -#define _FILE_OFFSET_BITS 64 - #include -#include -#include #include #include #define _GNU_SOURCE #include -#ifdef _MSC_VER -#include /* _setmode() */ -#include /* _O_BINARY */ -#endif +#include "common/common.h" +#include "x264.h" +#include "muxers.h" #ifndef _MSC_VER #include "config.h" #endif -#include "common/common.h" -#include "x264.h" -#include "muxers.h" - uint8_t *mux_buffer = NULL; int mux_buffer_size = 0;