summaryrefslogtreecommitdiff
path: root/va/va_fool.c
diff options
context:
space:
mode:
authorAustin Yuan <shengquan.yuan@gmail.com>2011-01-14 16:22:47 +0800
committerAustin Yuan <shengquan.yuan@gmail.com>2011-01-14 16:22:47 +0800
commitb7849f39151a5efda5ae103486b8d00dbe6b2ff2 (patch)
treec32005d2c7e9435b15eab2638846128090e95931 /va/va_fool.c
parentaa7a8a0b05d25f9daedaa3c1e7dd5fa360dd28cd (diff)
downloadlibva-b7849f39151a5efda5ae103486b8d00dbe6b2ff2.tar.gz
Refine VA_FOOL, and delete the hard coded clip va_fool_264.h
Move test/vainfo into test/vainfo/* Add prototype of vaCreateSurfacesForUserPtr for V4L2 user pointer support Fix klocwork critical issues. Use strnlen and snprintf instead of strlen and sprintf. New interface vaQuerySrufaceError for decode error report and concealment Encode data structure change (long term reference picture interface) Add h264 constrained baseline profile support. Signed-off-by: Elaine Wang <elaine.wang@intel.com> Signed-off-by: Bignlin Chen <binglin.chen.wang@intel.com> Signed-off-by: Yan Zhuang <yanx.zhunag@intel.com> Signed-off-by: Guoliang Ji <guoliangx.ji@intel.com>
Diffstat (limited to 'va/va_fool.c')
-rw-r--r--va/va_fool.c380
1 files changed, 198 insertions, 182 deletions
diff --git a/va/va_fool.c b/va/va_fool.c
index 519304d..be2540b 100644
--- a/va/va_fool.c
+++ b/va/va_fool.c
@@ -26,6 +26,7 @@
#include "va.h"
#include "va_backend.h"
#include "va_trace.h"
+#include "va_fool.h"
#include <assert.h>
#include <stdarg.h>
@@ -39,9 +40,6 @@
#include <unistd.h>
#include <time.h>
-#include "va_fool_264.h"
-
-
/*
* Do dummy decode/encode, ignore the input data
* In order to debug memory leak or low performance issues, we need to isolate driver problems
@@ -49,10 +47,10 @@
*
* LIBVA_FOOL_DECODE:
* . if set, decode does nothing, but fill in some YUV data
- * LIBVA_FOOL_ENCODE:
- * . if set, encode does nothing, but fill in a hard-coded 720P clip into coded buffer.
+ * LIBVA_FOOL_ENCODE=<clip name>:
+ * . if set, encode does nothing, but fill in the coded buffer from a H264 clip.
* . VA CONTEXT/CONFIG/SURFACE will call into drivers, but VA Buffer creation is done in here
- * . Bypass all ~SvaBeginPic/vaRenderPic/vaEndPic~T
+ * . Bypass all "vaBeginPic/vaRenderPic/vaEndPic"
* LIBVA_FOOL_POSTP:
* . if set, do nothing for vaPutSurface
*/
@@ -61,20 +59,28 @@
/* global settings */
/* LIBVA_FOOL_DECODE/LIBVA_FOOL_ENCODE/LIBVA_FOOL_POSTP */
-static int fool_decode = 0;
-static int fool_encode = 0;
+int fool_decode = 0;
+int fool_encode = 0;
int fool_postp = 0;
+
+
+#define NAL_BUF_SIZE 65536 // maximum NAL unit size
+#define RING_BUF_SIZE 8192 // input ring buffer size, MUST be a power of two!
+#define MAX_FRAME 16
+#define SLICE_NUM 4
+
#define FOOL_CONTEXT_MAX 4
/* per context settings */
static struct _fool_context {
VADisplay dpy; /* should use context as the key */
-
+
VAProfile fool_profile; /* current profile for buffers */
VAEntrypoint fool_entrypoint; /* current entrypoint */
FILE *fool_fp_codedclip; /* load a clip from disk for fooling encode*/
-
+ char *frame_buf;
+
/* all buffers with same type share one malloc-ed memory
* bufferID = (buffer numbers with the same type << 8) || type
* the malloc-ed memory can be find by fool_buf[bufferID & 0xff]
@@ -88,22 +94,23 @@ static struct _fool_context {
#define FOOL_DECODE(idx) (fool_decode && (fool_context[idx].fool_entrypoint == VAEntrypointVLD))
#define FOOL_ENCODE(idx) \
-(fool_encode \
- && (fool_context[idx].fool_entrypoint == VAEntrypointEncSlice) \
- && (fool_context[idx].fool_profile >= VAProfileH264Baseline) \
- && (fool_context[idx].fool_profile <= VAProfileH264High))
+ (fool_encode \
+ && (fool_context[idx].fool_entrypoint == VAEntrypointEncSlice) \
+ && (fool_context[idx].fool_profile >= VAProfileH264Baseline) \
+ && (fool_context[idx].fool_profile <= VAProfileH264High))
+
+#define DPY2INDEX(dpy) \
+ int idx; \
+ \
+ for (idx = 0; idx < FOOL_CONTEXT_MAX; idx++) \
+ if (fool_context[idx].dpy == dpy) \
+ break; \
+ \
+ if (idx == FOOL_CONTEXT_MAX) \
+ return 0; /* let driver go */
-#define DPY2INDEX(dpy) \
- int idx; \
- \
- for (idx = 0; idx < FOOL_CONTEXT_MAX; idx++) \
- if (fool_context[idx].dpy == dpy) \
- break; \
- \
- if (idx == FOOL_CONTEXT_MAX) \
- return 0; /* let driver go */ \
/* Prototype declarations (functions defined in va.c) */
@@ -113,29 +120,29 @@ void va_infoMessage(const char *msg, ...);
int va_parseConfig(char *env, char *env_value);
VAStatus vaBufferInfo(
- VADisplay dpy,
- VAContextID context, /* in */
- VABufferID buf_id, /* in */
- VABufferType *type, /* out */
- unsigned int *size, /* out */
- unsigned int *num_elements /* out */
+ VADisplay dpy,
+ VAContextID context, /* in */
+ VABufferID buf_id, /* in */
+ VABufferType *type, /* out */
+ unsigned int *size, /* out */
+ unsigned int *num_elements /* out */
);
VAStatus vaLockSurface(VADisplay dpy,
- VASurfaceID surface,
- unsigned int *fourcc, /* following are output argument */
- unsigned int *luma_stride,
- unsigned int *chroma_u_stride,
- unsigned int *chroma_v_stride,
- unsigned int *luma_offset,
- unsigned int *chroma_u_offset,
- unsigned int *chroma_v_offset,
- unsigned int *buffer_name,
- void **buffer
+ VASurfaceID surface,
+ unsigned int *fourcc, /* following are output argument */
+ unsigned int *luma_stride,
+ unsigned int *chroma_u_stride,
+ unsigned int *chroma_v_stride,
+ unsigned int *luma_offset,
+ unsigned int *chroma_u_offset,
+ unsigned int *chroma_v_offset,
+ unsigned int *buffer_name,
+ void **buffer
);
VAStatus vaUnlockSurface(VADisplay dpy,
- VASurfaceID surface
+ VASurfaceID surface
);
@@ -155,23 +162,30 @@ void va_FoolInit(VADisplay dpy)
fool_postp = 1;
va_infoMessage("LIBVA_FOOL_POSTP is on, dummy vaPutSurface\n");
}
-
-
+
+
if (va_parseConfig("LIBVA_FOOL_DECODE", NULL) == 0) {
fool_decode = 1;
va_infoMessage("LIBVA_FOOL_DECODE is on, dummy decode\n");
}
-
+
if (va_parseConfig("LIBVA_FOOL_ENCODE", &env_value[0]) == 0) {
- FILE *tmp = fopen(env_value, "r");
+ fool_context[fool_index].fool_fp_codedclip = fopen(env_value, "r");
- if (tmp)
- fool_context[fool_index].fool_fp_codedclip = tmp;
-
- fool_encode = 1;
+ if (fool_context[fool_index].fool_fp_codedclip) {
+ fool_encode = 1;
+ } else
+ fool_encode = 0;
- va_infoMessage("LIBVA_FOOL_ENCODE is on, dummy encode\n");
+ if (fool_encode) /* malloc the buffer for fake clip */
+ fool_context[fool_index].frame_buf = malloc(MAX_FRAME*SLICE_NUM*NAL_BUF_SIZE*sizeof(char));
+
+ if (fool_context[fool_index].frame_buf == NULL)
+ fool_encode = 0;
+
+ if (fool_encode)
+ va_infoMessage("LIBVA_FOOL_ENCODE is on, dummy encode\n");
}
if (fool_encode || fool_decode)
@@ -182,12 +196,18 @@ void va_FoolInit(VADisplay dpy)
int va_FoolEnd(VADisplay dpy)
{
int i;
-
+
DPY2INDEX(dpy);
-
- for (i = 0; i < VABufferTypeMax; i++) /* free memory */
+
+ for (i = 0; i < VABufferTypeMax; i++) {/* free memory */
if (fool_context[idx].fool_buf[i])
free(fool_context[idx].fool_buf[i]);
+ }
+ if (fool_context[idx].fool_fp_codedclip)
+ fclose(fool_context[idx].fool_fp_codedclip);
+
+ if (fool_context[idx].frame_buf)
+ free(fool_context[idx].frame_buf);
memset(&fool_context[idx], sizeof(struct _fool_context), 0);
return 0;
@@ -201,16 +221,16 @@ int va_FoolCodedBuf(VADisplay dpy)
int va_FoolCreateConfig(
- VADisplay dpy,
- VAProfile profile,
- VAEntrypoint entrypoint,
- VAConfigAttrib *attrib_list,
- int num_attribs,
- VAConfigID *config_id /* out */
+ VADisplay dpy,
+ VAProfile profile,
+ VAEntrypoint entrypoint,
+ VAConfigAttrib *attrib_list,
+ int num_attribs,
+ VAConfigID *config_id /* out */
)
{
DPY2INDEX(dpy);
-
+
/* call into driver level to allocate real context/surface/buffers, etc */
fool_context[idx].fool_profile = profile;
fool_context[idx].fool_entrypoint = entrypoint;
@@ -218,12 +238,12 @@ int va_FoolCreateConfig(
}
static int yuvgen_planar(
- int width, int height,
- unsigned char *Y_start, int Y_pitch,
- unsigned char *U_start, int U_pitch,
- unsigned char *V_start, int V_pitch,
- int UV_interleave, int box_width, int row_shift,
- int field
+ int width, int height,
+ unsigned char *Y_start, int Y_pitch,
+ unsigned char *U_start, int U_pitch,
+ unsigned char *V_start, int V_pitch,
+ int UV_interleave, int box_width, int row_shift,
+ int field
)
{
int row;
@@ -237,33 +257,33 @@ static int yuvgen_planar(
/* fill garbage data into the other field */
if (((field == VA_TOP_FIELD) && (row &1))
- || ((field == VA_BOTTOM_FIELD) && ((row &1)==0))) {
+ || ((field == VA_BOTTOM_FIELD) && ((row &1)==0))) {
memset(Y_row, 0xff, width);
continue;
}
-
+
for (jj=0; jj<width; jj++) {
xpos = ((row_shift + jj) / box_width) & 0x1;
-
+
if ((xpos == 0) && (ypos == 0))
Y_row[jj] = 0xeb;
if ((xpos == 1) && (ypos == 1))
Y_row[jj] = 0xeb;
-
+
if ((xpos == 1) && (ypos == 0))
Y_row[jj] = 0x10;
if ((xpos == 0) && (ypos == 1))
Y_row[jj] = 0x10;
}
}
-
+
/* copy UV data */
for( row =0; row < height/2; row++) {
unsigned short value = 0x80;
/* fill garbage data into the other field */
if (((field == VA_TOP_FIELD) && (row &1))
- || ((field == VA_BOTTOM_FIELD) && ((row &1)==0))) {
+ || ((field == VA_BOTTOM_FIELD) && ((row &1)==0))) {
value = 0xff;
}
@@ -274,7 +294,7 @@ static int yuvgen_planar(
} else {
unsigned char *U_row = U_start + row * U_pitch;
unsigned char *V_row = V_start + row * V_pitch;
-
+
memset (U_row,value,width/2);
memset (V_row,value,width/2);
}
@@ -285,12 +305,12 @@ static int yuvgen_planar(
int va_FoolCreateSurfaces(
- VADisplay dpy,
- int width,
- int height,
- int format,
- int num_surfaces,
- VASurfaceID *surfaces /* out */
+ VADisplay dpy,
+ int width,
+ int height,
+ int format,
+ int num_surfaces,
+ VASurfaceID *surfaces /* out */
)
{
int i;
@@ -308,73 +328,73 @@ int va_FoolCreateSurfaces(
int box_width = num_surfaces/2;
int row_shift = 0;
VAStatus va_status;
-
+
DPY2INDEX(dpy);
if (FOOL_DECODE(idx)) {
- /* call into driver level to allocate real context/surface/buffers, etc
- * fill in the YUV data, will be overwrite if it is encode context
- */
- for (i = 0; i < num_surfaces; i++) {
- /* fool decoder: fill with auto-generated YUV data */
- va_status = vaLockSurface(dpy, surfaces[i], &fourcc,
- &luma_stride, &chroma_u_stride, &chroma_v_stride,
- &luma_offset, &chroma_u_offset, &chroma_v_offset,
- &buffer_name, &buffer);
-
- if (va_status != VA_STATUS_SUCCESS)
- return 0;
-
- if (!buffer) {
- vaUnlockSurface(dpy, surfaces[i]);
- return 0;
- }
-
- Y_data = buffer;
-
- /* UV should be same for NV12 */
- U_data = buffer + chroma_u_offset;
- V_data = buffer + chroma_v_offset;
-
- yuvgen_planar(width, height,
- Y_data, luma_stride,
- U_data, chroma_v_stride,
- V_data, chroma_v_stride,
- (fourcc==VA_FOURCC_NV12),
- box_width, row_shift, 0);
-
- vaUnlockSurface(dpy, surfaces[i]);
-
- row_shift++;
- if (row_shift==(2*box_width))
- row_shift= 0;
- }
- return 0; /* the return value is ignored */
+ /* call into driver level to allocate real context/surface/buffers, etc
+ * fill in the YUV data, will be overwrite if it is encode context
+ */
+ for (i = 0; i < num_surfaces; i++) {
+ /* fool decoder: fill with auto-generated YUV data */
+ va_status = vaLockSurface(dpy, surfaces[i], &fourcc,
+ &luma_stride, &chroma_u_stride, &chroma_v_stride,
+ &luma_offset, &chroma_u_offset, &chroma_v_offset,
+ &buffer_name, &buffer);
+
+ if (va_status != VA_STATUS_SUCCESS)
+ return 0;
+
+ if (!buffer) {
+ vaUnlockSurface(dpy, surfaces[i]);
+ return 0;
+ }
+
+ Y_data = buffer;
+
+ /* UV should be same for NV12 */
+ U_data = buffer + chroma_u_offset;
+ V_data = buffer + chroma_v_offset;
+
+ yuvgen_planar(width, height,
+ Y_data, luma_stride,
+ U_data, chroma_v_stride,
+ V_data, chroma_v_stride,
+ (fourcc==VA_FOURCC_NV12),
+ box_width, row_shift, 0);
+
+ vaUnlockSurface(dpy, surfaces[i]);
+
+ row_shift++;
+ if (row_shift==(2*box_width))
+ row_shift= 0;
+ }
+ return 0; /* the return value is ignored */
}
return 0; /* the return value is ignored */
}
VAStatus va_FoolCreateBuffer (
- VADisplay dpy,
- VAContextID context, /* in */
- VABufferType type, /* in */
- unsigned int size, /* in */
- unsigned int num_elements, /* in */
- void *data, /* in */
- VABufferID *buf_id /* out */
+ VADisplay dpy,
+ VAContextID context, /* in */
+ VABufferType type, /* in */
+ unsigned int size, /* in */
+ unsigned int num_elements, /* in */
+ void *data, /* in */
+ VABufferID *buf_id /* out */
)
{
DPY2INDEX(dpy);
if (FOOL_ENCODE(idx) || FOOL_DECODE(idx)) { /* fool buffer creation */
int new_size = size * num_elements;
-
+
if (type == VAEncCodedBufferType) /* only a VACodedBufferSegment */
new_size = sizeof(VACodedBufferSegment);
-
- if (fool_context[idx].fool_buf_size[type] == 0)
- fool_context[idx].fool_buf[type] = calloc(1, new_size);
- else if (fool_context[idx].fool_buf_size[type] <= new_size)
+
+ if (fool_context[idx].fool_buf_size[type] == 0)
+ fool_context[idx].fool_buf[type] = calloc(1, new_size);
+ else if (fool_context[idx].fool_buf_size[type] <= new_size)
fool_context[idx].fool_buf[type] = realloc(fool_context[idx].fool_buf, new_size);
if (fool_context[idx].fool_buf[type] == NULL) {
@@ -388,18 +408,17 @@ VAStatus va_FoolCreateBuffer (
*/
fool_context[idx].fool_buf_count[type]++;
*buf_id = (fool_context[idx].fool_buf_count[type] << 8) | type;
-
+
return 1; /* don't call into driver */
}
-
+
return 0; /* let driver go ... */
}
-
VAStatus va_FoolMapBuffer (
- VADisplay dpy,
- VABufferID buf_id, /* in */
- void **pbuf /* out */
+ VADisplay dpy,
+ VABufferID buf_id, /* in */
+ void **pbuf /* out */
)
{
VABufferType type;
@@ -409,11 +428,11 @@ VAStatus va_FoolMapBuffer (
if (FOOL_ENCODE(idx) || FOOL_DECODE(idx)) { /* fool buffer creation */
unsigned int buf_idx = buf_id & 0xff;
-
- /*Image buffer?*/
- vaBufferInfo(dpy, fool_context[idx].context, buf_id, &type, &size, &num_elements);
- if (type == VAImageBufferType && FOOL_ENCODE(idx))
- return 0;
+
+ /* Image buffer? */
+ vaBufferInfo(dpy, fool_context[idx].context, buf_id, &type, &size, &num_elements);
+ if (type == VAImageBufferType && FOOL_ENCODE(idx))
+ return 0;
/* buf_id is the buffer type */
if (fool_context[idx].fool_buf[buf_idx] != NULL)
@@ -423,47 +442,44 @@ VAStatus va_FoolMapBuffer (
/* expect APP to MapBuffer when get the the coded data */
if (*pbuf && (buf_idx == VAEncCodedBufferType)) { /* it is coded buffer */
- /* should read from a clip, here we use the hardcoded h264_720p_nal */
- memcpy(*pbuf, &h264_720p_nal[h264_720p_nal_idx], sizeof(VACodedBufferSegment));
- h264_720p_nal_idx++;
- if (h264_720p_nal_idx == H264_720P_NAL_NUMBER)
- h264_720p_nal_idx = 0; /* reset to 0 */
+ /* read from a clip */
+ va_FoolGetFrame(fool_context[idx].fool_fp_codedclip,
+ fool_context[idx].frame_buf);
+ *pbuf = fool_context[idx].frame_buf;
}
-
return 1; /* don't call into driver */
}
-
+
return 0; /* let driver go ... */
}
int va_FoolBeginPicture(
- VADisplay dpy,
- VAContextID context,
- VASurfaceID render_target
+ VADisplay dpy,
+ VAContextID context,
+ VASurfaceID render_target
)
{
DPY2INDEX(dpy);
-
- if (FOOL_ENCODE(idx) || FOOL_DECODE(idx))
- {
- if (fool_context[idx].context == 0)
- fool_context[idx].context = context;
+
+ if (FOOL_ENCODE(idx) || FOOL_DECODE(idx)) {
+ if (fool_context[idx].context == 0)
+ fool_context[idx].context = context;
return 1; /* don't call into driver level */
}
-
+
return 0; /* let driver go ... */
}
int va_FoolRenderPicture(
- VADisplay dpy,
- VAContextID context,
- VABufferID *buffers,
- int num_buffers
+ VADisplay dpy,
+ VAContextID context,
+ VABufferID *buffers,
+ int num_buffers
)
{
DPY2INDEX(dpy);
-
+
if (FOOL_ENCODE(idx) || FOOL_DECODE(idx))
return 1; /* don't call into driver level */
@@ -472,8 +488,8 @@ int va_FoolRenderPicture(
int va_FoolEndPicture(
- VADisplay dpy,
- VAContextID context
+ VADisplay dpy,
+ VAContextID context
)
{
DPY2INDEX(dpy);
@@ -499,46 +515,46 @@ int va_FoolEndPicture(
}
int va_FoolSyncSurface(
- VADisplay dpy,
- VASurfaceID render_target)
+ VADisplay dpy,
+ VASurfaceID render_target
+)
{
DPY2INDEX(dpy);
+
/*Fill in black and white squares. */
if (FOOL_DECODE(idx) || FOOL_DECODE(idx))
- {
- return 1;
- }
+ return 1;
return 0;
}
-VAStatus va_FoolUnmapBuffer (
- VADisplay dpy,
- VABufferID buf_id /* in */
+VAStatus va_FoolUnmapBuffer(
+ VADisplay dpy,
+ VABufferID buf_id /* in */
)
{
DPY2INDEX(dpy);
- if (FOOL_ENCODE(idx) || FOOL_DECODE(idx)) { /* fool buffer creation */
- return 1;
- }
+ if (FOOL_ENCODE(idx) || FOOL_DECODE(idx))
+ return 1; /* fool buffer creation */
+
return 0;
}
-VAStatus va_FoolQuerySubpictureFormats (
- VADisplay dpy,
- VAImageFormat *format_list,
- unsigned int *flags,
- unsigned int *num_formats
+VAStatus va_FoolQuerySubpictureFormats(
+ VADisplay dpy,
+ VAImageFormat *format_list,
+ unsigned int *flags,
+ unsigned int *num_formats
)
{
DPY2INDEX(dpy);
if (FOOL_ENCODE(idx) || FOOL_DECODE(idx)) {
- if (num_formats)
- *num_formats = 0;
- return 1;
+ if (num_formats)
+ *num_formats = 0;
+ return 1;
}
return 0;
}