[MPlayer-dev-eng] [PATCH] Switch libavutil macros instead of defining our own

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sun Feb 25 11:58:05 CET 2007


Hello,
On Sat, Feb 24, 2007 at 06:35:10PM +0100, Reimar D?ffinger wrote:
> attached patch replaces MIN, MAX, BE_32 and BE_16 in some places with
> the libavutil equivalent.
> Do you think this is okay despite it's size?
> I assume it would also fix
> http://bugzilla.mplayerhq.hu/show_bug.cgi?id=767 along the way, though
> that is not really the main intention (and could be done by copying the
> definitions from rmff.c instead).

Improved and expanded to improve some other places I stumbled upon in a
quick search.
It does get a bit large, though the changes should be trivial to
understand.
If someone prefers it split (and in which way) please say so.

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: vobsub.c
===================================================================
--- vobsub.c	(revision 22339)
+++ vobsub.c	(working copy)
@@ -23,10 +23,8 @@
 #ifdef USE_UNRARLIB
 #include "unrarlib.h"
 #endif
+#include "libavutil/common.h"
 
-#define MIN(a, b)	((a)<(b)?(a):(b))
-#define MAX(a, b)	((a)>(b)?(a):(b))
-
 extern int vobsub_id;
 
 /**********************************************************************
@@ -820,9 +818,9 @@
 	r = tmp >> 16 & 0xff;
 	g = tmp >> 8 & 0xff;
 	b = tmp & 0xff;
-	y = MIN(MAX((int)(0.1494 * r + 0.6061 * g + 0.2445 * b), 0), 0xff);
-	u = MIN(MAX((int)(0.6066 * r - 0.4322 * g - 0.1744 * b) + 128, 0), 0xff);
-	v = MIN(MAX((int)(-0.08435 * r - 0.3422 * g + 0.4266 * b) + 128, 0), 0xff);
+	y = av_clip_uint8( 0.1494  * r + 0.6061 * g + 0.2445 * b);
+	u = av_clip_uint8( 0.6066  * r - 0.4322 * g - 0.1744 * b + 128);
+	v = av_clip_uint8(-0.08435 * r - 0.3422 * g + 0.4266 * b + 128);
 	vob->palette[n++] = y << 16 | u << 8 | v;
 	if (n == 16)
 	    break;
@@ -1332,9 +1330,9 @@
 	    if (i)
 		putc(',', me->fidx);
 	    fprintf(me->fidx, " %02x%02x%02x",
-		    MIN(MAX((int)(y + 1.4022 * u), 0), 0xff),
-		    MIN(MAX((int)(y - 0.3456 * u - 0.7145 * v), 0), 0xff),
-		    MIN(MAX((int)(y + 1.7710 * v), 0), 0xff));
+		    av_clip_uint8(y + 1.4022 * u),
+		    av_clip_uint8(y - 0.3456 * u - 0.7145 * v),
+		    av_clip_uint8(y + 1.7710 * v));
 	}
 	putc('\n', me->fidx);
     }
Index: libmpcodecs/vf_bmovl.c
===================================================================
--- libmpcodecs/vf_bmovl.c	(revision 22339)
+++ libmpcodecs/vf_bmovl.c	(working copy)
@@ -71,6 +71,7 @@
 #ifndef HAVE_NO_POSIX_SELECT
 
 #include "mp_msg.h"
+#include "libavutil/common.h"
 
 #include "libvo/fastmemcpy.h"
 
@@ -89,8 +90,6 @@
 #define TRUE  1
 #define FALSE 0
 
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
 #define INRANGE(a,b,c)	( ((a) < (b)) ? (b) : ( ((a) > (c)) ? (c) : (a) ) )
 
 #define rgb2y(R,G,B)  ( (( 263*R + 516*G + 100*B) >> 10) + 16  )
@@ -298,10 +297,10 @@
 					vf->priv->x2 = vf->priv->y2 = 0;
 				}
 				// Define how much of our bitmap that contains graphics!
-				vf->priv->x1 = MAX( 0, MIN(vf->priv->x1, imgx) );
-				vf->priv->y1 = MAX( 0, MIN(vf->priv->y1, imgy) );
-				vf->priv->x2 = MIN( vf->priv->w, MAX(vf->priv->x2, ( imgx + imgw)) );
-				vf->priv->y2 = MIN( vf->priv->h, MAX(vf->priv->y2, ( imgy + imgh)) );
+				vf->priv->x1 = av_clip(imgx, 0, vf->priv->x1);
+				vf->priv->y1 = av_clip(imgy, 0, vf->priv->y1);
+				vf->priv->x2 = av_clip(imgx + imgw, vf->priv->x2, vf->priv->w);
+				vf->priv->y2 = av_clip(imgy + imgh, vf->priv->y2, vf->priv->h);
 			}
 			
 			if( command == CMD_CLEAR ) {
Index: libmpcodecs/vf_unsharp.c
===================================================================
--- libmpcodecs/vf_unsharp.c	(revision 22339)
+++ libmpcodecs/vf_unsharp.c	(working copy)
@@ -35,14 +35,8 @@
 #include "mp_image.h"
 #include "vf.h"
 #include "libvo/fastmemcpy.h"
+#include "libavutil/common.h"
 
-#ifndef MIN
-#define        MIN(a,b) (((a)<(b))?(a):(b))
-#endif
-#ifndef MAX
-#define        MAX(a,b) (((a)>(b))?(a):(b))
-#endif
-
 //===========================================================================//
 
 #define MIN_MATRIX_SIZE 3
@@ -258,8 +252,8 @@
     fp->msizeY = ( z && z+1<max ) ? atoi( pos=z+1 ) : fp->msizeX;
 
     // min/max & odd
-    fp->msizeX = 1 | MIN( MAX( fp->msizeX, MIN_MATRIX_SIZE ), MAX_MATRIX_SIZE );
-    fp->msizeY = 1 | MIN( MAX( fp->msizeY, MIN_MATRIX_SIZE ), MAX_MATRIX_SIZE );
+    fp->msizeX = 1 | av_clip(fp->msizeX, MIN_MATRIX_SIZE, MAX_MATRIX_SIZE);
+    fp->msizeY = 1 | av_clip(fp->msizeY, MIN_MATRIX_SIZE, MAX_MATRIX_SIZE);
 
     // parse amount
     pos = strchr( pos+1, ':' );
Index: stream/realrtsp/real.c
===================================================================
--- stream/realrtsp/real.c	(revision 22339)
+++ stream/realrtsp/real.c	(working copy)
@@ -32,7 +32,6 @@
 
 #include "../config.h"
 #include "libavutil/common.h"
-#include "mpbswap.h"
 #include "real.h"
 #include "asmrp.h"
 #include "sdpplin.h"
@@ -42,6 +41,7 @@
 #else
 #include "libavutil/md5.h"
 #endif
+#include "libavutil/intreadwrite.h"
 #include "../http.h"
 #include "mp_msg.h"
 
@@ -57,16 +57,6 @@
     0x10, 0x57, 0x05, 0x18, 0x54, 0x00, 0x00, 0x00 };
 
 
-#define BE_32C(x,y) (*((uint32_t*)(x))=be2me_32(y))
-
-#define BE_16(x)  be2me_16(*(uint16_t*)(x))
-
-#define BE_32(x)  be2me_32(*(uint32_t*)(x))
-
-#ifndef MAX
-#define MAX(x,y) ((x>y) ? x : y)
-#endif
-
 #define BUF_SIZE 4096
 
 #ifdef LOG
@@ -125,9 +115,9 @@
   /* initialize buffer */
   memset(buf, 0, 128);
   ptr=buf;
