[MPlayer-cvslog] CVS: main/libmpdemux aviheader.c,1.64,1.65
Reimar Döffinger CVS
syncmail at mplayerhq.hu
Sun Jan 2 15:29:46 CET 2005
CVS change done by Reimar Döffinger CVS
Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var2/tmp/cvs-serv28689/libmpdemux
Modified Files:
aviheader.c
Log Message:
Use libc qsort to sort ODML index.
Based on patch by phillip at phdcam dot com
Index: aviheader.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/aviheader.c,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -r1.64 -r1.65
--- aviheader.c 31 Dec 2004 16:02:47 -0000 1.64
+++ aviheader.c 2 Jan 2005 14:29:43 -0000 1.65
@@ -44,45 +44,10 @@
return 0;
}
-/**
- * Simple quicksort for AVIINDEXENTRYs
- * To avoid too deep recursion, the bigger part is handled iteratively,
- * thus limiting recursion to log2(n) levels.
- * The pivot element is randomized to "even out" otherwise extreme cases.
- */
-static void avi_idx_quicksort(AVIINDEXENTRY *idx, int from, int to)
-{
- AVIINDEXENTRY temp;
- int lo;
- int hi;
- off_t pivot_ofs;
- int pivot_idx;
- while (from < to) {
- pivot_idx = from;
- pivot_idx += rand() % (to - from + 1);
- pivot_ofs = AVI_IDX_OFFSET(&idx[pivot_idx]);
- lo = to;
- hi = from;
- do {
- while(pivot_ofs < AVI_IDX_OFFSET(&idx[lo])) lo--;
- while(pivot_ofs > AVI_IDX_OFFSET(&idx[hi])) hi++;
- if(hi <= lo) {
- if (hi != lo) {
- memcpy(&temp, &idx[lo], sizeof(temp));
- memcpy(&idx[lo], &idx[hi], sizeof(temp));
- memcpy(&idx[hi], &temp, sizeof(temp));
- }
- lo--; hi++;
- }
- } while (lo >= hi);
- if ((lo - from) < (to - hi)) {
- avi_idx_quicksort(idx, from, lo);
- from = hi;
- } else {
- avi_idx_quicksort(idx, hi, to);
- to = lo;
- }
- }
+int avi_idx_cmp(const void *elem1,const void *elem2) {
+ register off_t a = AVI_IDX_OFFSET((AVIINDEXENTRY *)elem1);
+ register off_t b = AVI_IDX_OFFSET((AVIINDEXENTRY *)elem2);
+ return (a > b) - (b > a);
}
void read_avi_header(demuxer_t *demuxer,int index_mode){
@@ -535,7 +500,7 @@
}
}
}
- avi_idx_quicksort(priv->idx, 0, priv->idx_size-1);
+ qsort(priv->idx, priv->idx_size, sizeof(AVIINDEXENTRY), avi_idx_cmp);
/*
Hack to work around a "wrong" index in some divx odml files
More information about the MPlayer-cvslog
mailing list