GK SDK 源码库: XMIPCLinuxV100R005C00SPC030 (kernel/tools/open_source excluded)
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
ifeq ($(CFG_XMEDIA_EXPORT_FLAG),)
|
||||
SDK_DIR := $(shell cd $(CURDIR)/../../../.. && /bin/pwd)
|
||||
endif
|
||||
|
||||
include $(SDK_DIR)/build/base.mk
|
||||
|
||||
SYS_LIBS := -lpthread -lm -lc -lrt -ldl -lstdc++
|
||||
|
||||
GMP_LIBS += -lxmedia_vpss \
|
||||
-lxmedia_region \
|
||||
-lxmedia_vi \
|
||||
-lxmedia_vgs \
|
||||
-lxmedia_common \
|
||||
-lxmedia_tde \
|
||||
-lxmedia_isp \
|
||||
-lxmedia_ae \
|
||||
-lxmedia_venc \
|
||||
-lxmedia_vo \
|
||||
-lxmedia_awb \
|
||||
-lxmedia_svp \
|
||||
-lxmedia_cl \
|
||||
-lxmedia_npu \
|
||||
-lxmedia_flatcc
|
||||
|
||||
TOOL_LIBS += -L$(XMEDIA_STATIC_LIB_DIR)
|
||||
TOOL_LIBS += -Wl,-Bstatic,--start-group $(GMP_LIBS) -Wl,--end-group,-Bdynamic $(SYS_LIBS)
|
||||
|
||||
CFLAGS := $(SDK_USR_CFLAGS) $(TOOL_LIBS)
|
||||
CFLAGS += -I$(SDK_DIR)/source/gmp/include
|
||||
|
||||
SRCS := $(wildcard ./*.c)
|
||||
|
||||
OBJS := $(patsubst %.c, %.o, $(SRCS))
|
||||
|
||||
TARGET := $(OBJS:%.o=%)
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
.PHONY : clean all $(SNS)
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET):%:%.o
|
||||
$(AT)$(CC) -o $@ $^ $(CFLAGS)
|
||||
$(AT)rm $^
|
||||
|
||||
%.o : %.c
|
||||
$(AT)$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
clean:
|
||||
$(AT)rm -f $(TARGET)
|
||||
$(AT)rm -f $(OBJS)
|
||||
Executable
BIN
Binary file not shown.
Executable
+504
@@ -0,0 +1,504 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "xmedia_vi.h"
|
||||
#include "xmedia_mmz.h"
|
||||
#include "xmedia_video_common.h"
|
||||
|
||||
#define MAX_FRAME_CNT 100
|
||||
#define MAX_FRAME_WIDTH 3840
|
||||
|
||||
#define MAX_WAIT_TIME 1000 // 获取帧最长等待时间,单位ms
|
||||
|
||||
#define RAW_DUMP_DEPTH 2
|
||||
|
||||
#define FILE_NAME_LEN 256
|
||||
|
||||
#define r_printf(fmt, ...) \
|
||||
do { \
|
||||
printf("\e[31m\e[1m [%s]-%d: " fmt "\e[0m", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
xmedia_void vi_bayer_dump_usage(xmedia_void)
|
||||
{
|
||||
printf("\n"
|
||||
"***************************************************************\n"
|
||||
"Usage: ./vi_bayer_dump [pipe] [frame_cnt] [ratio_show]\n"
|
||||
"pipe: \n"
|
||||
" 0 ~ 7: Vi pipe 0 ~ 7, default is 0\n"
|
||||
"frame_cnt: \n"
|
||||
" The count of frame to be dump, default is 1\n"
|
||||
"ratio_show: \n"
|
||||
" Whether the file name of raw show ratio info, default is 0\n"
|
||||
"e.g: ./vi_bayer_dump 0 1 1\n"
|
||||
"***************************************************************\n"
|
||||
"\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
xmedia_s32 get_dump_pipe(xmedia_s32 pipe, xmedia_vi_dev_bind_pipe_attr *dev_bind_pipe)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_s32 dev;
|
||||
xmedia_s32 i, j;
|
||||
xmedia_bool is_get_dev = XMEDIA_FALSE;
|
||||
xmedia_vi_grp_config grp_config;
|
||||
xmedia_bool is_wdr_pipe = XMEDIA_FALSE;
|
||||
xmedia_vi_dev_bind_pipe_attr dev_bind_pipe_tmp;
|
||||
|
||||
for (i = 0; i < VI_MAX_DEV_NUM; i++) {
|
||||
ret = xmedia_vi_get_pipe_by_dev(i, &dev_bind_pipe_tmp);
|
||||
if (ret == XMEDIA_SUCCESS) {
|
||||
for (j = 0; j < dev_bind_pipe_tmp.pipe_num; j++) {
|
||||
if (pipe == dev_bind_pipe_tmp.pipe_id[j]) {
|
||||
dev = i;
|
||||
is_get_dev = XMEDIA_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_get_dev == XMEDIA_FALSE) {
|
||||
r_printf("pipe %d get bind dev failed\n", pipe);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
memset(dev_bind_pipe, 0, sizeof(xmedia_vi_dev_bind_pipe_attr));
|
||||
|
||||
ret = xmedia_vi_get_pipe_by_dev(dev, dev_bind_pipe);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("xmedia_vi_get_pipe_by_dev failed with 0x%x\n", ret);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
for (i = 0; i < VI_MAX_GRP_NUM; i++) {
|
||||
ret = xmedia_vi_get_grp_config(i, &grp_config);
|
||||
if (ret == XMEDIA_SUCCESS) {
|
||||
if (grp_config.grp_type == XMEDIA_VI_GRP_TYPE_WDR) {
|
||||
for (j = 0; j < VI_MAX_WDR_NUM; j++) {
|
||||
if (grp_config.wdr_grp_config.pipe_id[j] == pipe) {
|
||||
is_wdr_pipe = XMEDIA_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_wdr_pipe == XMEDIA_FALSE) {
|
||||
dev_bind_pipe->pipe_num = 1;
|
||||
dev_bind_pipe->pipe_id[0] = pipe;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
xmedia_char *compress_mode_to_string(xmedia_video_compress_mode compress_mode)
|
||||
{
|
||||
if (compress_mode == XMEDIA_VIDEO_COMPRESS_MODE_NONE) {
|
||||
return "cmp_none";
|
||||
} else if (compress_mode == XMEDIA_VIDEO_COMPRESS_MODE_LINE) {
|
||||
return "cmp_line";
|
||||
} else if (compress_mode == XMEDIA_VIDEO_COMPRESS_MODE_SEG) {
|
||||
return "cmp_seg";
|
||||
} else {
|
||||
return "cmp_xxx";
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_u32 data_width_to_num(xmedia_video_data_width data_width)
|
||||
{
|
||||
if (data_width == XMEDIA_VIDEO_DATA_WIDTH_8) {
|
||||
return 8;
|
||||
} else if (data_width == XMEDIA_VIDEO_DATA_WIDTH_10) {
|
||||
return 10;
|
||||
} else if (data_width == XMEDIA_VIDEO_DATA_WIDTH_12) {
|
||||
return 12;
|
||||
} else if (data_width == XMEDIA_VIDEO_DATA_WIDTH_14) {
|
||||
return 14;
|
||||
} else if (data_width == XMEDIA_VIDEO_DATA_WIDTH_16) {
|
||||
return 16;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_s32 save_uncompress_raw_to_file(xmedia_video_frame *frame, FILE *fd)
|
||||
{
|
||||
xmedia_s32 i;
|
||||
xmedia_u32 row;
|
||||
xmedia_u32 stride;
|
||||
xmedia_u64 phy_addr, size;
|
||||
xmedia_u8 *data = XMEDIA_NULL;
|
||||
xmedia_u8 *data_tmp = XMEDIA_NULL;
|
||||
xmedia_u8 *usr_page_addr = XMEDIA_NULL;
|
||||
xmedia_u16 *buf_tmp = XMEDIA_NULL;
|
||||
xmedia_u32 tmp;
|
||||
xmedia_u64 value;
|
||||
xmedia_u32 out_cnt;
|
||||
|
||||
stride = frame->stride.y_stride;
|
||||
|
||||
size = stride * frame->height;
|
||||
|
||||
phy_addr = frame->addr.y_phy_addr;
|
||||
|
||||
usr_page_addr = xmedia_mmz_map(phy_addr, size, XMEDIA_FALSE);
|
||||
if (usr_page_addr == XMEDIA_NULL) {
|
||||
r_printf("mmz map phy 0x%llx size %llu failed\n", phy_addr, size);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (frame->bit_width != XMEDIA_VIDEO_DATA_WIDTH_8 && frame->bit_width != XMEDIA_VIDEO_DATA_WIDTH_16) {
|
||||
buf_tmp = (xmedia_u16 *)malloc(frame->width * 2); // 文件非紧凑排布,10,12,14bits不超两倍
|
||||
if (buf_tmp == XMEDIA_NULL) {
|
||||
r_printf("malloc failed\n");
|
||||
xmedia_mmz_unmap(usr_page_addr);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
data = usr_page_addr;
|
||||
|
||||
printf("saving Y............\n");
|
||||
|
||||
for (row = 0; row < frame->height; row++) {
|
||||
out_cnt = 0;
|
||||
if (frame->bit_width == XMEDIA_VIDEO_DATA_WIDTH_8) {
|
||||
fwrite(data, frame->width, 1, fd);
|
||||
} else if (frame->bit_width == XMEDIA_VIDEO_DATA_WIDTH_16) {
|
||||
fwrite(data, frame->width, 2, fd);
|
||||
} else if (frame->bit_width == XMEDIA_VIDEO_DATA_WIDTH_10) {
|
||||
// 4 pixels consist of 5 bytes
|
||||
tmp = frame->width / 4;
|
||||
for (i = 0; i < tmp; i++) {
|
||||
// byte4 byte3 byte2 byte1 byte0
|
||||
data_tmp = data + 5 * i;
|
||||
value = data_tmp[0] + ((xmedia_u32)data_tmp[1] << 8) + ((xmedia_u32)data_tmp[2] << 16) +
|
||||
((xmedia_u32)data_tmp[3] << 24) + ((xmedia_u64)data_tmp[4] << 32);
|
||||
buf_tmp[out_cnt++] = value & 0x3ff;
|
||||
buf_tmp[out_cnt++] = (value >> 10) & 0x3ff;
|
||||
buf_tmp[out_cnt++] = (value >> 20) & 0x3ff;
|
||||
buf_tmp[out_cnt++] = (value >> 30) & 0x3ff;
|
||||
}
|
||||
fwrite(buf_tmp, frame->width, 2, fd);
|
||||
} else if (frame->bit_width == XMEDIA_VIDEO_DATA_WIDTH_12) {
|
||||
// 2 pixels consist of 3 bytes
|
||||
tmp = frame->width / 2;
|
||||
for (i = 0; i < tmp; i++) {
|
||||
// byte2 byte1 byte0
|
||||
data_tmp = data + 3 * i;
|
||||
value = data_tmp[0] + ((xmedia_u32)data_tmp[1] << 8) + ((xmedia_u32)data_tmp[2] << 16);
|
||||
buf_tmp[out_cnt++] = value & 0xfff;
|
||||
buf_tmp[out_cnt++] = (value >> 12) & 0xfff;
|
||||
}
|
||||
fwrite(buf_tmp, frame->width, 2, fd);
|
||||
} else if (frame->bit_width == XMEDIA_VIDEO_DATA_WIDTH_14) {
|
||||
// 4 pixels consist of 7 bytes
|
||||
tmp = frame->width / 4;
|
||||
for (i = 0; i < tmp; i++) {
|
||||
// byte6 byte5 byte4 byte3 byte2 byte1 byte0
|
||||
data_tmp = data + 7 * i;
|
||||
value = data_tmp[0] + ((xmedia_u32)data_tmp[1] << 8) + ((xmedia_u32)data_tmp[2] << 16) +
|
||||
((xmedia_u32)data_tmp[3] << 24) + ((xmedia_u64)data_tmp[4] << 32) +
|
||||
((xmedia_u64)data_tmp[5] << 40) + ((xmedia_u64)data_tmp[6] << 48);
|
||||
buf_tmp[out_cnt++] = value & 0x3fff;
|
||||
buf_tmp[out_cnt++] = (value >> 14) & 0x3fff;
|
||||
buf_tmp[out_cnt++] = (value >> 28) & 0x3fff;
|
||||
buf_tmp[out_cnt++] = (value >> 42) & 0x3fff;
|
||||
}
|
||||
fwrite(buf_tmp, frame->width, 2, fd);
|
||||
}
|
||||
data += frame->stride.y_stride;
|
||||
}
|
||||
|
||||
if (frame->bit_width != XMEDIA_VIDEO_DATA_WIDTH_8 && frame->bit_width != XMEDIA_VIDEO_DATA_WIDTH_16) {
|
||||
free(buf_tmp);
|
||||
}
|
||||
|
||||
xmedia_mmz_unmap(usr_page_addr);
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
xmedia_s32 save_compress_raw_to_file(xmedia_video_frame *frame, FILE *fd)
|
||||
{
|
||||
// todo
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
xmedia_s32 save_raw_to_file(xmedia_video_frame *frame, FILE *fd)
|
||||
{
|
||||
if (frame->compress_mode == XMEDIA_VIDEO_COMPRESS_MODE_NONE) {
|
||||
return save_uncompress_raw_to_file(frame, fd);
|
||||
} else {
|
||||
return save_compress_raw_to_file(frame, fd);
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_s32 dump_linear_bayer(xmedia_s32 pipe, xmedia_u32 cnt, xmedia_u32 ratio_show)
|
||||
{
|
||||
xmedia_s32 i, j;
|
||||
xmedia_s32 ret;
|
||||
FILE *fd = NULL;
|
||||
xmedia_char file_name[FILE_NAME_LEN] = { 0 };
|
||||
xmedia_video_frame_info *frame_info = XMEDIA_NULL;
|
||||
|
||||
frame_info = malloc(sizeof(xmedia_video_frame_info) * cnt);
|
||||
if (frame_info == XMEDIA_NULL) {
|
||||
r_printf("malloc failed\n");
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
ret = xmedia_vi_acquire_pipe_frame(pipe, &frame_info[i], MAX_WAIT_TIME);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("linear: get pipe %d frame failed with 0x%x", pipe, ret);
|
||||
r_printf("only get %d frames\n", i);
|
||||
break;
|
||||
}
|
||||
|
||||
printf("linear: get pipe %d frame %d ok\n", pipe, i);
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
free(frame_info);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
// make file name
|
||||
if (ratio_show == 0) {
|
||||
snprintf(file_name, FILE_NAME_LEN, "./vi_pipe_%d_%ux%u_%d_%dbits_%s_%d.raw", pipe, frame_info[0].frame.width,
|
||||
frame_info[0].frame.height, cnt, data_width_to_num(frame_info[0].frame.bit_width),
|
||||
compress_mode_to_string(frame_info[0].frame.compress_mode), ratio_show);
|
||||
} else {
|
||||
// todo
|
||||
snprintf(file_name, FILE_NAME_LEN, "./vi_pipe_%d_%ux%u_%d_%dbits_%s_%d.raw", pipe, frame_info[0].frame.width,
|
||||
frame_info[0].frame.height, cnt, data_width_to_num(frame_info[0].frame.bit_width),
|
||||
compress_mode_to_string(frame_info[0].frame.compress_mode), ratio_show);
|
||||
}
|
||||
|
||||
fd = fopen(file_name, "wb");
|
||||
if (fd == NULL) {
|
||||
r_printf("open file faied\n");
|
||||
goto failed;
|
||||
}
|
||||
|
||||
// todo,压缩文件,先保存压缩param
|
||||
|
||||
for (j = 0; j < i; j++) {
|
||||
printf("frame %d save start\n", j);
|
||||
save_raw_to_file(&frame_info[j].frame, fd);
|
||||
printf("frame %d save completed\n", j);
|
||||
xmedia_vi_release_pipe_frame(pipe, &frame_info[j]);
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
|
||||
free(frame_info);
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
|
||||
failed:
|
||||
for (j = 0; j < i; j++) {
|
||||
xmedia_vi_release_pipe_frame(pipe, &frame_info[j]);
|
||||
}
|
||||
|
||||
free(frame_info);
|
||||
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
xmedia_s32 dump_wdr_bayer(xmedia_vi_dev_bind_pipe_attr *bind_attr, xmedia_u32 cnt, xmedia_u32 ratio_show)
|
||||
{
|
||||
xmedia_s32 i, j, k;
|
||||
xmedia_s32 ret;
|
||||
FILE *fd = NULL;
|
||||
xmedia_u32 frame_cnt = 0;
|
||||
xmedia_char file_name[FILE_NAME_LEN] = { 0 };
|
||||
xmedia_video_frame_info *frame_info[VI_MAX_WDR_FRAME_NUM] = { XMEDIA_NULL };
|
||||
|
||||
for (i = 0; i < bind_attr->pipe_num; i++) {
|
||||
frame_info[i] = malloc(sizeof(xmedia_video_frame_info) * cnt);
|
||||
if (frame_info[i] == XMEDIA_NULL) {
|
||||
r_printf("pipe %d malloc frame info failed\n", bind_attr->pipe_id[i]);
|
||||
for (j = 0; j < i; j++) {
|
||||
free(frame_info[j]);
|
||||
}
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
for (j = 0; j < bind_attr->pipe_num; j++) {
|
||||
ret = xmedia_vi_acquire_pipe_frame(bind_attr->pipe_id[j], &frame_info[j][i], MAX_WAIT_TIME);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("wdr: get pipe %d frame failed with 0x%x", bind_attr->pipe_id[j], ret);
|
||||
r_printf("only get %d frames\n", i);
|
||||
frame_cnt = i;
|
||||
for (k = 0; k < bind_attr->pipe_num; k++) {
|
||||
xmedia_vi_release_pipe_frame(bind_attr->pipe_id[k], &frame_info[k][i]);
|
||||
goto save_frame;
|
||||
}
|
||||
} else {
|
||||
printf("wdr: get pipe %d frame %d ok\n", bind_attr->pipe_id[j], i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frame_cnt = i;
|
||||
|
||||
// make file name
|
||||
if (ratio_show == 0) {
|
||||
snprintf(file_name, FILE_NAME_LEN, "./vi_pipe_%d_%ux%u_%d_%dbits_%s_%d_wdr.raw", bind_attr->pipe_id[0],
|
||||
frame_info[0][0].frame.width, frame_info[0][0].frame.height, cnt * bind_attr->pipe_num,
|
||||
data_width_to_num(frame_info[0][0].frame.bit_width),
|
||||
compress_mode_to_string(frame_info[0][0].frame.compress_mode), ratio_show);
|
||||
} else {
|
||||
// todo
|
||||
snprintf(file_name, FILE_NAME_LEN, "./vi_pipe_%d_%ux%u_%d_%dbits_%s_%d_wdr.raw", bind_attr->pipe_id[0],
|
||||
frame_info[0][0].frame.width, frame_info[0][0].frame.height, cnt * bind_attr->pipe_num,
|
||||
data_width_to_num(frame_info[0][0].frame.bit_width),
|
||||
compress_mode_to_string(frame_info[0][0].frame.compress_mode), ratio_show);
|
||||
}
|
||||
|
||||
fd = fopen(file_name, "wb");
|
||||
if (fd == NULL) {
|
||||
r_printf("open file faied\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
save_frame:
|
||||
if (frame_cnt == 0) {
|
||||
for (i = 0; i < bind_attr->pipe_num; i++) {
|
||||
free(frame_info[i]);
|
||||
}
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
for (i = 0; i < frame_cnt; i++) {
|
||||
for (j = 0; j < bind_attr->pipe_num; j++) {
|
||||
printf("pipe %d frame %d save start\n", bind_attr->pipe_id[j], i);
|
||||
save_raw_to_file(&frame_info[j][i].frame, fd);
|
||||
printf("pipe %d frame %d save completed\n", bind_attr->pipe_id[j], i);
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
if (fd != XMEDIA_NULL) {
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
for (i = 0; i < frame_cnt; i++) {
|
||||
for (j = 0; j < bind_attr->pipe_num; j++) {
|
||||
xmedia_vi_release_pipe_frame(bind_attr->pipe_id[j], &frame_info[j][i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < bind_attr->pipe_num; i++) {
|
||||
free(frame_info[i]);
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
xmedia_s32 main(xmedia_s32 argc, xmedia_char *argv[])
|
||||
{
|
||||
xmedia_s32 i;
|
||||
xmedia_s32 ret;
|
||||
xmedia_s32 pipe = 0;
|
||||
xmedia_u32 frame_cnt = 1;
|
||||
xmedia_u32 ratio_show = 0;
|
||||
xmedia_vi_dev_bind_pipe_attr dev_bind_pipe;
|
||||
xmedia_vi_frame_dump_attr dump_attr;
|
||||
xmedia_vi_frame_dump_attr dump_attr_tmp;
|
||||
|
||||
printf("\nNOTIC: this tool only can be used for TESTING !!!\n");
|
||||
printf("\n To see more usage, please enter: ./vi_bayer_dump -h\n\n");
|
||||
|
||||
if (argc > 1) {
|
||||
if (strncmp(argv[1], "-h", 2) == 0) {
|
||||
vi_bayer_dump_usage();
|
||||
exit(XMEDIA_SUCCESS);
|
||||
} else {
|
||||
pipe = atoi(argv[1]); // pipe
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > 2) {
|
||||
frame_cnt = atoi(argv[2]); // the frame number
|
||||
if (frame_cnt < 1 || frame_cnt > MAX_FRAME_CNT) {
|
||||
r_printf("invalid frame cnt %u, range [1, %d]\n", frame_cnt, MAX_FRAME_CNT);
|
||||
exit(XMEDIA_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > 3) {
|
||||
if (atoi(argv[3]) > 0) {
|
||||
ratio_show = 1;
|
||||
} else {
|
||||
ratio_show = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ret = xmedia_vi_init();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("vi init failed !\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = get_dump_pipe(pipe, &dev_bind_pipe);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
xmedia_vi_exit();
|
||||
r_printf("get_dump_pipe failed !\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (i = 0; i < dev_bind_pipe.pipe_num; i++) {
|
||||
ret = xmedia_vi_get_pipe_frame_dump_attr(dev_bind_pipe.pipe_id[i], &dump_attr_tmp);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
xmedia_vi_exit();
|
||||
r_printf("get pipe %d dump attr failed with 0x%x\n", dev_bind_pipe.pipe_id[i], ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
dump_attr.enable = XMEDIA_TRUE;
|
||||
dump_attr.depth = RAW_DUMP_DEPTH;
|
||||
ret = xmedia_vi_set_pipe_frame_dump_attr(dev_bind_pipe.pipe_id[i], &dump_attr);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("set pipe %d dump attr failed with 0x%x\n", dev_bind_pipe.pipe_id[i], ret);
|
||||
xmedia_vi_exit();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (dev_bind_pipe.pipe_num == 1) {
|
||||
dump_linear_bayer(pipe, frame_cnt, ratio_show);
|
||||
} else {
|
||||
dump_wdr_bayer(&dev_bind_pipe, frame_cnt, ratio_show);
|
||||
}
|
||||
|
||||
for (i = 0; i < dev_bind_pipe.pipe_num; i++) {
|
||||
ret = xmedia_vi_set_pipe_frame_dump_attr(dev_bind_pipe.pipe_id[i], &dump_attr_tmp);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("set pipe %d dump attr failed with 0x%x\n", dev_bind_pipe.pipe_id[i], ret);
|
||||
xmedia_vi_exit();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_vi_exit();
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
Executable
+446
@@ -0,0 +1,446 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "xmedia_vi.h"
|
||||
#include "xmedia_mmz.h"
|
||||
#include "xmedia_vb.h"
|
||||
#include "xmedia_vgs.h"
|
||||
#include "xmedia_video_common.h"
|
||||
|
||||
#define MAX_FRAME_CNT 100
|
||||
#define MAX_FRAME_WIDTH 3840
|
||||
|
||||
#define MAX_WAIT_TIME 1000 // 获取帧最长等待时间,单位ms
|
||||
|
||||
#define YUV_DUMP_DEPTH 2
|
||||
|
||||
#define FILE_NAME_LEN 256
|
||||
|
||||
#define PIXEL_NAME_LEN 10
|
||||
#define VIDEO_FRAME_LEN 20
|
||||
|
||||
#define r_printf(fmt, ...) \
|
||||
do { \
|
||||
printf("\e[31m\e[1m [%s]-%d: " fmt "\e[0m", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
xmedia_void vi_chn_dump_usage(xmedia_void)
|
||||
{
|
||||
printf("\n"
|
||||
"***************************************************************\n"
|
||||
"Usage: ./vi_chn_dump [pipe] [chn] [frame_cnt]\n"
|
||||
"pipe: \n"
|
||||
" 0 ~ 7: Vi pipe 0 ~ 7\n"
|
||||
"chn: \n"
|
||||
" 0: Vi chn\n"
|
||||
"frame_cnt: \n"
|
||||
" The count of frame to be dump\n"
|
||||
"e.g: ./vi_chn_dump 0 0 1\n"
|
||||
"***************************************************************\n"
|
||||
"\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
xmedia_s32 make_yuv_file_name(xmedia_s32 pipe, xmedia_s32 chn, xmedia_u32 cnt, xmedia_char *file_name)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_char pixel_format[PIXEL_NAME_LEN];
|
||||
xmedia_char video_format[VIDEO_FRAME_LEN];
|
||||
xmedia_video_frame_info frame_info;
|
||||
|
||||
ret = xmedia_vi_acquire_chn_frame(pipe, chn, &frame_info, MAX_WAIT_TIME);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("pipe %d chn %d get chn frame failed with 0x%x\n", pipe, chn, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
switch (frame_info.frame.pixel_fmt) {
|
||||
case XMEDIA_VIDEO_PIXEL_FMT_YUV_SEMIPLANAR_420:
|
||||
case XMEDIA_VIDEO_PIXEL_FMT_YVU_SEMIPLANAR_420:
|
||||
snprintf(pixel_format, PIXEL_NAME_LEN, "p420");
|
||||
break;
|
||||
|
||||
case XMEDIA_VIDEO_PIXEL_FMT_YUV_SEMIPLANAR_422:
|
||||
case XMEDIA_VIDEO_PIXEL_FMT_YVU_SEMIPLANAR_422:
|
||||
snprintf(pixel_format, PIXEL_NAME_LEN, "p422");
|
||||
break;
|
||||
|
||||
case XMEDIA_VIDEO_PIXEL_FMT_YUV_400:
|
||||
snprintf(pixel_format, PIXEL_NAME_LEN, "p400");
|
||||
break;
|
||||
|
||||
default:
|
||||
snprintf(pixel_format, PIXEL_NAME_LEN, "--");
|
||||
break;
|
||||
}
|
||||
|
||||
switch (frame_info.frame.video_fmt) {
|
||||
case XMEDIA_VIDEO_FMT_LINEAR:
|
||||
snprintf(video_format, VIDEO_FRAME_LEN, "linear");
|
||||
break;
|
||||
|
||||
case XMEDIA_VIDEO_FMT_TILE_32x4:
|
||||
snprintf(video_format, VIDEO_FRAME_LEN, "tile_32x4");
|
||||
break;
|
||||
|
||||
case XMEDIA_VIDEO_FMT_TILE_64x4:
|
||||
snprintf(video_format, VIDEO_FRAME_LEN, "tile_64x4");
|
||||
break;
|
||||
|
||||
default:
|
||||
snprintf(video_format, VIDEO_FRAME_LEN, "--");
|
||||
break;
|
||||
}
|
||||
|
||||
snprintf(file_name, FILE_NAME_LEN, "./vi_pipe%d_chn%d_%ux%u_%s_%s_%u.yuv", pipe, chn, frame_info.frame.width,
|
||||
frame_info.frame.height, pixel_format, video_format, cnt);
|
||||
|
||||
ret = xmedia_vi_release_chn_frame(pipe, chn, &frame_info);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("pipe %d chn %d release chn frame failed with 0x%x\n", pipe, chn, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
xmedia_s32 save_yuv_8bit_to_file(xmedia_video_frame *frame, FILE *fd)
|
||||
{
|
||||
xmedia_u32 width, height, size;
|
||||
xmedia_u32 c_height;
|
||||
xmedia_u64 phy_addr;
|
||||
xmedia_char *usr_page_addr = XMEDIA_NULL;
|
||||
xmedia_char *y_virt = XMEDIA_NULL;
|
||||
xmedia_char *c_virt = XMEDIA_NULL;
|
||||
xmedia_char *mem_offset = XMEDIA_NULL;
|
||||
xmedia_char buf_tmp[MAX_FRAME_WIDTH];
|
||||
|
||||
if (frame->pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YUV_SEMIPLANAR_420 ||
|
||||
frame->pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YVU_SEMIPLANAR_420) {
|
||||
size = frame->stride.y_stride * frame->height * 3 / 2;
|
||||
c_height = frame->height / 2;
|
||||
} else if (frame->pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YUV_SEMIPLANAR_422 ||
|
||||
frame->pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YVU_SEMIPLANAR_422) {
|
||||
size = frame->stride.y_stride * frame->height * 2;
|
||||
c_height = frame->height;
|
||||
} else if (frame->pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YUV_400) {
|
||||
size = frame->width * frame->height;
|
||||
c_height = 0;
|
||||
} else {
|
||||
r_printf("unknown pixel format %d\n", frame->pixel_fmt);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
phy_addr = frame->addr.y_phy_addr;
|
||||
|
||||
usr_page_addr = xmedia_mmz_map(phy_addr, size, XMEDIA_FALSE);
|
||||
if (usr_page_addr == XMEDIA_NULL) {
|
||||
r_printf("mmz map phy 0x%llx size %u failed\n", phy_addr, size);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
y_virt = usr_page_addr;
|
||||
c_virt = y_virt + frame->stride.y_stride * frame->height;
|
||||
|
||||
printf("saving......Y......\n");
|
||||
for (height = 0; height < frame->height; height++) {
|
||||
mem_offset = y_virt + frame->stride.y_stride * height;
|
||||
fwrite(mem_offset, frame->width, 1, fd);
|
||||
}
|
||||
|
||||
if (frame->pixel_fmt != XMEDIA_VIDEO_PIXEL_FMT_YUV_400) {
|
||||
printf("saving......U......\n");
|
||||
for (height = 0; height < c_height; height++) {
|
||||
mem_offset = c_virt + frame->stride.c_stride * height;
|
||||
mem_offset += 1;
|
||||
|
||||
for (width = 0; width < frame->width / 2; width++) {
|
||||
buf_tmp[width] = *mem_offset;
|
||||
mem_offset += 2;
|
||||
}
|
||||
fwrite(buf_tmp, frame->width / 2, 1, fd);
|
||||
}
|
||||
|
||||
printf("saving......V......\n");
|
||||
for (height = 0; height < c_height; height++) {
|
||||
mem_offset = c_virt + frame->stride.c_stride * height;
|
||||
|
||||
for (width = 0; width < frame->width / 2; width++) {
|
||||
buf_tmp[width] = *mem_offset;
|
||||
mem_offset += 2;
|
||||
}
|
||||
fwrite(buf_tmp, frame->width / 2, 1, fd);
|
||||
}
|
||||
}
|
||||
|
||||
printf("done %llu\n", frame->pts);
|
||||
|
||||
xmedia_mmz_unmap(usr_page_addr);
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
xmedia_s32 submit_vgs_to_transform(xmedia_s32 pipe, xmedia_s32 chn, xmedia_video_frame_info *in_frame, FILE *fd)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_vb_base_info base_info;
|
||||
xmedia_vb_cal_cfg cal_cfg;
|
||||
xmedia_vb_pool_config pool_config = {0};
|
||||
xmedia_u32 pool_id;
|
||||
xmedia_handle vb_handle;
|
||||
xmedia_u64 phy_addr;
|
||||
xmedia_s32 handle;
|
||||
xmedia_vgs_frame_info task_info;
|
||||
xmedia_video_rotation rot = XMEDIA_VIDEO_ROTATION_0;
|
||||
xmedia_video_frame_info out_frame;
|
||||
xmedia_vb_config vb_config = {0};
|
||||
|
||||
base_info.align = 0;
|
||||
base_info.bit_width = in_frame->frame.bit_width;
|
||||
base_info.cmp_mode = XMEDIA_VIDEO_COMPRESS_MODE_NONE;
|
||||
base_info.width = in_frame->frame.width;
|
||||
base_info.height = in_frame->frame.height;
|
||||
base_info.pixel_fmt = in_frame->frame.pixel_fmt;
|
||||
base_info.video_fmt = XMEDIA_VIDEO_FMT_LINEAR;
|
||||
|
||||
ret = xmedia_vb_get_buffer_config(&base_info, &cal_cfg);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("pipe %d chn %d get buffer config failed with 0x%x\n", pipe, chn, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
vb_config.max_pool_cnt = 1;
|
||||
vb_config.common_pool[0].block_size = cal_cfg.vb_size;
|
||||
vb_config.common_pool[0].block_cnt = 1;
|
||||
ret = xmedia_vb_init(&vb_config);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("vb init failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
pool_config.block_size = cal_cfg.vb_size;
|
||||
pool_config.block_cnt = 1;
|
||||
pool_config.map_mode = XMEDIA_VB_MAP_MODE_NONE;
|
||||
pool_id = xmedia_vb_create_pool(&pool_config);
|
||||
if (pool_id == VB_INVALID_POOLID) {
|
||||
r_printf("pipe %d chn %d create pool failed\n", pipe, chn);
|
||||
xmedia_vb_exit();
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
vb_handle = xmedia_vb_get_block(pool_id, cal_cfg.vb_size, XMEDIA_NULL);
|
||||
if (vb_handle == VB_INVALID_HANDLE) {
|
||||
r_printf("pipe %d chn %d get block failed\n", pipe, chn);
|
||||
xmedia_vb_exit();
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
phy_addr = xmedia_vb_handle_to_phy_addr(vb_handle);
|
||||
|
||||
memset(&out_frame, 0, sizeof(xmedia_video_frame_info));
|
||||
out_frame.pool_id = pool_id;
|
||||
out_frame.mod_id = MOD_ID_VI;
|
||||
out_frame.frame.addr.y_phy_addr = phy_addr;
|
||||
out_frame.frame.addr.c_phy_addr = phy_addr + cal_cfg.main_y_size;
|
||||
out_frame.frame.width = in_frame->frame.width;
|
||||
out_frame.frame.height = in_frame->frame.height;
|
||||
out_frame.frame.stride.y_stride = cal_cfg.main_stride;
|
||||
out_frame.frame.stride.c_stride = cal_cfg.main_stride;
|
||||
out_frame.frame.compress_mode = XMEDIA_VIDEO_COMPRESS_MODE_NONE;
|
||||
out_frame.frame.pixel_fmt = in_frame->frame.pixel_fmt;
|
||||
out_frame.frame.video_fmt = XMEDIA_VIDEO_FMT_LINEAR;
|
||||
out_frame.frame.dynamic_range = in_frame->frame.dynamic_range;
|
||||
out_frame.frame.pts = in_frame->frame.pts;
|
||||
out_frame.frame.index = in_frame->frame.index;
|
||||
|
||||
ret = xmedia_vgs_init();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("pipe %d chn %d init failed\n", pipe, chn);
|
||||
xmedia_vb_release_block(vb_handle);
|
||||
xmedia_vb_destroy_pool(pool_id);
|
||||
xmedia_vb_exit();
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = xmedia_vgs_create_job(&handle);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("pipe %d chn %d create vgs job failed\n", pipe, chn);
|
||||
xmedia_vgs_exit();
|
||||
xmedia_vb_release_block(vb_handle);
|
||||
xmedia_vb_destroy_pool(pool_id);
|
||||
xmedia_vb_exit();
|
||||
return ret;
|
||||
}
|
||||
|
||||
memcpy(&task_info.img_in, in_frame, sizeof(xmedia_video_frame_info));
|
||||
memcpy(&task_info.img_out, &out_frame, sizeof(xmedia_video_frame_info));
|
||||
|
||||
ret = xmedia_vgs_add_task_rotation(handle, &task_info, rot);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("pipe %d chn %d add vgs task failed\n", pipe, chn);
|
||||
xmedia_vgs_cancel_job(handle);
|
||||
xmedia_vgs_exit();
|
||||
xmedia_vb_release_block(vb_handle);
|
||||
xmedia_vb_destroy_pool(pool_id);
|
||||
xmedia_vb_exit();
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = xmedia_vgs_submit_job(handle);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("pipe %d chn %d submit vgs job failed\n", pipe, chn);
|
||||
xmedia_vgs_cancel_job(handle);
|
||||
xmedia_vgs_exit();
|
||||
xmedia_vb_release_block(vb_handle);
|
||||
xmedia_vb_destroy_pool(pool_id);
|
||||
xmedia_vb_exit();
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = xmedia_vgs_wait_job(handle, 2000);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("pipe %d chn %d wait vgs job failed\n", pipe, chn);
|
||||
xmedia_vgs_exit();
|
||||
xmedia_vb_release_block(vb_handle);
|
||||
xmedia_vb_destroy_pool(pool_id);
|
||||
xmedia_vb_exit();
|
||||
return ret;
|
||||
}
|
||||
|
||||
save_yuv_8bit_to_file(&task_info.img_out.frame, fd);
|
||||
|
||||
xmedia_vgs_exit();
|
||||
xmedia_vb_release_block(vb_handle);
|
||||
xmedia_vb_destroy_pool(pool_id);
|
||||
xmedia_vb_exit();
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
xmedia_void dump_yuv(xmedia_s32 pipe, xmedia_s32 chn, xmedia_u32 cnt)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
FILE *fd = XMEDIA_NULL;
|
||||
xmedia_char file_name[FILE_NAME_LEN];
|
||||
xmedia_video_frame_info frame_info;
|
||||
|
||||
ret = make_yuv_file_name(pipe, chn, cnt, file_name);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
|
||||
fd = fopen(file_name, "wb");
|
||||
if (fd == XMEDIA_NULL) {
|
||||
r_printf("opne file failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
while (cnt--) {
|
||||
ret = xmedia_vi_acquire_chn_frame(pipe, chn, &frame_info, MAX_WAIT_TIME);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("pipe %d chn %d get chn frame %u failed with 0x%x\n", pipe, chn, cnt, ret);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (frame_info.frame.compress_mode != XMEDIA_VIDEO_COMPRESS_MODE_NONE ||
|
||||
frame_info.frame.video_fmt != XMEDIA_VIDEO_FMT_LINEAR) {
|
||||
submit_vgs_to_transform(pipe, chn, &frame_info, fd);
|
||||
} else {
|
||||
save_yuv_8bit_to_file(&frame_info.frame, fd);
|
||||
}
|
||||
|
||||
ret = xmedia_vi_release_chn_frame(pipe, chn, &frame_info);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("pipe %d chn %d release chn frame %u failed with 0x%x\n", pipe, chn, cnt, ret);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
xmedia_s32 main(xmedia_s32 argc, xmedia_char *argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_s32 pipe;
|
||||
xmedia_s32 chn;
|
||||
xmedia_u32 frame_cnt = 0;
|
||||
xmedia_u32 origin_depth;
|
||||
xmedia_u32 depth;
|
||||
|
||||
printf("\nNOTIC: this tool only can be used for TESTING !!!\n");
|
||||
printf("\n To see more usage, please enter: ./vi_chn_dump -h\n\n");
|
||||
|
||||
if (argc > 1) {
|
||||
if (strncmp(argv[1], "-h", 2) == 0) {
|
||||
vi_chn_dump_usage();
|
||||
exit(XMEDIA_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc < 4) {
|
||||
vi_chn_dump_usage();
|
||||
exit(XMEDIA_SUCCESS);
|
||||
}
|
||||
|
||||
pipe = atoi(argv[1]);
|
||||
if (pipe < 0 || pipe >= VI_MAX_PIPE_NUM) {
|
||||
r_printf("pipe %d is illegal!\n", pipe);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
chn = atoi(argv[2]);
|
||||
if (chn < 0 || chn >= VI_MAX_CHN_NUM) {
|
||||
r_printf("chn %d is illegal!\n", chn);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
frame_cnt = atoi(argv[3]);
|
||||
if (frame_cnt < 0 || frame_cnt > MAX_FRAME_CNT) {
|
||||
r_printf("frame cnt %d is illegal!\n", frame_cnt);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
ret = xmedia_vi_init();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("vi init failed\n");
|
||||
return ret;
|
||||
}
|
||||
ret = xmedia_vi_get_chn_depth(pipe, chn, &origin_depth);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("pipe %d chn %d get chn depth failed with 0x%x", pipe, chn, ret);
|
||||
xmedia_vi_exit();
|
||||
return ret;
|
||||
}
|
||||
|
||||
depth = YUV_DUMP_DEPTH;
|
||||
ret = xmedia_vi_set_chn_depth(pipe, chn, depth);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("pipe %d chn %d set chn depth failed with 0x%x", pipe, chn, ret);
|
||||
xmedia_vi_exit();
|
||||
return ret;
|
||||
}
|
||||
|
||||
dump_yuv(pipe, chn, frame_cnt);
|
||||
|
||||
depth = origin_depth;
|
||||
ret = xmedia_vi_set_chn_depth(pipe, chn, depth);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
r_printf("pipe %d chn %d set chn depth failed with 0x%x", pipe, chn, ret);
|
||||
xmedia_vi_exit();
|
||||
return ret;
|
||||
}
|
||||
|
||||
xmedia_vi_exit();
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
Executable
+289
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "xmedia_sys.h"
|
||||
#include "xmedia_mmz.h"
|
||||
#include "xmedia_vb.h"
|
||||
#include "xmedia_vo.h"
|
||||
|
||||
#define VALUE_BETWEEN(x,min,max) (((x) >= (min)) && ((x) <= (max)))
|
||||
|
||||
static volatile sig_atomic_t g_vo_signal_flag = 0;
|
||||
static xmedia_vo_layer g_vo_layer_id = 0;
|
||||
static xmedia_vo_chn g_vo_chn_id = 0;
|
||||
static xmedia_video_frame_info g_vo_frame_info;
|
||||
|
||||
static FILE* g_vo_fd = XMEDIA_NULL;
|
||||
|
||||
static void vo_dump_8bit_yuv(xmedia_video_frame *video_frame, FILE *fd)
|
||||
{
|
||||
unsigned int w, h;
|
||||
char* virt_addr_y;
|
||||
char* virt_addr_c;
|
||||
char* mem_content;
|
||||
unsigned char tmp_buff[8192];
|
||||
xmedia_u64 phy_addr;
|
||||
xmedia_u32 c_height;
|
||||
xmedia_u32 size;
|
||||
xmedia_char* page_addr[2];
|
||||
xmedia_bool uv_invert;
|
||||
xmedia_video_pixel_format pixel_fmt = video_frame->pixel_fmt;
|
||||
|
||||
uv_invert = (pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YUV_SEMIPLANAR_420) ? XMEDIA_TRUE : XMEDIA_FALSE;
|
||||
|
||||
if (video_frame->compress_mode != XMEDIA_VIDEO_COMPRESS_MODE_NONE) {
|
||||
video_frame->stride.y_stride = video_frame->width;
|
||||
video_frame->stride.c_stride = video_frame->width;
|
||||
}
|
||||
|
||||
if ((pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YVU_SEMIPLANAR_420) ||
|
||||
(pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YUV_SEMIPLANAR_420)) {
|
||||
size = video_frame->stride.y_stride * video_frame->height * 3 / 2;
|
||||
c_height = video_frame->height / 2;
|
||||
} else if (pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YUV_400) {
|
||||
size = video_frame->stride.y_stride * video_frame->height;
|
||||
c_height = video_frame->height;
|
||||
} else {
|
||||
size = video_frame->stride.y_stride * video_frame->height * 3 / 2;
|
||||
c_height = video_frame->height / 2;
|
||||
}
|
||||
|
||||
phy_addr = video_frame->addr.y_phy_addr;
|
||||
|
||||
page_addr[0] = (xmedia_char*)xmedia_mmz_map(phy_addr, size, XMEDIA_FALSE);
|
||||
if (XMEDIA_NULL == page_addr[0]) {
|
||||
return;
|
||||
}
|
||||
|
||||
virt_addr_y = page_addr[0];
|
||||
virt_addr_c = virt_addr_y + (video_frame->stride.y_stride) * (video_frame->height);
|
||||
|
||||
fprintf(stderr, "saving......Y......");
|
||||
fflush(stderr);
|
||||
for (h = 0; h < video_frame->height; h++) {
|
||||
mem_content = virt_addr_y + h * video_frame->stride.y_stride;
|
||||
fwrite(mem_content, video_frame->width, 1, fd);
|
||||
}
|
||||
|
||||
if (pixel_fmt != XMEDIA_VIDEO_PIXEL_FMT_YUV_400) {
|
||||
fflush(fd);
|
||||
fprintf(stderr, "U......");
|
||||
fflush(stderr);
|
||||
|
||||
for (h = 0; h < c_height; h++) {
|
||||
mem_content = virt_addr_c + h * video_frame->stride.c_stride;
|
||||
|
||||
if (!uv_invert) {
|
||||
mem_content += 1;
|
||||
}
|
||||
|
||||
for (w = 0; w < video_frame->width / 2; w++) {
|
||||
tmp_buff[w] = *mem_content;
|
||||
mem_content += 2;
|
||||
}
|
||||
fwrite(tmp_buff, video_frame->width / 2, 1, fd);
|
||||
}
|
||||
fflush(fd);
|
||||
|
||||
fprintf(stderr, "V......");
|
||||
fflush(stderr);
|
||||
for (h = 0; h < c_height; h++) {
|
||||
mem_content = virt_addr_c + h * video_frame->stride.c_stride;
|
||||
|
||||
if (uv_invert) {
|
||||
mem_content += 1;
|
||||
}
|
||||
|
||||
for (w = 0; w < video_frame->width / 2; w++) {
|
||||
tmp_buff[w] = *mem_content;
|
||||
mem_content += 2;
|
||||
}
|
||||
fwrite(tmp_buff, video_frame->width / 2, 1, fd);
|
||||
}
|
||||
}
|
||||
fflush(fd);
|
||||
|
||||
fprintf(stderr, "done!\n");
|
||||
fflush(stderr);
|
||||
|
||||
xmedia_mmz_unmap(page_addr[0]);
|
||||
page_addr[0] = XMEDIA_NULL;
|
||||
}
|
||||
|
||||
|
||||
void vo_chn_dump_handle_signal(xmedia_s32 signal)
|
||||
{
|
||||
if (g_vo_signal_flag != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (signal == SIGINT || signal == SIGTERM) {
|
||||
g_vo_signal_flag = 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
xmedia_void vo_misc_dump(xmedia_vo_layer layer_id, xmedia_vo_chn chn_id, xmedia_u32 frame_cnt)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_char yuv_name[128];
|
||||
xmedia_char pixel_format[10];
|
||||
xmedia_char sys_chmod[140];
|
||||
xmedia_s32 millisec = -1;
|
||||
xmedia_vo_chn_attr chn_attr;
|
||||
xmedia_s32 i = 0;
|
||||
|
||||
ret = xmedia_vo_init();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("vo init failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = xmedia_vo_get_chn_attr(layer_id, chn_id, &chn_attr);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ochn(%d) get ochn attr failed!\n", layer_id, chn_id);
|
||||
goto OUT;
|
||||
}
|
||||
memset(&g_vo_frame_info, 0, sizeof(xmedia_video_frame_info));
|
||||
g_vo_frame_info.pool_id = VB_INVALID_POOLID;
|
||||
|
||||
for(i = 0;i < frame_cnt;i++) {
|
||||
if (xmedia_vo_acquire_chn_frame(layer_id, chn_id, &g_vo_frame_info, millisec) != XMEDIA_SUCCESS) {
|
||||
printf("layer(%d) chn(%d) get frame error for 10 times, now exit!\n", layer_id, chn_id);
|
||||
goto OUT;
|
||||
}
|
||||
if(g_vo_fd == XMEDIA_NULL) {
|
||||
switch (g_vo_frame_info.frame.pixel_fmt) {
|
||||
case XMEDIA_VIDEO_PIXEL_FMT_YVU_SEMIPLANAR_420:
|
||||
case XMEDIA_VIDEO_PIXEL_FMT_YUV_SEMIPLANAR_420:
|
||||
snprintf(pixel_format, 10, "P420");
|
||||
break;
|
||||
case XMEDIA_VIDEO_PIXEL_FMT_YUV_400:
|
||||
snprintf(pixel_format, 10, "YUV400");
|
||||
break;
|
||||
default:
|
||||
snprintf(pixel_format, 10, "P420");
|
||||
break;
|
||||
}
|
||||
snprintf(yuv_name, 128, "./layer%d_chn%d_%dx%d_%s_%d.yuv", layer_id, chn_id,
|
||||
g_vo_frame_info.frame.width, g_vo_frame_info.frame.height, pixel_format, frame_cnt);
|
||||
|
||||
printf("layer(%d) chn(%d) dump frame to file: \"%s\"\n", layer_id, chn_id, yuv_name);
|
||||
fflush(stdout);
|
||||
|
||||
g_vo_fd = fopen(yuv_name, "wb");
|
||||
if (g_vo_fd == XMEDIA_NULL) {
|
||||
printf("open file failed:%s!\n", strerror(errno));
|
||||
goto OUT;
|
||||
}
|
||||
}
|
||||
|
||||
vo_dump_8bit_yuv(&g_vo_frame_info.frame, g_vo_fd);
|
||||
|
||||
ret = xmedia_vo_release_chn_frame(layer_id, chn_id, &g_vo_frame_info);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("layer(%d) chn(%d) release frame failed!\n", layer_id, chn_id);
|
||||
goto OUT;
|
||||
}
|
||||
memset(&g_vo_frame_info, 0, sizeof(xmedia_video_frame_info));
|
||||
g_vo_frame_info.pool_id = VB_INVALID_POOLID;
|
||||
}
|
||||
|
||||
sprintf(sys_chmod, "chmod 666 %s", yuv_name);
|
||||
system(sys_chmod);
|
||||
|
||||
OUT:
|
||||
if(g_vo_fd != XMEDIA_NULL) {
|
||||
fclose(g_vo_fd);
|
||||
g_vo_fd = XMEDIA_NULL;
|
||||
}
|
||||
if(g_vo_frame_info.pool_id != VB_INVALID_POOLID) {
|
||||
ret = xmedia_vo_release_chn_frame(layer_id, chn_id, &g_vo_frame_info);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("layer(%d) chn(%d) release frame failed!\n", layer_id, chn_id);
|
||||
}
|
||||
}
|
||||
xmedia_vo_exit();
|
||||
return;
|
||||
}
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf(
|
||||
"\n"
|
||||
"*************************************************\n"
|
||||
"Usage: ./vo_chn_dump [dev_id] [chn_id] [frame_cnt]\n"
|
||||
"1)dev_id: \n"
|
||||
" vo dev id\n"
|
||||
"2)chn_id: \n"
|
||||
" vo chn id\n"
|
||||
"3)frame_cnt: \n"
|
||||
" the count of frame to be dumped\n"
|
||||
"*)Example:\n"
|
||||
" e.g : ./vo_chn_dump 0 0 1\n"
|
||||
" e.g : ./vo_chn_dump 1 0 2\n"
|
||||
"*************************************************\n"
|
||||
"\n");
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_u32 frame_cnt;
|
||||
|
||||
printf("\nNOTICE: This tool only can be used for TESTING !!!\n");
|
||||
printf("\tTo see more usage, please enter: ./vo_chn_dump -h\n\n");
|
||||
|
||||
if (argc > 1) {
|
||||
if (!strncmp(argv[1], "-h", 2)) {
|
||||
usage();
|
||||
exit(XMEDIA_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc < 4) {
|
||||
usage();
|
||||
exit(XMEDIA_SUCCESS);
|
||||
}
|
||||
|
||||
g_vo_layer_id = atoi(argv[1]);
|
||||
|
||||
if (!VALUE_BETWEEN(g_vo_layer_id, 0, XMEDIA_VO_DEV_MAX - 1)) {
|
||||
printf("vo dev id must be [0,%d]!\n\n", XMEDIA_VO_DEV_MAX - 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_vo_chn_id = atoi(argv[2]);
|
||||
|
||||
if (!VALUE_BETWEEN(g_vo_chn_id, 0, VO_MAX_CHN_NUM - 1)) {
|
||||
printf("vo chn id must be [0,%d]!\n\n", VO_MAX_CHN_NUM - 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
frame_cnt = atoi(argv[3]);
|
||||
if (frame_cnt < 1) {
|
||||
printf("frame_cnt can't be small than 1!\n\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_vo_signal_flag = 0;
|
||||
g_vo_fd = XMEDIA_NULL;
|
||||
g_vo_frame_info.pool_id = VB_INVALID_POOLID;
|
||||
|
||||
signal(SIGINT, vo_chn_dump_handle_signal);
|
||||
signal(SIGTERM, vo_chn_dump_handle_signal);
|
||||
|
||||
vo_misc_dump(g_vo_layer_id, g_vo_chn_id, frame_cnt);
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
Executable
+280
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "xmedia_sys.h"
|
||||
#include "xmedia_mmz.h"
|
||||
#include "xmedia_vb.h"
|
||||
#include "xmedia_vo.h"
|
||||
|
||||
#define VALUE_BETWEEN(x,min,max) (((x) >= (min)) && ((x) <= (max)))
|
||||
|
||||
|
||||
static volatile sig_atomic_t g_vo_signal_flag = 0;
|
||||
static xmedia_vo_layer g_vo_layer_id = 0;
|
||||
static xmedia_video_frame_info g_vo_frame_info;
|
||||
|
||||
static FILE* g_vo_fd = XMEDIA_NULL;
|
||||
|
||||
static void vo_dump_8bit_yuv(xmedia_video_frame *video_frame, FILE *fd)
|
||||
{
|
||||
unsigned int w, h;
|
||||
char* virt_addr_y;
|
||||
char* virt_addr_c;
|
||||
char* mem_content;
|
||||
unsigned char tmp_buff[8192];
|
||||
xmedia_u64 phy_addr;
|
||||
xmedia_u32 c_height;
|
||||
xmedia_u32 size;
|
||||
xmedia_char* page_addr[2];
|
||||
xmedia_bool uv_invert;
|
||||
xmedia_video_pixel_format pixel_fmt = video_frame->pixel_fmt;
|
||||
|
||||
uv_invert = (pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YUV_SEMIPLANAR_420) ? XMEDIA_TRUE : XMEDIA_FALSE;
|
||||
|
||||
if (video_frame->compress_mode != XMEDIA_VIDEO_COMPRESS_MODE_NONE) {
|
||||
video_frame->stride.y_stride = video_frame->width;
|
||||
video_frame->stride.c_stride = video_frame->width;
|
||||
}
|
||||
|
||||
if ((pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YVU_SEMIPLANAR_420) ||
|
||||
(pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YUV_SEMIPLANAR_420)) {
|
||||
size = video_frame->stride.y_stride * video_frame->height * 3 / 2;
|
||||
c_height = video_frame->height / 2;
|
||||
} else if (pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YUV_400) {
|
||||
size = video_frame->stride.y_stride * video_frame->height;
|
||||
c_height = video_frame->height;
|
||||
} else {
|
||||
size = video_frame->stride.y_stride * video_frame->height * 3 / 2;
|
||||
c_height = video_frame->height / 2;
|
||||
}
|
||||
|
||||
phy_addr = video_frame->addr.y_phy_addr;
|
||||
|
||||
page_addr[0] = (xmedia_char*)xmedia_mmz_map(phy_addr, size, XMEDIA_FALSE);
|
||||
if (XMEDIA_NULL == page_addr[0]) {
|
||||
return;
|
||||
}
|
||||
|
||||
virt_addr_y = page_addr[0];
|
||||
virt_addr_c = virt_addr_y + (video_frame->stride.y_stride) * (video_frame->height);
|
||||
|
||||
fprintf(stderr, "saving......Y......");
|
||||
fflush(stderr);
|
||||
for (h = 0; h < video_frame->height; h++) {
|
||||
mem_content = virt_addr_y + h * video_frame->stride.y_stride;
|
||||
fwrite(mem_content, video_frame->width, 1, fd);
|
||||
}
|
||||
|
||||
if (pixel_fmt != XMEDIA_VIDEO_PIXEL_FMT_YUV_400) {
|
||||
fflush(fd);
|
||||
fprintf(stderr, "U......");
|
||||
fflush(stderr);
|
||||
|
||||
for (h = 0; h < c_height; h++) {
|
||||
mem_content = virt_addr_c + h * video_frame->stride.c_stride;
|
||||
|
||||
if (!uv_invert) {
|
||||
mem_content += 1;
|
||||
}
|
||||
|
||||
for (w = 0; w < video_frame->width / 2; w++) {
|
||||
tmp_buff[w] = *mem_content;
|
||||
mem_content += 2;
|
||||
}
|
||||
fwrite(tmp_buff, video_frame->width / 2, 1, fd);
|
||||
}
|
||||
fflush(fd);
|
||||
|
||||
fprintf(stderr, "V......");
|
||||
fflush(stderr);
|
||||
for (h = 0; h < c_height; h++) {
|
||||
mem_content = virt_addr_c + h * video_frame->stride.c_stride;
|
||||
|
||||
if (uv_invert) {
|
||||
mem_content += 1;
|
||||
}
|
||||
|
||||
for (w = 0; w < video_frame->width / 2; w++) {
|
||||
tmp_buff[w] = *mem_content;
|
||||
mem_content += 2;
|
||||
}
|
||||
fwrite(tmp_buff, video_frame->width / 2, 1, fd);
|
||||
}
|
||||
}
|
||||
fflush(fd);
|
||||
|
||||
fprintf(stderr, "done!\n");
|
||||
fflush(stderr);
|
||||
|
||||
xmedia_mmz_unmap(page_addr[0]);
|
||||
page_addr[0] = XMEDIA_NULL;
|
||||
}
|
||||
|
||||
|
||||
void vo_chn_dump_handle_signal(xmedia_s32 signal)
|
||||
{
|
||||
if (g_vo_signal_flag != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (signal == SIGINT || signal == SIGTERM) {
|
||||
g_vo_signal_flag = 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
xmedia_void vo_misc_dump(xmedia_vo_layer layer_id, xmedia_u32 frame_cnt)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_char yuv_name[128];
|
||||
xmedia_char pixel_format[10];
|
||||
xmedia_char sys_chmod[140];
|
||||
xmedia_s32 millisec = -1;
|
||||
xmedia_s32 i = 0;
|
||||
xmedia_vo_layer_config layer_config;
|
||||
|
||||
ret = xmedia_vo_init();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("vo init failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = xmedia_vo_get_layer_config(layer_id, &layer_config);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) get ochn attr failed!\n", layer_id);
|
||||
goto OUT;
|
||||
}
|
||||
memset(&g_vo_frame_info, 0, sizeof(xmedia_video_frame_info));
|
||||
g_vo_frame_info.pool_id = VB_INVALID_POOLID;
|
||||
|
||||
for(i = 0;i < frame_cnt;i++) {
|
||||
if (xmedia_vo_acquire_layer_frame(layer_id, &g_vo_frame_info, millisec) != XMEDIA_SUCCESS) {
|
||||
printf("layer(%d) get frame error for 10 times, now exit!\n", layer_id);
|
||||
goto OUT;
|
||||
}
|
||||
if(g_vo_fd == XMEDIA_NULL) {
|
||||
switch (g_vo_frame_info.frame.pixel_fmt) {
|
||||
case XMEDIA_VIDEO_PIXEL_FMT_YVU_SEMIPLANAR_420:
|
||||
case XMEDIA_VIDEO_PIXEL_FMT_YUV_SEMIPLANAR_420:
|
||||
snprintf(pixel_format, 10, "P420");
|
||||
break;
|
||||
case XMEDIA_VIDEO_PIXEL_FMT_YUV_400:
|
||||
snprintf(pixel_format, 10, "YUV400");
|
||||
break;
|
||||
default:
|
||||
snprintf(pixel_format, 10, "P420");
|
||||
break;
|
||||
}
|
||||
snprintf(yuv_name, 128, "./layer%d_%dx%d_%s_%d.yuv", layer_id,
|
||||
g_vo_frame_info.frame.width, g_vo_frame_info.frame.height, pixel_format, frame_cnt);
|
||||
|
||||
printf("layer(%d) dump frame to file: \"%s\"\n", layer_id, yuv_name);
|
||||
fflush(stdout);
|
||||
|
||||
g_vo_fd = fopen(yuv_name, "wb");
|
||||
if (g_vo_fd == XMEDIA_NULL) {
|
||||
printf("open file failed:%s!\n", strerror(errno));
|
||||
goto OUT;
|
||||
}
|
||||
}
|
||||
|
||||
vo_dump_8bit_yuv(&g_vo_frame_info.frame, g_vo_fd);
|
||||
|
||||
ret = xmedia_vo_release_layer_frame(layer_id, &g_vo_frame_info);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("layer(%d) release frame failed!\n", layer_id);
|
||||
goto OUT;
|
||||
}
|
||||
memset(&g_vo_frame_info, 0, sizeof(xmedia_video_frame_info));
|
||||
g_vo_frame_info.pool_id = VB_INVALID_POOLID;
|
||||
}
|
||||
|
||||
sprintf(sys_chmod, "chmod 666 %s", yuv_name);
|
||||
system(sys_chmod);
|
||||
|
||||
OUT:
|
||||
if(g_vo_fd != XMEDIA_NULL) {
|
||||
fclose(g_vo_fd);
|
||||
g_vo_fd = XMEDIA_NULL;
|
||||
}
|
||||
if(g_vo_frame_info.pool_id != VB_INVALID_POOLID) {
|
||||
ret = xmedia_vo_release_layer_frame(layer_id, &g_vo_frame_info);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("layer(%d) release frame failed!\n", layer_id);
|
||||
}
|
||||
}
|
||||
xmedia_vo_exit();
|
||||
return;
|
||||
}
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf(
|
||||
"\n"
|
||||
"*************************************************\n"
|
||||
"Usage: ./vo_chn_dump [dev_id] [frame_cnt]\n"
|
||||
"1)dev_id: \n"
|
||||
" vo dev id\n"
|
||||
"2)frame_cnt: \n"
|
||||
" the count of frame to be dumped\n"
|
||||
"*)Example:\n"
|
||||
" e.g : ./vo_chn_dump 0 1\n"
|
||||
" e.g : ./vo_chn_dump 1 20\n"
|
||||
"*************************************************\n"
|
||||
"\n");
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_u32 frame_cnt;
|
||||
|
||||
printf("\nNOTICE: This tool only can be used for TESTING !!!\n");
|
||||
printf("\tTo see more usage, please enter: ./vo_chn_dump -h\n\n");
|
||||
|
||||
if (argc > 1) {
|
||||
if (!strncmp(argv[1], "-h", 2)) {
|
||||
usage();
|
||||
exit(XMEDIA_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc < 3) {
|
||||
usage();
|
||||
exit(XMEDIA_SUCCESS);
|
||||
}
|
||||
|
||||
g_vo_layer_id = atoi(argv[1]);
|
||||
|
||||
if (!VALUE_BETWEEN(g_vo_layer_id, 0, XMEDIA_VO_DEV_MAX - 1)) {
|
||||
printf("vo dev id must be [0,%d]!\n\n", XMEDIA_VO_DEV_MAX - 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
frame_cnt = atoi(argv[2]);
|
||||
if (frame_cnt < 1) {
|
||||
printf("frame_cnt can't be small than 1!\n\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_vo_signal_flag = 0;
|
||||
g_vo_fd = XMEDIA_NULL;
|
||||
g_vo_frame_info.pool_id = VB_INVALID_POOLID;
|
||||
|
||||
signal(SIGINT, vo_chn_dump_handle_signal);
|
||||
signal(SIGTERM, vo_chn_dump_handle_signal);
|
||||
|
||||
vo_misc_dump(g_vo_layer_id, frame_cnt);
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,569 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "xmedia_sys.h"
|
||||
#include "xmedia_mmz.h"
|
||||
#include "xmedia_vb.h"
|
||||
#include "xmedia_vpss.h"
|
||||
#include "xmedia_vgs.h"
|
||||
|
||||
#define VALUE_BETWEEN(x,min,max) (((x) >= (min)) && ((x) <= (max)))
|
||||
|
||||
#define VPSS_MAX_FRAME_CNT 50
|
||||
|
||||
static volatile sig_atomic_t g_vpss_signal_flag = 0;
|
||||
static xmedia_u32 g_vpss_continuous_dump = 0;
|
||||
|
||||
static xmedia_s32 g_vpss_pipe_id = 0;
|
||||
static xmedia_s32 g_vpss_ichn_id = 0;
|
||||
static xmedia_video_frame_info g_vpss_frame_info;
|
||||
static xmedia_video_frame_info g_vpss_multi_frame_info[VPSS_MAX_FRAME_CNT];
|
||||
|
||||
static FILE* g_vpss_fd = XMEDIA_NULL;
|
||||
|
||||
static void vpss_ichn_dump_8bit_yuv(xmedia_video_frame *video_frame, FILE *fd)
|
||||
{
|
||||
unsigned int w, h;
|
||||
char* virt_addr_y;
|
||||
char* virt_addr_c;
|
||||
char* mem_content;
|
||||
unsigned char tmp_buff[8192];
|
||||
xmedia_u64 phy_addr;
|
||||
xmedia_u32 c_height;
|
||||
xmedia_u32 size;
|
||||
xmedia_char* page_addr[2];
|
||||
xmedia_bool uv_invert;
|
||||
xmedia_video_pixel_format pixel_fmt = video_frame->pixel_fmt;
|
||||
|
||||
uv_invert = (pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YUV_SEMIPLANAR_420) ? XMEDIA_TRUE : XMEDIA_FALSE;
|
||||
|
||||
if (video_frame->compress_mode != XMEDIA_VIDEO_COMPRESS_MODE_NONE) {
|
||||
video_frame->stride.y_stride = video_frame->width;
|
||||
video_frame->stride.c_stride = video_frame->width;
|
||||
}
|
||||
|
||||
if ((pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YVU_SEMIPLANAR_420) ||
|
||||
(pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YUV_SEMIPLANAR_420)) {
|
||||
size = video_frame->stride.y_stride * video_frame->height * 3 / 2;
|
||||
c_height = video_frame->height / 2;
|
||||
} else if (pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YUV_400) {
|
||||
size = video_frame->stride.y_stride * video_frame->height;
|
||||
c_height = video_frame->height;
|
||||
} else {
|
||||
size = video_frame->stride.y_stride * video_frame->height * 3 / 2;
|
||||
c_height = video_frame->height / 2;
|
||||
}
|
||||
|
||||
phy_addr = video_frame->addr.y_phy_addr;
|
||||
|
||||
page_addr[0] = (xmedia_char*)xmedia_mmz_map(phy_addr, size, XMEDIA_FALSE);
|
||||
if (XMEDIA_NULL == page_addr[0]) {
|
||||
return;
|
||||
}
|
||||
|
||||
virt_addr_y = page_addr[0];
|
||||
virt_addr_c = virt_addr_y + (video_frame->stride.y_stride) * (video_frame->height);
|
||||
|
||||
fprintf(stderr, "saving......Y......");
|
||||
fflush(stderr);
|
||||
for (h = 0; h < video_frame->height; h++) {
|
||||
mem_content = virt_addr_y + h * video_frame->stride.y_stride;
|
||||
fwrite(mem_content, video_frame->width, 1, fd);
|
||||
}
|
||||
|
||||
if (pixel_fmt != XMEDIA_VIDEO_PIXEL_FMT_YUV_400) {
|
||||
fflush(fd);
|
||||
fprintf(stderr, "U......");
|
||||
fflush(stderr);
|
||||
|
||||
for (h = 0; h < c_height; h++) {
|
||||
mem_content = virt_addr_c + h * video_frame->stride.c_stride;
|
||||
|
||||
if (!uv_invert) {
|
||||
mem_content += 1;
|
||||
}
|
||||
|
||||
for (w = 0; w < video_frame->width / 2; w++) {
|
||||
tmp_buff[w] = *mem_content;
|
||||
mem_content += 2;
|
||||
}
|
||||
fwrite(tmp_buff, video_frame->width / 2, 1, fd);
|
||||
}
|
||||
fflush(fd);
|
||||
|
||||
fprintf(stderr, "V......");
|
||||
fflush(stderr);
|
||||
for (h = 0; h < c_height; h++) {
|
||||
mem_content = virt_addr_c + h * video_frame->stride.c_stride;
|
||||
|
||||
if (uv_invert) {
|
||||
mem_content += 1;
|
||||
}
|
||||
|
||||
for (w = 0; w < video_frame->width / 2; w++) {
|
||||
tmp_buff[w] = *mem_content;
|
||||
mem_content += 2;
|
||||
}
|
||||
fwrite(tmp_buff, video_frame->width / 2, 1, fd);
|
||||
}
|
||||
}
|
||||
fflush(fd);
|
||||
|
||||
fprintf(stderr, "done!\n");
|
||||
fflush(stderr);
|
||||
|
||||
xmedia_mmz_unmap(page_addr[0]);
|
||||
page_addr[0] = XMEDIA_NULL;
|
||||
}
|
||||
|
||||
static xmedia_s32 vpss_ichn_restore(xmedia_s32 pipe_id, xmedia_s32 ichn_id)
|
||||
{
|
||||
xmedia_s32 ret = XMEDIA_FAILURE;
|
||||
xmedia_u32 i;
|
||||
|
||||
if (g_vpss_continuous_dump == 0) {
|
||||
if (g_vpss_frame_info.pool_id != VB_INVALID_POOLID) {
|
||||
ret = xmedia_vpss_release_ichn_frame(pipe_id, ichn_id, &g_vpss_frame_info);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ichn(%d) release frame failed!\n", pipe_id, ichn_id);
|
||||
}
|
||||
|
||||
g_vpss_frame_info.pool_id = VB_INVALID_POOLID;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < VPSS_MAX_FRAME_CNT; i++) {
|
||||
if (g_vpss_multi_frame_info[i].pool_id != VB_INVALID_POOLID) {
|
||||
ret = xmedia_vpss_release_ichn_frame(pipe_id, ichn_id, &g_vpss_multi_frame_info[i]);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ichn(%d) release frame failed!\n", pipe_id, ichn_id);
|
||||
}
|
||||
|
||||
g_vpss_multi_frame_info[i].pool_id = VB_INVALID_POOLID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (g_vpss_fd != XMEDIA_NULL) {
|
||||
fclose(g_vpss_fd);
|
||||
g_vpss_fd = XMEDIA_NULL;
|
||||
}
|
||||
|
||||
ret = xmedia_vpss_exit();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("vpss exit failed!\n");
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
void vpss_ichn_dump_handle_signal(xmedia_s32 signal)
|
||||
{
|
||||
if (g_vpss_signal_flag != 0) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (signal == SIGINT || signal == SIGTERM) {
|
||||
g_vpss_signal_flag++;
|
||||
vpss_ichn_restore(g_vpss_pipe_id, g_vpss_ichn_id);
|
||||
g_vpss_signal_flag--;
|
||||
printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
|
||||
}
|
||||
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
static xmedia_s32 vpss_ichn_dump_transform_format(xmedia_video_frame_info *frame_in,
|
||||
xmedia_video_frame_info *frame_out)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_vgs_frame_info task_info;
|
||||
xmedia_s32 job_handle;
|
||||
|
||||
ret = xmedia_vgs_init();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("vgs init failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = xmedia_vgs_create_job(&job_handle);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("create vgs job failed\n");
|
||||
xmedia_vgs_exit();
|
||||
goto EXIT1;
|
||||
}
|
||||
|
||||
memcpy(&task_info.img_in, frame_in, sizeof(xmedia_video_frame_info));
|
||||
memcpy(&task_info.img_out, frame_out, sizeof(xmedia_video_frame_info));
|
||||
ret = xmedia_vgs_add_task_rotation(job_handle, &task_info, XMEDIA_VIDEO_ROTATION_0);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("add vgs task failed\n");
|
||||
goto EXIT2;
|
||||
}
|
||||
|
||||
ret = xmedia_vgs_submit_job(job_handle);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("submit vgs job failed\n");
|
||||
goto EXIT2;
|
||||
}
|
||||
|
||||
ret = xmedia_vgs_wait_job(job_handle, 2000);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("wait vgs job failed\n");
|
||||
goto EXIT1;
|
||||
}
|
||||
|
||||
xmedia_vgs_exit();
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
|
||||
EXIT2:
|
||||
xmedia_vgs_cancel_job(job_handle);
|
||||
EXIT1:
|
||||
xmedia_vgs_exit();
|
||||
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
static xmedia_void vpss_ichn_uncontinuous_dump(xmedia_s32 pipe_id, xmedia_s32 ichn_id,
|
||||
xmedia_u32 frame_cnt, xmedia_char *yuv_name)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_u32 cnt = frame_cnt;
|
||||
xmedia_s32 millisec = -1;
|
||||
xmedia_handle vb_handle = VB_INVALID_HANDLE;
|
||||
xmedia_vb_base_info base_info;
|
||||
xmedia_vb_cal_cfg cal_cfg;
|
||||
xmedia_video_frame_info frame_out = {0};
|
||||
|
||||
while (cnt--) {
|
||||
if (xmedia_vpss_acquire_ichn_frame(pipe_id, ichn_id, &g_vpss_frame_info, millisec) != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ichn(%d) get frame failed!\n", pipe_id, ichn_id);
|
||||
usleep(1000);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("pipe(%d) ichn(%d) save frame %d!\n", pipe_id, ichn_id, cnt);
|
||||
|
||||
if (g_vpss_frame_info.frame.video_fmt != XMEDIA_VIDEO_FMT_LINEAR) {
|
||||
base_info.align = 0;
|
||||
base_info.bit_width = g_vpss_frame_info.frame.bit_width;
|
||||
base_info.cmp_mode = XMEDIA_VIDEO_COMPRESS_MODE_NONE;
|
||||
base_info.width = g_vpss_frame_info.frame.width;
|
||||
base_info.height = g_vpss_frame_info.frame.height;
|
||||
base_info.pixel_fmt = g_vpss_frame_info.frame.pixel_fmt;
|
||||
base_info.video_fmt = XMEDIA_VIDEO_FMT_LINEAR;
|
||||
|
||||
ret = xmedia_vb_get_buffer_config(&base_info, &cal_cfg);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("get buffer config failed with 0x%x\n", ret);
|
||||
xmedia_vpss_release_ichn_frame(pipe_id, ichn_id, &g_vpss_frame_info);
|
||||
return;
|
||||
}
|
||||
|
||||
vb_handle = xmedia_vb_get_block(-1, cal_cfg.vb_size, XMEDIA_NULL);
|
||||
if (vb_handle == VB_INVALID_HANDLE) {
|
||||
printf("get block failed\n");
|
||||
xmedia_vpss_release_ichn_frame(pipe_id, ichn_id, &g_vpss_frame_info);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(&frame_out, &g_vpss_frame_info, sizeof(xmedia_video_frame_info));
|
||||
frame_out.pool_id = xmedia_vb_handle_to_pool_id(vb_handle);
|
||||
frame_out.frame.addr.y_phy_addr = xmedia_vb_handle_to_phy_addr(vb_handle);
|
||||
frame_out.frame.addr.y_head_phy_addr = frame_out.frame.addr.y_phy_addr;
|
||||
frame_out.frame.addr.c_phy_addr = frame_out.frame.addr.y_phy_addr + cal_cfg.main_y_size;
|
||||
frame_out.frame.stride.y_stride = cal_cfg.main_stride;
|
||||
frame_out.frame.stride.c_stride = cal_cfg.main_stride;
|
||||
frame_out.frame.compress_mode = XMEDIA_VIDEO_COMPRESS_MODE_NONE;
|
||||
frame_out.frame.video_fmt = XMEDIA_VIDEO_FMT_LINEAR;
|
||||
|
||||
ret = vpss_ichn_dump_transform_format(&g_vpss_frame_info, &frame_out);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe %d ichn %d vpss_ichn_dump_transform_format failed\n", pipe_id, ichn_id);
|
||||
xmedia_vpss_release_ichn_frame(pipe_id, ichn_id, &g_vpss_frame_info);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
memcpy(&frame_out, &g_vpss_frame_info, sizeof(xmedia_video_frame_info));
|
||||
}
|
||||
|
||||
vpss_ichn_dump_8bit_yuv(&frame_out.frame, g_vpss_fd);
|
||||
|
||||
if (g_vpss_frame_info.frame.video_fmt != XMEDIA_VIDEO_FMT_LINEAR) {
|
||||
xmedia_vb_release_block(vb_handle);
|
||||
}
|
||||
|
||||
ret = xmedia_vpss_release_ichn_frame(pipe_id, ichn_id, &g_vpss_frame_info);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ichn(%d) release frame failed!\n", pipe_id, ichn_id);
|
||||
return;
|
||||
}
|
||||
|
||||
g_vpss_frame_info.pool_id = VB_INVALID_POOLID;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static xmedia_void vpss_ichn_continuous_dump(xmedia_s32 pipe_id, xmedia_s32 ichn_id,
|
||||
xmedia_u32 frame_cnt, xmedia_char *yuv_name)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_u32 cnt = frame_cnt;
|
||||
xmedia_s32 millisec = -1;
|
||||
xmedia_u32 get_frame_cnt = 0;
|
||||
xmedia_handle vb_handle = VB_INVALID_HANDLE;
|
||||
xmedia_vb_base_info base_info;
|
||||
xmedia_vb_cal_cfg cal_cfg;
|
||||
xmedia_video_frame_info frame_out = {0};
|
||||
|
||||
while (cnt--) {
|
||||
if (xmedia_vpss_acquire_ichn_frame(pipe_id, ichn_id, &g_vpss_multi_frame_info[get_frame_cnt], millisec) !=
|
||||
XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ichn(%d) get frame failed!\n", pipe_id, ichn_id);
|
||||
usleep(1000);
|
||||
continue;
|
||||
}
|
||||
|
||||
get_frame_cnt++;
|
||||
if (get_frame_cnt >= VPSS_MAX_FRAME_CNT) {
|
||||
printf("pipe(%d) ichn(%d) get frame cnt err!\n", pipe_id, ichn_id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
cnt = 0;
|
||||
|
||||
while (cnt < get_frame_cnt) {
|
||||
printf("pipe(%d) ichn(%d) save frame %d!\n", pipe_id, ichn_id, (get_frame_cnt - cnt - 1));
|
||||
|
||||
if (g_vpss_multi_frame_info[cnt].frame.video_fmt != XMEDIA_VIDEO_FMT_LINEAR) {
|
||||
base_info.align = 0;
|
||||
base_info.bit_width = g_vpss_multi_frame_info[cnt].frame.bit_width;
|
||||
base_info.cmp_mode = XMEDIA_VIDEO_COMPRESS_MODE_NONE;
|
||||
base_info.width = g_vpss_multi_frame_info[cnt].frame.width;
|
||||
base_info.height = g_vpss_multi_frame_info[cnt].frame.height;
|
||||
base_info.pixel_fmt = g_vpss_multi_frame_info[cnt].frame.pixel_fmt;
|
||||
base_info.video_fmt = XMEDIA_VIDEO_FMT_LINEAR;
|
||||
|
||||
ret = xmedia_vb_get_buffer_config(&base_info, &cal_cfg);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("get buffer config failed with 0x%x\n", ret);
|
||||
xmedia_vpss_release_ichn_frame(pipe_id, ichn_id, &g_vpss_multi_frame_info[cnt]);
|
||||
return;
|
||||
}
|
||||
|
||||
vb_handle = xmedia_vb_get_block(-1, cal_cfg.vb_size, XMEDIA_NULL);
|
||||
if (vb_handle == VB_INVALID_HANDLE) {
|
||||
printf("get block failed\n");
|
||||
xmedia_vpss_release_ichn_frame(pipe_id, ichn_id, &g_vpss_multi_frame_info[cnt]);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(&frame_out, &g_vpss_multi_frame_info[cnt], sizeof(xmedia_video_frame_info));
|
||||
frame_out.pool_id = xmedia_vb_handle_to_pool_id(vb_handle);
|
||||
frame_out.frame.addr.y_phy_addr = xmedia_vb_handle_to_phy_addr(vb_handle);
|
||||
frame_out.frame.addr.y_head_phy_addr = frame_out.frame.addr.y_phy_addr;
|
||||
frame_out.frame.addr.c_phy_addr = frame_out.frame.addr.y_phy_addr + cal_cfg.main_y_size;
|
||||
frame_out.frame.stride.y_stride = cal_cfg.main_stride;
|
||||
frame_out.frame.stride.c_stride = cal_cfg.main_stride;
|
||||
frame_out.frame.compress_mode = XMEDIA_VIDEO_COMPRESS_MODE_NONE;
|
||||
frame_out.frame.video_fmt = XMEDIA_VIDEO_FMT_LINEAR;
|
||||
|
||||
ret = vpss_ichn_dump_transform_format(&g_vpss_multi_frame_info[cnt], &frame_out);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe %d ichn %d vpss_ichn_dump_transform_format failed\n", pipe_id, ichn_id);
|
||||
xmedia_vpss_release_ichn_frame(pipe_id, ichn_id, &g_vpss_multi_frame_info[cnt]);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
memcpy(&frame_out, &g_vpss_multi_frame_info[cnt], sizeof(xmedia_video_frame_info));
|
||||
}
|
||||
|
||||
vpss_ichn_dump_8bit_yuv(&frame_out.frame, g_vpss_fd);
|
||||
|
||||
if (g_vpss_multi_frame_info[cnt].frame.video_fmt != XMEDIA_VIDEO_FMT_LINEAR) {
|
||||
xmedia_vb_release_block(vb_handle);
|
||||
}
|
||||
|
||||
ret = xmedia_vpss_release_ichn_frame(pipe_id, ichn_id, &g_vpss_multi_frame_info[cnt]);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ichn(%d) release frame failed!\n", pipe_id, ichn_id);
|
||||
return;
|
||||
}
|
||||
|
||||
g_vpss_multi_frame_info[cnt].pool_id = VB_INVALID_POOLID;
|
||||
|
||||
cnt++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
xmedia_void vpss_ichn_misc_dump(xmedia_s32 pipe_id, xmedia_s32 ichn_id, xmedia_u32 frame_cnt)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_char yuv_name[128];
|
||||
xmedia_char pixel_format[10];
|
||||
xmedia_char sys_chmod[140];
|
||||
xmedia_u32 cnt = frame_cnt;
|
||||
xmedia_s32 millisec = -1;
|
||||
|
||||
ret = xmedia_vpss_init();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("vpss init failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
memset(&g_vpss_frame_info, 0, sizeof(xmedia_video_frame_info));
|
||||
g_vpss_frame_info.pool_id = VB_INVALID_POOLID;
|
||||
|
||||
if (xmedia_vpss_acquire_ichn_frame(pipe_id, ichn_id, &g_vpss_frame_info, millisec) != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ichn(%d) get frame error, now exit!\n", pipe_id, ichn_id);
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
switch (g_vpss_frame_info.frame.pixel_fmt) {
|
||||
case XMEDIA_VIDEO_PIXEL_FMT_YVU_SEMIPLANAR_420:
|
||||
case XMEDIA_VIDEO_PIXEL_FMT_YUV_SEMIPLANAR_420:
|
||||
snprintf(pixel_format, 10, "P420");
|
||||
break;
|
||||
|
||||
case XMEDIA_VIDEO_PIXEL_FMT_YUV_400:
|
||||
snprintf(pixel_format, 10, "YUV400");
|
||||
break;
|
||||
|
||||
default:
|
||||
snprintf(pixel_format, 10, "P420");
|
||||
break;
|
||||
}
|
||||
|
||||
snprintf(yuv_name, 128, "./pipe%d_ichn%d_%dx%d_%s_%d.yuv", pipe_id, ichn_id,
|
||||
g_vpss_frame_info.frame.width, g_vpss_frame_info.frame.height, pixel_format, cnt);
|
||||
|
||||
printf("pipe(%d) ichn(%d) dump frame to file: \"%s\"\n", pipe_id, ichn_id, yuv_name);
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
ret = xmedia_vpss_release_ichn_frame(pipe_id, ichn_id, &g_vpss_frame_info);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ichn(%d) release frame failed!\n", pipe_id, ichn_id);
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
g_vpss_frame_info.pool_id = VB_INVALID_POOLID;
|
||||
|
||||
g_vpss_fd = fopen(yuv_name, "wb");
|
||||
if (g_vpss_fd == XMEDIA_NULL) {
|
||||
printf("open file failed:%s!\n", strerror(errno));
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
if (g_vpss_continuous_dump == 0) {
|
||||
vpss_ichn_uncontinuous_dump(pipe_id, ichn_id, frame_cnt, yuv_name);
|
||||
} else {
|
||||
vpss_ichn_continuous_dump(pipe_id, ichn_id, frame_cnt, yuv_name);
|
||||
}
|
||||
|
||||
sprintf(sys_chmod, "chmod 666 %s", yuv_name);
|
||||
system(sys_chmod);
|
||||
|
||||
EXIT:
|
||||
vpss_ichn_restore(pipe_id, ichn_id);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf(
|
||||
"\n"
|
||||
"*************************************************\n"
|
||||
"Usage: ./vpss_ichn_dump [pipe_id] [ichn_id] [frame_cnt] [mode]\n"
|
||||
"1)pipe_id: \n"
|
||||
" vpss pipe id\n"
|
||||
"2)ichn_id: \n"
|
||||
" vpss ichn id\n"
|
||||
"3)frame_cnt: \n"
|
||||
" the count of frame to be dumped\n"
|
||||
"*)Example:\n"
|
||||
" e.g : ./vpss_ichn_dump 0 0 1\n"
|
||||
"*************************************************\n"
|
||||
"\n");
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_u32 frame_cnt;
|
||||
xmedia_u32 i;
|
||||
|
||||
printf("\nNOTICE: This tool only can be used for TESTING !!!\n");
|
||||
printf("\tTo see more usage, please enter: ./vpss_ichn_dump -h\n\n");
|
||||
|
||||
if (argc > 1) {
|
||||
if (!strncmp(argv[1], "-h", 2)) {
|
||||
usage();
|
||||
exit(XMEDIA_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc < 4) {
|
||||
usage();
|
||||
exit(XMEDIA_SUCCESS);
|
||||
}
|
||||
|
||||
g_vpss_pipe_id = atoi(argv[1]);
|
||||
|
||||
if (!VALUE_BETWEEN(g_vpss_pipe_id, 0, VPSS_MAX_PIPE_NUM - 1)) {
|
||||
printf("vpss pipe id must be [0,%d]!\n\n", VPSS_MAX_PIPE_NUM - 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_vpss_ichn_id = atoi(argv[2]);
|
||||
|
||||
if (!VALUE_BETWEEN(g_vpss_ichn_id, 0, VPSS_MAX_ICHN_NUM - 1)) {
|
||||
printf("vpss ichn id must be [0,%d]!\n\n", VPSS_MAX_ICHN_NUM - 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
frame_cnt = atoi(argv[3]);
|
||||
if (frame_cnt < 1) {
|
||||
printf("frame_cnt can't be small than 1!\n\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!VALUE_BETWEEN(g_vpss_continuous_dump, 0, 1)) {
|
||||
printf("vpss dump mode must be [0,1]!\n\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((g_vpss_continuous_dump == 1) && (frame_cnt > VPSS_MAX_FRAME_CNT)) {
|
||||
printf("frame_cnt must be [1,%d] in continuous mode!\n\n", VPSS_MAX_FRAME_CNT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_vpss_signal_flag = 0;
|
||||
g_vpss_fd = XMEDIA_NULL;
|
||||
g_vpss_frame_info.pool_id = VB_INVALID_POOLID;
|
||||
|
||||
for (i = 0; i < VPSS_MAX_FRAME_CNT; i++) {
|
||||
g_vpss_multi_frame_info[i].pool_id = VB_INVALID_POOLID;
|
||||
}
|
||||
|
||||
signal(SIGINT, vpss_ichn_dump_handle_signal);
|
||||
signal(SIGTERM, vpss_ichn_dump_handle_signal);
|
||||
|
||||
vpss_ichn_misc_dump(g_vpss_pipe_id, g_vpss_ichn_id, frame_cnt);
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
Executable
+776
@@ -0,0 +1,776 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "xmedia_sys.h"
|
||||
#include "xmedia_mmz.h"
|
||||
#include "xmedia_vb.h"
|
||||
#include "xmedia_vpss.h"
|
||||
#include "xmedia_vgs.h"
|
||||
|
||||
#define VALUE_BETWEEN(x,min,max) (((x) >= (min)) && ((x) <= (max)))
|
||||
|
||||
#define VPSS_MAX_FRAME_CNT 50
|
||||
|
||||
static xmedia_u32 g_vpss_depth_flag = 0;
|
||||
static volatile sig_atomic_t g_vpss_signal_flag = 0;
|
||||
static xmedia_u32 g_vpss_continuous_dump = 0;
|
||||
|
||||
static xmedia_s32 g_vpss_pipe_id = 0;
|
||||
static xmedia_s32 g_vpss_ochn_id = 0;
|
||||
static xmedia_u32 g_vpss_ori_depth = 0;
|
||||
static xmedia_video_frame_info g_vpss_frame_info;
|
||||
static xmedia_video_frame_info g_vpss_multi_frame_info[VPSS_MAX_FRAME_CNT];
|
||||
|
||||
static FILE* g_vpss_fd = XMEDIA_NULL;
|
||||
|
||||
static void vpss_ochn_dump_8bit_yuv(xmedia_video_frame *video_frame, FILE *fd)
|
||||
{
|
||||
unsigned int w, h;
|
||||
char* virt_addr_y;
|
||||
char* virt_addr_c;
|
||||
char* mem_content;
|
||||
unsigned char tmp_buff[8192];
|
||||
xmedia_u64 phy_addr;
|
||||
xmedia_u32 c_height;
|
||||
xmedia_u32 size;
|
||||
xmedia_char* page_addr[2];
|
||||
xmedia_bool uv_invert;
|
||||
xmedia_video_pixel_format pixel_fmt = video_frame->pixel_fmt;
|
||||
|
||||
uv_invert = (pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YUV_SEMIPLANAR_420) ? XMEDIA_TRUE : XMEDIA_FALSE;
|
||||
|
||||
if (video_frame->compress_mode != XMEDIA_VIDEO_COMPRESS_MODE_NONE) {
|
||||
video_frame->stride.y_stride = video_frame->width;
|
||||
video_frame->stride.c_stride = video_frame->width;
|
||||
}
|
||||
|
||||
if ((pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YVU_SEMIPLANAR_420) ||
|
||||
(pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YUV_SEMIPLANAR_420)) {
|
||||
size = video_frame->stride.y_stride * video_frame->height * 3 / 2;
|
||||
c_height = video_frame->height / 2;
|
||||
} else if (pixel_fmt == XMEDIA_VIDEO_PIXEL_FMT_YUV_400) {
|
||||
size = video_frame->stride.y_stride * video_frame->height;
|
||||
c_height = video_frame->height;
|
||||
} else {
|
||||
size = video_frame->stride.y_stride * video_frame->height * 3 / 2;
|
||||
c_height = video_frame->height / 2;
|
||||
}
|
||||
|
||||
phy_addr = video_frame->addr.y_phy_addr;
|
||||
|
||||
page_addr[0] = (xmedia_char*)xmedia_mmz_map(phy_addr, size, XMEDIA_FALSE);
|
||||
if (XMEDIA_NULL == page_addr[0]) {
|
||||
return;
|
||||
}
|
||||
|
||||
virt_addr_y = page_addr[0];
|
||||
virt_addr_c = virt_addr_y + (video_frame->stride.y_stride) * (video_frame->height);
|
||||
|
||||
fprintf(stderr, "saving......Y......");
|
||||
fflush(stderr);
|
||||
for (h = 0; h < video_frame->height; h++) {
|
||||
mem_content = virt_addr_y + h * video_frame->stride.y_stride;
|
||||
fwrite(mem_content, video_frame->width, 1, fd);
|
||||
}
|
||||
|
||||
if (pixel_fmt != XMEDIA_VIDEO_PIXEL_FMT_YUV_400) {
|
||||
fflush(fd);
|
||||
fprintf(stderr, "U......");
|
||||
fflush(stderr);
|
||||
|
||||
for (h = 0; h < c_height; h++) {
|
||||
mem_content = virt_addr_c + h * video_frame->stride.c_stride;
|
||||
|
||||
if (!uv_invert) {
|
||||
mem_content += 1;
|
||||
}
|
||||
|
||||
for (w = 0; w < video_frame->width / 2; w++) {
|
||||
tmp_buff[w] = *mem_content;
|
||||
mem_content += 2;
|
||||
}
|
||||
fwrite(tmp_buff, video_frame->width / 2, 1, fd);
|
||||
}
|
||||
fflush(fd);
|
||||
|
||||
fprintf(stderr, "V......");
|
||||
fflush(stderr);
|
||||
for (h = 0; h < c_height; h++) {
|
||||
mem_content = virt_addr_c + h * video_frame->stride.c_stride;
|
||||
|
||||
if (uv_invert) {
|
||||
mem_content += 1;
|
||||
}
|
||||
|
||||
for (w = 0; w < video_frame->width / 2; w++) {
|
||||
tmp_buff[w] = *mem_content;
|
||||
mem_content += 2;
|
||||
}
|
||||
fwrite(tmp_buff, video_frame->width / 2, 1, fd);
|
||||
}
|
||||
}
|
||||
fflush(fd);
|
||||
|
||||
fprintf(stderr, "done!\n");
|
||||
fflush(stderr);
|
||||
|
||||
xmedia_mmz_unmap(page_addr[0]);
|
||||
page_addr[0] = XMEDIA_NULL;
|
||||
}
|
||||
|
||||
static xmedia_s32 vpss_ochn_restore(xmedia_s32 pipe_id, xmedia_s32 ochn_id)
|
||||
{
|
||||
xmedia_s32 ret = XMEDIA_FAILURE;
|
||||
xmedia_u32 i;
|
||||
|
||||
if (g_vpss_continuous_dump == 0) {
|
||||
if (g_vpss_frame_info.pool_id != VB_INVALID_POOLID) {
|
||||
ret = xmedia_vpss_release_ochn_frame(pipe_id, ochn_id, &g_vpss_frame_info);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ochn(%d) release frame failed!\n", pipe_id, ochn_id);
|
||||
}
|
||||
|
||||
g_vpss_frame_info.pool_id = VB_INVALID_POOLID;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < VPSS_MAX_FRAME_CNT; i++) {
|
||||
if (g_vpss_multi_frame_info[i].pool_id != VB_INVALID_POOLID) {
|
||||
ret = xmedia_vpss_release_ochn_frame(pipe_id, ochn_id, &g_vpss_multi_frame_info[i]);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ochn(%d) release frame failed!\n", pipe_id, ochn_id);
|
||||
}
|
||||
|
||||
g_vpss_multi_frame_info[i].pool_id = VB_INVALID_POOLID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (g_vpss_fd != XMEDIA_NULL) {
|
||||
fclose(g_vpss_fd);
|
||||
g_vpss_fd = XMEDIA_NULL;
|
||||
}
|
||||
|
||||
if (g_vpss_depth_flag != 0) {
|
||||
if (ochn_id < VPSS_MAX_PHY_OCHN_NUM) {
|
||||
xmedia_vpss_ochn_attr ochn_attr = {0};
|
||||
|
||||
ret = xmedia_vpss_get_ochn_attr(pipe_id, ochn_id, &ochn_attr) ;
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ochn(%d) get ochn attr failed!\n", pipe_id, ochn_id);
|
||||
}
|
||||
|
||||
ochn_attr.depth = g_vpss_ori_depth;
|
||||
|
||||
ret = xmedia_vpss_set_ochn_attr(pipe_id, ochn_id, &ochn_attr) ;
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ochn(%d) set ochn attr failed!\n", pipe_id, ochn_id);
|
||||
}
|
||||
} else {
|
||||
xmedia_vpss_ext_ochn_attr ext_ochn_attr = {0};
|
||||
|
||||
ret = xmedia_vpss_get_ext_ochn_attr(pipe_id, ochn_id, &ext_ochn_attr) ;
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ochn(%d) get ext ochn attr failed!\n", pipe_id, ochn_id);
|
||||
}
|
||||
|
||||
ext_ochn_attr.depth = g_vpss_ori_depth;
|
||||
|
||||
ret = xmedia_vpss_set_ext_ochn_attr(pipe_id, ochn_id, &ext_ochn_attr) ;
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ochn(%d) set ext ochn attr failed!\n", pipe_id, ochn_id);
|
||||
}
|
||||
}
|
||||
|
||||
g_vpss_depth_flag = 0;
|
||||
}
|
||||
|
||||
ret = xmedia_vpss_exit();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("vpss exit failed!\n");
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
void vpss_ochn_dump_handle_signal(xmedia_s32 signal)
|
||||
{
|
||||
if (g_vpss_signal_flag != 0) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (signal == SIGINT || signal == SIGTERM) {
|
||||
g_vpss_signal_flag++;
|
||||
vpss_ochn_restore(g_vpss_pipe_id, g_vpss_ochn_id);
|
||||
g_vpss_signal_flag--;
|
||||
printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");
|
||||
}
|
||||
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
static xmedia_s32 vpss_ochn_dump_transform_format(xmedia_video_frame_info *frame_in,
|
||||
xmedia_video_frame_info *tmp_frame, xmedia_video_frame_info *frame_out)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_vgs_frame_info task_info;
|
||||
xmedia_s32 job_handle;
|
||||
|
||||
ret = xmedia_vgs_init();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("vgs init failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = xmedia_vgs_create_job(&job_handle);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("create vgs job failed\n");
|
||||
xmedia_vgs_exit();
|
||||
goto EXIT1;
|
||||
}
|
||||
|
||||
memcpy(&task_info.img_in, tmp_frame, sizeof(xmedia_video_frame_info));
|
||||
memcpy(&task_info.img_out, frame_out, sizeof(xmedia_video_frame_info));
|
||||
ret = xmedia_vgs_add_task_rotation(job_handle, &task_info, XMEDIA_VIDEO_ROTATION_0);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("add vgs task failed\n");
|
||||
goto EXIT2;
|
||||
}
|
||||
|
||||
ret = xmedia_vgs_submit_job(job_handle);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("submit vgs job failed\n");
|
||||
goto EXIT2;
|
||||
}
|
||||
|
||||
ret = xmedia_vgs_wait_job(job_handle, 2000);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("wait vgs job failed\n");
|
||||
goto EXIT1;
|
||||
}
|
||||
|
||||
xmedia_vgs_exit();
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
|
||||
EXIT2:
|
||||
xmedia_vgs_cancel_job(job_handle);
|
||||
EXIT1:
|
||||
xmedia_vgs_exit();
|
||||
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
static xmedia_void vpss_ochn_uncontinuous_dump(xmedia_s32 pipe_id, xmedia_s32 ochn_id,
|
||||
xmedia_u32 frame_cnt, xmedia_char *yuv_name)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_u32 cnt = frame_cnt;
|
||||
xmedia_s32 millisec = -1;
|
||||
xmedia_handle vb_handle = VB_INVALID_HANDLE;
|
||||
xmedia_handle tmp_handle = VB_INVALID_HANDLE;
|
||||
xmedia_vb_base_info base_info;
|
||||
xmedia_vb_cal_cfg cal_cfg;
|
||||
xmedia_video_frame_info tmp_frame = {0};
|
||||
xmedia_video_frame_info frame_out = {0};
|
||||
xmedia_vb_config vb_config = {0};
|
||||
xmedia_u32 pool_num = 0;
|
||||
xmedia_s32 vb_pool_init = 0;
|
||||
|
||||
while (cnt--) {
|
||||
if (xmedia_vpss_acquire_ochn_frame(pipe_id, ochn_id, &g_vpss_frame_info, millisec) != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ochn(%d) get frame failed!\n", pipe_id, ochn_id);
|
||||
usleep(1000);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("pipe(%d) ochn(%d) video_fmt(%d) save frame %d!\n", pipe_id, ochn_id,
|
||||
g_vpss_frame_info.frame.video_fmt, cnt);
|
||||
|
||||
if (g_vpss_frame_info.frame.video_fmt != XMEDIA_VIDEO_FMT_LINEAR) {
|
||||
base_info.align = 0;
|
||||
base_info.bit_width = g_vpss_frame_info.frame.bit_width;
|
||||
base_info.cmp_mode = XMEDIA_VIDEO_COMPRESS_MODE_NONE;
|
||||
base_info.width = g_vpss_frame_info.frame.width;
|
||||
base_info.height = g_vpss_frame_info.frame.height;
|
||||
base_info.pixel_fmt = g_vpss_frame_info.frame.pixel_fmt;
|
||||
|
||||
if(vb_pool_init == 0) {
|
||||
base_info.video_fmt = XMEDIA_VIDEO_FMT_LINEAR;
|
||||
ret = xmedia_vb_get_buffer_config(&base_info, &cal_cfg);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("get buffer config failed with 0x%x\n", ret);
|
||||
goto RELEASE;
|
||||
}
|
||||
|
||||
vb_config.common_pool[pool_num].block_size = cal_cfg.vb_size;
|
||||
vb_config.common_pool[pool_num].block_cnt = 1;
|
||||
vb_config.common_pool[pool_num].map_mode = XMEDIA_VB_MAP_MODE_NONE;
|
||||
pool_num++;
|
||||
vb_config.max_pool_cnt = pool_num;
|
||||
|
||||
ret = xmedia_vb_init(&vb_config);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("vb init failed\n");
|
||||
goto RELEASE;
|
||||
}
|
||||
|
||||
vb_pool_init = 1;
|
||||
}
|
||||
|
||||
memcpy(&tmp_frame, &g_vpss_frame_info, sizeof(xmedia_video_frame_info));
|
||||
|
||||
base_info.video_fmt = XMEDIA_VIDEO_FMT_LINEAR;
|
||||
ret = xmedia_vb_get_buffer_config(&base_info, &cal_cfg);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("get buffer config failed with 0x%x\n", ret);
|
||||
goto FREEVB;
|
||||
}
|
||||
|
||||
vb_handle = xmedia_vb_get_block(-1, cal_cfg.vb_size, XMEDIA_NULL);
|
||||
if (vb_handle == VB_INVALID_HANDLE) {
|
||||
printf("get block failed\n");
|
||||
goto FREEVB;
|
||||
}
|
||||
|
||||
memcpy(&frame_out, &tmp_frame, sizeof(xmedia_video_frame_info));
|
||||
frame_out.pool_id = xmedia_vb_handle_to_pool_id(vb_handle);
|
||||
frame_out.frame.addr.y_phy_addr = xmedia_vb_handle_to_phy_addr(vb_handle);
|
||||
frame_out.frame.addr.y_head_phy_addr = frame_out.frame.addr.y_phy_addr;
|
||||
frame_out.frame.addr.c_phy_addr = frame_out.frame.addr.y_phy_addr + cal_cfg.main_y_size;
|
||||
frame_out.frame.stride.y_stride = cal_cfg.main_stride;
|
||||
frame_out.frame.stride.c_stride = cal_cfg.main_stride;
|
||||
frame_out.frame.compress_mode = XMEDIA_VIDEO_COMPRESS_MODE_NONE;
|
||||
frame_out.frame.video_fmt = XMEDIA_VIDEO_FMT_LINEAR;
|
||||
|
||||
ret = vpss_ochn_dump_transform_format(&g_vpss_frame_info, &tmp_frame, &frame_out);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe %d ochn %d vpss_ochn_dump_transform_format failed\n", pipe_id, ochn_id);
|
||||
goto FREEVB;
|
||||
}
|
||||
} else {
|
||||
memcpy(&frame_out, &g_vpss_frame_info, sizeof(xmedia_video_frame_info));
|
||||
}
|
||||
|
||||
vpss_ochn_dump_8bit_yuv(&frame_out.frame, g_vpss_fd);
|
||||
FREEVB:
|
||||
if (tmp_handle != VB_INVALID_HANDLE) {
|
||||
xmedia_vb_release_block(tmp_handle);
|
||||
tmp_handle = VB_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (vb_handle != VB_INVALID_HANDLE) {
|
||||
xmedia_vb_release_block(vb_handle);
|
||||
vb_handle = VB_INVALID_HANDLE;
|
||||
}
|
||||
RELEASE:
|
||||
ret = xmedia_vpss_release_ochn_frame(pipe_id, ochn_id, &g_vpss_frame_info);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ochn(%d) release frame failed!\n", pipe_id, ochn_id);
|
||||
break;
|
||||
}
|
||||
|
||||
g_vpss_frame_info.pool_id = VB_INVALID_POOLID;
|
||||
}
|
||||
|
||||
if(vb_pool_init == 1) {
|
||||
ret = xmedia_vb_exit();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("vb exit fail!\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static xmedia_void vpss_ochn_continuous_dump(xmedia_s32 pipe_id, xmedia_s32 ochn_id,
|
||||
xmedia_u32 frame_cnt, xmedia_char *yuv_name)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_u32 cnt = frame_cnt;
|
||||
xmedia_s32 millisec = -1;
|
||||
xmedia_u32 get_frame_cnt = 0;
|
||||
xmedia_handle vb_handle = VB_INVALID_HANDLE;
|
||||
xmedia_handle tmp_handle = VB_INVALID_HANDLE;
|
||||
xmedia_vb_base_info base_info;
|
||||
xmedia_vb_cal_cfg cal_cfg;
|
||||
xmedia_video_frame_info tmp_frame = {0};
|
||||
xmedia_video_frame_info frame_out = {0};
|
||||
xmedia_vb_config vb_config = {0};
|
||||
xmedia_u32 pool_num = 0;
|
||||
xmedia_s32 vb_pool_init = 0;
|
||||
|
||||
while (cnt--) {
|
||||
if (xmedia_vpss_acquire_ochn_frame(pipe_id, ochn_id, &g_vpss_multi_frame_info[get_frame_cnt], millisec) !=
|
||||
XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ochn(%d) get frame failed!\n", pipe_id, ochn_id);
|
||||
usleep(1000);
|
||||
continue;
|
||||
}
|
||||
|
||||
get_frame_cnt++;
|
||||
if (get_frame_cnt >= VPSS_MAX_FRAME_CNT) {
|
||||
printf("pipe(%d) ochn(%d) get frame cnt err!\n", pipe_id, ochn_id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
cnt = 0;
|
||||
|
||||
while (cnt < get_frame_cnt) {
|
||||
printf("pipe(%d) ochn(%d) save frame %d!\n", pipe_id, ochn_id, (get_frame_cnt - cnt - 1));
|
||||
|
||||
if (g_vpss_multi_frame_info[cnt].frame.video_fmt != XMEDIA_VIDEO_FMT_LINEAR) {
|
||||
base_info.align = 0;
|
||||
base_info.bit_width = g_vpss_multi_frame_info[cnt].frame.bit_width;
|
||||
base_info.cmp_mode = XMEDIA_VIDEO_COMPRESS_MODE_NONE;
|
||||
base_info.width = g_vpss_multi_frame_info[cnt].frame.width;
|
||||
base_info.height = g_vpss_multi_frame_info[cnt].frame.height;
|
||||
base_info.pixel_fmt = g_vpss_multi_frame_info[cnt].frame.pixel_fmt;
|
||||
|
||||
if(vb_pool_init == 0) {
|
||||
if (g_vpss_frame_info.frame.video_fmt == XMEDIA_VIDEO_FMT_TILE_16x4) {
|
||||
base_info.video_fmt = XMEDIA_VIDEO_FMT_TILE_64x4;
|
||||
ret = xmedia_vb_get_buffer_config(&base_info, &cal_cfg);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("get buffer config failed with 0x%x\n", ret);
|
||||
goto RELEASE;
|
||||
}
|
||||
|
||||
vb_config.common_pool[pool_num].block_size = cal_cfg.vb_size;
|
||||
vb_config.common_pool[pool_num].block_cnt = 1;
|
||||
vb_config.common_pool[pool_num].map_mode = XMEDIA_VB_MAP_MODE_NONE;
|
||||
pool_num++;
|
||||
}
|
||||
|
||||
base_info.video_fmt = XMEDIA_VIDEO_FMT_LINEAR;
|
||||
ret = xmedia_vb_get_buffer_config(&base_info, &cal_cfg);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("get buffer config failed with 0x%x\n", ret);
|
||||
goto RELEASE;
|
||||
}
|
||||
|
||||
vb_config.common_pool[pool_num].block_size = cal_cfg.vb_size;
|
||||
vb_config.common_pool[pool_num].block_cnt = 1;
|
||||
vb_config.common_pool[pool_num].map_mode = XMEDIA_VB_MAP_MODE_NONE;
|
||||
pool_num++;
|
||||
vb_config.max_pool_cnt = pool_num;
|
||||
|
||||
ret = xmedia_vb_init(&vb_config);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("vb init failed\n");
|
||||
goto RELEASE;
|
||||
}
|
||||
|
||||
vb_pool_init = 1;
|
||||
}
|
||||
|
||||
if (g_vpss_multi_frame_info[cnt].frame.video_fmt == XMEDIA_VIDEO_FMT_TILE_16x4) {
|
||||
base_info.video_fmt = XMEDIA_VIDEO_FMT_TILE_64x4;
|
||||
ret = xmedia_vb_get_buffer_config(&base_info, &cal_cfg);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("get buffer config failed with 0x%x\n", ret);
|
||||
goto RELEASE;
|
||||
}
|
||||
|
||||
tmp_handle = xmedia_vb_get_block(-1, cal_cfg.vb_size, XMEDIA_NULL);
|
||||
if (tmp_handle == VB_INVALID_HANDLE) {
|
||||
printf("get block failed\n");
|
||||
goto RELEASE;
|
||||
}
|
||||
|
||||
memcpy(&tmp_frame, &g_vpss_multi_frame_info[cnt], sizeof(xmedia_video_frame_info));
|
||||
tmp_frame.pool_id = xmedia_vb_handle_to_pool_id(tmp_handle);
|
||||
tmp_frame.frame.addr.y_phy_addr = xmedia_vb_handle_to_phy_addr(tmp_handle);
|
||||
tmp_frame.frame.addr.y_head_phy_addr = tmp_frame.frame.addr.y_phy_addr;
|
||||
tmp_frame.frame.addr.c_phy_addr = tmp_frame.frame.addr.y_phy_addr + cal_cfg.main_y_size;
|
||||
tmp_frame.frame.stride.y_stride = cal_cfg.main_stride;
|
||||
tmp_frame.frame.stride.c_stride = cal_cfg.main_stride;
|
||||
tmp_frame.frame.compress_mode = XMEDIA_VIDEO_COMPRESS_MODE_NONE;
|
||||
tmp_frame.frame.video_fmt = XMEDIA_VIDEO_FMT_TILE_64x4;
|
||||
} else {
|
||||
memcpy(&tmp_frame, &g_vpss_multi_frame_info[cnt], sizeof(xmedia_video_frame_info));
|
||||
}
|
||||
|
||||
base_info.video_fmt = XMEDIA_VIDEO_FMT_LINEAR;
|
||||
ret = xmedia_vb_get_buffer_config(&base_info, &cal_cfg);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("get buffer config failed with 0x%x\n", ret);
|
||||
goto FREEVB;
|
||||
}
|
||||
|
||||
vb_handle = xmedia_vb_get_block(-1, cal_cfg.vb_size, XMEDIA_NULL);
|
||||
if (vb_handle == VB_INVALID_HANDLE) {
|
||||
printf("get block failed\n");
|
||||
goto FREEVB;
|
||||
}
|
||||
|
||||
memcpy(&frame_out, &tmp_frame, sizeof(xmedia_video_frame_info));
|
||||
frame_out.pool_id = xmedia_vb_handle_to_pool_id(vb_handle);
|
||||
frame_out.frame.addr.y_phy_addr = xmedia_vb_handle_to_phy_addr(vb_handle);
|
||||
frame_out.frame.addr.y_head_phy_addr = frame_out.frame.addr.y_phy_addr;
|
||||
frame_out.frame.addr.c_phy_addr = frame_out.frame.addr.y_phy_addr + cal_cfg.main_y_size;
|
||||
frame_out.frame.stride.y_stride = cal_cfg.main_stride;
|
||||
frame_out.frame.stride.c_stride = cal_cfg.main_stride;
|
||||
frame_out.frame.compress_mode = XMEDIA_VIDEO_COMPRESS_MODE_NONE;
|
||||
frame_out.frame.video_fmt = XMEDIA_VIDEO_FMT_LINEAR;
|
||||
|
||||
ret = vpss_ochn_dump_transform_format(&g_vpss_multi_frame_info[cnt], &tmp_frame, &frame_out);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe %d ochn %d vpss_ochn_dump_transform_format failed\n", pipe_id, ochn_id);
|
||||
goto FREEVB;
|
||||
}
|
||||
|
||||
} else {
|
||||
memcpy(&frame_out, &g_vpss_multi_frame_info[cnt], sizeof(xmedia_video_frame_info));
|
||||
}
|
||||
|
||||
vpss_ochn_dump_8bit_yuv(&frame_out.frame, g_vpss_fd);
|
||||
FREEVB:
|
||||
if (tmp_handle != VB_INVALID_HANDLE) {
|
||||
xmedia_vb_release_block(tmp_handle);
|
||||
tmp_handle = VB_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (vb_handle != VB_INVALID_HANDLE) {
|
||||
xmedia_vb_release_block(vb_handle);
|
||||
vb_handle = VB_INVALID_HANDLE;
|
||||
}
|
||||
RELEASE:
|
||||
ret = xmedia_vpss_release_ochn_frame(pipe_id, ochn_id, &g_vpss_multi_frame_info[cnt]);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ochn(%d) release frame failed!\n", pipe_id, ochn_id);
|
||||
cnt++;
|
||||
continue;
|
||||
}
|
||||
|
||||
g_vpss_multi_frame_info[cnt].pool_id = VB_INVALID_POOLID;
|
||||
|
||||
cnt++;
|
||||
}
|
||||
|
||||
if(vb_pool_init == 1) {
|
||||
ret = xmedia_vb_exit();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("vb exit fail!\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
xmedia_void vpss_ochn_misc_dump(xmedia_s32 pipe_id, xmedia_s32 ochn_id, xmedia_u32 frame_cnt)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_char yuv_name[128];
|
||||
xmedia_char pixel_format[10];
|
||||
xmedia_char sys_chmod[140];
|
||||
xmedia_u32 cnt = frame_cnt;
|
||||
xmedia_u32 depth = 1;
|
||||
xmedia_s32 millisec = -1;
|
||||
|
||||
ret = xmedia_vpss_init();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("vpss init failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ochn_id < VPSS_MAX_PHY_OCHN_NUM) {
|
||||
xmedia_vpss_ochn_attr ochn_attr = {0};
|
||||
|
||||
ret = xmedia_vpss_get_ochn_attr(pipe_id, ochn_id, &ochn_attr);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ochn(%d) get ochn attr failed!\n", pipe_id, ochn_id);
|
||||
return;
|
||||
}
|
||||
|
||||
g_vpss_ori_depth = ochn_attr.depth;
|
||||
ochn_attr.depth = depth;
|
||||
|
||||
ret = xmedia_vpss_set_ochn_attr(pipe_id, ochn_id, &ochn_attr);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ochn(%d) set ochn attr failed!\n", pipe_id, ochn_id);
|
||||
vpss_ochn_restore(pipe_id, ochn_id);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
xmedia_vpss_ext_ochn_attr ext_ochn_attr = {0};
|
||||
|
||||
ret = xmedia_vpss_get_ext_ochn_attr(pipe_id, ochn_id, &ext_ochn_attr);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ochn(%d) get ext ochn attr failed!\n", pipe_id, ochn_id);
|
||||
return;
|
||||
}
|
||||
|
||||
g_vpss_ori_depth = ext_ochn_attr.depth;
|
||||
ext_ochn_attr.depth = depth;
|
||||
|
||||
ret = xmedia_vpss_set_ext_ochn_attr(pipe_id, ochn_id, &ext_ochn_attr);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ochn(%d) set ext ochn attr failed!\n", pipe_id, ochn_id);
|
||||
vpss_ochn_restore(pipe_id, ochn_id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
g_vpss_depth_flag = 1;
|
||||
|
||||
memset(&g_vpss_frame_info, 0, sizeof(xmedia_video_frame_info));
|
||||
g_vpss_frame_info.pool_id = VB_INVALID_POOLID;
|
||||
|
||||
if (xmedia_vpss_acquire_ochn_frame(pipe_id, ochn_id, &g_vpss_frame_info, millisec) != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ochn(%d) get frame error, now exit!\n", pipe_id, ochn_id);
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
switch (g_vpss_frame_info.frame.pixel_fmt) {
|
||||
case XMEDIA_VIDEO_PIXEL_FMT_YVU_SEMIPLANAR_420:
|
||||
case XMEDIA_VIDEO_PIXEL_FMT_YUV_SEMIPLANAR_420:
|
||||
snprintf(pixel_format, 10, "P420");
|
||||
break;
|
||||
|
||||
case XMEDIA_VIDEO_PIXEL_FMT_YUV_400:
|
||||
snprintf(pixel_format, 10, "YUV400");
|
||||
break;
|
||||
|
||||
default:
|
||||
snprintf(pixel_format, 10, "P420");
|
||||
break;
|
||||
}
|
||||
|
||||
snprintf(yuv_name, 128, "./pipe%d_ochn%d_%dx%d_%s_%d.yuv", pipe_id, ochn_id,
|
||||
g_vpss_frame_info.frame.width, g_vpss_frame_info.frame.height, pixel_format, cnt);
|
||||
|
||||
printf("pipe(%d) ochn(%d) dump frame to file: \"%s\"\n", pipe_id, ochn_id, yuv_name);
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
ret = xmedia_vpss_release_ochn_frame(pipe_id, ochn_id, &g_vpss_frame_info);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("pipe(%d) ochn(%d) release frame failed!\n", pipe_id, ochn_id);
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
g_vpss_frame_info.pool_id = VB_INVALID_POOLID;
|
||||
|
||||
g_vpss_fd = fopen(yuv_name, "wb");
|
||||
if (g_vpss_fd == XMEDIA_NULL) {
|
||||
printf("open file failed:%s!\n", strerror(errno));
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
if (g_vpss_continuous_dump == 0) {
|
||||
vpss_ochn_uncontinuous_dump(pipe_id, ochn_id, frame_cnt, yuv_name);
|
||||
} else {
|
||||
vpss_ochn_continuous_dump(pipe_id, ochn_id, frame_cnt, yuv_name);
|
||||
}
|
||||
|
||||
sprintf(sys_chmod, "chmod 666 %s", yuv_name);
|
||||
system(sys_chmod);
|
||||
|
||||
EXIT:
|
||||
vpss_ochn_restore(pipe_id, ochn_id);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf(
|
||||
"\n"
|
||||
"*************************************************\n"
|
||||
"Usage: ./vpss_ochn_dump [pipe_id] [ochn_id] [frame_cnt] [mode]\n"
|
||||
"1)pipe_id: \n"
|
||||
" vpss pipe id\n"
|
||||
"2)ochn_id: \n"
|
||||
" vpss ochn id\n"
|
||||
"3)frame_cnt: \n"
|
||||
" the count of frame to be dumped\n"
|
||||
"4)mode: \n"
|
||||
" 0: uncontinuous dump\n"
|
||||
" 1: continuous dump\n"
|
||||
"*)Example:\n"
|
||||
" e.g : ./vpss_ochn_dump 0 0 1 0\n"
|
||||
" e.g : ./vpss_ochn_dump 1 0 2 1\n"
|
||||
"*************************************************\n"
|
||||
"\n");
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_u32 frame_cnt;
|
||||
xmedia_u32 i;
|
||||
|
||||
printf("\nNOTICE: This tool only can be used for TESTING !!!\n");
|
||||
printf("\tTo see more usage, please enter: ./vpss_ochn_dump -h\n\n");
|
||||
|
||||
if (argc > 1) {
|
||||
if (!strncmp(argv[1], "-h", 2)) {
|
||||
usage();
|
||||
exit(XMEDIA_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc < 5) {
|
||||
usage();
|
||||
exit(XMEDIA_SUCCESS);
|
||||
}
|
||||
|
||||
g_vpss_pipe_id = atoi(argv[1]);
|
||||
|
||||
if (!VALUE_BETWEEN(g_vpss_pipe_id, 0, VPSS_MAX_PIPE_NUM - 1)) {
|
||||
printf("vpss pipe id must be [0,%d]!\n\n", VPSS_MAX_PIPE_NUM - 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_vpss_ochn_id = atoi(argv[2]);
|
||||
|
||||
if (!VALUE_BETWEEN(g_vpss_ochn_id, 0, VPSS_MAX_OCHN_NUM - 1)) {
|
||||
printf("vpss ochn id must be [0,%d]!\n\n", VPSS_MAX_OCHN_NUM - 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
frame_cnt = atoi(argv[3]);
|
||||
if (frame_cnt < 1) {
|
||||
printf("frame_cnt can't be small than 1!\n\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_vpss_continuous_dump = atoi(argv[4]);
|
||||
|
||||
if (!VALUE_BETWEEN(g_vpss_continuous_dump, 0, 1)) {
|
||||
printf("vpss dump mode must be [0,1]!\n\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((g_vpss_continuous_dump == 1) && (frame_cnt > VPSS_MAX_FRAME_CNT)) {
|
||||
printf("frame_cnt must be [1,%d] in continuous mode!\n\n", VPSS_MAX_FRAME_CNT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_vpss_depth_flag = 0;
|
||||
g_vpss_signal_flag = 0;
|
||||
g_vpss_ori_depth = 0;
|
||||
g_vpss_fd = XMEDIA_NULL;
|
||||
g_vpss_frame_info.pool_id = VB_INVALID_POOLID;
|
||||
|
||||
for (i = 0; i < VPSS_MAX_FRAME_CNT; i++) {
|
||||
g_vpss_multi_frame_info[i].pool_id = VB_INVALID_POOLID;
|
||||
}
|
||||
|
||||
signal(SIGINT, vpss_ochn_dump_handle_signal);
|
||||
signal(SIGTERM, vpss_ochn_dump_handle_signal);
|
||||
|
||||
vpss_ochn_misc_dump(g_vpss_pipe_id, g_vpss_ochn_id, frame_cnt);
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user