-  BE_32C(ptr, 0xa1e9149d);
+  AV_WB32(ptr, 0xa1e9149d);
   ptr+=4;
-  BE_32C(ptr, 0x0e6b3b59);
+  AV_WB32(ptr, 0x0e6b3b59);
   ptr+=4;
 
   /* some (length) checks */
@@ -193,7 +183,7 @@
   mlti_chunk+=4;
 
   /* next 16 bits are the number of rules */
-  numrules=BE_16(mlti_chunk);
+  numrules=AV_RB16(mlti_chunk);
   if (selection >= numrules) return 0;
 
   /* now <numrules> indices of codecs follows */
@@ -201,13 +191,13 @@
   mlti_chunk+=(selection+1)*2;
 
   /* get our index */
-  codec=BE_16(mlti_chunk);
+  codec=AV_RB16(mlti_chunk);
 
   /* skip to number of codecs */
   mlti_chunk+=(numrules-selection)*2;
 
   /* get number of codecs */
-  numrules=BE_16(mlti_chunk);
+  numrules=AV_RB16(mlti_chunk);
 
   if (codec >= numrules) {
     mp_msg(MSGT_STREAM, MSGL_WARN, "realrtsp: codec index >= number of codecs. %i %i\n",
@@ -219,11 +209,11 @@
  
   /* now seek to selected codec */
   for (i=0; i<codec; i++) {
-    size=BE_32(mlti_chunk);
+    size=AV_RB32(mlti_chunk);
     mlti_chunk+=size+4;
   }
   
-  size=BE_32(mlti_chunk);
+  size=AV_RB32(mlti_chunk);
 
 #ifdef LOG
   hexdump(mlti_chunk+4, size);
@@ -309,10 +299,10 @@
 	len,
 	buf);
 
-    duration=MAX(duration,desc->stream[i]->duration);
+    duration=FFMAX(duration,desc->stream[i]->duration);
     max_bit_rate+=desc->stream[i]->max_bit_rate;
     avg_bit_rate+=desc->stream[i]->avg_bit_rate;
-    max_packet_size=MAX(max_packet_size, desc->stream[i]->max_packet_size);
+    max_packet_size=FFMAX(max_packet_size, desc->stream[i]->max_packet_size);
     if (avg_packet_size)
       avg_packet_size=(avg_packet_size + desc->stream[i]->avg_packet_size) / 2;
     else
@@ -392,7 +382,7 @@
   unknown1=(header[5]<<16)+(header[6]<<8)+(header[7]);
   n=rtsp_read_data(rtsp_session, header, 6);
   if (n<6) return 0;
-  ts=BE_32(header);
+  ts=AV_RB32(header);
   
 #ifdef LOG
   printf("ts: %u, size: %u, flags: 0x%02x, unknown values: 0x%06x 0x%02x 0x%02x\n", 
Index: stream/realrtsp/rmff.c
===================================================================
--- stream/realrtsp/rmff.c	(revision 22339)
+++ stream/realrtsp/rmff.c	(working copy)
@@ -29,17 +29,12 @@
 #include "rmff.h"
 #include "xbuffer.h"
 #include "mp_msg.h"
+#include "libavutil/intreadwrite.h"
 
 /*
 #define LOG
 */
 
-#define BE_16(x)  ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
-#define BE_32(x)  ((((uint8_t*)(x))[0] << 24) | \
-                   (((uint8_t*)(x))[1] << 16) | \
-                   (((uint8_t*)(x))[2] << 8) | \
-                    ((uint8_t*)(x))[3])
-
 static void hexdump (const char *buf, int length) {
 
   int i;
@@ -78,40 +73,40 @@
 static void rmff_dump_fileheader(rmff_fileheader_t *fileheader, char *buffer) {
 
   if (!fileheader) return;
-  fileheader->object_id=BE_32(&fileheader->object_id);
-  fileheader->size=BE_32(&fileheader->size);
-  fileheader->object_version=BE_16(&fileheader->object_version);
-  fileheader->file_version=BE_32(&fileheader->file_version);
-  fileheader->num_headers=BE_32(&fileheader->num_headers);
+  fileheader->object_id=AV_RB32(&fileheader->object_id);
+  fileheader->size=AV_RB32(&fileheader->size);
+  fileheader->object_version=AV_RB16(&fileheader->object_version);
+  fileheader->file_version=AV_RB32(&fileheader->file_version);
+  fileheader->num_headers=AV_RB32(&fileheader->num_headers);
   
   memcpy(buffer, fileheader, 8);
   memcpy(&buffer[8], &fileheader->object_version, 2);
   memcpy(&buffer[10], &fileheader->file_version, 8);
 
-  fileheader->size=BE_32(&fileheader->size);
-  fileheader->object_version=BE_16(&fileheader->object_version);
-  fileheader->file_version=BE_32(&fileheader->file_version);
-  fileheader->num_headers=BE_32(&fileheader->num_headers);
-  fileheader->object_id=BE_32(&fileheader->object_id);
+  fileheader->size=AV_RB32(&fileheader->size);
+  fileheader->object_version=AV_RB16(&fileheader->object_version);
+  fileheader->file_version=AV_RB32(&fileheader->file_version);
+  fileheader->num_headers=AV_RB32(&fileheader->num_headers);
+  fileheader->object_id=AV_RB32(&fileheader->object_id);
 }
 
 static void rmff_dump_prop(rmff_prop_t *prop, char *buffer) {
 
   if (!prop) return;
-  prop->object_id=BE_32(&prop->object_id);
-  prop->size=BE_32(&prop->size);
-  prop->object_version=BE_16(&prop->object_version);
-  prop->max_bit_rate=BE_32(&prop->max_bit_rate);
-  prop->avg_bit_rate=BE_32(&prop->avg_bit_rate);
-  prop->max_packet_size=BE_32(&prop->max_packet_size);
-  prop->avg_packet_size=BE_32(&prop->avg_packet_size);
-  prop->num_packets=BE_32(&prop->num_packets);
-  prop->duration=BE_32(&prop->duration);
-  prop->preroll=BE_32(&prop->preroll);
-  prop->index_offset=BE_32(&prop->index_offset);
-  prop->data_offset=BE_32(&prop->data_offset);
-  prop->num_streams=BE_16(&prop->num_streams);
-  prop->flags=BE_16(&prop->flags);
+  prop->object_id=AV_RB32(&prop->object_id);
+  prop->size=AV_RB32(&prop->size);
+  prop->object_version=AV_RB16(&prop->object_version);
+  prop->max_bit_rate=AV_RB32(&prop->max_bit_rate);
+  prop->avg_bit_rate=AV_RB32(&prop->avg_bit_rate);
+  prop->max_packet_size=AV_RB32(&prop->max_packet_size);
+  prop->avg_packet_size=AV_RB32(&prop->avg_packet_size);
+  prop->num_packets=AV_RB32(&prop->num_packets);
+  prop->duration=AV_RB32(&prop->duration);
+  prop->preroll=AV_RB32(&prop->preroll);
+  prop->index_offset=AV_RB32(&prop->index_offset);
+  prop->data_offset=AV_RB32(&prop->data_offset);
+  prop->num_streams=AV_RB16(&prop->num_streams);
+  prop->flags=AV_RB16(&prop->flags);
 
   memcpy(buffer, prop, 8);
   memcpy(&buffer[8], &prop->object_version, 2);
@@ -119,20 +114,20 @@
   memcpy(&buffer[46], &prop->num_streams, 2);
   memcpy(&buffer[48], &prop->flags, 2);
   
-  prop->size=BE_32(&prop->size);
-  prop->object_version=BE_16(&prop->object_version);
-  prop->max_bit_rate=BE_32(&prop->max_bit_rate);
-  prop->avg_bit_rate=BE_32(&prop->avg_bit_rate);
-  prop->max_packet_size=BE_32(&prop->max_packet_size);
-  prop->avg_packet_size=BE_32(&prop->avg_packet_size);
-  prop->num_packets=BE_32(&prop->num_packets);
-  prop->duration=BE_32(&prop->duration);
-  prop->preroll=BE_32(&prop->preroll);
-  prop->index_offset=BE_32(&prop->index_offset);
-  prop->data_offset=BE_32(&prop->data_offset);
-  prop->num_streams=BE_16(&prop->num_streams);
-  prop->flags=BE_16(&prop->flags);
-  prop->object_id=BE_32(&prop->object_id);
+  prop->size=AV_RB32(&prop->size);
+  prop->object_version=AV_RB16(&prop->object_version);
+  prop->max_bit_rate=AV_RB32(&prop->max_bit_rate);
+  prop->avg_bit_rate=AV_RB32(&prop->avg_bit_rate);
+  prop->max_packet_size=AV_RB32(&prop->max_packet_size);
+  prop->avg_packet_size=AV_RB32(&prop->avg_packet_size);
+  prop->num_packets=AV_RB32(&prop->num_packets);
+  prop->duration=AV_RB32(&prop->duration);
+  prop->preroll=AV_RB32(&prop->preroll);
+  prop->index_offset=AV_RB32(&prop->index_offset);
+  prop->data_offset=AV_RB32(&prop->data_offset);
+  prop->num_streams=AV_RB16(&prop->num_streams);
+  prop->flags=AV_RB16(&prop->flags);
+  prop->object_id=AV_RB32(&prop->object_id);
 }
 
 static void rmff_dump_mdpr(rmff_mdpr_t *mdpr, char *buffer) {
@@ -140,17 +135,17 @@
   int s1, s2, s3;
 
   if (!mdpr) return;
-  mdpr->object_id=BE_32(&mdpr->object_id);
-  mdpr->size=BE_32(&mdpr->size);
-  mdpr->object_version=BE_16(&mdpr->object_version);
-  mdpr->stream_number=BE_16(&mdpr->stream_number);
-  mdpr->max_bit_rate=BE_32(&mdpr->max_bit_rate);
-  mdpr->avg_bit_rate=BE_32(&mdpr->avg_bit_rate);
-  mdpr->max_packet_size=BE_32(&mdpr->max_packet_size);
-  mdpr->avg_packet_size=BE_32(&mdpr->avg_packet_size);
-  mdpr->start_time=BE_32(&mdpr->start_time);
-  mdpr->preroll=BE_32(&mdpr->preroll);
-  mdpr->duration=BE_32(&mdpr->duration);
+  mdpr->object_id=AV_RB32(&mdpr->object_id);
+  mdpr->size=AV_RB32(&mdpr->size);
+  mdpr->object_version=AV_RB16(&mdpr->object_version);
+  mdpr->stream_number=AV_RB16(&mdpr->stream_number);
+  mdpr->max_bit_rate=AV_RB32(&mdpr->max_bit_rate);
+  mdpr->avg_bit_rate=AV_RB32(&mdpr->avg_bit_rate);
+  mdpr->max_packet_size=AV_RB32(&mdpr->max_packet_size);
+  mdpr->avg_packet_size=AV_RB32(&mdpr->avg_packet_size);
+  mdpr->start_time=AV_RB32(&mdpr->start_time);
+  mdpr->preroll=AV_RB32(&mdpr->preroll);
+  mdpr->duration=AV_RB32(&mdpr->duration);
 
   memcpy(buffer, mdpr, 8);
   memcpy(&buffer[8], &mdpr->object_version, 2);
@@ -164,22 +159,22 @@
   s2=mdpr->mime_type_size;
   memcpy(&buffer[42+s1], mdpr->mime_type, s2);
   
-  mdpr->type_specific_len=BE_32(&mdpr->type_specific_len);
+  mdpr->type_specific_len=AV_RB32(&mdpr->type_specific_len);
   memcpy(&buffer[42+s1+s2], &mdpr->type_specific_len, 4);
-  mdpr->type_specific_len=BE_32(&mdpr->type_specific_len);
+  mdpr->type_specific_len=AV_RB32(&mdpr->type_specific_len);
   s3=mdpr->type_specific_len;
   memcpy(&buffer[46+s1+s2], mdpr->type_specific_data, s3);
 
-  mdpr->size=BE_32(&mdpr->size);
-  mdpr->stream_number=BE_16(&mdpr->stream_number);
-  mdpr->max_bit_rate=BE_32(&mdpr->max_bit_rate);
-  mdpr->avg_bit_rate=BE_32(&mdpr->avg_bit_rate);
-  mdpr->max_packet_size=BE_32(&mdpr->max_packet_size);
-  mdpr->avg_packet_size=BE_32(&mdpr->avg_packet_size);
-  mdpr->start_time=BE_32(&mdpr->start_time);
-  mdpr->preroll=BE_32(&mdpr->preroll);
-  mdpr->duration=BE_32(&mdpr->duration);
-  mdpr->object_id=BE_32(&mdpr->object_id);
+  mdpr->size=AV_RB32(&mdpr->size);
+  mdpr->stream_number=AV_RB16(&mdpr->stream_number);
+  mdpr->max_bit_rate=AV_RB32(&mdpr->max_bit_rate);
+  mdpr->avg_bit_rate=AV_RB32(&mdpr->avg_bit_rate);
+  mdpr->max_packet_size=AV_RB32(&mdpr->max_packet_size);
+  mdpr->avg_packet_size=AV_RB32(&mdpr->avg_packet_size);
+  mdpr->start_time=AV_RB32(&mdpr->start_time);
+  mdpr->preroll=AV_RB32(&mdpr->preroll);
+  mdpr->duration=AV_RB32(&mdpr->duration);
+  mdpr->object_id=AV_RB32(&mdpr->object_id);
 
 }
 
@@ -188,59 +183,59 @@
   int p;
 
   if (!cont) return;
-  cont->object_id=BE_32(&cont->object_id);
-  cont->size=BE_32(&cont->size);
-  cont->object_version=BE_16(&cont->object_version);
+  cont->object_id=AV_RB32(&cont->object_id);
+  cont->size=AV_RB32(&cont->size);
+  cont->object_version=AV_RB16(&cont->object_version);
 
   memcpy(buffer, cont, 8);
   memcpy(&buffer[8], &cont->object_version, 2);
   
-  cont->title_len=BE_16(&cont->title_len);
+  cont->title_len=AV_RB16(&cont->title_len);
   memcpy(&buffer[10], &cont->title_len, 2);
-  cont->title_len=BE_16(&cont->title_len);
+  cont->title_len=AV_RB16(&cont->title_len);
   memcpy(&buffer[12], cont->title, cont->title_len);
   p=12+cont->title_len;
 
-  cont->author_len=BE_16(&cont->author_len);
+  cont->author_len=AV_RB16(&cont->author_len);
   memcpy(&buffer[p], &cont->author_len, 2);
-  cont->author_len=BE_16(&cont->author_len);
+  cont->author_len=AV_RB16(&cont->author_len);
   memcpy(&buffer[p+2], cont->author, cont->author_len);
   p+=2+cont->author_len;
 
-  cont->copyright_len=BE_16(&cont->copyright_len);
+  cont->copyright_len=AV_RB16(&cont->copyright_len);
   memcpy(&buffer[p], &cont->copyright_len, 2);
-  cont->copyright_len=BE_16(&cont->copyright_len);
+  cont->copyright_len=AV_RB16(&cont->copyright_len);
   memcpy(&buffer[p+2], cont->copyright, cont->copyright_len);
   p+=2+cont->copyright_len;
 
-  cont->comment_len=BE_16(&cont->comment_len);
+  cont->comment_len=AV_RB16(&cont->comment_len);
   memcpy(&buffer[p], &cont->comment_len, 2);
-  cont->comment_len=BE_16(&cont->comment_len);
+  cont->comment_len=AV_RB16(&cont->comment_len);
   memcpy(&buffer[p+2], cont->comment, cont->comment_len);
 
-  cont->size=BE_32(&cont->size);
-  cont->object_version=BE_16(&cont->object_version);
-  cont->object_id=BE_32(&cont->object_id);
+  cont->size=AV_RB32(&cont->size);
+  cont->object_version=AV_RB16(&cont->object_version);
+  cont->object_id=AV_RB32(&cont->object_id);
 }
 
 static void rmff_dump_dataheader(rmff_data_t *data, char *buffer) {
 
   if (!data) return;
-  data->object_id=BE_32(&data->object_id);
-  data->size=BE_32(&data->size);
-  data->object_version=BE_16(&data->object_version);
-  data->num_packets=BE_32(&data->num_packets);
-  data->next_data_header=BE_32(&data->next_data_header);
+  data->object_id=AV_RB32(&data->object_id);
+  data->size=AV_RB32(&data->size);
+  data->object_version=AV_RB16(&data->object_version);
+  data->num_packets=AV_RB32(&data->num_packets);
+  data->next_data_header=AV_RB32(&data->next_data_header);
 
   memcpy(buffer, data, 8);
   memcpy(&buffer[8], &data->object_version, 2);
   memcpy(&buffer[10], &data->num_packets, 8);
   
-  data->num_packets=BE_32(&data->num_packets);
-  data->next_data_header=BE_32(&data->next_data_header);
-  data->size=BE_32(&data->size);
-  data->object_version=BE_16(&data->object_version);
-  data->object_id=BE_32(&data->object_id);
+  data->num_packets=AV_RB32(&data->num_packets);
+  data->next_data_header=AV_RB32(&data->next_data_header);
+  data->size=AV_RB32(&data->size);
+  data->object_version=AV_RB16(&data->object_version);
+  data->object_id=AV_RB32(&data->object_id);
 }
 
 int rmff_dump_header(rmff_header_t *h, char *buffer, int max) {
@@ -290,16 +285,16 @@
 
   rmff_fileheader_t *fileheader=malloc(sizeof(rmff_fileheader_t));
 
-  fileheader->object_id=BE_32(data);
-  fileheader->size=BE_32(&data[4]);
-  fileheader->object_version=BE_16(&data[8]);
+  fileheader->object_id=AV_RB32(data);
+  fileheader->size=AV_RB32(&data[4]);
+  fileheader->object_version=AV_RB16(&data[8]);
   if (fileheader->object_version != 0)
   {
     mp_msg(MSGT_STREAM, MSGL_WARN, "warning: unknown object version in .RMF: 0x%04x\n",
       fileheader->object_version);
   }
-  fileheader->file_version=BE_32(&data[10]);
-  fileheader->num_headers=BE_32(&data[14]);
+  fileheader->file_version=AV_RB32(&data[10]);
+  fileheader->num_headers=AV_RB32(&data[14]);
 
   return fileheader;
 }
@@ -308,25 +303,25 @@
 
   rmff_prop_t *prop=malloc(sizeof(rmff_prop_t));
 
-  prop->object_id=BE_32(data);
-  prop->size=BE_32(&data[4]);
-  prop->object_version=BE_16(&data[8]);
+  prop->object_id=AV_RB32(data);
+  prop->size=AV_RB32(&data[4]);
+  prop->object_version=AV_RB16(&data[8]);
   if (prop->object_version != 0)
   {
     mp_msg(MSGT_STREAM, MSGL_WARN, "warning: unknown object version in PROP: 0x%04x\n",
       prop->object_version);
   }
-  prop->max_bit_rate=BE_32(&data[10]);
-  prop->avg_bit_rate=BE_32(&data[14]);
-  prop->max_packet_size=BE_32(&data[18]);
-  prop->avg_packet_size=BE_32(&data[22]);
-  prop->num_packets=BE_32(&data[26]);
-  prop->duration=BE_32(&data[30]);
-  prop->preroll=BE_32(&data[34]);
-  prop->index_offset=BE_32(&data[38]);
-  prop->data_offset=BE_32(&data[42]);
-  prop->num_streams=BE_16(&data[46]);
-  prop->flags=BE_16(&data[48]);
+  prop->max_bit_rate=AV_RB32(&data[10]);
+  prop->avg_bit_rate=AV_RB32(&data[14]);
+  prop->max_packet_size=AV_RB32(&data[18]);
+  prop->avg_packet_size=AV_RB32(&data[22]);
+  prop->num_packets=AV_RB32(&data[26]);
+  prop->duration=AV_RB32(&data[30]);
+  prop->preroll=AV_RB32(&data[34]);
+  prop->index_offset=AV_RB32(&data[38]);
+  prop->data_offset=AV_RB32(&data[42]);
+  prop->num_streams=AV_RB16(&data[46]);
+  prop->flags=AV_RB16(&data[48]);
 
   return prop;
 }
