You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1463 lines
52 KiB

/*
* Copyright (c) Technologies Co., Ltd. 2012-2019. All rights reserved.
* Description: vi test common function
* Author: sdk
* Create: 2013-11-15
*/
#include <sys/stat.h>
#include "test_vi_print.h"
#include "vi_st_common.h"
#define TEST_VI_CUVA_SUPPORT 0x1
#define HDCP_PACKAGE_LEN (2 * 1024)
#define HDCP_KEY_NUM 6
static td_char *g_hdcp_path[HDCP_KEY_NUM] = {"hdmirx_1x_key_reserved9_cs.bin", "hdmirx_2x_key_reserved9_cs.bin",
"hdmirx_1x_key_reserved9_es.bin", "hdmirx_2x_key_reserved9_es.bin",
"HDCP14_RX_reserved5_otp_10.bin", "HDCP2X_RX_reserved5_otp_10.bin"};
td_u8 g_edid14[] = {
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x58, 0xAE, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
0x2F, 0x18, 0x01, 0x03, 0x80, 0x3C, 0x22, 0x61, 0x2B, 0xD4, 0xAC, 0xA3, 0x57, 0x49, 0x9C, 0x25,
0x11, 0x48, 0x4B, 0xBF, 0xEF, 0x80, 0x81, 0xC0, 0xD1, 0xC0, 0xD1, 0x00, 0xA9, 0x40, 0xB3, 0x00,
0x95, 0x00, 0x81, 0x00, 0x81, 0x40, 0x02, 0x3A, 0x80, 0x18, 0x71, 0x38, 0x2D, 0x40, 0x58, 0x2C,
0x45, 0x00, 0xC4, 0x8E, 0x21, 0x00, 0x00, 0x1E, 0x01, 0x1D, 0x00, 0x72, 0x51, 0xD0, 0x1E, 0x20,
0x6E, 0x28, 0x55, 0x00, 0xC4, 0x8E, 0x21, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x41,
0x42, 0x20, 0x54, 0x56, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xFD,
0x00, 0x14, 0x5A, 0x0A, 0x64, 0x1E, 0x00, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x39,
0x02, 0x03, 0x38, 0x74, 0x51, 0x02, 0x04, 0x11, 0x13, 0x20, 0x22, 0x90, 0x21, 0x1F, 0x06, 0x15,
0x03, 0x07, 0x12, 0x16, 0x05, 0x14, 0x2C, 0x09, 0x7F, 0x01, 0x15, 0x07, 0x50, 0x57, 0x07, 0x00,
0x3D, 0x07, 0x50, 0x83, 0x01, 0x00, 0x00, 0x6D, 0x03, 0x0C, 0x00, 0x10, 0x00, 0xB8, 0x3C, 0x20,
0x00, 0x60, 0x01, 0x02, 0x03, 0xE2, 0x00, 0xCF, 0x01, 0x1D, 0x00, 0xBC, 0x52, 0xD0, 0x1E, 0x20,
0xB8, 0x28, 0x55, 0x40, 0xC4, 0x8E, 0x21, 0x00, 0x00, 0x1E, 0x01, 0x1D, 0x80, 0xD0, 0x72, 0x1C,
0x16, 0x20, 0x10, 0x2C, 0x25, 0x80, 0xC4, 0x8E, 0x21, 0x00, 0x00, 0x9E, 0x8C, 0x0A, 0xD0, 0x8A,
0x20, 0xE0, 0x2D, 0x10, 0x10, 0x3E, 0x96, 0x00, 0xC4, 0x90, 0x21, 0x00, 0x00, 0x18, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
};
td_u8 g_edid20[] = {
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x58, 0xAE, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01,
0x33, 0x18, 0x01, 0x03, 0x81, 0x00, 0x00, 0x78, 0x0A, 0xEE, 0x9D, 0xA3, 0x54, 0x4C, 0x99, 0x26,
0x0F, 0x47, 0x4A, 0xBF, 0xEF, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x3A, 0x80, 0x18, 0x71, 0x38, 0x2D, 0x40, 0x58, 0x2C,
0x45, 0x00, 0xC4, 0x8E, 0x21, 0x00, 0x00, 0x1E, 0x66, 0x21, 0x50, 0xB0, 0x51, 0x00, 0x1B, 0x30,
0x40, 0x70, 0x36, 0x00, 0xC4, 0x8E, 0x21, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x41,
0x42, 0x20, 0x54, 0x56, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xFD,
0x00, 0x30, 0x4C, 0x0F, 0x55, 0x3C, 0x00, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0xC9,
0x02, 0x03, 0x60, 0x74, 0x57, 0x61, 0x60, 0x66, 0x65, 0x02, 0x04, 0x11, 0x13, 0x20, 0x22, 0x90,
0x21, 0x1F, 0x06, 0x15, 0x03, 0x12, 0x16, 0x05, 0x14, 0x5D, 0x5E, 0x5F, 0x2F, 0x09, 0x7F, 0x01,
0x15, 0x07, 0x50, 0x57, 0x07, 0x00, 0x3D, 0x07, 0x50, 0x5F, 0x7E, 0x01, 0x83, 0x01, 0x00, 0x00,
0x6D, 0x03, 0x0C, 0x00, 0x10, 0x00, 0xB8, 0x3C, 0x20, 0x00, 0x60, 0x01, 0x02, 0x03, 0x67, 0xD8,
0x5D, 0xC4, 0x01, 0x78, 0x80, 0x03, 0xE2, 0x00, 0xCF, 0xE3, 0x05, 0xC0, 0x00, 0xE2, 0x0F, 0x0F,
0xE3, 0x06, 0x0D, 0x01, 0xEB, 0x01, 0x46, 0xD0, 0x00, 0x43, 0x0C, 0x43, 0x98, 0x99, 0xEE, 0xD3,
0x01, 0x1D, 0x00, 0xBC, 0x52, 0xD0, 0x1E, 0x20, 0xB8, 0x28, 0x55, 0x40, 0xC4, 0x8E, 0x21, 0x00,
0x00, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9F
};
td_u8 g_edid21[] = {
#if TEST_VI_CUVA_SUPPORT
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x21, 0x33, 0x01, 0x20, 0x00, 0x0E, 0x00, 0x00,
0x0B, 0x1E, 0x01, 0x03, 0x80, 0x66, 0x39, 0x78, 0x0A, 0xA8, 0x33, 0xAB, 0x50, 0x45, 0xA5, 0x27,
0x0D, 0x48, 0x48, 0x21, 0x08, 0x00, 0x71, 0x4F, 0x81, 0xC0, 0x81, 0x00, 0x81, 0x80, 0x95, 0x00,
0xA9, 0xC0, 0xB3, 0x00, 0xD1, 0xC0, 0x08, 0xE8, 0x00, 0x30, 0xF2, 0x70, 0x5A, 0x80, 0xB0, 0x58,
0x8A, 0x00, 0x50, 0x1D, 0x74, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0xFD, 0x00, 0x18, 0x78, 0x0F,
0xFF, 0x77, 0x00, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x53,
0x79, 0x6E, 0x63, 0x4D, 0x61, 0x73, 0x74, 0x65, 0x72, 0x0A, 0x20, 0x20, 0x00, 0x00, 0x00, 0xFF,
0x00, 0x48, 0x31, 0x41, 0x4B, 0x35, 0x30, 0x30, 0x30, 0x30, 0x30, 0x0A, 0x20, 0x20, 0x01, 0xB7,
0x02, 0x03, 0x6D, 0xF0, 0x5D, 0x61, 0x10, 0x1F, 0x04, 0x13, 0x05, 0x14, 0x21, 0x22, 0x5E, 0x5F,
0x60, 0x65, 0x66, 0x64, 0x07, 0x03, 0x12, 0x75, 0x76, 0xDA, 0xDB, 0xC3, 0xC4, 0xC6, 0xC7, 0xC8,
0xC9, 0x01, 0x29, 0x09, 0x07, 0x07, 0x15, 0x07, 0x50, 0x57, 0x07, 0x00, 0x83, 0x01, 0x00, 0x00,
0xE2, 0x00, 0x4F, 0xE3, 0x05, 0xDB, 0x01, 0x6E, 0x03, 0x0C, 0x00, 0x40, 0x00, 0xB8, 0x3C, 0x28,
0x00, 0x80, 0x01, 0x02, 0x03, 0x04, 0x6D, 0xD8, 0x5D, 0xC4, 0x01, 0x78, 0x80, 0x53, 0x00, 0x00,
0x00, 0xC3, 0x54, 0x3F, 0xE3, 0x06, 0x0D, 0x01, 0xE5, 0x0F, 0x01, 0x38, 0xF8, 0x1F, 0xEE, 0x01,
0x03, 0x75, 0x04, 0x01, 0x02, 0x07, 0x08, 0x09, 0x0A, 0x03, 0x04, 0x05, 0x06, 0x56, 0x5E, 0x00,
0xA0, 0xA0, 0xA0, 0x29, 0x50, 0x30, 0x20, 0x35, 0x00, 0x50, 0x1D, 0x74, 0x00, 0x00, 0x1A, 0x38
#else
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x58, 0xAE, 0x01, 0x20, 0x00, 0x0E, 0x00, 0x00,
0x0B, 0x1E, 0x01, 0x03, 0x80, 0x66, 0x39, 0x78, 0x0A, 0xA8, 0x33, 0xAB, 0x50, 0x45, 0xA5, 0x27,
0x0D, 0x48, 0x48, 0x21, 0x08, 0x00, 0x71, 0x4F, 0x81, 0xC0, 0x81, 0x00, 0x81, 0x80, 0x95, 0x00,
0xA9, 0xC0, 0xB3, 0x00, 0xD1, 0xC0, 0x08, 0xE8, 0x00, 0x30, 0xF2, 0x70, 0x5A, 0x80, 0xB0, 0x58,
0x8A, 0x00, 0x50, 0x1D, 0x74, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0xFD, 0x00, 0x18, 0x78, 0x0F,
0xFF, 0x77, 0x00, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x41,
0x42, 0x43, 0x20, 0x54, 0x56, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xFF,
0x00, 0x48, 0x31, 0x41, 0x4B, 0x35, 0x30, 0x30, 0x30, 0x30, 0x30, 0x0A, 0x20, 0x20, 0x01, 0xFE,
0x02, 0x03, 0x6C, 0xF0, 0x5C, 0x61, 0x10, 0x1F, 0x04, 0x13, 0x05, 0x14, 0x21, 0x22, 0x5E, 0x5F,
0x60, 0x65, 0x66, 0x64, 0x03, 0x12, 0x75, 0x76, 0xDA, 0xDB, 0xC3, 0xC4, 0xC6, 0xC7, 0xC8, 0xC9,
0x01, 0x29, 0x09, 0x07, 0x07, 0x15, 0x07, 0x50, 0x57, 0x07, 0x00, 0x83, 0x01, 0x00, 0x00, 0xE2,
0x00, 0x4F, 0xE3, 0x05, 0xC3, 0x01, 0x6E, 0x03, 0x0C, 0x00, 0x40, 0x00, 0xB8, 0x3C, 0x28, 0x00,
0x80, 0x01, 0x02, 0x03, 0x04, 0x6D, 0xD8, 0x5D, 0xC4, 0x01, 0x78, 0x80, 0x53, 0x00, 0x00, 0x00,
0xC3, 0x54, 0x3F, 0xE3, 0x06, 0x0D, 0x01, 0xEE, 0x01, 0x03, 0x75, 0x04, 0x01, 0x10, 0x40, 0x4B,
0x4C, 0x00, 0x00, 0x00, 0x80, 0x00, 0xE5, 0x0F, 0x01, 0x38, 0xFE, 0x07, 0x56, 0x5E, 0x00, 0xA0,
0xA0, 0xA0, 0x29, 0x50, 0x30, 0x20, 0x35, 0x00, 0x50, 0x1D, 0x74, 0x00, 0x00, 0x1A, 0x00, 0x3A
#endif
};
td_s32 st_iapi_vi_init(td_void)
{
return uapi_vi_init();
}
td_s32 st_iapi_vi_deinit(td_void)
{
return uapi_vi_deinit();
}
td_s32 st_iapi_vi_get_default_attr(uapi_vi_attr *attr)
{
return uapi_vi_get_default_attr(attr);
}
td_s32 st_iapi_vi_create(uapi_vi_attr *attr, td_handle *vi_handle)
{
return uapi_vi_create(attr, vi_handle);
}
td_s32 st_iapi_vi_destroy(td_handle vi_handle)
{
return uapi_vi_destroy(vi_handle);
}
td_s32 st_iapi_vi_start(td_handle vi_handle)
{
return uapi_vi_start(vi_handle);
}
td_s32 st_iapi_vi_stop(td_handle vi_handle)
{
return uapi_vi_stop(vi_handle);
}
td_s32 st_iapi_vi_update_nstd_info(td_handle vi_handle, uapi_video_nonstd_info *info)
{
return uapi_vi_update_nstd_info(vi_handle, info);
}
td_s32 st_iapi_vi_set_src_quantization_range(td_handle vi_handle, uapi_vi_quantization_range range_type)
{
return uapi_vi_set_src_quantization_range(vi_handle, range_type);
}
td_s32 st_iapi_vi_set_config(td_handle vi_handle, uapi_vi_config *cfg)
{
return uapi_vi_set_config(vi_handle, cfg);
}
td_s32 st_iapi_vi_get_config(td_handle vi_handle, uapi_vi_config *cfg)
{
return uapi_vi_get_config(vi_handle, cfg);
}
td_s32 st_iapi_vi_get_attr(td_handle vi_handle, uapi_vi_attr *attr)
{
return uapi_vi_get_attr(vi_handle, attr);
}
td_s32 st_iapi_vi_attach(td_handle vi_handle, td_handle vo_handle)
{
return ext_mpi_vi_attach(vi_handle, vo_handle);
}
td_s32 st_iapi_vi_detach(td_handle vi_handle, td_handle vo_handle)
{
return ext_mpi_vi_detach(vi_handle, vo_handle);
}
td_s32 st_iapi_vi_acquire(td_handle vi_handle, uapi_video_frame_info *frame_info, td_u32 timeout_ms)
{
return uapi_vi_acquire_frame(vi_handle, frame_info, timeout_ms);
}
td_s32 st_iapi_vi_release(td_handle vi_handle, uapi_video_frame_info *frame_info)
{
return uapi_vi_release_frame(vi_handle, frame_info);
}
static td_s32 st_vi_comm_get_file_str(char *file, char *out_str, td_u32 len)
{
td_char temp_line[0x100] = {0x0};
td_char *start = TD_NULL;
td_char *end = TD_NULL;
FILE *filp = TD_NULL;
if (out_str == TD_NULL) {
return TD_FAILURE;
}
filp = fopen(file, "rt");
if (filp == TD_NULL) {
vi_log_print("Error: File %s open error!\n", file);
return TD_FAILURE;
}
fgets(temp_line, 256, filp);
fclose(filp);
start = &temp_line[0x0];
while (*start == ' ') {
*start = 0;
start++;
}
if (*start == 0) {
vi_log_print("is empty string\n");
return TD_FAILURE;
}
end = start + strlen(start);
while (*end == ' ') {
*end = 0;
end--;
}
if (*start == 0) {
vi_log_print("is empty string\n");
return TD_FAILURE;
}
end++;
strncpy_s(out_str, len, start, end - start);
return TD_SUCCESS;
}
static td_s32 st_vi_comm_check_vi_proc_irq_info(uapi_vi_access_type access_type)
{
td_char val_str[0x100] = {0x0};
td_s32 val;
td_u32 vi_id;
vi_id = st_vi_comm_get_vi_id(access_type);
if (vi_id == 0x0) {
system("cat /proc/msp/vi0000 | grep \"IntCnt(total\" | \
cut -d \":\" -f 2 | cut -d \",\" -f 1 > /mnt/vicheck.txt");
} else {
system("cat /proc/msp/vi0001 | grep \"IntCnt(total\" | \
cut -d \":\" -f 2 | cut -d \",\" -f 1 > /mnt/vicheck.txt");
}
if (st_vi_comm_get_file_str("/mnt/vicheck.txt", val_str, sizeof(val_str)) != TD_SUCCESS) {
vi_log_print("call st_vi_comm_get_file_str fail!\n");
return TD_FAILURE;
}
val = atoi(val_str);
vi_log_print("IntCnt--totol=%u!\n", val);
if (val <= 0x0) {
vi_log_print("IntCnt--totol=%u,is error!\n", val);
return TD_FAILURE;
}
if (vi_id == 0x0) {
system("cat /proc/msp/vi0000 | grep \"IntCnt(cc\" | cut -d \":\" -f 2 | cut -d \",\" -f 1 > /mnt/vicheck.txt");
} else {
system("cat /proc/msp/vi0001 | grep \"IntCnt(cc\" | cut -d \":\" -f 2 | cut -d \",\" -f 1 > /mnt/vicheck.txt");
}
if (st_vi_comm_get_file_str("/mnt/vicheck.txt", val_str, sizeof(val_str)) != TD_SUCCESS) {
vi_log_print("call st_vi_comm_get_file_str fail!\n");
return TD_FAILURE;
}
val = atoi(val_str);
vi_log_print("IntCnt--cc=%u!\n", val);
if (val <= 0x0) {
vi_log_print("IntCnt--cc=%u,is error!\n", val);
return TD_FAILURE;
}
if (vi_id == 0x0) {
system("cat /proc/msp/vi0000 | grep \"IntErr(lost/overflow\" | \
cut -d \":\" -f 2 | cut -d \",\" -f 2 > /mnt/vicheck.txt");
} else {
system("cat /proc/msp/vi0001 | grep \"IntErr(lost/overflow\" | \
cut -d \":\" -f 2 | cut -d \",\" -f 2 > /mnt/vicheck.txt");
}
if (st_vi_comm_get_file_str("/mnt/vicheck.txt", val_str, sizeof(val_str)) != TD_SUCCESS) {
vi_log_print("call st_vi_comm_get_file_str fail!\n");
return TD_FAILURE;
}
val = atoi(val_str);
vi_log_print("IntErr--overflow=%u!\n", val);
if (val != 0x0) {
vi_log_print("IntErr--overflow=%u,is error!\n", val);
return TD_FAILURE;
}
return TD_SUCCESS;
}
static td_s32 st_vi_comm_tvd_init(td_void)
{
#ifdef VI_SUPPORT_TVD
return uapi_tvd_init();
#else
return TD_SUCCESS;
#endif
}
static td_s32 st_vi_comm_tvd_deinit(td_void)
{
#ifdef VI_SUPPORT_TVD
return uapi_tvd_deinit();
#else
return TD_SUCCESS;
#endif
}
static td_s32 st_vi_comm_tvd_connect(uapi_tvd_src_attr *src_attr)
{
(void)(src_attr);
#ifdef VI_SUPPORT_TVD
return uapi_tvd_connect(src_attr);
#else
printf("[%s %d]not support tvd!\n", __func__, __LINE__);
return TD_FAILURE;
#endif
}
static td_s32 st_vi_comm_tvd_disconnect(td_void)
{
#ifdef VI_SUPPORT_TVD
return uapi_tvd_disconnect();
#else
printf("[%s %d]not support tvd!\n", __func__, __LINE__);
return TD_FAILURE;
#endif
}
static td_s32 st_vi_comm_tvd_get_signal_status(uapi_sig_status *signal_status)
{
(void)(signal_status);
#ifdef VI_SUPPORT_TVD
return uapi_tvd_get_signal_status(signal_status);
#else
printf("[%s %d]not support tvd!\n", __func__, __LINE__);
return TD_FAILURE;
#endif
}
static td_s32 st_vi_comm_tvd_get_timing_info(uapi_tvd_timing_info *tvd_timing_info)
{
(void)(tvd_timing_info);
#ifdef VI_SUPPORT_TVD
return uapi_tvd_get_timing_info(tvd_timing_info);
#else
printf("[%s %d]not support tvd!\n", __func__, __LINE__);
return TD_FAILURE;
#endif
}
static td_s32 st_vi_comm_tvd_set_comb_filter_mode(uapi_tvd_comb_mode mode)
{
(void)(mode);
#ifdef VI_SUPPORT_TVD
return uapi_tvd_set_comb_filter_mode(mode);
#else
printf("[%s %d]not support tvd!\n", __func__, __LINE__);
return TD_FAILURE;
#endif
}
static td_void st_vi_comm_hdmirx_edid_init(td_void)
{
uapi_hdmirx_edid hdmirx_edid[3]; /* 2 is test case used */
uapi_hdmirx_capability hdmirx_capability = { 0 };
td_u32 port_num;
uapi_hdmirx_ver hdmirx_ver;
td_u32 i;
if (uapi_hdmirx_get_capability(&hdmirx_capability) != TD_SUCCESS) {
vi_log_err("call uapi_hdmirx_get_capability fail!\n");
port_num = UAPI_HDMIRX_PORT_MAX;
for (i = 0; i < port_num; i++) {
hdmirx_capability.caps[i].enable = TD_TRUE;
hdmirx_capability.caps[i].ver = UAPI_HDMIRX_VER_20;
}
} else {
port_num = hdmirx_capability.port_max;
}
vi_st_green_print("hdmirx port num is %u\n", hdmirx_capability.port_max);
for (i = 0; i < port_num; i++) {
hdmirx_edid[0].edid = (td_u8 *)g_edid14;
hdmirx_edid[1].edid = (td_u8 *)g_edid20;
hdmirx_edid[2].edid = (td_u8 *)g_edid21;
hdmirx_edid[0].edid_length = 256; /* 256 is test case used */
hdmirx_edid[1].edid_length = 256; /* 256 is test case used */
hdmirx_edid[2].edid_length = 256; /* 256 is test case used */
hdmirx_edid[0].cec_addr = 0x10 * (i + 1);
hdmirx_edid[1].cec_addr = 0x10 * (i + 1);
hdmirx_edid[2].cec_addr = 0x10 * (i + 1);
if (hdmirx_capability.caps[i].enable != TD_TRUE) {
vi_log_err("hdmirx_capability.caps[%u].enabl=%u, is error!", i, hdmirx_capability.caps[i].enable);
hdmirx_ver = UAPI_HDMIRX_VER_20;
} else {
hdmirx_ver = hdmirx_capability.caps[i].ver;
}
vi_st_green_print("hdmirx port %u ver is %u\n", i, hdmirx_ver);
if (hdmirx_ver == UAPI_HDMIRX_VER_14) {
uapi_hdmirx_init_edid(i, hdmirx_edid, 0x1);
uapi_hdmirx_set_edid_mode(i, UAPI_HDMIRX_EDID_MODE_14);
} else if (hdmirx_ver == UAPI_HDMIRX_VER_20) {
uapi_hdmirx_init_edid(i, hdmirx_edid, 0x2);
uapi_hdmirx_set_edid_mode(i, UAPI_HDMIRX_EDID_MODE_20);
} else {
uapi_hdmirx_init_edid(i, hdmirx_edid, 0x3);
uapi_hdmirx_set_edid_mode(i, UAPI_HDMIRX_EDID_MODE_21);
}
}
}
static td_u32 st_hdmirx_hdcp_file_check(const td_char *hdcp_path, td_u32 path_size, td_u8 *key_package)
{
td_s32 ret;
td_u32 length;
size_t fread_ret;
td_char *real_path = TD_NULL;
FILE *file = TD_NULL;
struct stat sb;
if (path_size == 0) {
vi_log_print("path_size is 0!\n");
return 0;
}
if (realpath(hdcp_path, real_path) == TD_NULL) {
vi_log_print("invalid hdcp key path: %s\n", hdcp_path);
return 0;
}
file = fopen(hdcp_path, "rb");
if (file == TD_NULL) {
vi_log_print("open %s failed!\n", real_path);
return 0;
}
ret = stat(real_path, &sb);
if (ret || (sb.st_size >= HDCP_PACKAGE_LEN)) {
vi_log_print("stat or key file size error(%u)\n", (td_u32)sb.st_size);
fclose(file);
return 0;
}
fread_ret = fread(key_package, 1, (td_u32)sb.st_size, file);
fclose(file);
if (fread_ret != (size_t)sb.st_size) {
vi_log_print("fread error(ret = %u, size = %u)\n", (td_u32)fread_ret, (td_u32)sb.st_size);
return 0;
}
length = (td_u32)sb.st_size;
return length;
}
static td_u32 st_vi_comm_chip_info_check_hdcp(td_u8 *key_package_1x, td_u8 *key_package_2x,
uapi_hdmirx_hdcp *hdcp_1x, uapi_hdmirx_hdcp *hdcp_2x)
{
ext_chip_name_id chip_version = CHIP_NAME_RESERVED5;
ext_chip_revision chip_revision = CHIP_REVISION_A;
if (st_vi_comm_get_chip_info(&chip_version, &chip_revision) != TD_SUCCESS) {
vi_log_err("call st_vi_comm_get_chip_info fail!\n");
return TD_FAILURE;
}
vi_st_green_print("chip_version=0x%x,chip_revision=0x%x\n", chip_version, chip_revision);
if (((chip_version == CHIP_NAME_RESERVED9) || (chip_version == CHIP_NAME_RESERVED13) ||
(chip_version == CHIP_NAME_RESERVED6) || (chip_version == CHIP_NAME_RESERVED8)) &&
(chip_revision != CHIP_REVISION_A)) {
hdcp_1x->hdcp_length = st_hdmirx_hdcp_file_check(g_hdcp_path[0], sizeof(g_hdcp_path[0]), key_package_1x);
hdcp_2x->hdcp_length = st_hdmirx_hdcp_file_check(g_hdcp_path[1], sizeof(g_hdcp_path[1]), key_package_2x);
} else if (((chip_version == CHIP_NAME_RESERVED9) || (chip_version == CHIP_NAME_RESERVED13) ||
(chip_version == CHIP_NAME_RESERVED6) || (chip_version == CHIP_NAME_RESERVED8)) &&
(chip_revision == CHIP_REVISION_A)) {
hdcp_1x->hdcp_length = st_hdmirx_hdcp_file_check(g_hdcp_path[2], sizeof(g_hdcp_path[2]), key_package_1x);
hdcp_2x->hdcp_length = st_hdmirx_hdcp_file_check(g_hdcp_path[3], sizeof(g_hdcp_path[3]), key_package_2x);
} else {
hdcp_1x->hdcp_length = st_hdmirx_hdcp_file_check(g_hdcp_path[4], sizeof(g_hdcp_path[4]), key_package_1x);
hdcp_2x->hdcp_length = st_hdmirx_hdcp_file_check(g_hdcp_path[5], sizeof(g_hdcp_path[5]), key_package_2x);
}
return TD_SUCCESS;
}
static td_void st_vi_comm_hdmirx_hdcp_init(td_void)
{
td_s32 ret;
uapi_hdmirx_capability hdmirx_capability = {0};
td_u32 port_num;
uapi_hdmirx_hdcp hdcp_1x;
uapi_hdmirx_hdcp hdcp_2x;
td_u32 i;
td_u8 *key_package_1x = (td_u8 *)malloc(HDCP_PACKAGE_LEN * sizeof(td_u8));
if (key_package_1x == TD_NULL) {
vi_log_err("key_package_2x is null\n");
}
hdcp_1x.hdcp_data = key_package_1x;
td_u8 *key_package_2x = (td_u8 *)malloc(HDCP_PACKAGE_LEN * sizeof(td_u8));
if (key_package_2x == TD_NULL) {
vi_log_err("key_package_2x is null\n");
}
hdcp_2x.hdcp_data = key_package_2x;
if (uapi_hdmirx_get_capability(&hdmirx_capability) != TD_SUCCESS) {
vi_log_err("call uapi_hdmirx_get_capability fail!\n");
port_num = UAPI_HDMIRX_PORT_MAX;
} else {
port_num = hdmirx_capability.port_max;
}
ret = st_vi_comm_chip_info_check_hdcp(key_package_1x, key_package_2x, &hdcp_1x, &hdcp_2x);
if (ret != TD_SUCCESS) {
vi_log_err("st_vi_comm_chip_info_check_hdcp failed\n");
}
for (i = 0; i < port_num; i++) { /* 2 is test case used */
ret = uapi_hdmirx_load_hdcp(i, UAPI_HDMIRX_HDCP_VER_1X, &hdcp_1x);
if (ret != TD_SUCCESS) {
vi_st_yellow_print("[%d] HDCP2x Load 1x Fail!\n", i);
}
ret = uapi_hdmirx_load_hdcp(i, UAPI_HDMIRX_HDCP_VER_2X, &hdcp_2x);
if (ret != TD_SUCCESS) {
vi_st_yellow_print("[%d] HDCP2x Load 2x Fail!\n", i);
}
}
free(key_package_1x);
free(key_package_2x);
}
static td_void st_vi_comm_hdmirx_init(td_void)
{
test_equal_nsp(uapi_sys_init(), TD_SUCCESS);
test_equal_nsp(uapi_hdmirx_init(), TD_SUCCESS);
sleep(1);
st_vi_comm_hdmirx_edid_init();
sleep(1);
st_vi_comm_hdmirx_hdcp_init();
sleep(1);
}
static td_void st_vi_comm_ctx_print(st_vi_test_info *test_info)
{
st_vi_ctx *vi_ctx = (st_vi_ctx *)test_info->private_date;
st_vi_timing *vi_timing = TD_NULL;
uapi_vi_access_type tmp_access_type; /* 接口类型 */
td_char *bit_depth[] = {"DEFAULT", "8BIT", "10BIT", "12BIT", "16BIT", "BUTT"};
td_char *access_type[] = {"TVD", "HDDEC", "HDMIRX0", "HDMIRX1", "HDMIRX2", "HDMIRX3", "BUTT"};
td_char *over_sample[] = {"1X", "2X", "4X", "BUTT"};
td_char *video_3d_type[] = {"2D", "SBS", "TAB", "FS", "FPK", "MAX"};
vi_timing = &vi_ctx->vi_timing;
if (test_info->frontend_param.source_type == UAPI_VIDEO_SOURCE_ATV) {
tmp_access_type = UAPI_VI_ACCESS_TVD;
} else if (test_info->frontend_param.source_type == UAPI_VIDEO_SOURCE_CVBS) {
tmp_access_type = UAPI_VI_ACCESS_TVD;
} else if (test_info->frontend_param.source_type == UAPI_VIDEO_SOURCE_VGA) {
tmp_access_type = UAPI_VI_ACCESS_HDDEC;
} else if (test_info->frontend_param.source_type == UAPI_VIDEO_SOURCE_YPBPR) {
tmp_access_type = UAPI_VI_ACCESS_HDDEC;
} else if (test_info->frontend_param.source_type == UAPI_VIDEO_SOURCE_HDMI) {
if (test_info->frontend_param.port == 0) {
tmp_access_type = UAPI_VI_ACCESS_HDMIRX_PORT0;
} else if (test_info->frontend_param.port == 1) {
tmp_access_type = UAPI_VI_ACCESS_HDMIRX_PORT1;
} else if (test_info->frontend_param.port == 2) {
tmp_access_type = UAPI_VI_ACCESS_HDMIRX_PORT2;
} else if (test_info->frontend_param.port == 3) {
tmp_access_type = UAPI_VI_ACCESS_HDMIRX_PORT3;
} else {
tmp_access_type = UAPI_VI_ACCESS_HDMIRX_PORT0;
}
} else {
tmp_access_type = UAPI_VI_ACCESS_HDMIRX_PORT0;
}
printf("*********************ViTestCtx*********************\n");
printf("%-12s%-2s0x%-8x%-2s", "ViHandle", ":", vi_ctx->vi_handle, "|");
printf("%-12s%-2s0x%-8x%-2s\n", "WinHandle", ":", vi_ctx->vo_handle, "|");
printf("%-12s%-2s%-10lx%-2s", "bMonitorThr", ":", vi_ctx->monitor_thread, "|");
printf("%-12s%-2s%-10s%-2s\n", "bMonitorRun", ":", (vi_ctx->monitor_running ? "Run" : "Stop"), "|");
printf("---------------------TimingInfo--------------------\n");
printf("%-12s%-2s%-10s%-2s", "access_type", ":", access_type[tmp_access_type], "|");
printf("%-12s%-2s%-10d%-2s\n", "vblank", ":", vi_timing->vblank, "|");
printf("%-12s%-2s%-10s%-2s", "3d_type", ":", video_3d_type[vi_timing->video_3d_type], "|");
printf("%-12s%-2s%-10d%-2s\n", "pixel_format", ":", vi_timing->pixel_format, "|");
printf("%-12s%-2s%-10d%-2s", "width", ":", vi_timing->width, "|");
printf("%-12s%-2s%-10d%-2s\n", "height", ":", vi_timing->height, "|");
printf("%-12s%-2s%-10d%-2s", "frame_rate", ":", vi_timing->frame_rate, "|");
printf("%-12s%-2s%-10s%-2s\n", "interlace", ":", vi_timing->interlace ? "I" : "P", "|");
printf("%-12s%-2s%-10s%-2s", "over_sample", ":", over_sample[vi_timing->over_sample], "|");
printf("%-12s%-2s%-10s%-2s\n", "bit_depth", ":", bit_depth[vi_timing->bit_depth], "|");
printf("***************************************************\n");
sleep(1);
}
static td_s32 st_vi_comm_frontend_init(td_void)
{
test_equal_nsp(uapi_sys_init(), TD_SUCCESS);
test_equal_nsp(st_vi_comm_tvd_init(), TD_SUCCESS);
st_vi_comm_hdmirx_init();
return TD_SUCCESS;
}
static td_s32 st_vi_comm_frontend_deinit(td_void)
{
test_equal_nsp(st_vi_comm_tvd_deinit(), TD_SUCCESS);
test_equal_nsp(uapi_hdmirx_deinit(), TD_SUCCESS);
return TD_SUCCESS;
}
static td_s32 st_vi_comm_backend_init(td_void)
{
uapi_pq_init(TD_NULL);
uapi_disp_init();
uapi_disp_set_virtual_screen(UAPI_DISPLAY0, VI_BACKEND_WIDTH, VI_BACKEND_HEIGHT);
uapi_disp_open(UAPI_DISPLAY0);
uapi_win_init();
return TD_SUCCESS;
}
static td_s32 st_vi_comm_backend_deinit(td_void)
{
uapi_win_deinit();
uapi_disp_close(UAPI_DISPLAY0);
uapi_disp_deinit();
uapi_pq_deinit();
return TD_SUCCESS;
}
static td_void st_vi_comm_init_player(td_void)
{
test_equal_nsp(st_vi_comm_backend_init(), TD_SUCCESS);
test_equal_nsp(uapi_vi_init(), TD_SUCCESS);
test_equal_nsp(st_vi_comm_frontend_init(), TD_SUCCESS);
}
static td_void st_vi_comm_deinit_player(td_void)
{
test_equal_nsp(st_vi_comm_backend_deinit(), TD_SUCCESS);
test_equal_nsp(uapi_vi_deinit(), TD_SUCCESS);
test_equal_nsp(st_vi_comm_frontend_deinit(), TD_SUCCESS);
}
static td_void st_vi_comm_create_vi(st_vi_setting *vi_setting, st_vi_timing *vi_timing,
st_vi_frontend_param *frontend_param, td_handle *vi_handle)
{
td_handle vi = TD_INVALID_HANDLE;
uapi_vi_attr vi_attr = {0};
uapi_vi_access_type access_type;
if (frontend_param->source_type == UAPI_VIDEO_SOURCE_ATV) {
access_type = UAPI_VI_ACCESS_TVD;
} else if (frontend_param->source_type == UAPI_VIDEO_SOURCE_CVBS) {
access_type = UAPI_VI_ACCESS_TVD;
} else if (frontend_param->source_type == UAPI_VIDEO_SOURCE_VGA) {
access_type = UAPI_VI_ACCESS_HDDEC;
} else if (frontend_param->source_type == UAPI_VIDEO_SOURCE_YPBPR) {
access_type = UAPI_VI_ACCESS_HDDEC;
} else if (frontend_param->source_type == UAPI_VIDEO_SOURCE_HDMI) {
if (frontend_param->port == 0) {
access_type = UAPI_VI_ACCESS_HDMIRX_PORT0;
} else if (frontend_param->port == 1) {
access_type = UAPI_VI_ACCESS_HDMIRX_PORT1;
} else if (frontend_param->port == 2) {
access_type = UAPI_VI_ACCESS_HDMIRX_PORT2;
} else if (frontend_param->port == 3) {
access_type = UAPI_VI_ACCESS_HDMIRX_PORT3;
} else {
access_type = UAPI_VI_ACCESS_HDMIRX_PORT0;
}
} else {
access_type = UAPI_VI_ACCESS_HDMIRX_PORT0;
}
test_equal_nsp(uapi_vi_get_default_attr(&vi_attr), TD_SUCCESS);
vi_attr.vi_type = UAPI_VI_MAIN;
vi_attr.intf_mode = UAPI_VI_INTF_FVHDE;
vi_attr.secure = TD_FALSE;
vi_attr.source_type = frontend_param->source_type;
vi_attr.access_type = access_type;
vi_attr.video_3d_type = vi_timing->video_3d_type;
vi_attr.pixel_format = vi_timing->pixel_format;
vi_attr.color_description = vi_timing->color_description;
vi_attr.bit_depth = vi_timing->bit_depth;
vi_attr.over_sample = vi_timing->over_sample;
vi_attr.vblank = vi_timing->vblank;
vi_attr.vi_config.width = vi_timing->width;
vi_attr.vi_config.height = vi_timing->height;
vi_attr.vi_config.interlace = vi_timing->interlace;
vi_attr.vi_config.frame_rate = vi_timing->frame_rate / 1000;
vi_attr.vi_config.color_sys = vi_timing->color_sys;
vi_attr.vi_config.input_rect.x = 0;
vi_attr.vi_config.input_rect.y = 0;
vi_attr.vi_config.input_rect.width = vi_timing->width;
vi_attr.vi_config.input_rect.height = vi_timing->height;
vi_attr.vi_config.display_field = vi_setting->display_field;
vi_attr.picture_mode = vi_setting->picture_mode;
test_equal_nsp(uapi_vi_create(&vi_attr, &vi), TD_SUCCESS);
*vi_handle = vi;
}
static td_void st_vi_comm_create_player(st_vi_test_info *test_info, st_vi_timing *vi_timing,
td_handle *vi_handle, td_handle *vo_handle)
{
st_vi_setting *vi_setting = TD_NULL;
st_vi_frontend_param *frontend_param = TD_NULL;
st_vi_backend_param *backend_param = TD_NULL;
st_vi_ctx *vi_ctx = TD_NULL;
td_handle vi = TD_INVALID_HANDLE;
td_handle vo = TD_INVALID_HANDLE;
uapi_win_attr win_attr = {0};
vi_ctx = (st_vi_ctx *)test_info->private_date;
vi_setting = &test_info->vi_setting;
frontend_param = &test_info->frontend_param;
backend_param = &test_info->backend_param;
st_vi_comm_create_vi(vi_setting, vi_timing, frontend_param, &vi);
if (backend_param->vo_bypass != TD_TRUE) {
win_attr.disp_id = UAPI_DISPLAY0;
win_attr.priority = UAPI_WIN_WIN_PRIORITY_AUTO;
win_attr.is_virtual = TD_FALSE;
win_attr.asp_convert_mode = UAPI_WIN_ASPECT_CONVERT_FULL;
win_attr.video_format = UAPI_FORMAT_DEFAULT;
test_equal_nsp(uapi_win_create(&win_attr, &vo), TD_SUCCESS);
test_equal_nsp(uapi_vi_attach_win(vi, vo), TD_SUCCESS);
if (vi_setting->picture_mode == UAPI_VI_PICTURE_MODE_PC) {
test_equal_nsp(uapi_win_set_quick_output_enable(vo, TD_TRUE), TD_SUCCESS);
}
test_equal_nsp(uapi_win_set_enable(vo, TD_TRUE), TD_SUCCESS);
} else {
vo = 0x0;
test_equal_nsp(uapi_vi_attach_win(vi, vo), TD_SUCCESS);
}
test_equal_nsp(uapi_vi_start(vi), TD_SUCCESS);
*vi_handle = vi;
*vo_handle = vo;
if (backend_param->vo_bypass != TD_TRUE) {
st_vi_set_win_outrect(test_info, backend_param->x, backend_param->y,
backend_param->width, backend_param->height);
} else {
st_vi_comm_create_user_acquire_frame_thread(vi_ctx);
}
}
static td_void st_vi_comm_destroy_player(st_vi_ctx *vi_ctx)
{
td_handle vi_handle = vi_ctx->vi_handle;
td_handle vo_handle = vi_ctx->vo_handle;
if (vi_handle != TD_INVALID_HANDLE && vo_handle != TD_INVALID_HANDLE) {
test_equal_nsp(uapi_vi_stop(vi_handle), TD_SUCCESS);
if (vo_handle != 0x0) {
test_equal_nsp(uapi_win_set_enable(vo_handle, TD_FALSE), TD_SUCCESS);
test_equal_nsp(uapi_win_set_quick_output_enable(vo_handle, TD_FALSE), TD_SUCCESS);
test_equal_nsp(uapi_vi_detach_win(vi_handle, vo_handle), TD_SUCCESS);
test_equal_nsp(uapi_win_destroy(vo_handle), TD_SUCCESS);
} else {
test_equal_nsp(uapi_vi_detach_win(vi_handle, 0x0), TD_SUCCESS);
st_vi_comm_destroy_user_acquire_frame_thread(vi_ctx);
}
test_equal_nsp(uapi_vi_destroy(vi_handle), TD_SUCCESS);
}
}
td_void st_vi_comm_set_vi(st_vi_test_info *test_info, st_vi_timing *vi_timing, td_handle vi_handle)
{
st_vi_setting *vi_setting = TD_NULL;
uapi_vi_config cfg = {0x0};
vi_setting = &test_info->vi_setting;
if (vi_setting->set_vi_config == TD_TRUE) {
test_equal_nsp(uapi_vi_get_config(vi_handle, &cfg), TD_SUCCESS);
cfg.width = vi_timing->width;
cfg.height = vi_timing->height;
cfg.interlace = vi_timing->interlace;
cfg.frame_rate = vi_timing->frame_rate / 1000;
cfg.color_sys = vi_timing->color_sys;
cfg.input_rect.x = vi_setting->crop_rect.left_offset;
cfg.input_rect.y = vi_setting->crop_rect.top_offset;
cfg.input_rect.width = vi_timing->width - vi_setting->crop_rect.left_offset -
vi_setting->crop_rect.right_offset;
cfg.input_rect.height = vi_timing->height - vi_setting->crop_rect.top_offset -
vi_setting->crop_rect.bottom_offset;
cfg.display_field = vi_setting->display_field;
test_equal_nsp(uapi_vi_set_config(vi_handle, &cfg), TD_SUCCESS);
}
if (vi_setting->set_picture_mode == TD_TRUE) {
test_equal_nsp(uapi_vi_set_picture_mode(vi_handle, vi_setting->picture_mode), TD_SUCCESS);
}
if (vi_setting->set_quantify_range == TD_TRUE) {
test_equal_nsp(uapi_vi_set_src_quantization_range(vi_handle, vi_setting->quantify_range), TD_SUCCESS);
}
if (vi_setting->set_nonstd_info == TD_TRUE) {
test_equal_nsp(uapi_vi_update_nstd_info(vi_handle, &vi_setting->nonstd_info), TD_SUCCESS);
}
}
static td_s32 st_vi_comm_frontend_get_timing(st_vi_frontend_param *frontend_param, st_vi_timing *vi_timing)
{
uapi_hdmirx_timing_info hdmirx_timing_info;
uapi_tvd_timing_info tvd_timing_info = {0x0};
if (frontend_param->source_type == UAPI_VIDEO_SOURCE_ATV) {
vi_st_red_print("frontend_param->source_type=%u,temp not support!\n", frontend_param->source_type);
return TD_FAILURE;
} else if (frontend_param->source_type == UAPI_VIDEO_SOURCE_CVBS) {
test_equal_nsp(st_vi_comm_tvd_get_timing_info(&tvd_timing_info), TD_SUCCESS);
vi_timing->video_3d_type = UAPI_FRAME_PACKING_TYPE_2D;
vi_timing->pixel_format = tvd_timing_info.pixel_fmt;
vi_timing->bit_depth = tvd_timing_info.bit_depth;
vi_timing->color_sys = UAPI_COLOR_SYS_AUTO;
vi_timing->over_sample = tvd_timing_info.oversample;
vi_timing->frame_rate = tvd_timing_info.frame_rate * 1000;
vi_timing->width = tvd_timing_info.width;
vi_timing->height = tvd_timing_info.height;
vi_timing->interlace = TD_TRUE;
} else if (frontend_param->source_type == UAPI_VIDEO_SOURCE_VGA) {
vi_st_red_print("frontend_param->source_type=%u,temp not support!\n", frontend_param->source_type);
return TD_FAILURE;
} else if (frontend_param->source_type == UAPI_VIDEO_SOURCE_YPBPR) {
vi_st_red_print("frontend_param->source_type=%u,temp not support!\n", frontend_param->source_type);
return TD_FAILURE;
} else if (frontend_param->source_type == UAPI_VIDEO_SOURCE_HDMI) {
test_equal_nsp(uapi_hdmirx_get_timing_info(frontend_param->port, &hdmirx_timing_info), TD_SUCCESS);
vi_timing->video_3d_type = hdmirx_timing_info.fmt;
vi_timing->pixel_format = hdmirx_timing_info.pixel_fmt;
vi_timing->bit_depth = hdmirx_timing_info.depth;
vi_timing->color_description = hdmirx_timing_info.color_space;
vi_timing->color_sys = UAPI_COLOR_SYS_AUTO;
vi_timing->over_sample = hdmirx_timing_info.oversample;
vi_timing->vblank = hdmirx_timing_info.v_blank;
vi_timing->frame_rate = hdmirx_timing_info.frame_rate * 1000;
vi_timing->width = hdmirx_timing_info.width;
vi_timing->height = hdmirx_timing_info.height;
vi_timing->interlace = hdmirx_timing_info.is_interlace;
} else {
vi_st_red_print("frontend_param->source_type=%u,not support!\n", frontend_param->source_type);
return TD_FAILURE;
}
return TD_SUCCESS;
}
static td_void st_vi_comm_frontend_update_status(st_vi_test_info *test_info, st_vi_timing *vi_timing,
uapi_sig_status curr_sig_status, uapi_sig_status *last_sig_status)
{
st_vi_ctx *vi_ctx = (st_vi_ctx *)test_info->private_date;
if (curr_sig_status == *last_sig_status) {
vi_ctx->vi_timing = *vi_timing;
usleep(10 * 1000); /* 10 1000 is test case used */
return;
}
if (curr_sig_status == UAPI_SIG_STATUS_SUPPORT) {
vi_ctx->vi_timing = *vi_timing;
st_vi_comm_create_player(test_info, vi_timing, &vi_ctx->vi_handle, &vi_ctx->vo_handle);
st_vi_comm_ctx_print(test_info);
} else if (curr_sig_status == UAPI_SIG_STATUS_NO_SIGNAL) {
printf("%s,%d - dec vi_timing no signal.\n", __FUNCTION__, __LINE__);
st_vi_comm_destroy_player(vi_ctx);
vi_ctx->vi_handle = TD_INVALID_HANDLE;
vi_ctx->vo_handle = TD_INVALID_HANDLE;
} else if (curr_sig_status == UAPI_SIG_STATUS_UNSTABLE) {
printf("%s,%d - dec vi_timing unstable.\n", __FUNCTION__, __LINE__);
st_vi_comm_destroy_player(vi_ctx);
vi_ctx->vi_handle = TD_INVALID_HANDLE;
vi_ctx->vo_handle = TD_INVALID_HANDLE;
} else if (curr_sig_status == UAPI_SIG_STATUS_NOT_SUPPORT) {
printf("%s,%d - dec not support.\n", __FUNCTION__, __LINE__);
st_vi_comm_destroy_player(vi_ctx);
vi_ctx->vi_handle = TD_INVALID_HANDLE;
vi_ctx->vo_handle = TD_INVALID_HANDLE;
} else {
vi_st_yellow_print("%s,%d - err enCurSigStatus\n", __FUNCTION__, __LINE__);
}
*last_sig_status = curr_sig_status;
}
static td_void *st_vi_monitor_thread_fun(td_void *arg)
{
st_vi_test_info *test_info = arg;
st_vi_ctx *vi_ctx = (st_vi_ctx *)test_info->private_date;
uapi_video_source source_type;
uapi_sig_status curr_sig_status = UAPI_SIG_STATUS_MAX;
uapi_sig_status last_sig_status = UAPI_SIG_STATUS_MAX;
st_vi_timing cur_vi_timing = {0};
sleep(2); /* 2 is test case used */
source_type = test_info->frontend_param.source_type;
while (vi_ctx->monitor_running) {
if (source_type == UAPI_VIDEO_SOURCE_CVBS) {
test_equal_nsp(st_vi_comm_tvd_get_signal_status(&curr_sig_status), TD_SUCCESS);
} else if (source_type == UAPI_VIDEO_SOURCE_HDMI) {
if (uapi_hdmirx_get_signal_status(test_info->frontend_param.port, &curr_sig_status) != TD_SUCCESS) {
vi_log_err("hdmirx %u,call uapi_hdmirx_get_signal_status fail!\n", test_info->frontend_param.port);
}
} else {
usleep(10 * 1000); /* 10 1000 is test case used */
continue;
}
if (curr_sig_status == UAPI_SIG_STATUS_SUPPORT) {
memset_s(&cur_vi_timing, sizeof(cur_vi_timing), 0, sizeof(cur_vi_timing));
test_equal_nsp(st_vi_comm_frontend_get_timing(&test_info->frontend_param, &cur_vi_timing), TD_SUCCESS);
}
st_vi_comm_frontend_update_status(test_info, &cur_vi_timing, curr_sig_status, &last_sig_status);
}
if (curr_sig_status == UAPI_SIG_STATUS_SUPPORT) {
st_vi_comm_destroy_player(vi_ctx);
vi_ctx->vi_handle = TD_INVALID_HANDLE;
vi_ctx->vo_handle = TD_INVALID_HANDLE;
}
vi_st_green_print("hdmirx %u path monitor thread quit!\n", test_info->frontend_param.port);
return TD_NULL;
}
td_void st_vi_comm_wait_quit_test(td_void)
{
td_u32 get_char = 0;
vi_print("wait quit, please input q:");
while (1) {
get_char = getchar();
if ((get_char == 'q') || (get_char == 'Q')) {
break;
}
}
}
td_bool st_vi_comm_wait_input_select(td_char *str)
{
td_u32 get_char = 0;
vi_print("%s please input y/n:", str);
while (TD_TRUE) {
get_char = getchar();
if ((get_char == 'y') || (get_char == 'Y')) {
return TD_TRUE;
}
if ((get_char == 'n') || (get_char == 'N')) {
return TD_FALSE;
}
}
return TD_FALSE;
}
td_s32 st_vi_comm_wait_input_num(td_char *str)
{
td_s32 num = 0;
vi_print("%s please input num:", str);
scanf("%d", &num);
vi_print("lrb: input:%d", num);
return num;
}
td_s32 st_vi_comm_get_chip_info(ext_chip_name_id *chip_version, ext_chip_revision *chip_revision)
{
/* chip_version or chip_revision maybe NULL, but not all */
if ((chip_version == TD_NULL) && (chip_revision == TD_NULL)) {
vi_log_err("invalid input parameter\n");
return TD_FAILURE;
}
if (chip_version != TD_NULL) {
*chip_version = 0x2002;
}
if (chip_revision != TD_NULL) {
*chip_revision = 0x01;
}
return TD_SUCCESS;
}
uapi_vi_access_type st_vi_comm_source2acess(uapi_video_source source_type, td_u32 port_index)
{
uapi_vi_access_type access_type;
if (source_type == UAPI_VIDEO_SOURCE_ATV) {
access_type = UAPI_VI_ACCESS_TVD;
} else if (source_type == UAPI_VIDEO_SOURCE_CVBS) {
access_type = UAPI_VI_ACCESS_TVD;
} else if (source_type == UAPI_VIDEO_SOURCE_VGA) {
access_type = UAPI_VI_ACCESS_HDDEC;
} else if (source_type == UAPI_VIDEO_SOURCE_YPBPR) {
access_type = UAPI_VI_ACCESS_HDDEC;
} else if (source_type == UAPI_VIDEO_SOURCE_HDMI) {
if (port_index == 0x0) {
access_type = UAPI_VI_ACCESS_HDMIRX_PORT0;
} else if (port_index == 0x1) {
access_type = UAPI_VI_ACCESS_HDMIRX_PORT1;
} else if (port_index == 0x2) {
access_type = UAPI_VI_ACCESS_HDMIRX_PORT2;
} else if (port_index == 0x3) {
access_type = UAPI_VI_ACCESS_HDMIRX_PORT3;
} else {
access_type = UAPI_VI_ACCESS_HDMIRX_PORT0;
}
} else {
access_type = UAPI_VI_ACCESS_HDMIRX_PORT0;
}
return access_type;
}
td_u32 st_vi_comm_get_hdmirx_port_num(td_void)
{
uapi_hdmirx_capability hdmirx_capability = {0};
td_u32 port_num;
if (uapi_hdmirx_get_capability(&hdmirx_capability) != TD_SUCCESS) {
vi_log_err("call uapi_hdmirx_get_capability fail!\n");
port_num = UAPI_HDMIRX_PORT_MAX;
} else {
port_num = hdmirx_capability.port_max;
}
return port_num;
}
td_s32 st_vi_comm_win_init(td_handle vi, td_handle *vo_p)
{
uapi_win_attr win_attr = {0};
win_attr.disp_id = UAPI_DISPLAY0;
win_attr.priority = UAPI_WIN_WIN_PRIORITY_AUTO;
win_attr.is_virtual = TD_FALSE;
win_attr.asp_convert_mode = UAPI_WIN_ASPECT_CONVERT_FULL;
win_attr.video_format = UAPI_FORMAT_DEFAULT;
test_equal_nsp(uapi_win_init(), TD_SUCCESS);
test_equal_nsp(uapi_win_create(&win_attr, vo_p), TD_SUCCESS);
test_equal_nsp(uapi_vi_attach_win(vi, *vo_p), TD_SUCCESS);
test_equal_nsp(uapi_win_set_enable(*vo_p, TD_TRUE), TD_SUCCESS);
return TD_SUCCESS;
}
td_s32 st_vi_comm_win_deinit(td_handle vi, td_handle vo)
{
test_equal_nsp(uapi_win_set_enable(vo, TD_FALSE), TD_SUCCESS);
test_equal_nsp(uapi_vi_detach_win(vi, vo), TD_SUCCESS);
test_equal_nsp(uapi_win_destroy(vo), TD_SUCCESS);
test_equal_nsp(uapi_win_deinit(), TD_SUCCESS);
return TD_SUCCESS;
}
td_void st_vi_set_win_outrect(st_vi_test_info *test_info, td_u32 x, td_u32 y, td_u32 w, td_u32 h)
{
st_vi_ctx *vi_ctx = (st_vi_ctx *)test_info->private_date;
uapi_video_rect outrect = {0x0};
outrect.x = x;
outrect.y = y;
outrect.width = w;
outrect.height = h;
uapi_win_set_outrect(&vi_ctx->vo_handle, &outrect, 1);
uapi_win_set_abs_zorder(vi_ctx->vo_handle, test_info->backend_param.abs_zorder);
vi_st_green_print("\nset out rect x=%u,y=%u,w=%u,h=%u!\n", outrect.x, outrect.y, outrect.width, outrect.height);
}
td_u32 st_vi_comm_get_vi_num(td_void)
{
ext_chip_name_id chip_version = CHIP_NAME_RESERVED5;
ext_chip_revision chip_revision = CHIP_REVISION_A;
td_u32 vi_num;
if (st_vi_comm_get_chip_info(&chip_version, &chip_revision) != TD_SUCCESS) {
vi_log_err("call st_vi_comm_get_chip_info fail!\n");
}
if (((chip_version == CHIP_NAME_RESERVED9) || (chip_version == CHIP_NAME_RESERVED13) ||
(chip_version == CHIP_NAME_RESERVED6) || (chip_version == CHIP_NAME_RESERVED8)) &&
(chip_revision != CHIP_REVISION_A)) {
vi_num = 0x2;
} else {
vi_num = 0x1;
}
return vi_num;
}
td_u32 st_vi_comm_get_vi_id(uapi_vi_access_type access_type)
{
ext_chip_name_id chip_version = CHIP_NAME_RESERVED5;
ext_chip_revision chip_revision = CHIP_REVISION_A;
td_u32 vi_id;
if (st_vi_comm_get_chip_info(&chip_version, &chip_revision) != TD_SUCCESS) {
vi_log_err("call st_vi_comm_get_chip_info fail!\n");
}
if (chip_version == CHIP_NAME_RESERVED5) {
vi_id = 0x0;
} else if ((chip_version == CHIP_NAME_RESERVED9) || (chip_version == CHIP_NAME_RESERVED13) ||
(chip_version == CHIP_NAME_RESERVED6) || (chip_version == CHIP_NAME_RESERVED8)) {
if (chip_revision == CHIP_REVISION_A) {
if (access_type == UAPI_VI_ACCESS_HDMIRX_PORT1) {
vi_id = 0x1;
} else {
vi_id = 0x0;
}
} else {
if (access_type == UAPI_VI_ACCESS_HDMIRX_PORT3) {
vi_id = 0x0;
} else {
vi_id = 0x1;
}
}
} else {
vi_id = 0x0;
}
vi_log_print("access_type=%u,vi_id=%u\n", access_type, vi_id);
return vi_id;
}
td_s32 st_vi_comm_is_created(uapi_vi_access_type access_type)
{
struct stat statbuff;
td_u32 vi_id;
vi_id = st_vi_comm_get_vi_id(access_type);
if (vi_id == 0x0) {
system("cat /proc/msp/vi0000 | grep \"VI\" > /mnt/vicheck.txt");
} else {
system("cat /proc/msp/vi0001 | grep \"VI\" > /mnt/vicheck.txt");
}
if (stat("/mnt/vicheck.txt", &statbuff) == TD_FAILURE) {
vi_st_red_print("stat failure\n");
return TD_FAILURE;
}
if (statbuff.st_size == 0) {
vi_st_red_print("st_size is 0\n");
return TD_FAILURE;
}
return TD_SUCCESS;
}
td_s32 st_vi_comm_is_started(uapi_vi_access_type access_type)
{
struct stat statbuff;
td_u32 vi_id;
vi_id = st_vi_comm_get_vi_id(access_type);
if (vi_id == 0x0) {
system("cat /proc/msp/vi0000 | grep \"VI(ViHandle/VoHandle/Status)\" | grep \"START\" > /mnt/vicheck.txt");
} else {
system("cat /proc/msp/vi0001 | grep \"VI(ViHandle/VoHandle/Status)\" | grep \"START\" > /mnt/vicheck.txt");
}
if (stat("/mnt/vicheck.txt", &statbuff) == TD_FAILURE) {
vi_st_red_print("stat failure\n");
return TD_FAILURE;
}
if (statbuff.st_size == 0) {
vi_st_red_print("st_size is 0\n");
return TD_FAILURE;
}
return TD_SUCCESS;
}
td_s32 st_vi_comm_check_vi_proc_info(uapi_vi_access_type access_type)
{
if (st_vi_comm_is_created(access_type) != TD_SUCCESS) {
vi_log_print("call st_vi_comm_is_created fail!\n");
return TD_FAILURE;
}
if (st_vi_comm_is_started(access_type) != TD_SUCCESS) {
vi_log_print("call st_vi_comm_is_started fail!\n");
return TD_FAILURE;
}
if (st_vi_comm_check_vi_proc_irq_info(access_type) != TD_SUCCESS) {
vi_log_print("call st_vi_comm_check_vi_proc_irq_info fail!\n");
return TD_FAILURE;
}
return TD_SUCCESS;
}
td_void st_vi_comm_ctx_init(st_vi_ctx *vi_ctx)
{
memset_s(vi_ctx, sizeof(*vi_ctx), 0, sizeof(st_vi_ctx));
vi_ctx->vi_handle = TD_INVALID_HANDLE;
vi_ctx->vo_handle = TD_INVALID_HANDLE;
}
td_void st_vi_comm_set_gentiming(uapi_vi_access_type access_type, td_u32 gen_data_type)
{
char gen[FILE_PATH_MAX_SIZE] = {0};
td_u32 vi_id;
vi_id = st_vi_comm_get_vi_id(access_type);
if (vi_id == 1) {
snprintf_s(gen, sizeof(gen), FILE_PATH_MAX_SIZE - 1, "echo gentiming %d > /proc/msp/vi0001", gen_data_type);
} else {
snprintf_s(gen, sizeof(gen), FILE_PATH_MAX_SIZE - 1, "echo gentiming %d > /proc/msp/vi0000", gen_data_type);
}
system(gen);
}
td_void st_vi_comm_create_monitor(st_vi_test_info *test_info)
{
st_vi_ctx *vi_ctx = TD_NULL;
uapi_tvd_src_attr tvd_src_attr = {0x0};
td_s32 ret;
vi_ctx = malloc(sizeof(st_vi_ctx));
if (vi_ctx == TD_NULL) {
vi_log_print("call malloc fail!\n");
return;
}
test_info->private_date = vi_ctx;
st_vi_comm_ctx_init(vi_ctx);
if (test_info->frontend_param.frontend_bypass == TD_TRUE) {
vi_ctx->vi_timing = test_info->vi_timing;
st_vi_comm_create_player(test_info, &vi_ctx->vi_timing, &vi_ctx->vi_handle, &vi_ctx->vo_handle);
} else {
if (test_info->frontend_param.source_type == UAPI_VIDEO_SOURCE_CVBS) {
tvd_src_attr.type = UAPI_VIDEO_SOURCE_CVBS;
tvd_src_attr.index = test_info->frontend_param.port;
test_equal_nsp(st_vi_comm_tvd_connect(&tvd_src_attr), TD_SUCCESS);
test_equal_nsp(st_vi_comm_tvd_set_comb_filter_mode(UAPI_TVD_COMB_MODE_FORCE_1D), TD_SUCCESS);
} else if (test_info->frontend_param.source_type == UAPI_VIDEO_SOURCE_HDMI) {
vi_st_green_print("connect hdmirx %u!\n", test_info->frontend_param.port);
test_equal_nsp(uapi_hdmirx_connect((uapi_hdmirx_port)test_info->frontend_param.port), TD_SUCCESS);
} else {
vi_log_print("not support source %u!\n", test_info->frontend_param.source_type);
}
vi_ctx->monitor_running = TD_TRUE;
ret = pthread_create(&vi_ctx->monitor_thread, NULL, st_vi_monitor_thread_fun, test_info);
test_equal_nsp(ret, TD_SUCCESS);
}
}
td_void st_vi_comm_destroy_monitor(st_vi_test_info *test_info)
{
st_vi_ctx *vi_ctx = (st_vi_ctx *)test_info->private_date;
if (test_info->frontend_param.frontend_bypass == TD_TRUE) {
st_vi_comm_destroy_player(vi_ctx);
vi_ctx->vi_handle = TD_INVALID_HANDLE;
vi_ctx->vo_handle = TD_INVALID_HANDLE;
} else {
vi_ctx->monitor_running = TD_FALSE;
pthread_join(vi_ctx->monitor_thread, NULL);
if (test_info->frontend_param.source_type == UAPI_VIDEO_SOURCE_CVBS) {
test_equal_nsp(st_vi_comm_tvd_disconnect(), TD_SUCCESS);
} else if (test_info->frontend_param.source_type == UAPI_VIDEO_SOURCE_HDMI) {
vi_st_green_print("disconnect hdmirx %u!\n", test_info->frontend_param.port);
test_equal_nsp(uapi_hdmirx_disconnect((uapi_hdmirx_port)test_info->frontend_param.port), TD_SUCCESS);
} else {
vi_log_print("not support source %u!\n", test_info->frontend_param.source_type);
}
}
free(vi_ctx);
test_info->private_date = TD_NULL;
}
td_void st_vi_comm_init_monitor(td_void)
{
st_vi_comm_init_player();
}
td_void st_vi_comm_deinit_monitor(td_void)
{
st_vi_comm_deinit_player();
}
static td_void *st_vi_acquire_frame_thread(td_void *arg)
{
td_s32 ret;
TD_UNUSED(arg);
st_vi_ctx *vi_ctx = (st_vi_ctx *)arg;
uapi_video_frame_info frame_info;
vi_print("st_vi_acquire_thread enter...\n");
while (vi_ctx->acquire_thread_running) {
ret = st_iapi_vi_acquire(vi_ctx->vi_handle, &frame_info, 0);
if (ret != TD_SUCCESS) {
vi_print("acquire failed!\n");
continue;
}
vi_print("acquire success! index:%d\n",frame_info.frame_index);
ret = st_iapi_vi_release(vi_ctx->vi_handle, &frame_info);
if (ret != TD_SUCCESS) {
vi_print("release failed!\n");
}
}
return TD_NULL;
}
#define time_5s 1000*1000*5
#define time_1s 1000*1000*1
td_void st_vi_self_running(td_void)
{
td_handle vi_handle = 0;
uapi_vi_attr stviattr = {0};
td_s32 ret = 0;
st_vi_ctx vi_ctx;
pthread_t acquire_frame_thread;
pthread_attr_t acquire_thread_attr;
struct sched_param sched_param;
(td_void) pthread_attr_init(&acquire_thread_attr);
/* use default priority real_time */
(td_void) pthread_attr_setschedpolicy(&acquire_thread_attr, SCHED_RR);
(td_void) pthread_attr_getschedparam(&acquire_thread_attr, &sched_param);
sched_param.sched_priority = 99; /* 99 is priority */
(td_void) pthread_attr_setschedparam(&acquire_thread_attr, &sched_param);
vi_print("vi create...\n");
test_equal_nsp(st_iapi_vi_init(), TD_SUCCESS);
test_equal_nsp(st_iapi_vi_get_default_attr(&stviattr), TD_SUCCESS);
test_equal_nsp(st_iapi_vi_create(&stviattr, &vi_handle), TD_SUCCESS);
test_equal_nsp(st_iapi_vi_attach(vi_handle, 0), TD_SUCCESS);
test_equal_nsp(st_iapi_vi_start(vi_handle), TD_SUCCESS);
vi_ctx.vi_handle = vi_handle;
vi_ctx.acquire_thread_running = TD_TRUE;
usleep(time_1s);
vi_print("thread running...\n");
ret = pthread_create(&acquire_frame_thread, &acquire_thread_attr, st_vi_acquire_frame_thread, &vi_ctx);
pthread_attr_destroy(&acquire_thread_attr);
if (ret != TD_SUCCESS) {
vi_print("pthread_create acquire_thread fail\n");
pthread_attr_destroy(&acquire_thread_attr);
return;
}
st_vi_comm_wait_quit_test();
vi_ctx.acquire_thread_running = TD_FALSE;
pthread_join(acquire_frame_thread, NULL);
vi_print("thread stop.\n");
test_equal_nsp(st_iapi_vi_stop(vi_handle), TD_SUCCESS);
test_equal_nsp(st_iapi_vi_detach(vi_handle, 0), TD_SUCCESS);
test_equal_nsp(st_iapi_vi_destroy(vi_handle), TD_SUCCESS);
test_equal_nsp(st_iapi_vi_deinit(), TD_SUCCESS);
vi_print("destroy ok!\n");
}
td_void st_vi_comm_create_user_acquire_frame_thread(st_vi_ctx *vi_ctx)
{
td_s32 ret = 0;
pthread_attr_t acquire_thread_attr;
struct sched_param sched_param;
(td_void) pthread_attr_init(&acquire_thread_attr);
/* use default priority real_time */
(td_void) pthread_attr_setschedpolicy(&acquire_thread_attr, SCHED_RR);
(td_void) pthread_attr_getschedparam(&acquire_thread_attr, &sched_param);
sched_param.sched_priority = 99; /* 99 is priority */
(td_void) pthread_attr_setschedparam(&acquire_thread_attr, &sched_param);
usleep(time_1s);
vi_print("thread running ...\n");
vi_ctx->acquire_thread_running = TD_TRUE;
ret = pthread_create(&vi_ctx->acquire_frame_thread, &acquire_thread_attr, st_vi_acquire_frame_thread, vi_ctx);
pthread_attr_destroy(&acquire_thread_attr);
if (ret != TD_SUCCESS) {
vi_print("pthread_create acquire_thread fail\n");
pthread_attr_destroy(&acquire_thread_attr);
return;
}
}
td_void st_vi_comm_destroy_user_acquire_frame_thread(st_vi_ctx *vi_ctx)
{
vi_ctx->acquire_thread_running = TD_FALSE;
pthread_join(vi_ctx->acquire_frame_thread, NULL);
}