diff --git a/ffserver.c b/ffserver.c
index 33508ec5eb9e5711513aad94626be72c8e71db7e..aa8e72c8964148341985ef8e2ebdb9f52939d7cf 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -17,10 +17,10 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 #define HAVE_AV_CONFIG_H
-#include <netinet/in.h>
 #include "avformat.h"
 
 #include <stdarg.h>
+#include <netinet/in.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
@@ -31,11 +31,7 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/wait.h>
-#ifndef __BEOS__
-# include <arpa/inet.h>
-#else
-# include "libav/barpainet.h"
-#endif
+#include <arpa/inet.h>
 #include <netdb.h>
 #include <ctype.h>
 #include <signal.h>
diff --git a/libav/http.c b/libav/http.c
index 64025f2258e82547602b4a35a9ce014156c70b1a..7271a6da818a960b9bccb4716d76174e505a5476 100644
--- a/libav/http.c
+++ b/libav/http.c
@@ -16,11 +16,11 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-#include <sys/socket.h>
 #include "avformat.h"
 #include <unistd.h>
 #include <ctype.h>
 #include <sys/types.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #ifndef __BEOS__
 # include <arpa/inet.h>
diff --git a/libav/rtp.c b/libav/rtp.c
index b42065fbea666b92dcdcc804110cde6db68df6b6..714787c88b119c118a2f8bbfed3c8d2f38b054c8 100644
--- a/libav/rtp.c
+++ b/libav/rtp.c
@@ -16,11 +16,11 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-#include <sys/socket.h>
 #include "avformat.h"
 
 #include <unistd.h>
 #include <sys/types.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #ifndef __BEOS__
 # include <arpa/inet.h>
diff --git a/libav/rtpproto.c b/libav/rtpproto.c
index 25b10b8bf2810b9f7df74cea6fb43bd524eef101..41823fc82937b6ae81a9c7c31dcdd57c602e2099 100644
--- a/libav/rtpproto.c
+++ b/libav/rtpproto.c
@@ -16,12 +16,12 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-#include <sys/socket.h>
 #include "avformat.h"
 
 #include <unistd.h>
 #include <stdarg.h>
 #include <sys/types.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #ifndef __BEOS__
 # include <arpa/inet.h>
diff --git a/libav/rtsp.c b/libav/rtsp.c
index 667a3c095a14d168d72e2c5714f6e47631115dd4..81b59f89161aacce2ec6b9b0363f5d5c0b34367d 100644
--- a/libav/rtsp.c
+++ b/libav/rtsp.c
@@ -16,10 +16,10 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-#include <netinet/in.h>
 #include "avformat.h"
 
 #include <sys/time.h>
+#include <netinet/in.h>
 #include <sys/socket.h>
 #ifndef __BEOS__
 # include <arpa/inet.h>
diff --git a/libav/tcp.c b/libav/tcp.c
index 6f4c037dcb9e7b403b5b2c8edd1345d0710a46f6..61d8665525dda72d35f8ebb2e2de652d9df3d40c 100644
--- a/libav/tcp.c
+++ b/libav/tcp.c
@@ -16,11 +16,11 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-#include <sys/socket.h>
 #include "avformat.h"
 #include <unistd.h>
 #include <ctype.h>
 #include <sys/types.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #ifndef __BEOS__
 # include <arpa/inet.h>
diff --git a/libav/udp.c b/libav/udp.c
index 6e91a22350ae50809db8ec042bc73c3d62261d8e..8df93a8a8a9ec23967d7061046f434bc3456105a 100644
--- a/libav/udp.c
+++ b/libav/udp.c
@@ -16,10 +16,10 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-#include <sys/socket.h>
 #include "avformat.h"
 #include <unistd.h>
 #include <sys/types.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #ifndef __BEOS__
 # include <arpa/inet.h>