@@ -335,22 +330,22 @@
 
   rmff_mdpr_t *mdpr=malloc(sizeof(rmff_mdpr_t));
 
-  mdpr->object_id=BE_32(data);
-  mdpr->size=BE_32(&data[4]);
-  mdpr->object_version=BE_16(&data[8]);
+  mdpr->object_id=AV_RB32(data);
+  mdpr->size=AV_RB32(&data[4]);
+  mdpr->object_version=AV_RB16(&data[8]);
   if (mdpr->object_version != 0)
   {
     mp_msg(MSGT_STREAM, MSGL_WARN, "warning: unknown object version in MDPR: 0x%04x\n",
       mdpr->object_version);
   }
-  mdpr->stream_number=BE_16(&data[10]);
-  mdpr->max_bit_rate=BE_32(&data[12]);
-  mdpr->avg_bit_rate=BE_32(&data[16]);
-  mdpr->max_packet_size=BE_32(&data[20]);
-  mdpr->avg_packet_size=BE_32(&data[24]);
-  mdpr->start_time=BE_32(&data[28]);
-  mdpr->preroll=BE_32(&data[32]);
-  mdpr->duration=BE_32(&data[36]);
+  mdpr->stream_number=AV_RB16(&data[10]);
+  mdpr->max_bit_rate=AV_RB32(&data[12]);
+  mdpr->avg_bit_rate=AV_RB32(&data[16]);
+  mdpr->max_packet_size=AV_RB32(&data[20]);
+  mdpr->avg_packet_size=AV_RB32(&data[24]);
+  mdpr->start_time=AV_RB32(&data[28]);
+  mdpr->preroll=AV_RB32(&data[32]);
+  mdpr->duration=AV_RB32(&data[36]);
   
   mdpr->stream_name_size=data[40];
   mdpr->stream_name=malloc(mdpr->stream_name_size+1);
