From e8c1df890a9f309226dc66f221dd6b7720ed22b2 Mon Sep 17 00:00:00 2001 From: Austin Yuan Date: Tue, 24 Apr 2012 23:17:03 -0700 Subject: [PATCH] VAEncXXXH264Baseline: start to drop VAEncXXXXBaseline Signed-off-by: Austin Yuan --- test/encode/h264encode_android.cpp | 4 +- test/encode/h264encode_common.c | 219 ++++++++++++++++++------------------- test/encode/h264encode_x11.c | 7 +- va/va.h | 32 ------ va/va_trace.c | 68 +----------- va/va_trace.h | 2 + 6 files changed, 120 insertions(+), 212 deletions(-) diff --git a/test/encode/h264encode_android.cpp b/test/encode/h264encode_android.cpp index 84b315b..a3f4db4 100644 --- a/test/encode/h264encode_android.cpp +++ b/test/encode/h264encode_android.cpp @@ -49,7 +49,7 @@ sp client; sp android_surface; sp android_isurface; sp surface_ctrl; - +#if 0 static int display_surface(int frame_id, int *exit_encode) { VAStatus va_status; @@ -67,4 +67,4 @@ static int display_surface(int frame_id, int *exit_encode) *exit_encode = 0; return 0; } - +#endif diff --git a/test/encode/h264encode_common.c b/test/encode/h264encode_common.c index bcc0671..0e4fa45 100644 --- a/test/encode/h264encode_common.c +++ b/test/encode/h264encode_common.c @@ -25,10 +25,8 @@ /* * 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 * ./h264encode -w -h -n - * */ #include #include @@ -40,6 +38,7 @@ #include #include #include +#include #ifdef ANDROID #include #else @@ -47,10 +46,10 @@ #endif #define CHECK_VASTATUS(va_status,func) \ -if (va_status != VA_STATUS_SUCCESS) { \ - fprintf(stderr,"%s:%s (%d) failed,exit\n", __func__, func, __LINE__); \ - exit(1); \ -} + if (va_status != VA_STATUS_SUCCESS) { \ + fprintf(stderr,"%s:%s (%d) failed,exit\n", __func__, func, __LINE__); \ + exit(1); \ + } #include "../loadsurface.h" #define SURFACE_NUM 18 /* 16 surfaces for src, 2 surface for reconstructed/reference */ @@ -62,7 +61,7 @@ static VAContextID context_id; static Display *x11_display; static int coded_fd; static char coded_file[256]; -static int frame_width, frame_height; +static int frame_width=320, frame_height=240; static int win_width; static int win_height; static int frame_display = 0; /* display the frame during encoding */ @@ -82,11 +81,11 @@ static int upload_source_YUV_once_for_all() int box_width=8; int row_shift=0; int i; - + for (i=0; i\n"); - printf(" -w -h: resolution\n"); - printf(" -n frame number\n"); - printf(" -d display the source frame\n"); - printf(" -p P frame count between two I frames\n"); - printf(" -f frame rate\n"); - printf(" -r bit rate\n"); - printf(" -q initial QP\n"); - printf(" -s maximum QP\n"); - printf(" -o coded file\n"); - exit(0); + case 'w': + frame_width = atoi(optarg); + break; + case 'h': + frame_height = atoi(optarg); + break; + case 'n': + frame_count = atoi(optarg); + break; + case 'p': + intra_count = atoi(optarg); + break; + case 'f': + frame_rate = atoi(optarg); + break; + case 'b': + frame_bitrate = atoi(optarg); + break; + case 'q': + initial_qp = atoi(optarg); + break; + case 's': + minimal_qp = atoi(optarg); + break; + case 'd': + frame_display = 1; + break; + case 'o': + strcpy(coded_file, optarg); + break; + case ':': + case '?': + printf("./h264encode \n"); + printf(" -w -h: resolution\n"); + printf(" -n frame number\n"); + printf(" -d display the source frame\n"); + printf(" -p P frame count between two I frames\n"); + printf(" -f frame rate\n"); + printf(" -r bit rate\n"); + printf(" -q initial QP\n"); + printf(" -s maximum QP\n"); + printf(" -o coded file\n"); + exit(0); } } - + #ifdef ANDROID x11_display = (Display*)malloc(sizeof(Display)); *(x11_display) = 0x18c34078; @@ -366,7 +365,7 @@ int main(int argc,char **argv) CHECK_VASTATUS(va_status, "vaInitialize"); vaQueryConfigEntrypoints(va_dpy, VAProfileH264Baseline, entrypoints, - &num_entrypoints); + &num_entrypoints); for (slice_entrypoint = 0; slice_entrypoint < num_entrypoints; slice_entrypoint++) { if (entrypoints[slice_entrypoint] == VAEntrypointEncSlice) break; @@ -380,7 +379,7 @@ int main(int argc,char **argv) attrib[0].type = VAConfigAttribRTFormat; attrib[1].type = VAConfigAttribRateControl; vaGetConfigAttributes(va_dpy, VAProfileH264Baseline, VAEntrypointEncSlice, - &attrib[0], 2); + &attrib[0], 2); if ((attrib[0].value & VA_RT_FORMAT_YUV420) == 0) { /* not find desired YUV420 RT format */ assert(0); @@ -392,23 +391,23 @@ int main(int argc,char **argv) } attrib[0].value = VA_RT_FORMAT_YUV420; /* set to desired RT format */ attrib[1].value = VA_RC_VBR; /* set to desired RC mode */ - + va_status = vaCreateConfig(va_dpy, VAProfileH264Baseline, VAEntrypointEncSlice, - &attrib[0], 2,&config_id); + &attrib[0], 2,&config_id); CHECK_VASTATUS(va_status, "vaCreateConfig"); - + va_status = vaCreateSurfaces( - va_dpy, - VA_RT_FORMAT_YUV420, frame_width, frame_height, - &surface_id[0], SURFACE_NUM, - NULL, 0 - ); + va_dpy, + VA_RT_FORMAT_YUV420, frame_width, frame_height, + &surface_id[0], SURFACE_NUM, + NULL, 0 + ); CHECK_VASTATUS(va_status, "vaCreateSurfaces"); - + /* Create a context for this decode pipe */ va_status = vaCreateContext(va_dpy, config_id, - frame_width, ((frame_height+15)/16)*16, - VA_PROGRESSIVE,&surface_id[0],SURFACE_NUM,&context_id); + frame_width, ((frame_height+15)/16)*16, + VA_PROGRESSIVE,&surface_id[0],SURFACE_NUM,&context_id); CHECK_VASTATUS(va_status, "vaCreateContext"); /* store coded data into a file */ @@ -419,22 +418,22 @@ int main(int argc,char **argv) } printf("Coded %d frames, %dx%d, save the coded file into %s\n", - frame_count, frame_width, frame_height, coded_file); + frame_count, frame_width, frame_height, coded_file); do_h264_encoding(); printf("\n\n"); - + vaDestroySurfaces(va_dpy,&surface_id[0],SURFACE_NUM); vaDestroyContext(va_dpy,context_id); vaDestroyConfig(va_dpy,config_id); - + vaTerminate(va_dpy); - + #ifdef ANDROID free(x11_display); #else XCloseDisplay(x11_display); #endif - + return 0; } diff --git a/test/encode/h264encode_x11.c b/test/encode/h264encode_x11.c index 7f9494c..3f7aff2 100644 --- a/test/encode/h264encode_x11.c +++ b/test/encode/h264encode_x11.c @@ -51,7 +51,11 @@ static VASurfaceID surface_id[SURFACE_NUM]; static Window display_win = 0; static int win_width; static int win_height; -static int frame_width=352, frame_height=288; + +static int display_surface(int frame_id, int *exit_encode); + +#include "h264encode_common.c" + static int display_surface(int frame_id, int *exit_encode) { @@ -96,4 +100,3 @@ static int display_surface(int frame_id, int *exit_encode) return 0; } -#include "h264encode_common.c" diff --git a/va/va.h b/va/va.h index 77feb67..7a58d46 100644 --- a/va/va.h +++ b/va/va.h @@ -1558,38 +1558,6 @@ typedef struct _VAEncSliceParameterBuffer } slice_flags; } VAEncSliceParameterBuffer; -/**************************** - * H.264 specific encode data structures - ****************************/ - -typedef struct _VAEncSequenceParameterBufferH264Baseline -{ - unsigned char seq_parameter_set_id; - unsigned char level_idc; - unsigned int intra_period; - unsigned int intra_idr_period; - unsigned int max_num_ref_frames; - unsigned int picture_width_in_mbs; - unsigned int picture_height_in_mbs; - unsigned int bits_per_second; - unsigned int frame_rate; - unsigned int initial_qp; - unsigned int min_qp; - unsigned int basic_unit_size; - unsigned char vui_flag; -} VAEncSequenceParameterBufferH264Baseline; - -#define H264_LAST_PICTURE_EOSEQ 0x01 /* the last picture in the sequence */ -#define H264_LAST_PICTURE_EOSTREAM 0x02 /* the last picture in the stream */ -typedef struct _VAEncPictureParameterBufferH264Baseline -{ - VASurfaceID reference_picture; - VASurfaceID reconstructed_picture; - VABufferID coded_buf; - unsigned short picture_width; - unsigned short picture_height; - unsigned char last_picture; -} VAEncPictureParameterBufferH264Baseline; /**************************** * H.263 specific encode data structures diff --git a/va/va_trace.c b/va/va_trace.c index e280e0d..a88f4a8 100644 --- a/va/va_trace.c +++ b/va/va_trace.c @@ -1145,40 +1145,7 @@ static void va_TraceVAIQMatrixBufferH264( va_TraceMsg(idx, NULL); } -static void va_TraceVAEncSequenceParameterBufferH264Baseline( - VADisplay dpy, - VAContextID context, - VABufferID buffer, - VABufferType type, - unsigned int size, - unsigned int num_elements, - void *data) -{ - VAEncSequenceParameterBufferH264Baseline *p = (VAEncSequenceParameterBufferH264Baseline *)data; - DPY2INDEX(dpy); - - va_TraceMsg(idx, "VAEncSequenceParameterBufferH264Baseline\n"); - - va_TraceMsg(idx, "\tseq_parameter_set_id = %d\n", p->seq_parameter_set_id); - va_TraceMsg(idx, "\tlevel_idc = %d\n", p->level_idc); - va_TraceMsg(idx, "\tintra_period = %d\n", p->intra_period); - va_TraceMsg(idx, "\tintra_idr_period = %d\n", p->intra_idr_period); - va_TraceMsg(idx, "\tmax_num_ref_frames = %d\n", p->max_num_ref_frames); - va_TraceMsg(idx, "\tpicture_width_in_mbs = %d\n", p->picture_width_in_mbs); - va_TraceMsg(idx, "\tpicture_height_in_mbs = %d\n", p->picture_height_in_mbs); - va_TraceMsg(idx, "\tbits_per_second = %d\n", p->bits_per_second); - va_TraceMsg(idx, "\tframe_rate = %d\n", p->frame_rate); - va_TraceMsg(idx, "\tinitial_qp = %d\n", p->initial_qp); - va_TraceMsg(idx, "\tmin_qp = %d\n", p->min_qp); - va_TraceMsg(idx, "\tbasic_unit_size = %d\n", p->basic_unit_size); - va_TraceMsg(idx, "\tvui_flag = %d\n", p->vui_flag); - va_TraceMsg(idx, NULL); - - /* start a new sequce, coded log file can be truncated */ - trace_context[idx].trace_sequence_start = 1; - return; -} static void va_TraceVAEncSequenceParameterBufferH264( VADisplay dpy, @@ -1245,31 +1212,6 @@ static void va_TraceVAEncSequenceParameterBufferH264( return; } -static void va_TraceVAEncPictureParameterBufferH264Baseline( - VADisplay dpy, - VAContextID context, - VABufferID buffer, - VABufferType type, - unsigned int size, - unsigned int num_elements, - void *data) -{ - VAEncPictureParameterBufferH264Baseline *p = (VAEncPictureParameterBufferH264Baseline *)data; - DPY2INDEX(dpy); - - va_TraceMsg(idx, "VAEncPictureParameterBufferH264Baseline\n"); - va_TraceMsg(idx, "\treference_picture = 0x%08x\n", p->reference_picture); - va_TraceMsg(idx, "\treconstructed_picture = 0x%08x\n", p->reconstructed_picture); - va_TraceMsg(idx, "\tcoded_buf = %08x\n", p->coded_buf); - va_TraceMsg(idx, "\tpicture_width = %d\n", p->picture_width); - va_TraceMsg(idx, "\tpicture_height = %d\n", p->picture_height); - va_TraceMsg(idx, "\tlast_picture = 0x%08x\n", p->last_picture); - va_TraceMsg(idx, NULL); - - trace_context[idx].trace_codedbuf = p->coded_buf; - - return; -} static void va_TraceVAEncPictureParameterBufferH264( VADisplay dpy, @@ -2048,16 +1990,10 @@ static void va_TraceH264Buf( case VAEncCodedBufferType: break; case VAEncSequenceParameterBufferType: - if (size == sizeof(VAEncSequenceParameterBufferH264Baseline)) - va_TraceVAEncSequenceParameterBufferH264Baseline(dpy, context, buffer, type, size, num_elements, pbuf); - if (size == sizeof(VAEncSequenceParameterBufferH264)) - va_TraceVAEncSequenceParameterBufferH264(dpy, context, buffer, type, size, num_elements, pbuf); + va_TraceVAEncSequenceParameterBufferH264(dpy, context, buffer, type, size, num_elements, pbuf); break; case VAEncPictureParameterBufferType: - if (size == sizeof(VAEncPictureParameterBufferH264Baseline)) - va_TraceVAEncPictureParameterBufferH264Baseline(dpy, context, buffer, type, size, num_elements, pbuf); - if (size == sizeof(VAEncPictureParameterBufferH264)) - va_TraceVAEncPictureParameterBufferH264(dpy, context, buffer, type, size, num_elements, pbuf); + va_TraceVAEncPictureParameterBufferH264(dpy, context, buffer, type, size, num_elements, pbuf); break; case VAEncSliceParameterBufferType: va_TraceVAEncSliceParameterBufferH264(dpy, context, buffer, type, size, num_elements, pbuf); diff --git a/va/va_trace.h b/va/va_trace.h index a211c82..6803c28 100644 --- a/va/va_trace.h +++ b/va/va_trace.h @@ -29,6 +29,8 @@ extern "C" { #endif +#include "va/va.h" + extern int trace_flag; #define VA_TRACE_FLAG_LOG 0x1 -- 2.7.4