[Ffmpeg-devel] [PATCH]: Too much alignment assumed by H264 decoder

David S. Miller davem
Thu Dec 22 17:25:18 CET 2005


These uint64_t cast memory operations cause unaligned accesses on
platforms such as Sparc, there really isn't anything in the
datastructures to ensure this level of alignment.

But uint32_t seems to work fine, as the following patch against
current CVS implements.

Please consider for inclusion, thanks.

--- libavcodec/h264.c.~1~	2005-12-22 08:16:17.000000000 -0800
+++ libavcodec/h264.c	2005-12-22 08:20:59.000000000 -0800
@@ -1407,14 +1407,18 @@
         if(!USES_LIST(mb_type, list)){
             if(1){ //FIXME skip or never read if mb_type doesn't use it
                 for(y=0; y<4; y++){
-                    *(uint64_t*)s->current_picture.motion_val[list][b_xy + 0 + y*h->b_stride]=
-                    *(uint64_t*)s->current_picture.motion_val[list][b_xy + 2 + y*h->b_stride]= 0;
+                    *(uint32_t*)s->current_picture.motion_val[list][b_xy + 0 + y*h->b_stride]=
+                    *(uint32_t*)s->current_picture.motion_val[list][b_xy + 1 + y*h->b_stride]=
+                    *(uint32_t*)s->current_picture.motion_val[list][b_xy + 2 + y*h->b_stride]=
+                    *(uint32_t*)s->current_picture.motion_val[list][b_xy + 3 + y*h->b_stride]= 0;
                 }
                 if( h->pps.cabac ) {
                     /* FIXME needed ? */
                     for(y=0; y<4; y++){
-                        *(uint64_t*)h->mvd_table[list][b_xy + 0 + y*h->b_stride]=
-                        *(uint64_t*)h->mvd_table[list][b_xy + 2 + y*h->b_stride]= 0;
+                        *(uint32_t*)h->mvd_table[list][b_xy + 0 + y*h->b_stride]=
+                        *(uint32_t*)h->mvd_table[list][b_xy + 1 + y*h->b_stride]=
+                        *(uint32_t*)h->mvd_table[list][b_xy + 2 + y*h->b_stride]=
+                        *(uint32_t*)h->mvd_table[list][b_xy + 3 + y*h->b_stride]= 0;
                     }
                 }
                 for(y=0; y<2; y++){
@@ -1426,13 +1430,17 @@
         }
 
         for(y=0; y<4; y++){
-            *(uint64_t*)s->current_picture.motion_val[list][b_xy + 0 + y*h->b_stride]= *(uint64_t*)h->mv_cache[list][scan8[0]+0 + 8*y];
-            *(uint64_t*)s->current_picture.motion_val[list][b_xy + 2 + y*h->b_stride]= *(uint64_t*)h->mv_cache[list][scan8[0]+2 + 8*y];
+            *(uint32_t*)s->current_picture.motion_val[list][b_xy + 0 + y*h->b_stride]= *(uint32_t*)h->mv_cache[list][scan8[0]+0 + 8*y];
+            *(uint32_t*)s->current_picture.motion_val[list][b_xy + 1 + y*h->b_stride]= *(uint32_t*)h->mv_cache[list][scan8[0]+1 + 8*y];
+            *(uint32_t*)s->current_picture.motion_val[list][b_xy + 2 + y*h->b_stride]= *(uint32_t*)h->mv_cache[list][scan8[0]+2 + 8*y];
+            *(uint32_t*)s->current_picture.motion_val[list][b_xy + 3 + y*h->b_stride]= *(uint32_t*)h->mv_cache[list][scan8[0]+3 + 8*y];
         }
         if( h->pps.cabac ) {
             for(y=0; y<4; y++){
-                *(uint64_t*)h->mvd_table[list][b_xy + 0 + y*h->b_stride]= *(uint64_t*)h->mvd_cache[list][scan8[0]+0 + 8*y];
-                *(uint64_t*)h->mvd_table[list][b_xy + 2 + y*h->b_stride]= *(uint64_t*)h->mvd_cache[list][scan8[0]+2 + 8*y];
+                *(uint32_t*)h->mvd_table[list][b_xy + 0 + y*h->b_stride]= *(uint32_t*)h->mvd_cache[list][scan8[0]+0 + 8*y];
+                *(uint32_t*)h->mvd_table[list][b_xy + 1 + y*h->b_stride]= *(uint32_t*)h->mvd_cache[list][scan8[0]+1 + 8*y];
+                *(uint32_t*)h->mvd_table[list][b_xy + 2 + y*h->b_stride]= *(uint32_t*)h->mvd_cache[list][scan8[0]+2 + 8*y];
+                *(uint32_t*)h->mvd_table[list][b_xy + 3 + y*h->b_stride]= *(uint32_t*)h->mvd_cache[list][scan8[0]+3 + 8*y];
             }
         }
         for(y=0; y<2; y++){





More information about the ffmpeg-devel mailing list