Commit 549946cf authored by Austin Yuan's avatar Austin Yuan

vatrace/vafool: refine it

remove va_fool_getframe.c which looks strange
correct some coding style for file va.c
simplify va_fool.c for both decode and encode
refine the surface dump of va_trace.c
Signed-off-by: default avatarAustin Yuan <shengquan.yuan@gmail.com>
parent 1092e4b5
......@@ -35,8 +35,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
va.c \
va_trace.c \
va_fool.c \
va_fool_getframe.c
va_fool.c
LOCAL_CFLAGS += \
-DANDROID \
......@@ -59,7 +58,7 @@ LOCAL_COPY_HEADERS_TO := libva/va
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libva
LOCAL_SHARED_LIBRARIES := libdl libdrm libcutils
LOCAL_SHARED_LIBRARIES := libdl libdrm libcutils liblog
include $(BUILD_SHARED_LIBRARY)
......
......@@ -34,7 +34,6 @@ LDADD = \
libva_source_c = \
va.c \
va_fool.c \
va_fool_getframe.c \
va_trace.c \
$(NULL)
......
......@@ -25,6 +25,8 @@
#define _GNU_SOURCE 1
#include "va.h"
#include "va_backend.h"
#include "va_trace.h"
#include "va_fool.h"
#include "va_android.h"
#include "va_dricommon.h" /* needs some helper functions from this file */
#include <stdio.h>
......@@ -267,11 +269,6 @@ extern "C" {
);
}
#define VA_TRACE(trace_func,...) \
if (trace_flag) { \
trace_func(__VA_ARGS__); \
}
VAStatus vaPutSurface (
VADisplay dpy,
VASurfaceID surface,
......@@ -300,9 +297,9 @@ VAStatus vaPutSurface (
CHECK_DISPLAY(dpy);
ctx = CTX(dpy);
VA_TRACE(va_TracePutSurface, dpy, surface, static_cast<void*>(&draw), srcx, srcy, srcw, srch,
destx, desty, destw, desth,
cliprects, number_cliprects, flags );
VA_TRACE_LOG(va_TracePutSurface, dpy, surface, static_cast<void*>(&draw), srcx, srcy, srcw, srch,
destx, desty, destw, desth,
cliprects, number_cliprects, flags );
return ctx->vtable->vaPutSurface( ctx, surface, static_cast<void*>(&draw), srcx, srcy, srcw, srch,
destx, desty, destw, desth,
......
This diff is collapsed.
This diff is collapsed.
......@@ -28,35 +28,40 @@
#include <stdio.h>
void va_FoolInit(VADisplay dpy);
int va_FoolEnd(VADisplay dpy);
#ifdef __cplusplus
extern "C" {
#endif
extern int fool_codec;
extern int fool_postp;
int va_FoolGetFrame(FILE *input_fp, char *frame_buf);
#define VA_FOOL_FLAG_DECODE 0x1
#define VA_FOOL_FLAG_ENCODE 0x2
#define VA_FOOL_FLAG_JPEG 0x4
int va_FoolCodedBuf(VADisplay dpy);
#define VA_FOOL_FUNC(fool_func,...) \
if (fool_codec) { \
ret = fool_func(__VA_ARGS__); \
}
#define VA_FOOL_RETURN() \
if (fool_codec) { \
return VA_STATUS_SUCCESS; \
}
void va_FoolInit(VADisplay dpy);
int va_FoolEnd(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 */
);
int va_FoolCreateSurfaces(
VADisplay dpy,
int width,
int height,
int format,
int num_surfaces,
VASurfaceID *surfaces /* out */
);
VAStatus va_FoolCreateBuffer (
VAStatus va_FoolCreateBuffer(
VADisplay dpy,
VAContextID context, /* in */
VABufferType type, /* in */
......@@ -72,41 +77,22 @@ VAStatus va_FoolMapBuffer (
void **pbuf /* out */
);
int va_FoolBeginPicture(
VADisplay dpy,
VAContextID context,
VASurfaceID render_target
);
int va_FoolRenderPicture(
VADisplay dpy,
VAContextID context,
VABufferID *buffers,
int num_buffers
);
int va_FoolEndPicture(
VADisplay dpy,
VAContextID context
);
VAStatus va_FoolUnmapBuffer (
VADisplay dpy,
VABufferID buf_id /* in */
VAStatus va_FoolUnmapBuffer(
VADisplay dpy,
VABufferID buf_id /* in */
);
VAStatus va_FoolQuerySubpictureFormats (
VAStatus va_FoolBufferInfo (
VADisplay dpy,
VAImageFormat *format_list,
unsigned int *flags,
unsigned int *num_formats
);
int va_FoolSyncSurface(
VADisplay dpy,
VASurfaceID render_target
VABufferID buf_id, /* in */
VABufferType *type, /* out */
unsigned int *size, /* out */
unsigned int *num_elements /* out */
);
#ifdef __cplusplus
}
#endif
#endif
/* The code refers to
* http://keyj.s2000.at/files/projects/h264-src.tar.gz
*/
#include <string.h>
#include <stdio.h>
#define SLICE_NUM 4
#define NAL_BUF_SIZE 65536 // maximum NAL unit size
#define RING_BUF_SIZE 8192 // input ring buffer size, MUST be a power of two!
typedef struct _nal_unit {
int NumBytesInNALunit;
int forbidden_zero_bit;
int nal_ref_idc;
int nal_unit_type;
unsigned char *last_rbsp_byte;
} nal_unit;
typedef struct _slice_header {
int first_mb_in_slice;
} slice_header;
static int get_next_nal_unit(FILE *input_fp, nal_unit *nalu);
static int get_unsigned_exp_golomb();
static void decode_slice_header(slice_header *sh);
static void input_read(FILE *input_fp, unsigned char *dest, int size);
static int input_get_bits(int bit_count);
static unsigned char nal_buf[NAL_BUF_SIZE];
static unsigned char ring_buf[RING_BUF_SIZE];
static int input_remain = 0;
static int ring_pos = 0;
static int nal_pos;
static int nal_bit;
static int frame_no = 0;
#define RING_MOD ((RING_BUF_SIZE)-1)
#define HALF_RING ((RING_BUF_SIZE)/2)
#define gnn_advance() do { \
ring_pos = (ring_pos+1)&RING_MOD; \
--input_remain; \
if (ring_pos==0) input_read(input_fp, &ring_buf[HALF_RING],HALF_RING); \
if (ring_pos==HALF_RING) input_read(input_fp, &ring_buf[0],HALF_RING); \
} while(0)
#define gnn_add_segment(end) do { \
int size = end-segment_start; \
if (size>0) { \
memcpy(&nal_buf[nalu_size],&ring_buf[segment_start],size); \
nalu_size += size; \
} \
segment_start = end&RING_MOD; \
} while(0)
static int input_get_bits(int bit_count)
{
int res = 0;
register unsigned int x =
(nal_buf[nal_pos]<<24)|
(nal_buf[nal_pos+1]<<16)|
(nal_buf[nal_pos+2]<<8)|
nal_buf[nal_pos+3];
res = (x>>(32-bit_count-nal_bit))&((1<<bit_count)-1);
nal_bit += bit_count;
nal_pos += nal_bit>>3;
nal_bit &= 7;
return res;
}
static int input_get_one_bit()
{
int res = (nal_buf[nal_pos]>>(7-nal_bit))&1;
if (++nal_bit>7) {
++nal_pos;
nal_bit = 0;
}
return res;
}
static int get_unsigned_exp_golomb()
{
int exp;
for(exp = 0; !input_get_one_bit(); ++exp);
if (exp)
return (1<<exp) - 1 + input_get_bits(exp);
else
return 0;
}
static void decode_slice_header(slice_header *sh )
{
memset((void*)sh,0,sizeof(slice_header));
sh->first_mb_in_slice = get_unsigned_exp_golomb();
}
static void input_read(FILE *input_fp, unsigned char *dest, int size)
{
int count = fread(dest, 1, size, input_fp);
input_remain += count;
}
static int get_next_nal_unit(FILE *input_fp, nal_unit *nalu)
{
int i,segment_start;
int nalu_size = 0;
int NumBytesInRbsp = 0;
/* search for the next NALU start
* here is the sync that the start of the NALU is 0x00000001
*/
for (;;) {
if (input_remain<= 4) {
/* clip restart */
memset(ring_buf,0,sizeof(char)*RING_BUF_SIZE);
memset(nal_buf,0,sizeof(char)*NAL_BUF_SIZE);
fseek(input_fp,0,SEEK_SET);
input_remain = 0;
input_read(input_fp, ring_buf, RING_BUF_SIZE);
ring_pos = 0;
return 1;
}
if ((!ring_buf[ring_pos]) &&
(!ring_buf[(ring_pos+1)&RING_MOD]) &&
(!ring_buf[(ring_pos+2)&RING_MOD]) &&
( ring_buf[(ring_pos+3)&RING_MOD]==1))
break;
gnn_advance();
}
for(i=0;i<4;++i)
gnn_advance();
/* add bytes to the NALU until the end is found */
segment_start = ring_pos;
while (input_remain) {
if ((!ring_buf[ring_pos]) &&
(!ring_buf[(ring_pos+1)&RING_MOD]) &&
(!ring_buf[(ring_pos+2)&RING_MOD]))
break;
ring_pos = (ring_pos+1)&RING_MOD;
--input_remain;
if (ring_pos==0) {
gnn_add_segment(RING_BUF_SIZE);
input_read(input_fp, &ring_buf[HALF_RING],HALF_RING);
}
if (ring_pos==HALF_RING) {
gnn_add_segment(HALF_RING);
input_read(input_fp, &ring_buf[0], HALF_RING);
}
}
gnn_add_segment(ring_pos);
/* read the NAL unit */
nal_pos = 0; nal_bit = 0;
nalu->forbidden_zero_bit = input_get_bits(1);
nalu->nal_ref_idc = input_get_bits(2);
nalu->nal_unit_type = input_get_bits(5);
nalu->last_rbsp_byte = &nal_buf[nalu_size-1];
nalu->NumBytesInNALunit = nalu_size;
return 1;
}
int va_FoolGetFrame(FILE *input_fp, char *frame_buf)
{
int i = 0, frame_pos = 0;
static slice_header sh;
static nal_unit nalu;
char nal_head[4] = {0x00,0x00,0x00,0x01};
/* read the clip , here is the first frame,
* &let the clip go on frame by frame
*/
if (!frame_no)
input_read(input_fp, ring_buf,RING_BUF_SIZE);
while (get_next_nal_unit(input_fp, &nalu)) {
if (nalu.nal_unit_type == 7 || nalu.nal_unit_type == 8) {
memcpy(frame_buf+frame_pos, nal_head, sizeof(char)*4);
frame_pos = frame_pos + 4;
memcpy(frame_buf+frame_pos, nal_buf, sizeof(char)*(nalu.NumBytesInNALunit));
frame_pos += nalu.NumBytesInNALunit;
}
else if (nalu.nal_unit_type == 1 || nalu.nal_unit_type == 5) {
decode_slice_header(&sh);
if (0 == sh.first_mb_in_slice) {
++frame_no;
}
memcpy(frame_buf+frame_pos, nal_head, sizeof(char)*4);
frame_pos = frame_pos + 4;
memcpy(frame_buf+frame_pos, nal_buf, sizeof(char)*(nalu.NumBytesInNALunit));
frame_pos += nalu.NumBytesInNALunit;
break;
}
}
return frame_pos;
}
This diff is collapsed.
......@@ -25,6 +25,35 @@
#ifndef VA_TRACE_H
#define VA_TRACE_H
#ifdef __cplusplus
extern "C" {
#endif
extern int trace_flag;
#define VA_TRACE_FLAG_LOG 0x1
#define VA_TRACE_FLAG_BUFDATA 0x2
#define VA_TRACE_FLAG_CODEDBUF 0x4
#define VA_TRACE_FLAG_SURFACE_DECODE 0x8
#define VA_TRACE_FLAG_SURFACE_ENCODE 0x10
#define VA_TRACE_FLAG_SURFACE_JPEG 0x20
#define VA_TRACE_FLAG_SURFACE (VA_TRACE_FLAG_SURFACE_DECODE | \
VA_TRACE_FLAG_SURFACE_ENCODE | \
VA_TRACE_FLAG_SURFACE_JPEG)
#define VA_TRACE_FUNC(trace_func,...) \
if (trace_flag) { \
trace_func(__VA_ARGS__); \
}
#define VA_TRACE_LOG(trace_func,...) \
if (trace_flag & VA_TRACE_FLAG_LOG) { \
trace_func(__VA_ARGS__); \
}
#define VA_TRACE_SURFACE(trace_func,...) \
if (trace_flag & (VA_TRACE_FLAG_SURFACE | VA_TRACE_FLAG_CODEDBUF)) { \
trace_func(__VA_ARGS__); \
}
void va_TraceInit(VADisplay dpy);
void va_TraceEnd(VADisplay dpy);
......@@ -92,7 +121,8 @@ void va_TraceRenderPicture(
void va_TraceEndPicture(
VADisplay dpy,
VAContextID context
VAContextID context,
int endpic_done
);
void va_TraceSyncSurface(
......@@ -155,6 +185,9 @@ void va_TracePutSurface (
unsigned int flags /* de-interlacing flags */
);
#ifdef __cplusplus
}
#endif
#endif /* VA_TRACE_H */
......@@ -26,6 +26,8 @@
#include "sysdeps.h"
#include "va.h"
#include "va_backend.h"
#include "va_trace.h"
#include "va_fool.h"
#include "va_x11.h"
#include "va_dri.h"
#include "va_dri2.h"
......@@ -208,13 +210,6 @@ VADisplay vaGetDisplay (
#define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
#define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
extern int fool_postp; /* do nothing for vaPutSurface if set */
extern int trace_flag; /* trace vaPutSurface parameters */
#define VA_TRACE(trace_func,...) \
if (trace_flag) { \
trace_func(__VA_ARGS__); \
}
void va_TracePutSurface (
VADisplay dpy,
VASurfaceID surface,
......@@ -258,8 +253,8 @@ VAStatus vaPutSurface (
CHECK_DISPLAY(dpy);
ctx = CTX(dpy);
VA_TRACE(va_TracePutSurface, dpy, surface, (void *)draw, srcx, srcy, srcw, srch,
destx, desty, destw, desth,
VA_TRACE_FUNC(va_TracePutSurface, dpy, surface, (void *)draw, srcx, srcy, srcw, srch,
destx, desty, destw, desth,
cliprects, number_cliprects, flags );
return ctx->vtable->vaPutSurface( ctx, surface, (void *)draw, srcx, srcy, srcw, srch,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment