summaryrefslogtreecommitdiff
path: root/test/encode
diff options
context:
space:
mode:
authorFei Jiang <fei.jiang@intel.com>2010-06-11 10:38:21 +0800
committerFrancis Tharappel <francis.m.tharappel@intel.com>2010-06-15 15:23:52 -0700
commitb0fac498ca4863166252f1268fda83394db54153 (patch)
tree5a16620c688cf15eb5499f615b517ca166be17c2 /test/encode
parentb24acf60aa8e6652897501d47ccbd34f2699ade2 (diff)
downloadlibva-b0fac498ca4863166252f1268fda83394db54153.tar.gz
Replace wind river libva with intel UMG libva.
OpencoreHw will call the same vaPutSurface for texture streaming and overlay display. Divide libva into three libraries: libva, libva-android, libva-tpi libva: general va API libva-android: va API used for android platform libva-tpi: third party interface Reviewed-by:Francis Tharappel Change-Id: Ib8fb9da3b6a463af9b91241392a07fdbd9e1beb9
Diffstat (limited to 'test/encode')
-rw-r--r--test/encode/Makefile.am4
-rw-r--r--test/encode/h264encode.c60
2 files changed, 38 insertions, 26 deletions
diff --git a/test/encode/Makefile.am b/test/encode/Makefile.am
index 6d2d5a9..b353ca1 100644
--- a/test/encode/Makefile.am
+++ b/test/encode/Makefile.am
@@ -22,9 +22,9 @@
bin_PROGRAMS = h264encode
-AM_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/x11 -DIN_LIBVA
+AM_CFLAGS = -I$(top_srcdir)/va -I$(top_srcdir)/src/x11
-TEST_LIBS = $(top_srcdir)/src/$(libvabackendlib)
+TEST_LIBS = $(top_builddir)/va/$(libvabackendlib)
h264encode_LDADD = $(TEST_LIBS)
h264encode_SOURCES = h264encode.c
diff --git a/test/encode/h264encode.c b/test/encode/h264encode.c
index 46f1ff6..1e4ecec 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
* ./h264encode -w <width> -h <height> -n <frame_num>
*
*/
@@ -44,9 +44,8 @@
#include <assert.h>
-#include "va.h"
-#include "va_x11.h"
-
+#include <va/va.h>
+#include <va/va_x11.h>
#define CHECK_VASTATUS(va_status,func) \
if (va_status != VA_STATUS_SUCCESS) { \
@@ -106,20 +105,16 @@ static int upload_source_YUV_once_for_all()
static int save_coded_buf(VABufferID coded_buf, int current_frame, int frame_skipped)
{
void *coded_p=NULL;
- int coded_size,coded_offset,wrt_size;
+ VACodedBufferSegment *buf_list = NULL;
VAStatus va_status;
-
- va_status = vaMapBuffer(va_dpy,coded_buf,&coded_p);
- CHECK_VASTATUS(va_status,"vaMapBuffer");
+ unsigned int coded_size = 0;
- coded_size = *((unsigned long *) coded_p); /* first DWord is the coded video size */
- coded_offset = *((unsigned long *) (coded_p + 4)); /* second DWord is byte offset */
-
- wrt_size = write(coded_fd,coded_p+coded_offset,coded_size);
- if (wrt_size != coded_size) {
- fprintf(stderr, "Trying to write %d bytes, but actual %d bytes\n",
- coded_size, wrt_size);
- exit(1);
+ va_status = vaMapBuffer(va_dpy,coded_buf,(void **)(&buf_list));
+ CHECK_VASTATUS(va_status,"vaMapBuffer");
+ while (buf_list != NULL) {
+ printf("Write %d bytes\n", buf_list->size);
+ coded_size += write(coded_fd, buf_list->buf, buf_list->size);
+ buf_list = buf_list->next;
}
vaUnmapBuffer(va_dpy,coded_buf);
@@ -212,10 +207,11 @@ static int do_h264_encoding(void)
VAEncPictureParameterBufferH264 pic_h264;
VAEncSliceParameterBuffer slice_h264;
VAStatus va_status;
- VABufferID coded_buf, seq_param_buf, pic_param_buf, slice_param_buf;
+ VABufferID seq_param_buf, pic_param_buf, slice_param_buf;
int codedbuf_size;
VASurfaceStatus surface_status;
int src_surface, dst_surface, ref_surface;
+ int codedbuf_idx = 0;
int frame_skipped = 0;
int i;
@@ -229,12 +225,24 @@ static int do_h264_encoding(void)
codedbuf_size = (frame_width * frame_height * 400) / (16*16);
+ for (i = 0; i < CODEDBUF_NUM; i++) {
+ /* create coded buffer once for all
+ * other VA buffers which won't be used again after vaRenderPicture.
+ * so APP can always vaCreateBuffer for every frame
+ * but coded buffer need to be mapped and accessed after vaRenderPicture/vaEndPicture
+ * so VA won't maintain the coded buffer
+ */
+ va_status = vaCreateBuffer(va_dpy,context_id,VAEncCodedBufferType,
+ codedbuf_size, 1, NULL, &coded_buf[i]);
+ CHECK_VASTATUS(va_status,"vaBeginPicture");
+ }
+
src_surface = 0;
/* the last two frames are reference/reconstructed frame */
dst_surface = SURFACE_NUM - 1;
ref_surface = SURFACE_NUM - 2;
- for (i=0; i < frame_count; i++) {
+ for (i = 0; i < frame_count; i++) {
va_status = vaBeginPicture(va_dpy, context_id, surface_id[src_surface]);
CHECK_VASTATUS(va_status,"vaBeginPicture");
@@ -249,7 +257,7 @@ static int do_h264_encoding(void)
seq_h264.frame_rate = frame_rate;
seq_h264.initial_qp = initial_qp;
seq_h264.min_qp = minimal_qp;
- seq_h264.basic_unit_size = 6;
+ seq_h264.basic_unit_size = 0;
seq_h264.intra_period = intra_count;
va_status = vaCreateBuffer(va_dpy, context_id,
@@ -261,12 +269,10 @@ static int do_h264_encoding(void)
CHECK_VASTATUS(va_status,"vaRenderPicture");;
}
- va_status = vaCreateBuffer(va_dpy,context_id,VAEncCodedBufferType,
- codedbuf_size, 1, NULL, &coded_buf);
pic_h264.reference_picture = surface_id[ref_surface];
pic_h264.reconstructed_picture= surface_id[dst_surface];
- pic_h264.coded_buf = coded_buf;
+ pic_h264.coded_buf = coded_buf[codedbuf_idx];
pic_h264.picture_width = frame_width;
pic_h264.picture_height = frame_height;
pic_h264.last_picture = (i==frame_count);
@@ -300,7 +306,7 @@ static int do_h264_encoding(void)
va_status = vaQuerySurfaceStatus(va_dpy, surface_id[src_surface],&surface_status);
frame_skipped = (surface_status & VASurfaceSkipped);
- save_coded_buf(coded_buf, i, frame_skipped);
+ save_coded_buf(coded_buf[codedbuf_idx], i, frame_skipped);
/* should display reconstructed frame, but just diplay source frame */
if (frame_display) {
@@ -316,6 +322,11 @@ static int do_h264_encoding(void)
if (src_surface == (SURFACE_NUM - 2))
src_surface = 0;
+ /* use next codedbuf */
+ codedbuf_idx++;
+ if (codedbuf_idx == (CODEDBUF_NUM - 1))
+ codedbuf_idx = 0;
+
/* if a frame is skipped, current frame still use last reference frame */
if (frame_skipped == 0) {
/* swap ref/dst */
@@ -375,7 +386,8 @@ int main(int argc,char **argv)
case '?':
printf("./h264encode <options>\n");
printf(" -w -h: resolution\n");
- printf(" -n frame number\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");