@@ -362,7 +357,7 @@
   memcpy(mdpr->mime_type, &data[42+mdpr->stream_name_size], mdpr->mime_type_size);
   mdpr->mime_type[mdpr->mime_type_size]=0;
   
-  mdpr->type_specific_len=BE_32(&data[42+mdpr->stream_name_size+mdpr->mime_type_size]);
+  mdpr->type_specific_len=AV_RB32(&data[42+mdpr->stream_name_size+mdpr->mime_type_size]);
   mdpr->type_specific_data=malloc(mdpr->type_specific_len);
   memcpy(mdpr->type_specific_data, 
       &data[46+mdpr->stream_name_size+mdpr->mime_type_size], mdpr->type_specific_len);
@@ -375,30 +370,30 @@
   rmff_cont_t *cont=malloc(sizeof(rmff_cont_t));
   int pos;
 
-  cont->object_id=BE_32(data);
-  cont->size=BE_32(&data[4]);
-  cont->object_version=BE_16(&data[8]);
+  cont->object_id=AV_RB32(data);
+  cont->size=AV_RB32(&data[4]);
+  cont->object_version=AV_RB16(&data[8]);
   if (cont->object_version != 0)
   {
     mp_msg(MSGT_STREAM, MSGL_WARN, "warning: unknown object version in CONT: 0x%04x\n",
       cont->object_version);
   }