diff --git a/libavcodec/common.h b/libavcodec/common.h
index 67e25c76ac62843d70d25fd543ef00eb0f2aaa65..73e2d08f2e5bb2769c187c63a10e142b898d5022 100644
--- a/libavcodec/common.h
+++ b/libavcodec/common.h
@@ -161,13 +161,8 @@ inline void dprintf(const char* fmt,...) {}
 #define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
 #define ABS(a) ((a) >= 0 ? (a) : (-(a)))
 
-#ifndef MAX
-#    define MAX(a,b) ((a) > (b) ? (a) : (b))
-#endif
-
-#ifndef MIN
-#    define MIN(a,b) ((a) > (b) ? (b) : (a))
-#endif
+#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
+#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
 
 #ifdef ARCH_X86
 // avoid +32 for shift optimization (gcc should do that ...)
diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c
index 84b7bb8a0212198176ae63ae0720c27b3cde3ca2..5023ff2f4a45ee3e9a927f4329a7023ad8d86617 100644
--- a/libavcodec/error_resilience.c
+++ b/libavcodec/error_resilience.c
@@ -209,7 +209,7 @@ static void h_block_filter(MpegEncContext *s, UINT8 *dst, int w, int h, int stri
                 c= dst[offset + 9 + y*stride] - dst[offset + 8 + y*stride];
                 
                 d= ABS(b) - ((ABS(a) + ABS(c) + 1)>>1);
-                d= MAX(d, 0);
+                d= FFMAX(d, 0);
                 if(b<0) d= -d;
                 
                 if(d==0) continue;
@@ -269,7 +269,7 @@ static void v_block_filter(MpegEncContext *s, UINT8 *dst, int w, int h, int stri
                 c= dst[offset + x + 9*stride] - dst[offset + x + 8*stride];
                 
                 d= ABS(b) - ((ABS(a) + ABS(c)+1)>>1);
-                d= MAX(d, 0);
+                d= FFMAX(d, 0);
                 if(b<0) d= -d;
                 
                 if(d==0) continue;
@@ -430,10 +430,10 @@ int score_sum=0;
                             min_x=min_y=max_x=max_y=0;
                         }
                         for(j=0; j<pred_count; j++){
-                            max_x= MAX(max_x, mv_predictor[j][0]);
-                            max_y= MAX(max_y, mv_predictor[j][1]);
-                            min_x= MIN(min_x, mv_predictor[j][0]);
-                            min_y= MIN(min_y, mv_predictor[j][1]);
+                            max_x= FFMAX(max_x, mv_predictor[j][0]);
+                            max_y= FFMAX(max_y, mv_predictor[j][1]);
+                            min_x= FFMIN(min_x, mv_predictor[j][0]);
+                            min_y= FFMIN(min_y, mv_predictor[j][1]);
                         }
                         mv_predictor[pred_count+1][0] = sum_x - max_x - min_x;
                         mv_predictor[pred_count+1][1] = sum_y - max_y - min_y;
@@ -538,7 +538,7 @@ static int is_intra_more_likely(MpegEncContext *s){
     
     if(undamaged_count < 5) return 0; //allmost all MBs damaged -> use temporal prediction
     
-    skip_amount= MAX(undamaged_count/50, 1); //check only upto 50 MBs 
+    skip_amount= FFMAX(undamaged_count/50, 1); //check only upto 50 MBs 
     is_intra_likely=0;
 
     j=0;
diff --git a/libavcodec/h263.c b/libavcodec/h263.c
index 2c8b1ece32741bed544dfa905d016d6d704a1a05..df6fe37487bf93fd83feb210148681db127fa918 100644
--- a/libavcodec/h263.c
+++ b/libavcodec/h263.c
@@ -2204,7 +2204,7 @@ int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s){
         case S_TYPE:
             return s->f_code+15;
         case B_TYPE:
-            return MAX(MAX(s->f_code, s->b_code)+15, 17);
+            return FFMAX(FFMAX(s->f_code, s->b_code)+15, 17);
         default:
             return -1;
     }
@@ -3981,7 +3981,7 @@ static void mpeg4_decode_sprite_trajectory(MpegEncContext * s)
             s->sprite_shift[1]= alpha+rho+2;
             break;
         case 3:
-            min_ab= MIN(alpha, beta);
+            min_ab= FFMIN(alpha, beta);
             w3= w2>>min_ab;
             h3= h2>>min_ab;
             s->sprite_offset[0][0]=  (sprite_ref[0][0]<<(alpha+beta+rho-min_ab))
diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c
index e94657dcaa06c8ead2baa92a8eb1f82039c626f6..81447b3b66107ab5c587be1e446f1343251ff873 100644
--- a/libavcodec/motion_est.c
+++ b/libavcodec/motion_est.c
@@ -1600,8 +1600,8 @@ int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type)
             i= y*s->mb_width;
             for(x=0; x<s->mb_width; x++){
                 if(s->mb_type[i] & type){
-                    int fcode= MAX(fcode_tab[mv_table[xy][0] + MAX_MV],
-                                   fcode_tab[mv_table[xy][1] + MAX_MV]);
+                    int fcode= FFMAX(fcode_tab[mv_table[xy][0] + MAX_MV],
+                                     fcode_tab[mv_table[xy][1] + MAX_MV]);
                     int j;
                     
                     for(j=0; j<fcode && j<8; j++){
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 4f139806b7496f53bf27f171a6430b8d8352585a..21690f591fd76aee0dc9cf1147227160ec0b13af 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -1264,10 +1264,10 @@ static void emulated_edge_mc(MpegEncContext *s, UINT8 *src, int linesize, int bl
         src_x=1-block_w;
     }
 
-    start_y= MAX(0, -src_y);
-    start_x= MAX(0, -src_x);
-    end_y= MIN(block_h, h-src_y);
-    end_x= MIN(block_w, w-src_x);
+    start_y= FFMAX(0, -src_y);
+    start_x= FFMAX(0, -src_x);
+    end_y= FFMIN(block_h, h-src_y);
+    end_x= FFMIN(block_w, w-src_x);
 
     // copy existing part
     for(y=start_y; y<end_y; y++){
diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c
index 81dc91fbb424a87b1aa8af48d5fb7d769c95dd0d..f1746b4f6dd6fc64902f1c7e84bf8442effac551 100644
--- a/libavcodec/msmpeg4.c
+++ b/libavcodec/msmpeg4.c
@@ -425,7 +425,7 @@ void msmpeg4_encode_ext_header(MpegEncContext * s)
 {
         put_bits(&s->pb, 5, s->frame_rate / FRAME_RATE_BASE); //yes 29.97 -> 29
 
-        put_bits(&s->pb, 11, MIN(s->bit_rate/1024, 2047));
+        put_bits(&s->pb, 11, FFMIN(s->bit_rate/1024, 2047));
 
         if(s->msmpeg4_version<3)
             s->flipflop_rounding=0;
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index 99e46dbad28d7dbb66f01d3b77a9a62948ab595b..870cd21e320143ddaecb6c96619b87163b03e9b3 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -405,7 +405,7 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q,
             else if(d<0.0001) d=0.0001;
             q*= pow(d, 1.0/s->avctx->rc_buffer_aggressivity);
 
-            q= MIN(q, bits2qp(rce, MAX((min_rate - buffer_size + rcc->buffer_index)*2, 1)));
+            q= FFMIN(q, bits2qp(rce, FFMAX((min_rate - buffer_size + rcc->buffer_index)*2, 1)));
         }
 
         if(max_rate){
@@ -414,7 +414,7 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q,
             else if(d<0.0001) d=0.0001;
             q/= pow(d, 1.0/s->avctx->rc_buffer_aggressivity);
 
-            q= MAX(q, bits2qp(rce, MAX(rcc->buffer_index/2, 1)));
+            q= FFMAX(q, bits2qp(rce, FFMAX(rcc->buffer_index/2, 1)));
         }
     }
 //printf("q:%f max:%f min:%f size:%f index:%d bits:%f agr:%f\n", q,max_rate, min_rate, buffer_size, rcc->buffer_index, bits, s->avctx->rc_buffer_aggressivity);