| 
									
										
										
										
											2006-09-10 14:02:42 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * (c) 2001 Fabrice Bellard | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2006-10-07 15:30:46 +00:00
										 |  |  |  * This file is part of FFmpeg. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * FFmpeg is free software; you can redistribute it and/or | 
					
						
							| 
									
										
										
										
											2006-09-10 14:02:42 +00:00
										 |  |  |  * modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License as published by the Free Software Foundation; either | 
					
						
							| 
									
										
										
										
											2006-10-07 15:30:46 +00:00
										 |  |  |  * version 2.1 of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2006-09-10 14:02:42 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2006-10-07 15:30:46 +00:00
										 |  |  |  * FFmpeg is distributed in the hope that it will be useful, | 
					
						
							| 
									
										
										
										
											2006-09-10 14:02:42 +00:00
										 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  * Lesser General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Lesser General Public | 
					
						
							| 
									
										
										
										
											2006-10-07 15:30:46 +00:00
										 |  |  |  * License along with FFmpeg; if not, write to the Free Software | 
					
						
							| 
									
										
										
										
											2006-09-10 14:02:42 +00:00
										 |  |  |  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2003-03-06 11:32:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2010-04-20 14:45:34 +00:00
										 |  |  |  * @file | 
					
						
							| 
									
										
										
										
											2003-03-06 11:32:04 +00:00
										 |  |  |  * motion test. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <sys/time.h>
 | 
					
						
							|  |  |  | #include <unistd.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 11:29:51 +00:00
										 |  |  | #include "config.h"
 | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  | #include "dsputil.h"
 | 
					
						
							| 
									
										
										
										
											2009-03-20 11:48:27 +00:00
										 |  |  | #include "libavutil/lfg.h"
 | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-08 09:38:22 +00:00
										 |  |  | #undef printf
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  | #define WIDTH 64
 | 
					
						
							|  |  |  | #define HEIGHT 64
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-21 18:44:41 +02:00
										 |  |  | static uint8_t img1[WIDTH * HEIGHT]; | 
					
						
							|  |  |  | static uint8_t img2[WIDTH * HEIGHT]; | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-31 09:32:59 +00:00
										 |  |  | static void fill_random(uint8_t *tab, int size) | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     int i; | 
					
						
							| 
									
										
										
										
											2009-04-10 17:23:38 +00:00
										 |  |  |     AVLFG prng; | 
					
						
							| 
									
										
										
										
											2009-03-20 11:48:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 17:23:38 +00:00
										 |  |  |     av_lfg_init(&prng, 1); | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  |     for(i=0;i<size;i++) { | 
					
						
							|  |  |  | #if 1
 | 
					
						
							| 
									
										
										
										
											2009-04-10 17:23:38 +00:00
										 |  |  |         tab[i] = av_lfg_get(&prng) % 256; | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  |         tab[i] = i; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-31 09:32:59 +00:00
										 |  |  | static void help(void) | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     printf("motion-test [-h]\n" | 
					
						
							|  |  |  |            "test motion implementations\n"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-31 09:32:59 +00:00
										 |  |  | static int64_t gettime(void) | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     struct timeval tv; | 
					
						
							|  |  |  |     gettimeofday(&tv,NULL); | 
					
						
							| 
									
										
										
										
											2003-02-11 16:35:48 +00:00
										 |  |  |     return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec; | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define NB_ITS 500
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int dummy; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-31 09:32:59 +00:00
										 |  |  | static void test_motion(const char *name, | 
					
						
							| 
									
										
										
										
											2007-06-10 13:54:11 +00:00
										 |  |  |                  me_cmp_func test_func, me_cmp_func ref_func) | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     int x, y, d1, d2, it; | 
					
						
							| 
									
										
										
										
											2003-02-11 16:35:48 +00:00
										 |  |  |     uint8_t *ptr; | 
					
						
							|  |  |  |     int64_t ti; | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  |     printf("testing '%s'\n", name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* test correctness */ | 
					
						
							|  |  |  |     for(it=0;it<20;it++) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         fill_random(img1, WIDTH * HEIGHT); | 
					
						
							|  |  |  |         fill_random(img2, WIDTH * HEIGHT); | 
					
						
							| 
									
										
										
										
											2005-12-17 18:14:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  |         for(y=0;y<HEIGHT-17;y++) { | 
					
						
							|  |  |  |             for(x=0;x<WIDTH-17;x++) { | 
					
						
							| 
									
										
										
										
											2005-12-17 18:14:38 +00:00
										 |  |  |                 ptr = img2 + y * WIDTH + x; | 
					
						
							| 
									
										
										
										
											2007-06-10 13:54:11 +00:00
										 |  |  |                 d1 = test_func(NULL, img1, ptr, WIDTH, 1); | 
					
						
							|  |  |  |                 d2 = ref_func(NULL, img1, ptr, WIDTH, 1); | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  |                 if (d1 != d2) { | 
					
						
							|  |  |  |                     printf("error: mmx=%d c=%d\n", d1, d2); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2007-06-07 21:31:26 +00:00
										 |  |  |     emms_c(); | 
					
						
							| 
									
										
										
										
											2005-12-17 18:14:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  |     /* speed test */ | 
					
						
							|  |  |  |     ti = gettime(); | 
					
						
							|  |  |  |     d1 = 0; | 
					
						
							|  |  |  |     for(it=0;it<NB_ITS;it++) { | 
					
						
							|  |  |  |         for(y=0;y<HEIGHT-17;y++) { | 
					
						
							|  |  |  |             for(x=0;x<WIDTH-17;x++) { | 
					
						
							| 
									
										
										
										
											2005-12-17 18:14:38 +00:00
										 |  |  |                 ptr = img2 + y * WIDTH + x; | 
					
						
							| 
									
										
										
										
											2007-06-10 13:54:11 +00:00
										 |  |  |                 d1 += test_func(NULL, img1, ptr, WIDTH, 1); | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2007-06-07 21:31:26 +00:00
										 |  |  |     emms_c(); | 
					
						
							| 
									
										
										
										
											2007-12-01 22:21:04 +00:00
										 |  |  |     dummy = d1; /* avoid optimization */ | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  |     ti = gettime() - ti; | 
					
						
							| 
									
										
										
										
											2005-12-17 18:14:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     printf("  %0.0f kop/s\n", | 
					
						
							|  |  |  |            (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) / | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  |            (double)(ti / 1000.0)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int main(int argc, char **argv) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-06-10 13:54:11 +00:00
										 |  |  |     AVCodecContext *ctx; | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  |     int c; | 
					
						
							| 
									
										
										
										
											2007-06-10 13:54:11 +00:00
										 |  |  |     DSPContext cctx, mmxctx; | 
					
						
							| 
									
										
										
										
											2010-09-04 09:59:08 +00:00
										 |  |  |     int flags[2] = { AV_CPU_FLAG_MMX, AV_CPU_FLAG_MMX2 }; | 
					
						
							| 
									
										
										
										
											2009-04-10 11:29:51 +00:00
										 |  |  |     int flags_size = HAVE_MMX2 ? 2 : 1; | 
					
						
							| 
									
										
										
										
											2005-12-17 18:14:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  |     for(;;) { | 
					
						
							|  |  |  |         c = getopt(argc, argv, "h"); | 
					
						
							|  |  |  |         if (c == -1) | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         switch(c) { | 
					
						
							|  |  |  |         case 'h': | 
					
						
							|  |  |  |             help(); | 
					
						
							| 
									
										
										
										
											2011-09-21 18:46:56 +02:00
										 |  |  |             return 1; | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2005-12-17 18:14:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  |     printf("ffmpeg motion test\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-18 13:40:48 +02:00
										 |  |  |     ctx = avcodec_alloc_context3(NULL); | 
					
						
							| 
									
										
										
										
											2010-09-04 09:59:08 +00:00
										 |  |  |     ctx->dsp_mask = AV_CPU_FLAG_FORCE; | 
					
						
							| 
									
										
										
										
											2007-06-10 13:54:11 +00:00
										 |  |  |     dsputil_init(&cctx, ctx); | 
					
						
							| 
									
										
										
										
											2009-04-10 11:29:51 +00:00
										 |  |  |     for (c = 0; c < flags_size; c++) { | 
					
						
							| 
									
										
										
										
											2007-06-10 13:54:11 +00:00
										 |  |  |         int x; | 
					
						
							| 
									
										
										
										
											2010-09-04 09:59:08 +00:00
										 |  |  |         ctx->dsp_mask = AV_CPU_FLAG_FORCE | flags[c]; | 
					
						
							| 
									
										
										
										
											2007-06-10 13:54:11 +00:00
										 |  |  |         dsputil_init(&mmxctx, ctx); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (x = 0; x < 2; x++) { | 
					
						
							|  |  |  |             printf("%s for %dx%d pixels\n", c ? "mmx2" : "mmx", | 
					
						
							|  |  |  |                    x ? 8 : 16, x ? 8 : 16); | 
					
						
							|  |  |  |             test_motion("mmx",     mmxctx.pix_abs[x][0], cctx.pix_abs[x][0]); | 
					
						
							|  |  |  |             test_motion("mmx_x2",  mmxctx.pix_abs[x][1], cctx.pix_abs[x][1]); | 
					
						
							|  |  |  |             test_motion("mmx_y2",  mmxctx.pix_abs[x][2], cctx.pix_abs[x][2]); | 
					
						
							|  |  |  |             test_motion("mmx_xy2", mmxctx.pix_abs[x][3], cctx.pix_abs[x][3]); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     av_free(ctx); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-15 22:31:26 +00:00
										 |  |  |     return 0; | 
					
						
							|  |  |  | } |