[MPlayer-cvslog] r35504 - in trunk/libmpdemux: aviheader.c aviheader.h demux_avi.c

reimar subversion at mplayerhq.hu
Wed Nov 28 20:43:03 CET 2012


Author: reimar
Date: Wed Nov 28 20:43:03 2012
New Revision: 35504

Log:
Change declaration to use proper type to avoid a ridiculous
number of casts.

Modified:
   trunk/libmpdemux/aviheader.c
   trunk/libmpdemux/aviheader.h
   trunk/libmpdemux/demux_avi.c

Modified: trunk/libmpdemux/aviheader.c
==============================================================================
--- trunk/libmpdemux/aviheader.c	Wed Nov 28 20:36:55 2012	(r35503)
+++ trunk/libmpdemux/aviheader.c	Wed Nov 28 20:43:03 2012	(r35504)
@@ -394,7 +394,7 @@ while(1){
       read = stream_read(demuxer->stream,(char*)priv->idx,priv->idx_size<<4);
       priv->idx_size = FFMAX(read, 0) >> 4;
       for (i = 0; i < priv->idx_size; i++) {	// swap index to machine endian
-	AVIINDEXENTRY *entry=(AVIINDEXENTRY*)priv->idx + i;
+	AVIINDEXENTRY *entry=priv->idx + i;
 	le2me_AVIINDEXENTRY(entry);
 	/*
 	 * We (ab)use the upper word for bits 32-47 of the offset, so
@@ -551,7 +551,7 @@ if (priv->isodml && (index_mode==-1 || i
 	stream_reset (demuxer->stream);
 
 	// find out the video stream id. I have seen files with 01db.
-	for (idx = &((AVIINDEXENTRY *)priv->idx)[0], i=0; i<priv->idx_size; i++, idx++){
+	for (idx = priv->idx, i=0; i<priv->idx_size; i++, idx++){
 	    unsigned char res[2];
 	    if (odml_get_vstream_id(idx->ckid, res)) {
 		db = mmioFOURCC(res[0], res[1], 'd', 'b');
@@ -560,14 +560,14 @@ if (priv->isodml && (index_mode==-1 || i
 	}
 
 	// find first non keyframe
-	for (idx = &((AVIINDEXENTRY *)priv->idx)[0], i=0; i<priv->idx_size; i++, idx++){
+	for (idx = priv->idx, i=0; i<priv->idx_size; i++, idx++){
 	    if (!(idx->dwFlags & AVIIF_KEYFRAME) && idx->ckid == db) break;
 	}
 	if (i<priv->idx_size && db) {
 	    stream_seek(demuxer->stream, AVI_IDX_OFFSET(idx));
 	    id = stream_read_dword_le(demuxer->stream);
 	    if (id && id != db) // index fcc and real fcc differ? fix it.
-		for (idx = &((AVIINDEXENTRY *)priv->idx)[0], i=0; i<priv->idx_size; i++, idx++){
+		for (idx = priv->idx, i=0; i<priv->idx_size; i++, idx++){
 		    if (!(idx->dwFlags & AVIIF_KEYFRAME) && idx->ckid == db)
 			idx->ckid = id;
 	    }
@@ -616,7 +616,7 @@ if (index_file_load) {
   }
 
   for (i=0; i<priv->idx_size;i++) {
-    AVIINDEXENTRY *idx=&((AVIINDEXENTRY *)priv->idx)[i];
+    AVIINDEXENTRY *idx=priv->idx + i;
     fread(idx, sizeof(AVIINDEXENTRY), 1, fp);
     if (feof(fp)) {
       mp_msg(MSGT_HEADER,MSGL_ERR, MSGTR_MPDEMUX_AVIHDR_PrematureEOF, index_file_load);
@@ -661,7 +661,7 @@ if(index_mode>=2 || (priv->idx_size==0 &
       priv->idx=realloc(priv->idx,priv->idx_size*sizeof(AVIINDEXENTRY));
       if(!priv->idx){idx_pos=0; break;} // error!
     }
-    idx=&((AVIINDEXENTRY *)priv->idx)[idx_pos++];
+    idx=priv->idx + idx_pos++;
     idx->ckid=id;
     idx->dwFlags=AVIIF_KEYFRAME; // FIXME
     idx->dwFlags|=(demuxer->filepos>>16)&0xffff0000U;
@@ -727,7 +727,7 @@ skip_chunk:
     fwrite("MPIDX1", 6, 1, fp);
     fwrite(&priv->idx_size, sizeof(priv->idx_size), 1, fp);
     for (i=0; i<priv->idx_size; i++) {
-      AVIINDEXENTRY *idx = &((AVIINDEXENTRY *)priv->idx)[i];
+      AVIINDEXENTRY *idx = priv->idx + i;
       fwrite(idx, sizeof(AVIINDEXENTRY), 1, fp);
     }
     fclose(fp);

Modified: trunk/libmpdemux/aviheader.h
==============================================================================
--- trunk/libmpdemux/aviheader.h	Wed Nov 28 20:36:55 2012	(r35503)
+++ trunk/libmpdemux/aviheader.h	Wed Nov 28 20:43:03 2012	(r35504)
@@ -345,7 +345,7 @@ typedef enum {
 
 typedef struct {
   // index stuff:
-  void* idx;
+  AVIINDEXENTRY *idx;
   int idx_size;
   off_t idx_pos;
   off_t idx_pos_a;

Modified: trunk/libmpdemux/demux_avi.c
==============================================================================
--- trunk/libmpdemux/demux_avi.c	Wed Nov 28 20:36:55 2012	(r35503)
+++ trunk/libmpdemux/demux_avi.c	Wed Nov 28 20:43:03 2012	(r35504)
@@ -243,7 +243,7 @@ do{
   if(priv->idx_size>0 && priv->idx_pos<priv->idx_size){
     off_t pos;
 
-    AVIINDEXENTRY *idx=&((AVIINDEXENTRY *)priv->idx)[priv->idx_pos++];
+    AVIINDEXENTRY *idx = priv->idx + priv->idx_pos++;
 
     if(idx->dwFlags&AVIIF_LIST){
       if (!valid_stream_id(idx->ckid))
@@ -334,7 +334,7 @@ do{
 
   if(priv->idx_size>0 && idx_pos<priv->idx_size){
     off_t pos;
-    AVIINDEXENTRY *idx=&((AVIINDEXENTRY *)priv->idx)[idx_pos];
+    AVIINDEXENTRY *idx = priv->idx + idx_pos;
 
     if(idx->dwFlags&AVIIF_LIST){
       if (!valid_stream_id(idx->ckid))
@@ -480,17 +480,17 @@ static demuxer_t* demux_open_avi(demuxer
   if(priv->idx_size>1){
     // decide index format:
 #if 1
-    if((AVI_IDX_OFFSET(&((AVIINDEXENTRY *)priv->idx)[0])<demuxer->movi_start ||
-        AVI_IDX_OFFSET(&((AVIINDEXENTRY *)priv->idx)[1])<demuxer->movi_start )&& !priv->isodml)
+    if((AVI_IDX_OFFSET(priv->idx + 0)<demuxer->movi_start ||
+        AVI_IDX_OFFSET(priv->idx + 1)<demuxer->movi_start )&& !priv->isodml)
       priv->idx_offset=demuxer->movi_start-4;
 #else
-    if(AVI_IDX_OFFSET(&((AVIINDEXENTRY *)priv->idx)[0])<demuxer->movi_start)
+    if(AVI_IDX_OFFSET(priv->idx)<demuxer->movi_start)
       priv->idx_offset=demuxer->movi_start-4;
 #endif
     mp_msg(MSGT_DEMUX,MSGL_V,"AVI index offset: 0x%X (movi=0x%X idx0=0x%X idx1=0x%X)\n",
 	    (int)priv->idx_offset,(int)demuxer->movi_start,
-	    (int)((AVIINDEXENTRY *)priv->idx)[0].dwChunkOffset,
-	    (int)((AVIINDEXENTRY *)priv->idx)[1].dwChunkOffset);
+	    (int)priv->idx[0].dwChunkOffset,
+	    (int)priv->idx[1].dwChunkOffset);
   }
 
   if(priv->idx_size>0){
@@ -499,7 +499,7 @@ static demuxer_t* demux_open_avi(demuxer
       off_t a_pos=-1;
       off_t v_pos=-1;
       for(i=0;i<priv->idx_size;i++){
-        AVIINDEXENTRY* idx=&((AVIINDEXENTRY *)priv->idx)[i];
+        AVIINDEXENTRY *idx = priv->idx + i;
         demux_stream_t* ds=demux_avi_select_stream(demuxer,idx->ckid);
         off_t pos = priv->idx_offset + AVI_IDX_OFFSET(idx);
         if(a_pos==-1 && ds==demuxer->audio){
@@ -643,18 +643,18 @@ static void demux_seek_avi(demuxer_t *de
       if(rel_seek_frames>0){
         // seek forward
         while(video_chunk_pos<priv->idx_size-1){
-          int id=((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].ckid;
+          int id=priv->idx[video_chunk_pos].ckid;
           if(avi_stream_id(id)==d_video->id){  // video frame
-            if((--rel_seek_frames)<0 && ((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
+            if((--rel_seek_frames)<0 && priv->idx[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
           }
           ++video_chunk_pos;
         }
       } else {
         // seek backward
         while(video_chunk_pos>0){
-          int id=((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].ckid;
+          int id=priv->idx[video_chunk_pos].ckid;
           if(avi_stream_id(id)==d_video->id){  // video frame
-            if((++rel_seek_frames)>0 && ((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
+            if((++rel_seek_frames)>0 && priv->idx[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
           }
           --video_chunk_pos;
         }
@@ -664,7 +664,7 @@ static void demux_seek_avi(demuxer_t *de
       // re-calc video pts:
       d_video->pack_no=0;
       for(i=0;i<video_chunk_pos;i++){
-          int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;
+          int id=priv->idx[i].ckid;
           if(avi_stream_id(id)==d_video->id) ++d_video->pack_no;
       }
       priv->video_pack_no=
@@ -696,9 +696,9 @@ static void demux_seek_avi(demuxer_t *de
 
         // find audio chunk pos:
           for(i=0;i<chunk_max;i++){
-            int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;
+            int id=priv->idx[i].ckid;
             if(avi_stream_id(id)==d_audio->id){
-                len=((AVIINDEXENTRY *)priv->idx)[i].dwChunkLength;
+                len=priv->idx[i].dwChunkLength;
                 if(d_audio->dpos<=curr_audio_pos && curr_audio_pos<(d_audio->dpos+len)){
                   break;
                 }
@@ -722,9 +722,9 @@ static void demux_seek_avi(demuxer_t *de
 
         // find audio chunk pos:
           for(i=0;i<priv->idx_size && chunks>0;i++){
-            int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;
+            int id=priv->idx[i].ckid;
             if(avi_stream_id(id)==d_audio->id){
-                len=((AVIINDEXENTRY *)priv->idx)[i].dwChunkLength;
+                len=priv->idx[i].dwChunkLength;
 		if(i>chunk_max){
 		  skip_audio_bytes+=len;
 		} else {
@@ -754,7 +754,7 @@ static void demux_seek_avi(demuxer_t *de
 	  if(audio_chunk_pos<video_chunk_pos){
             // calc priv->skip_video_frames & adjust video pts counter:
 	    for(i=audio_chunk_pos;i<video_chunk_pos;i++){
-              int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;
+              int id=priv->idx[i].ckid;
               if(avi_stream_id(id)==d_video->id) ++priv->skip_video_frames;
             }
             // requires for correct audio pts calculation (demuxer):


More information about the MPlayer-cvslog mailing list