-  cont->title_len=BE_16(&data[10]);
+  cont->title_len=AV_RB16(&data[10]);
   cont->title=malloc(cont->title_len+1);
   memcpy(cont->title, &data[12], cont->title_len);
   cont->title[cont->title_len]=0;
   pos=cont->title_len+12;
-  cont->author_len=BE_16(&data[pos]);
+  cont->author_len=AV_RB16(&data[pos]);
   cont->author=malloc(cont->author_len+1);
   memcpy(cont->author, &data[pos+2], cont->author_len);
   cont->author[cont->author_len]=0;
   pos=pos+2+cont->author_len;
-  cont->copyright_len=BE_16(&data[pos]);
+  cont->copyright_len=AV_RB16(&data[pos]);
   cont->copyright=malloc(cont->copyright_len+1);
   memcpy(cont->copyright, &data[pos+2], cont->copyright_len);
   cont->copyright[cont->copyright_len]=0;
   pos=pos+2+cont->copyright_len;
-  cont->comment_len=BE_16(&data[pos]);
+  cont->comment_len=AV_RB16(&data[pos]);
   cont->comment=malloc(cont->comment_len+1);
   memcpy(cont->comment, &data[pos+2], cont->comment_len);
   cont->comment[cont->comment_len]=0;
@@ -410,16 +405,16 @@
 
   rmff_data_t *dh=malloc(sizeof(rmff_data_t));
 
