From d76376f10c25a56b593d21ba4220e9f449e2063d Mon Sep 17 00:00:00 2001 From: Austin Yuan Date: Tue, 1 Dec 2009 11:09:41 +0800 Subject: [PATCH] refine test program: putsurface/h264encode Signed-off-by: Austin Yuan --- test/encode/h264encode.c | 118 +++++++++++++++++++++++++++---------------- test/encode/loadsurface.h | 1 + test/putsurface/putsurface.c | 64 +++++++++++++++++++---- 3 files changed, 130 insertions(+), 53 deletions(-) create mode 120000 test/encode/loadsurface.h diff --git a/test/encode/h264encode.c b/test/encode/h264encode.c index 4a4d914..46f1ff6 100644 --- a/test/encode/h264encode.c +++ b/test/encode/h264encode.c @@ -26,7 +26,7 @@ * it is a real program to show how VAAPI encoding work, * It does H264 element stream level encoding on auto-generated YUV data * - * gcc -o h264encode h264encode -lva -lva-x11 -I /usr/include/va + * gcc -o h264encode h264encode -lva -lva-x11 -I/usr/include/va * ./h264encode -w -h -n * */ @@ -54,6 +54,8 @@ if (va_status != VA_STATUS_SUCCESS) { \ exit(1); \ } +#include "loadsurface.h" + #define SURFACE_NUM 18 /* 16 surfaces for src, 2 surface for reconstructed/reference */ static Display *x11_display; @@ -67,11 +69,15 @@ static int win_height; static int coded_fd; static char coded_file[256]; +#define CODEDBUF_NUM 5 +static VABufferID coded_buf[CODEDBUF_NUM]; + +static int frame_display = 0; /* display the frame during encoding */ static int frame_width=352, frame_height=288; static int frame_rate = 30; -static int frame_count = 1000; +static int frame_count = 400; static int intra_count = 30; -static int frame_bitrate = 64000; +static int frame_bitrate = 8000000; /* 8M */ static int initial_qp = 15; static int minimal_qp = 0; @@ -85,11 +91,13 @@ static int upload_source_YUV_once_for_all() int i; for (i=0; i #include #include @@ -37,8 +39,8 @@ #include #include -#include -#include +#include "va.h" +#include "va_x11.h" #include @@ -75,7 +77,7 @@ static Display *x11_display; static VADisplay *va_dpy; static int multi_thread=0; static int put_pixmap = 0; -static int test_clip = 1; +static int test_clip = 0; static int display_field = VA_FRAME_PICTURE; static int check_event = 1; static int verbose=0; @@ -185,6 +187,17 @@ static VASurfaceID get_next_free_surface(int *index) return surface_id[i]; } +/* + * Helper function for profiling purposes + */ +static unsigned long get_tick_count(void) +{ + struct timeval tv; + if (gettimeofday(&tv, NULL)) + return 0; + return tv.tv_usec/1000+tv.tv_sec*1000; +} + static int putsurface_thread(void *data) { int width=win_width, height=win_height; @@ -198,7 +211,9 @@ static int putsurface_thread(void *data) int index = 0; Bool is_event; XEvent event; - + unsigned int frame_num=0, start_time, putsurface_time; + VARectangle cliprects[2]; /* client supplied clip list */ + if (win == win_thread0) { printf("Enter into thread0\n\n"); pixmap = pixmap_thread0; @@ -218,7 +233,8 @@ static int putsurface_thread(void *data) printf("vaPutSurface into a Window directly\n\n"); draw = win; } - + + putsurface_time = 0; while (!quit) { VASurfaceID surface_id = VA_INVALID_SURFACE; @@ -228,13 +244,39 @@ static int putsurface_thread(void *data) if (verbose) printf("Thread %x Display surface 0x%p,\n", (unsigned int)win, (void *)surface_id); upload_surface(va_dpy, surface_id, box_width, row_shift, display_field); - + + start_time = get_tick_count(); vaStatus = vaPutSurface(va_dpy, surface_id, draw, 0,0,surface_width,surface_height, 0,0,width,height, - NULL,0,display_field); + (test_clip==0)?NULL:&cliprects[0], + (test_clip==0)?0:2, + display_field); CHECK_VASTATUS(vaStatus,"vaPutSurface"); - + putsurface_time += (get_tick_count() - start_time); + + if ((frame_num % 0xff) == 0) { + fprintf(stderr, "%.2f FPS \r", 256000.0 / (float)putsurface_time); + putsurface_time = 0; + + if (test_clip) { + srand((unsigned)time(NULL)); + + cliprects[0].x = (rand() % width); + cliprects[0].y = (rand() % height); + cliprects[0].width = (rand() % (width - cliprects[0].x)); + cliprects[0].height = (rand() % (height - cliprects[0].y)); + + cliprects[1].x = (rand() % width); + cliprects[1].y = (rand() % height); + cliprects[1].width = (rand() % (width - cliprects[1].x)); + cliprects[1].height = (rand() % (height - cliprects[1].y)); + printf("\nTest clip (%d,%d, %d x %d) and (%d,%d, %d x %d) \n", + cliprects[0].x, cliprects[0].y, cliprects[0].width, cliprects[0].height, + cliprects[1].x, cliprects[1].y, cliprects[1].width, cliprects[1].height); + } + } + if (put_pixmap) XCopyArea(x11_display, pixmap, win, context, 0, 0, width, height, 0, 0); @@ -242,7 +284,7 @@ static int putsurface_thread(void *data) if (check_event) { pthread_mutex_lock(&gmutex); - is_event =XCheckWindowEvent(x11_display, win, StructureNotifyMask|KeyPressMask,&event); + is_event = XCheckWindowEvent(x11_display, win, StructureNotifyMask|KeyPressMask,&event); pthread_mutex_unlock(&gmutex); if (is_event) { /* bail on any focused key press */ @@ -262,6 +304,8 @@ static int putsurface_thread(void *data) row_shift++; if (row_shift==(2*box_width)) row_shift= 0; + + frame_num++; } pthread_exit(NULL); @@ -277,7 +321,7 @@ int main(int argc,char **argv) char c; int i; - while ((c =getopt(argc,argv,"w:h:d:f:tep?nv") ) != EOF) { + while ((c =getopt(argc,argv,"w:h:d:f:tcep?nv") ) != EOF) { switch (c) { case '?': printf("putsurface \n"); -- 2.7.4