[format]: use astyle to format all source file

git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@96 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
ChenHengming
2015-08-13 02:26:39 +00:00
parent d1a1891f70
commit 3057548e07
12 changed files with 212 additions and 217 deletions

View File

@@ -22,21 +22,19 @@
#define VPU_API_NOPTS_VALUE (0x8000000000000000LL)
typedef enum VPU_API_CMD
{
VPU_API_ENC_SETCFG,
VPU_API_ENC_GETCFG,
VPU_API_ENC_SETFORMAT,
VPU_API_ENC_SETIDRFRAME,
VPU_API_ENABLE_DEINTERLACE,
VPU_API_SET_VPUMEM_CONTEXT,
VPU_API_USE_PRESENT_TIME_ORDER,
VPU_API_SET_DEFAULT_WIDTH_HEIGH,
VPU_API_SET_INFO_CHANGE,
typedef enum VPU_API_CMD {
VPU_API_ENC_SETCFG,
VPU_API_ENC_GETCFG,
VPU_API_ENC_SETFORMAT,
VPU_API_ENC_SETIDRFRAME,
VPU_API_ENABLE_DEINTERLACE,
VPU_API_SET_VPUMEM_CONTEXT,
VPU_API_USE_PRESENT_TIME_ORDER,
VPU_API_SET_DEFAULT_WIDTH_HEIGH,
VPU_API_SET_INFO_CHANGE,
} VPU_API_CMD;
typedef struct
{
typedef struct {
RK_U32 TimeLow;
RK_U32 TimeHigh;
} TIME_STAMP;
@@ -48,8 +46,7 @@ typedef struct VPUMem {
RK_U32 *offset;
} VPUMemLinear_t;
typedef struct tVPU_FRAME
{
typedef struct tVPU_FRAME {
RK_U32 FrameBusAddr[2]; // 0: Y address; 1: UV address;
RK_U32 FrameWidth; // buffer horizontal stride
RK_U32 FrameHeight; // buffer vertical stride
@@ -63,7 +60,7 @@ typedef struct tVPU_FRAME
RK_U32 DecodeFrmNum;
TIME_STAMP ShowTime;
RK_U32 ErrorInfo; // error information
RK_U32 employ_cnt;
RK_U32 employ_cnt;
VPUMemLinear_t vpumem;
struct tVPU_FRAME *next_frame;
RK_U32 Res[4];
@@ -110,8 +107,7 @@ typedef struct EncoderOut {
} EncoderOut_t;
typedef enum
{
typedef enum {
VPU_H264ENC_YUV420_PLANAR = 0, /* YYYY... UUUU... VVVV */
VPU_H264ENC_YUV420_SEMIPLANAR = 1, /* YYYY... UVUVUV... */
VPU_H264ENC_YUV422_INTERLEAVED_YUYV = 2, /* YUYVYUYV... */
@@ -167,36 +163,35 @@ typedef enum CODEC_TYPE {
CODEC_BUTT,
} CODEC_TYPE;
typedef enum VPU_API_ERR{
typedef enum VPU_API_ERR {
VPU_API_OK = 0,
VPU_API_ERR_UNKNOW = -1,
VPU_API_ERR_BASE = -1000,
VPU_API_ERR_LIST_STREAM = VPU_API_ERR_BASE -1,
VPU_API_ERR_INIT = VPU_API_ERR_BASE -2,
VPU_API_ERR_VPU_CODEC_INIT = VPU_API_ERR_BASE -3,
VPU_API_ERR_STREAM = VPU_API_ERR_BASE -4,
VPU_API_ERR_FATAL_THREAD = VPU_API_ERR_BASE -5,
VPU_API_EOS_STREAM_REACHED = VPU_API_ERR_BASE -11,
VPU_API_ERR_LIST_STREAM = VPU_API_ERR_BASE - 1,
VPU_API_ERR_INIT = VPU_API_ERR_BASE - 2,
VPU_API_ERR_VPU_CODEC_INIT = VPU_API_ERR_BASE - 3,
VPU_API_ERR_STREAM = VPU_API_ERR_BASE - 4,
VPU_API_ERR_FATAL_THREAD = VPU_API_ERR_BASE - 5,
VPU_API_EOS_STREAM_REACHED = VPU_API_ERR_BASE - 11,
VPU_API_ERR_BUTT,
} VPU_API_ERR;
typedef struct EncParameter
{
RK_S32 width;
RK_S32 height;
RK_S32 rc_mode;
RK_S32 bitRate;
RK_S32 framerate;
RK_S32 qp;
RK_S32 enableCabac;
RK_S32 cabacInitIdc;
RK_S32 format;
RK_S32 intraPicRate;
RK_S32 framerateout;
RK_S32 profileIdc;
RK_S32 levelIdc;
RK_S32 reserved[3];
typedef struct EncParameter {
RK_S32 width;
RK_S32 height;
RK_S32 rc_mode;
RK_S32 bitRate;
RK_S32 framerate;
RK_S32 qp;
RK_S32 enableCabac;
RK_S32 cabacInitIdc;
RK_S32 format;
RK_S32 intraPicRate;
RK_S32 framerateout;
RK_S32 profileIdc;
RK_S32 levelIdc;
RK_S32 reserved[3];
} EncParameter_t;
@@ -276,7 +271,7 @@ typedef struct VpuCodecContext {
RK_S32 (*encoder_sendframe)(struct VpuCodecContext *ctx, EncInputStream_t *aEncInStrm);
RK_S32 (*encoder_getstream)(struct VpuCodecContext *ctx, EncoderOut_t *aEncOut);
}VpuCodecContext_t;
} VpuCodecContext_t;
/* allocated vpu codec context */
#ifdef __cplusplus
@@ -298,8 +293,8 @@ RK_S32 vpu_close_context(struct VpuCodecContext **ctx);
typedef struct vpu_display_mem_pool vpu_display_mem_pool;
struct vpu_display_mem_pool {
int (*commit_hdl)(vpu_display_mem_pool *p, int hdl, int size);
void* (*get_free)(vpu_display_mem_pool *p);
int (*commit_hdl)(vpu_display_mem_pool *p, int hdl, int size);
void* (*get_free)(vpu_display_mem_pool *p);
int (*inc_used)(vpu_display_mem_pool *p, int hdl);
int (*put_used)(vpu_display_mem_pool *p, int hdl);
int (*reset)(vpu_display_mem_pool *p);

View File

@@ -86,7 +86,7 @@ static RK_S32 vpu_api_getframe(VpuCodecContext *ctx, DecoderOut_t *aDecOut)
return VPU_API_ERR_UNKNOW;
}
return api->decode_getoutframe(ctx,aDecOut);
return api->decode_getoutframe(ctx, aDecOut);
}
static RK_S32 vpu_api_sendframe(VpuCodecContext *ctx, EncInputStream_t *aEncInStrm)
@@ -118,7 +118,7 @@ static RK_S32 vpu_api_getstream(VpuCodecContext *ctx, EncoderOut_t *aEncOut)
return VPU_API_ERR_UNKNOW;
}
return api->encoder_getstream(ctx,aEncOut);
return api->encoder_getstream(ctx, aEncOut);
}
@@ -155,7 +155,7 @@ static RK_S32 vpu_api_flush(VpuCodecContext *ctx)
return api->flush(ctx);
}
static RK_S32 vpu_api_control(VpuCodecContext *ctx, VPU_API_CMD cmdType,void *param)
static RK_S32 vpu_api_control(VpuCodecContext *ctx, VPU_API_CMD cmdType, void *param)
{
if (ctx == NULL) {
mpp_log("vpu_api_decode fail, input invalid");
@@ -206,7 +206,7 @@ RK_S32 vpu_open_context(VpuCodecContext **ctx)
return 0;
}
if (!s->vpuApiObj){
if (!s->vpuApiObj) {
mpp_err("Input context has not been properly allocated and is not NULL either");
return -1;
}
@@ -228,7 +228,7 @@ RK_S32 vpu_close_context(VpuCodecContext **ctx)
mpp_free(s->extradata);
s->extradata = NULL;
}
if(s->private_data){
if (s->private_data) {
mpp_free(s->private_data);
s->private_data = NULL;
}

View File

@@ -116,7 +116,7 @@ RK_S32 VpuApi::encoder_sendframe(VpuCodecContext *ctx, EncInputStream_t *aEncInS
return 0;
}
RK_S32 VpuApi::encoder_getstream(VpuCodecContext *ctx,EncoderOut_t *aEncOut)
RK_S32 VpuApi::encoder_getstream(VpuCodecContext *ctx, EncoderOut_t *aEncOut)
{
mpp_log("%s in\n", __FUNCTION__);
(void)ctx;

View File

@@ -19,7 +19,8 @@
#include "vpu_api.h"
class VpuApi {
class VpuApi
{
public:
VpuApi();
~VpuApi();
@@ -29,7 +30,7 @@ public:
RK_S32 decode(VpuCodecContext *ctx, VideoPacket_t *pkt, DecoderOut_t *aDecOut);
RK_S32 decode_sendstream(VpuCodecContext *ctx, VideoPacket_t *pkt);
RK_S32 decode_getoutframe(VpuCodecContext *ctx,DecoderOut_t *aDecOut);
RK_S32 decode_getoutframe(VpuCodecContext *ctx, DecoderOut_t *aDecOut);
RK_S32 preProcessPacket(VpuCodecContext *ctx, VideoPacket_t *pkt);
RK_S32 encode(VpuCodecContext *ctx, EncInputStream_t *aEncInStrm, EncoderOut_t *aEncOut);

View File

@@ -27,11 +27,11 @@
RK_S32 os_get_env_u32(const char *name, RK_U32 *value, RK_U32 default_value)
{
char prop[PROP_VALUE_MAX+1];
char prop[PROP_VALUE_MAX + 1];
int len = __system_property_get(name, prop);
if (len > 0) {
char *endptr;
int base = (prop[0] == '0' && prop[1] == 'x')?(16):(10);
int base = (prop[0] == '0' && prop[1] == 'x') ? (16) : (10);
errno = 0;
*value = strtoul(prop, &endptr, base);
if (errno || (prop == endptr)) {
@@ -47,7 +47,7 @@ RK_S32 os_get_env_u32(const char *name, RK_U32 *value, RK_U32 default_value)
RK_S32 os_get_env_str(const char *name, char **value, char *default_value)
{
// use unsigned char to avoid warnning
static unsigned char env_str[2][PROP_VALUE_MAX+1];
static unsigned char env_str[2][PROP_VALUE_MAX + 1];
static RK_U32 env_idx = 0;
char *prop = (char *)env_str[env_idx];
int len = __system_property_get(name, prop);
@@ -62,16 +62,16 @@ RK_S32 os_get_env_str(const char *name, char **value, char *default_value)
RK_S32 os_set_env_u32(const char *name, RK_U32 value)
{
char buf[PROP_VALUE_MAX+1+2];
char buf[PROP_VALUE_MAX + 1 + 2];
snprintf(buf, sizeof(buf), "0x%x", value);
int len = __system_property_set(name, buf);
return (len)?(0):(-1);
return (len) ? (0) : (-1);
}
RK_S32 os_set_env_str(const char *name, char *value)
{
int len = __system_property_set(name, value);
return (len)?(0):(-1);
return (len) ? (0) : (-1);
}

View File

@@ -31,7 +31,8 @@
typedef void *(*node_destructor)(void *);
struct mpp_list_node;
class mpp_list {
class mpp_list
{
public:
mpp_list(node_destructor func);
~mpp_list();
@@ -77,8 +78,7 @@ private:
extern "C" {
#endif
struct list_head
{
struct list_head {
struct list_head *next, *prev;
};
@@ -93,7 +93,7 @@ struct list_head
#define list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
pos = n, n = pos->next)
#define list_entry(ptr, type, member) \
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
@@ -110,13 +110,13 @@ struct list_head
#define list_for_each_entry_safe(pos, n, head, type, member) \
for (pos = list_entry((head)->next, type, member), \
n = list_entry(pos->member.next, type, member); \
n = list_entry(pos->member.next, type, member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, type, member))
static inline void __list_add(struct list_head * _new,
struct list_head * prev,
struct list_head * next)
struct list_head * prev,
struct list_head * next)
{
next->prev = _new;
_new->next = next;

View File

@@ -28,7 +28,7 @@ RK_S32 os_get_env_u32(const char *name, RK_U32 *value, RK_U32 default_value)
*value = default_value;
} else {
char *endptr;
int base = (ptr[0] == '0' && ptr[1] == 'x')?(16):(10);
int base = (ptr[0] == '0' && ptr[1] == 'x') ? (16) : (10);
errno = 0;
*value = strtoul(ptr, &endptr, base);
if (errno || (ptr == endptr)) {

View File

@@ -51,7 +51,7 @@ static inline void list_node_init_with_key_and_size(mpp_list_node *node, RK_U32
static mpp_list_node* create_list(void *data, RK_S32 size, RK_U32 key)
{
mpp_list_node *node = (mpp_list_node*)malloc(sizeof(mpp_list_node)+size);
mpp_list_node *node = (mpp_list_node*)malloc(sizeof(mpp_list_node) + size);
if (node) {
void *dst = (void*)(node + 1);
list_node_init_with_key_and_size(node, key, size);

View File

@@ -52,11 +52,11 @@ void _mpp_log(const char *tag, const char *fmt, ...)
buf = msg_log_nothing;
} else if (len == MPP_LOG_MAX_LEN) {
buf = msg_log_warning;
} else if (fmt[len-1] != '\n') {
} else if (fmt[len - 1] != '\n') {
char msg[MPP_LOG_MAX_LEN];
snprintf(msg, sizeof(msg), "%s", fmt);
msg[len] = '\n';
msg[len+1] = '\0';
msg[len + 1] = '\0';
buf = msg;
}
@@ -78,11 +78,11 @@ void _mpp_err(const char *tag, const char *fmt, ...)
buf = msg_log_nothing;
} else if (len == MPP_LOG_MAX_LEN) {
buf = msg_log_warning;
} else if (fmt[len-1] != '\n') {
} else if (fmt[len - 1] != '\n') {
char msg[MPP_LOG_MAX_LEN];
snprintf(msg, sizeof(msg), "%s", fmt);
msg[len] = '\n';
msg[len+1] = '\0';
msg[len + 1] = '\0';
buf = msg;
}

View File

@@ -27,7 +27,7 @@ RK_S32 os_get_env_u32(const char *name, RK_U32 *value, RK_U32 default_value)
*value = default_value;
} else {
char *endptr;
int base = (ptr[0] == '0' && ptr[1] == 'x')?(16):(10);
int base = (ptr[0] == '0' && ptr[1] == 'x') ? (16) : (10);
errno = 0;
*value = strtoul(ptr, &endptr, base);
if (errno || (ptr == endptr)) {

View File

@@ -20,7 +20,7 @@
int os_malloc(void **memptr, size_t alignment, size_t size)
{
*memptr = _aligned_malloc(size, alignment);
return (*memptr)?(0):(-1);
return (*memptr) ? (0) : (-1);
}
void os_free(void *ptr)

View File

@@ -99,11 +99,11 @@ static RK_S32 show_help()
{
mpp_log("usage: vpu_apiDemo [options] input_file, \n\n");
RK_S32 i =0;
RK_S32 n = sizeof(vpuApiCmd)/sizeof(VpuApiCmd_t);
RK_S32 i = 0;
RK_S32 n = sizeof(vpuApiCmd) / sizeof(VpuApiCmd_t);
for (i = 0; i < n; i++) {
mpp_log("-%s %s\t\t%s\n",
vpuApiCmd[i].name, vpuApiCmd[i].argname, vpuApiCmd[i].help);
vpuApiCmd[i].name, vpuApiCmd[i].argname, vpuApiCmd[i].help);
}
return 0;
@@ -112,9 +112,9 @@ static RK_S32 show_help()
static RK_S32 parse_options(int argc, char **argv, VpuApiDemoCmdContext_t* cmdCxt)
{
char *opt;
RK_S32 optindex, handleoptions = 1, ret =0;
RK_S32 optindex, handleoptions = 1, ret = 0;
if ((argc <2) || (cmdCxt == NULL)) {
if ((argc < 2) || (cmdCxt == NULL)) {
mpp_log("vpu api demo, input parameter invalid\n");
show_usage();
return ERROR_INVALID_PARAM;
@@ -130,7 +130,7 @@ static RK_S32 parse_options(int argc, char **argv, VpuApiDemoCmdContext_t* cmdCx
if (opt[2] != '\0') {
opt++;
} else {
handleoptions = 0;
handleoptions = 0;
continue;
}
}
@@ -138,82 +138,82 @@ static RK_S32 parse_options(int argc, char **argv, VpuApiDemoCmdContext_t* cmdCx
opt++;
switch (*opt) {
case 'i':
if (argv[optindex]) {
memcpy(cmdCxt->input_file, argv[optindex], strlen(argv[optindex]));
cmdCxt->input_file[strlen(argv[optindex])] = '\0';
cmdCxt->have_input = 1;
} else {
mpp_log("input file is invalid\n");
ret = -1;
goto PARSE_OPINIONS_OUT;
}
case 'i':
if (argv[optindex]) {
memcpy(cmdCxt->input_file, argv[optindex], strlen(argv[optindex]));
cmdCxt->input_file[strlen(argv[optindex])] = '\0';
cmdCxt->have_input = 1;
} else {
mpp_log("input file is invalid\n");
ret = -1;
goto PARSE_OPINIONS_OUT;
}
break;
case 'o':
if (argv[optindex]) {
memcpy(cmdCxt->output_file, argv[optindex], strlen(argv[optindex]));
cmdCxt->output_file[strlen(argv[optindex])] = '\0';
cmdCxt->have_output = 1;
break;
case 'o':
if (argv[optindex]) {
memcpy(cmdCxt->output_file, argv[optindex], strlen(argv[optindex]));
cmdCxt->output_file[strlen(argv[optindex])] = '\0';
cmdCxt->have_output = 1;
break;
} else {
mpp_log("out file is invalid\n");
ret = -1;
goto PARSE_OPINIONS_OUT;
}
case 'd':
cmdCxt->disable_debug = 1;
} else {
mpp_log("out file is invalid\n");
ret = -1;
goto PARSE_OPINIONS_OUT;
}
case 'd':
cmdCxt->disable_debug = 1;
break;
case 'w':
if (argv[optindex]) {
cmdCxt->width = atoi(argv[optindex]);
break;
case 'w':
if (argv[optindex]) {
cmdCxt->width = atoi(argv[optindex]);
break;
} else {
mpp_log("input width is invalid\n");
ret = -1;
goto PARSE_OPINIONS_OUT;
}
case 'h':
if ((*(opt+1) != '\0') && !strncmp(opt, "help", 4)) {
show_help();
ret = VPU_DEMO_PARSE_HELP_OK;
goto PARSE_OPINIONS_OUT;
} else if (argv[optindex]) {
cmdCxt->height = atoi(argv[optindex]);
} else {
mpp_log("input height is invalid\n");
ret = -1;
goto PARSE_OPINIONS_OUT;
}
} else {
mpp_log("input width is invalid\n");
ret = -1;
goto PARSE_OPINIONS_OUT;
}
case 'h':
if ((*(opt + 1) != '\0') && !strncmp(opt, "help", 4)) {
show_help();
ret = VPU_DEMO_PARSE_HELP_OK;
goto PARSE_OPINIONS_OUT;
} else if (argv[optindex]) {
cmdCxt->height = atoi(argv[optindex]);
} else {
mpp_log("input height is invalid\n");
ret = -1;
goto PARSE_OPINIONS_OUT;
}
break;
case 't':
if (argv[optindex]) {
cmdCxt->codec_type = atoi(argv[optindex]);
break;
case 't':
if (argv[optindex]) {
cmdCxt->codec_type = atoi(argv[optindex]);
break;
} else {
mpp_log("input codec_type is invalid\n");
ret = -1;
goto PARSE_OPINIONS_OUT;
}
} else {
mpp_log("input codec_type is invalid\n");
ret = -1;
goto PARSE_OPINIONS_OUT;
}
default:
if ((*(opt+1) != '\0') && argv[optindex]) {
if (!strncmp(opt, "coding", 6)) {
mpp_log("coding, argv[optindex]: %s",
argv[optindex]);
cmdCxt->coding = atoi(argv[optindex]);
} else if (!strncmp(opt, "vframes", 7)) {
cmdCxt->record_frames = atoi(argv[optindex]);
} else if (!strncmp(opt, "ss", 2)) {
cmdCxt->record_start_ms = atoi(argv[optindex]);
} else {
ret = -1;
goto PARSE_OPINIONS_OUT;
}
default:
if ((*(opt + 1) != '\0') && argv[optindex]) {
if (!strncmp(opt, "coding", 6)) {
mpp_log("coding, argv[optindex]: %s",
argv[optindex]);
cmdCxt->coding = atoi(argv[optindex]);
} else if (!strncmp(opt, "vframes", 7)) {
cmdCxt->record_frames = atoi(argv[optindex]);
} else if (!strncmp(opt, "ss", 2)) {
cmdCxt->record_start_ms = atoi(argv[optindex]);
} else {
ret = -1;
goto PARSE_OPINIONS_OUT;
}
break;
} else {
ret = -1;
goto PARSE_OPINIONS_OUT;
}
break;
}
optindex += ret;
@@ -221,7 +221,7 @@ static RK_S32 parse_options(int argc, char **argv, VpuApiDemoCmdContext_t* cmdCx
}
PARSE_OPINIONS_OUT:
if (ret <0) {
if (ret < 0) {
mpp_log("vpu api demo, input parameter invalid\n");
show_usage();
return ERROR_INVALID_PARAM;
@@ -236,8 +236,7 @@ static RK_S32 readBytesFromFile(RK_U8* buf, RK_S32 aBytes, FILE* file)
}
RK_S32 ret = (RK_S32)fread(buf, 1, aBytes, file);
if(ret != aBytes)
{
if (ret != aBytes) {
mpp_log("read %d bytes from file fail\n", aBytes);
return -1;
}
@@ -260,21 +259,21 @@ static RK_S32 vpu_encode_demo(VpuApiDemoCmdContext_t *cmd)
EncoderOut_t *enc_out = NULL;
VpuApiEncInput enc_in_strm;
VpuApiEncInput *api_enc_in = &enc_in_strm;
EncInputStream_t *enc_in =NULL;
EncInputStream_t *enc_in = NULL;
EncParameter_t *enc_param = NULL;
RK_S64 fakeTimeUs =0;
RK_S64 fakeTimeUs = 0;
int Format = VPU_H264ENC_YUV420_SEMIPLANAR;
if ((cmd->have_input == 0) || (cmd->width <=0) || (cmd->height <=0)
|| (cmd->coding <= OMX_RK_VIDEO_CodingAutoDetect)) {
if ((cmd->have_input == 0) || (cmd->width <= 0) || (cmd->height <= 0)
|| (cmd->coding <= OMX_RK_VIDEO_CodingAutoDetect)) {
mpp_log("Warning: missing needed parameters for vpu api demo\n");
}
if (cmd->have_input) {
mpp_log("input bitstream w: %d, h: %d, coding: %d(%s), path: %s\n",
cmd->width, cmd->height, cmd->coding,
cmd->codec_type == CODEC_DECODER ? "decode" : "encode",
cmd->input_file);
cmd->width, cmd->height, cmd->coding,
cmd->codec_type == CODEC_DECODER ? "decode" : "encode",
cmd->input_file);
pInFile = fopen(cmd->input_file, "rb");
if (pInFile == NULL) {
@@ -288,7 +287,7 @@ static RK_S32 vpu_encode_demo(VpuApiDemoCmdContext_t *cmd)
if (cmd->have_output) {
mpp_log("vpu api demo output file: %s\n",
cmd->output_file);
cmd->output_file);
pOutFile = fopen(cmd->output_file, "wb");
if (pOutFile == NULL) {
mpp_log("can not write output file\n");
@@ -312,7 +311,7 @@ static RK_S32 vpu_encode_demo(VpuApiDemoCmdContext_t *cmd)
}
ret = vpu_open_context(&ctx);
if (ret || (ctx ==NULL)) {
if (ret || (ctx == NULL)) {
ENCODE_ERR_RET(ERROR_MEMORY);
}
@@ -327,7 +326,7 @@ static RK_S32 vpu_encode_demo(VpuApiDemoCmdContext_t *cmd)
ctx->no_thread = 1;
ctx->private_data = malloc(sizeof(EncParameter_t));
memset(ctx->private_data,0,sizeof(EncParameter_t));
memset(ctx->private_data, 0, sizeof(EncParameter_t));
enc_param = (EncParameter_t*)ctx->private_data;
enc_param->width = cmd->width;
@@ -338,9 +337,9 @@ static RK_S32 vpu_encode_demo(VpuApiDemoCmdContext_t *cmd)
enc_param->cabacInitIdc = 0;
enc_param->intraPicRate = 30;
if ((ret = ctx->init(ctx, NULL, 0)) !=0) {
mpp_log("init vpu api context fail, ret: 0x%X\n", ret);
ENCODE_ERR_RET(ERROR_INIT_VPU);
if ((ret = ctx->init(ctx, NULL, 0)) != 0) {
mpp_log("init vpu api context fail, ret: 0x%X\n", ret);
ENCODE_ERR_RET(ERROR_INIT_VPU);
}
/*
@@ -349,36 +348,36 @@ static RK_S32 vpu_encode_demo(VpuApiDemoCmdContext_t *cmd)
** after init.
*/
mpp_log("encode init ok, sps len: %d\n", ctx->extradata_size);
if(pOutFile && (ctx->extradata_size >0)) {
if (pOutFile && (ctx->extradata_size > 0)) {
mpp_log("dump %d bytes enc output stream to file\n",
ctx->extradata_size);
ctx->extradata_size);
/* save sps and pps */
fwrite(ctx->extradata, 1, ctx->extradata_size, pOutFile);
fflush(pOutFile);
}
ctx->control(ctx,VPU_API_ENC_SETFORMAT,&Format);
ctx->control(ctx, VPU_API_ENC_SETFORMAT, &Format);
ctx->control(ctx,VPU_API_ENC_GETCFG,enc_param);
ctx->control(ctx, VPU_API_ENC_GETCFG, enc_param);
enc_param->rc_mode = 1;
ctx->control(ctx,VPU_API_ENC_SETCFG,enc_param);
ctx->control(ctx, VPU_API_ENC_SETCFG, enc_param);
/*
** vpu api encode process.
*/
mpp_log("init vpu api context ok, input yuv stream file size: %d\n", fileSize);
RK_U32 w_align = ((ctx->width + 15) & (~15));
RK_U32 h_align = ((ctx->height + 15) & (~15));
size = w_align * h_align * 3/2;
size = w_align * h_align * 3 / 2;
nal = BSWAP32(nal);
do {
if (ftell(pInFile) >=fileSize) {
mpp_log("read end of file, complete\n");
break;
if (ftell(pInFile) >= fileSize) {
mpp_log("read end of file, complete\n");
break;
}
if (enc_in && (enc_in->size ==0)) {
if (enc_in && (enc_in->size == 0)) {
if (enc_in->buf == NULL) {
enc_in->buf = (RK_U8*)(malloc)(size);
if (enc_in->buf == NULL) {
@@ -387,7 +386,7 @@ static RK_S32 vpu_encode_demo(VpuApiDemoCmdContext_t *cmd)
api_enc_in->capability = size;
}
if (api_enc_in->capability <((RK_U32)size)) {
if (api_enc_in->capability < ((RK_U32)size)) {
enc_in->buf = (RK_U8*)(realloc)((void*)(enc_in->buf), size);
if (enc_in->buf == NULL) {
ENCODE_ERR_RET(ERROR_MEMORY);
@@ -400,27 +399,27 @@ static RK_S32 vpu_encode_demo(VpuApiDemoCmdContext_t *cmd)
} else {
enc_in->size = size;
enc_in->timeUs = fakeTimeUs;
fakeTimeUs +=40000;
fakeTimeUs += 40000;
}
mpp_log("read one frame, size: %d, timeUs: %lld, filePos: %ld\n",
enc_in->size, enc_in->timeUs , ftell(pInFile));
enc_in->size, enc_in->timeUs , ftell(pInFile));
}
if ((ret = ctx->encode(ctx, enc_in, enc_out)) < 0) {
ENCODE_ERR_RET(ERROR_VPU_DECODE);
ENCODE_ERR_RET(ERROR_VPU_DECODE);
} else {
mpp_log("vpu encode one frame, out len: %d, left size: %d\n",
enc_out->size, enc_in->size);
enc_out->size, enc_in->size);
/*
** encoder output stream is raw bitstream, you need to add nal
** head by yourself.
*/
if ((enc_out->size) && (enc_out->data)) {
if(pOutFile) {
if (pOutFile) {
mpp_log("dump %d bytes enc output stream to file\n",
enc_out->size);
enc_out->size);
fwrite((RK_U8*)&nal, 1, 4, pOutFile);
fwrite(enc_out->data, 1, enc_out->size, pOutFile);
fflush(pOutFile);
@@ -431,7 +430,7 @@ static RK_S32 vpu_encode_demo(VpuApiDemoCmdContext_t *cmd)
}
msleep(3);
}while(1);
} while (1);
ENCODE_OUT:
if (enc_in && enc_in->buf) {
@@ -477,28 +476,28 @@ static RK_S32 vpu_decode_demo(VpuApiDemoCmdContext_t *cmd)
FILE* pInFile = NULL;
FILE* pOutFile = NULL;
struct VpuCodecContext* ctx = NULL;
RK_S32 fileSize =0, pkt_size =0;
RK_S32 fileSize = 0, pkt_size = 0;
RK_S32 ret = 0;
RK_U32 frame_count = 0;
DecoderOut_t decOut;
VideoPacket_t demoPkt;
VideoPacket_t* pkt =NULL;
VideoPacket_t* pkt = NULL;
DecoderOut_t *pOut = NULL;
VPU_FRAME *frame = NULL;
RK_S64 fakeTimeUs =0;
RK_S64 fakeTimeUs = 0;
RK_U8* pExtra = NULL;
RK_U32 extraSize = 0;
if ((cmd->have_input == 0) || (cmd->width <=0) || (cmd->height <=0)
|| (cmd->coding <= OMX_RK_VIDEO_CodingAutoDetect)) {
if ((cmd->have_input == 0) || (cmd->width <= 0) || (cmd->height <= 0)
|| (cmd->coding <= OMX_RK_VIDEO_CodingAutoDetect)) {
mpp_log("Warning: missing needed parameters for vpu api demo\n");
}
if (cmd->have_input) {
mpp_log("input bitstream w: %d, h: %d, coding: %d(%s), path: %s\n",
cmd->width, cmd->height, cmd->coding,
cmd->codec_type == CODEC_DECODER ? "decode" : "encode",
cmd->input_file);
cmd->width, cmd->height, cmd->coding,
cmd->codec_type == CODEC_DECODER ? "decode" : "encode",
cmd->input_file);
pInFile = fopen(cmd->input_file, "rb");
if (pInFile == NULL) {
@@ -512,13 +511,13 @@ static RK_S32 vpu_decode_demo(VpuApiDemoCmdContext_t *cmd)
if (cmd->have_output) {
mpp_log("vpu api demo output file: %s\n",
cmd->output_file);
cmd->output_file);
pOutFile = fopen(cmd->output_file, "wb");
if (pOutFile == NULL) {
mpp_log("can not write output file\n");
DECODE_ERR_RET(ERROR_INVALID_PARAM);
}
if (cmd->record_frames ==0)
if (cmd->record_frames == 0)
cmd->record_frames = 5;
}
@@ -536,13 +535,13 @@ static RK_S32 vpu_decode_demo(VpuApiDemoCmdContext_t *cmd)
pOut = &decOut;
pOut->data = (RK_U8*)(malloc)(sizeof(VPU_FRAME));
if (pOut->data ==NULL) {
if (pOut->data == NULL) {
DECODE_ERR_RET(ERROR_MEMORY);
}
memset(pOut->data, 0, sizeof(VPU_FRAME));
ret = vpu_open_context(&ctx);
if (ret || (ctx ==NULL)) {
if (ret || (ctx == NULL)) {
DECODE_ERR_RET(ERROR_MEMORY);
}
@@ -556,7 +555,7 @@ static RK_S32 vpu_decode_demo(VpuApiDemoCmdContext_t *cmd)
mpp_log("codec extra data size: %d\n", extraSize);
pExtra = (RK_U8*)(malloc)(extraSize);
if (pExtra ==NULL) {
if (pExtra == NULL) {
DECODE_ERR_RET(ERROR_MEMORY);
}
memset(pExtra, 0, extraSize);
@@ -575,9 +574,9 @@ static RK_S32 vpu_decode_demo(VpuApiDemoCmdContext_t *cmd)
ctx->height = cmd->height;
ctx->no_thread = 1;
if ((ret = ctx->init(ctx, pExtra, extraSize)) !=0) {
mpp_log("init vpu api context fail, ret: 0x%X\n", ret);
DECODE_ERR_RET(ERROR_INIT_VPU);
if ((ret = ctx->init(ctx, pExtra, extraSize)) != 0) {
mpp_log("init vpu api context fail, ret: 0x%X\n", ret);
DECODE_ERR_RET(ERROR_INIT_VPU);
}
/*
@@ -586,27 +585,27 @@ static RK_S32 vpu_decode_demo(VpuApiDemoCmdContext_t *cmd)
mpp_log("init vpu api context ok, fileSize: %d\n", fileSize);
do {
if (ftell(pInFile) >=fileSize) {
mpp_log("read end of file, complete\n");
break;
if (ftell(pInFile) >= fileSize) {
mpp_log("read end of file, complete\n");
break;
}
if (pkt && (pkt->size ==0)) {
if (pkt && (pkt->size == 0)) {
if (readBytesFromFile((RK_U8*)(&pkt_size), 4, pInFile)) {
break;
}
if (pkt->data ==NULL) {
if (pkt->data == NULL) {
pkt->data = (RK_U8*)(malloc)(pkt_size);
if (pkt->data ==NULL) {
if (pkt->data == NULL) {
DECODE_ERR_RET(ERROR_MEMORY);
}
pkt->capability = pkt_size;
}
if (pkt->capability <((RK_U32)pkt_size)) {
if (pkt->capability < ((RK_U32)pkt_size)) {
pkt->data = (RK_U8*)(realloc)((void*)(pkt->data), pkt_size);
if (pkt->data ==NULL) {
if (pkt->data == NULL) {
DECODE_ERR_RET(ERROR_MEMORY);
}
pkt->capability = pkt_size;
@@ -617,21 +616,21 @@ static RK_S32 vpu_decode_demo(VpuApiDemoCmdContext_t *cmd)
} else {
pkt->size = pkt_size;
pkt->pts = fakeTimeUs;
fakeTimeUs +=40000;
fakeTimeUs += 40000;
}
mpp_log("read one packet, size: %d, pts: %lld, filePos: %ld\n",
pkt->size, pkt->pts, ftell(pInFile));
pkt->size, pkt->pts, ftell(pInFile));
}
/* note: must set out put size to 0 before do decoder. */
pOut->size = 0;
if ((ret = ctx->decode(ctx, pkt, pOut)) !=0) {
DECODE_ERR_RET(ERROR_VPU_DECODE);
if ((ret = ctx->decode(ctx, pkt, pOut)) != 0) {
DECODE_ERR_RET(ERROR_VPU_DECODE);
} else {
mpp_log("vpu decode one frame, out len: %d, left size: %d\n",
pOut->size, pkt->size);
pOut->size, pkt->size);
/*
** both virtual and physical address of the decoded frame are contained
@@ -641,13 +640,13 @@ static RK_S32 vpu_decode_demo(VpuApiDemoCmdContext_t *cmd)
if ((pOut->size) && (pOut->data)) {
frame = (VPU_FRAME *)(pOut->data);
VPUMemLink(&frame->vpumem);
RK_U32 wAlign16 = ((frame->DisplayWidth+ 15) & (~15));
RK_U32 wAlign16 = ((frame->DisplayWidth + 15) & (~15));
RK_U32 hAlign16 = ((frame->DisplayHeight + 15) & (~15));
RK_U32 frameSize = wAlign16*hAlign16*3/2;
RK_U32 frameSize = wAlign16 * hAlign16 * 3 / 2;
if(pOutFile && (frame_count++ <cmd->record_frames)) {
if (pOutFile && (frame_count++ < cmd->record_frames)) {
mpp_log("write %d frame(yuv420sp) data, %d bytes to file\n",
frame_count, frameSize);
frame_count, frameSize);
fwrite((RK_U8*)(frame->vpumem.vir_addr), 1, frameSize, pOutFile);
fflush(pOutFile);
@@ -663,7 +662,7 @@ static RK_S32 vpu_decode_demo(VpuApiDemoCmdContext_t *cmd)
}
msleep(3);
}while(!(ctx->decoder_err));
} while (!(ctx->decoder_err));
DECODE_OUT:
if (pkt && pkt->data) {
@@ -705,7 +704,7 @@ int main(int argc, char **argv)
mpp_log("/******* vpu api demo in *******/\n");
VpuApiDemoCmdContext_t demoCmdCtx;
RK_S32 ret =0;
RK_S32 ret = 0;
VPU_API_DEMO_DEBUG_DISABLE = 0;
if (argc == 1) {
@@ -717,7 +716,7 @@ int main(int argc, char **argv)
VpuApiDemoCmdContext_t* cmd = &demoCmdCtx;
memset (cmd, 0, sizeof(VpuApiDemoCmdContext_t));
cmd->codec_type = CODEC_DECODER;
if ((ret = parse_options(argc, argv, cmd)) !=0) {
if ((ret = parse_options(argc, argv, cmd)) != 0) {
if (ret == VPU_DEMO_PARSE_HELP_OK) {
return 0;
}