-  dh->object_id=BE_32(data);
-  dh->size=BE_32(&data[4]);
-  dh->object_version=BE_16(&data[8]);
+  dh->object_id=AV_RB32(data);
+  dh->size=AV_RB32(&data[4]);
+  dh->object_version=AV_RB16(&data[8]);
   if (dh->object_version != 0)
   {
     mp_msg(MSGT_STREAM, MSGL_WARN, "warning: unknown object version in DATA: 0x%04x\n",
       dh->object_version);
   }
-  dh->num_packets=BE_32(&data[10]);
-  dh->next_data_header=BE_32(&data[14]);
+  dh->num_packets=AV_RB32(&data[10]);
+  dh->next_data_header=AV_RB32(&data[14]);
 
   return dh;
 }
@@ -438,7 +433,7 @@
 	header->cont=NULL;
 	header->data=NULL;
 
-  chunk_type = BE_32(ptr);
+  chunk_type = AV_RB32(ptr);
   if (chunk_type != RMF_TAG)
   {
     mp_msg(MSGT_STREAM, MSGL_ERR, "rmff: not an real media file header (.RMF tag not found).\n");
@@ -454,7 +449,7 @@
   }
   
   for (i=1; i<header->fileheader->num_headers; i++) {
-    chunk_type = BE_32(ptr);
+    chunk_type = AV_RB32(ptr);
   
     if (ptr[0] == 0)
     {
@@ -504,8 +499,8 @@
   do {
     buf = xbuffer_ensure_size(buf, index+8);
     recv(fd, buf+index, 8, 0);
-    chunk_type=BE_32(buf+index); index+=4;
-    chunk_size=BE_32(buf+index); index+=4;
+    chunk_type=AV_RB32(buf+index); index+=4;
+    chunk_size=AV_RB32(buf+index); index+=4;
 
     switch (chunk_type) {
       case DATA_TAG:
@@ -534,10 +529,10 @@
 
 void rmff_scan_pheader(rmff_pheader_t *h, char *data) {
 
-  h->object_version=BE_16(data);
-  h->length=BE_16(data+2);
-  h->stream_number=BE_16(data+4);
-  h->timestamp=BE_32(data+6);
+  h->object_version=AV_RB16(data);
+  h->length=AV_RB16(data+2);
+  h->stream_number=AV_RB16(data+4);
+  h->timestamp=AV_RB32(data+6);
   h->reserved=(uint8_t)data[10];
   h->flags=(uint8_t)data[11];
 }
Index: stream/asf_streaming.c
===================================================================
--- stream/asf_streaming.c	(revision 22339)
+++ stream/asf_streaming.c	(working copy)
@@ -470,7 +470,7 @@
       if (drop_chunk) continue;
     }
     if (rest == 0 && waiting > 0 && size-read > 0) {
-      int s = MIN(waiting,size-read);
+      int s = FFMIN(waiting,size-read);
       memset(buffer+read,0,s);
       waiting -= s;
       read += s;
Index: spudec.c
===================================================================
--- spudec.c	(revision 22339)
+++ spudec.c	(working copy)
@@ -30,8 +30,6 @@
 #endif
 #include "libswscale/swscale.h"
 
-#define MIN(a, b)	((a)<(b)?(a):(b))
-
 /* Valid values for spu_aamode:
    0: none (fastest, most ugly)
    1: approximate
@@ -706,7 +704,7 @@
   }
   src_step = (delta_src << 16) / delta_tar >>1;
   for (t = 0; t<=delta_tar; src += (src_step << 1), t++){
-    table[t].position= MIN(src >> 16, end_src - 1);
+    table[t].position= FFMIN(src >> 16, end_src - 1);
     table[t].right_down = src & 0xffff;
     table[t].left_up = 0x10000 - table[t].right_down;
   }
@@ -936,7 +934,7 @@
 	    for (y = 0; y < spu->scaled_height; ++y) {
 	      const double unscaled_y = y * inv_scaley;
 	      const double unscaled_y_bottom = unscaled_y + inv_scaley;
-	      const unsigned int top_low_row = MIN(unscaled_y_bottom, unscaled_y + 1.0);
+	      const unsigned int top_low_row = FFMIN(unscaled_y_bottom, unscaled_y + 1.0);
 	      const double top = top_low_row - unscaled_y;
 	      const unsigned int height = unscaled_y_bottom > top_low_row
 		? (unsigned int) unscaled_y_bottom - top_low_row
@@ -947,7 +945,7 @@
 	      for (x = 0; x < spu->scaled_width; ++x) {
 		const double unscaled_x = x * inv_scalex;
 		const double unscaled_x_right = unscaled_x + inv_scalex;
-		const unsigned int left_right_column = MIN(unscaled_x_right, unscaled_x + 1.0);
+		const unsigned int left_right_column = FFMIN(unscaled_x_right, unscaled_x + 1.0);
 		const double left = left_right_column - unscaled_x;
 		const unsigned int width = unscaled_x_right > left_right_column
 		  ? (unsigned int) unscaled_x_right - left_right_column
Index: libmpdemux/demux_mkv.c
===================================================================
--- libmpdemux/demux_mkv.c	(revision 22339)
+++ libmpdemux/demux_mkv.c	(working copy)
@@ -42,13 +42,6 @@
 #include "libavutil/lzo.h"
 #endif
 
-#if !defined(MIN)
-#define MIN(a, b)	((a)<(b)?(a):(b))
-#endif
-#if !defined(MAX)
-#define MAX(a, b)	((a)>(b)?(a):(b))
-#endif
-
 static unsigned char sipr_swaps[38][2]={
     {0,63},{1,22},{2,44},{3,90},{5,81},{7,31},{8,86},{9,58},{10,36},{12,68},
     {13,39},{14,73},{15,53},{16,69},{17,57},{19,88},{20,34},{21,71},{24,46},
@@ -389,12 +382,9 @@
       r = tmp >> 16 & 0xff;
       g = tmp >> 8 & 0xff;
       b = tmp & 0xff;
-      y = MIN(MAX((int)(0.1494 * r + 0.6061 * g + 0.2445 * b), 0),
-              0xff);
-      u = MIN(MAX((int)(0.6066 * r - 0.4322 * g - 0.1744 * b) + 128,
-                  0), 0xff);
-      v = MIN(MAX((int)(-0.08435 * r - 0.3422 * g + 0.4266 * b) +
-                  128, 0), 0xff);
+      y = av_clip_uint8( 0.1494  * r + 0.6061 * g + 0.2445 * b);
+      u = av_clip_uint8( 0.6066  * r - 0.4322 * g - 0.1744 * b + 128);
+      v = av_clip_uint8(-0.08435 * r - 0.3422 * g + 0.4266 * b + 128);
       t->sh_sub.palette[i] = y << 16 | u << 8 | v;
       start += 6;
       while ((*start == ',') || isspace(*start))
Index: libmpdemux/asf.h
===================================================================
--- libmpdemux/asf.h	(revision 22339)
+++ libmpdemux/asf.h	(working copy)
@@ -6,10 +6,6 @@
 #include "libavutil/common.h"
 #include "mpbswap.h"
 
-#ifndef MIN
-#define MIN(a,b) (((a)<(b))?(a):(b))
-#endif
-
 ///////////////////////
 // MS GUID definition
 ///////////////////////
Index: libmpdemux/demux_gif.c
===================================================================
--- libmpdemux/demux_gif.c	(revision 22339)
+++ libmpdemux/demux_gif.c	(working copy)
@@ -160,10 +160,10 @@
   {
     int y;
     int cnt = FFMIN(effective_map->ColorCount, 256);
-    int l = FFMAX(FFMIN(gif->Image.Left, priv->w), 0);
-    int t = FFMAX(FFMIN(gif->Image.Top, priv->h), 0);
-    int w = FFMAX(FFMIN(gif->Image.Width, priv->w - l), 0);
-    int h = FFMAX(FFMIN(gif->Image.Height, priv->h - t), 0);
+    int l = av_clip(gif->Image.Left, 0, priv->w);
+    int t = av_clip(gif->Image.Top, 0, priv->h);
+    int w = av_clip(gif->Image.Width, 0, priv->w - l);
+    int h = av_clip(gif->Image.Height, 0, priv->h - t);
     unsigned char *dest = dp->buffer + priv->w * t + l;
 
     // copy the palette


More information about the MPlayer-dev-eng mailing list