Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources

This commit is contained in:
2026-07-06 11:30:13 +08:00
commit e76462eeb7
3451 changed files with 1415300 additions and 0 deletions

View File

@@ -0,0 +1,261 @@
/******************************************************************************
* 这个文件用于录风者录卡文件处理 *
* *
******************************************************************************/
#include "basic_include.h"
#include "file_process.h"
#include "fs/fatfs/osal_file.h"
#include "video_app/file_thumb.h"
#include "video_app/file_common_api.h"
#include "loop_record_moudle/loop_record_moudle.h"
#define LOOP_REMAIN_CAP (256) // 循环录像剩余空间控制
void *rec_create_file(struct file_process *file_process, char *file_name, char *file_path, uint32_t file_size)
{
void *fp = NULL;
void *node = NULL;
char *dir_path = NULL;
void *list = NULL;
uint32_t sd_cap = 0;
int res = 0;
uint8_t changeflag = 0;
uint32_t old_file_size = 0;
uint32_t unlink_size = 0;
void **loop = &file_process->loop;
char *main_path = file_process->rec_path;
char *extension_name = file_process->ext_name;
char sub_path[32];
char thumb_path[64];
res = osal_fatfsfree("0:", NULL, &sd_cap);
os_printf(KERN_INFO"sd_cap: %d, file_size: %d\r\n", sd_cap, file_size);
if (res != 0) {
goto rec_create_file_end;
}
rec_create_file_get_node:
if (sd_cap < LOOP_REMAIN_CAP)
{
if (!*loop) {
*loop = get_file_list2(main_path, extension_name, list);
}
if (*loop) {
node = get_file_node(*loop);
if (!node) {
list = get_err_dir_list(*loop);
free_file_list(*loop);
*loop = get_file_list2(main_path, extension_name, list);
if (!*loop) {
os_printf("%s %d\r\n", __FUNCTION__, __LINE__);
goto rec_create_file_end;
}
node = get_file_node(*loop);
}
while (!node) {
dir_path = get_file_dir(*loop);
res = osal_unlink_dir(dir_path, 0);
if (res != FR_OK) {
os_printf("unlink dir %s err, res: %d\r\n", dir_path, res);
if(res == FR_DENIED) {
err_dir_add_list(*loop, dir_path);
// res = osal_unlink_dir(dir_path, 1);
// if (res != FR_OK) {
// _os_printf("%s %d, force unlink dir %s err, res: %d\r\n", __FUNCTION__, __LINE__, dir_path, res);
// err_dir_add_list(*loop, dir_path);
// } else {
// _os_printf("force unlink dir %s\r\n", dir_path);
// }
} else if(res == FR_NO_FILE) {
os_printf("%s %d, could not find dir %s\r\n", __FUNCTION__, __LINE__, dir_path);
} else {
os_printf("%s %d\r\n", __FUNCTION__, __LINE__);
goto rec_create_file_end;
}
} else {
os_printf("unlink dir %s\r\n", dir_path);
}
list = get_err_dir_list(*loop);
free_file_list(*loop);
*loop = get_file_list2(main_path, extension_name, list);
if (!*loop) {
os_printf("%s %d\r\n", __FUNCTION__, __LINE__);
goto rec_create_file_end;
}
node = get_file_node(*loop);
if (node) {
break;
}
}
old_file_size = get_file_size(node);
os_printf("earliest file size: %d\r\n", old_file_size);
if(unlink_size + old_file_size < file_size) {
char path[64];
char *name = get_file_name(node);
dir_path = get_file_dir(*loop);
os_sprintf(path, "%s/%s", dir_path, name);
res = osal_unlink(path);
if(res != FR_OK) {
os_printf("%s %d\tunlink file %s fail, res: %d\r\n", __FUNCTION__, __LINE__, path, res);
} else {
os_printf("unlink file %s\r\n", path);
unlink_size += old_file_size;
}
gen_thumb_path(name, thumb_path, sizeof(thumb_path));
res = osal_unlink(thumb_path);
if (res != FR_OK) {
os_printf("unlink thumb_path %s err, res: %d\r\n", thumb_path, res);
} else {
os_printf("unlink thumb_path: %s\r\n", thumb_path);
}
free_file_node(node);
node = NULL;
goto rec_create_file_get_node;
}
changeflag = 1;
} else {
os_printf("%s %d\r\n", __FUNCTION__, __LINE__);
goto rec_create_file_end;
}
}
struct timeval *time;
struct timeval ptimeval;
time = &ptimeval;
gettimeofday(time, NULL);
if(file_process->frame_time)
{
time->tv_sec = time->tv_sec - (os_jiffies() - file_process->frame_time) / 1000;
time->tv_usec = time->tv_usec - ((os_jiffies() - file_process->frame_time) % 1000) * 1000;
}
if (get_extension_file_name_time(main_path, sub_path, file_name, extension_name, time)) {
os_printf("%s %d\tget_file_name fail\r\n", __FUNCTION__, __LINE__);
goto rec_create_file_end;
}
os_sprintf(file_path, "%s/%s", sub_path, file_name);
os_printf(KERN_INFO "file_path: %s\r\n", file_path);
void *sub_dir = osal_opendir(sub_path);
if (!sub_dir) {
res = osal_fmkdir(sub_path);
if (res != FR_OK) {
if(res == FR_DENIED) {
char path[64];
char *name = get_file_name(node);
dir_path = get_file_dir(*loop);
os_sprintf(path, "%s/%s", dir_path, name);
res = osal_unlink(path);
if(res != FR_OK) {
os_printf("%s %d\tunlink file %s fail, res: %d\r\n", __FUNCTION__, __LINE__, path, res);
goto rec_create_file_end;
}
os_printf("unlink file %s\r\n", path);
free_file_node(node);
node = NULL;
res = osal_fmkdir(sub_path);
if (res == FR_OK) {
goto rec_create_file_get_node;
} else {
os_printf("%s %d\tmkdir %s fail, res: %d\r\n", __FUNCTION__, __LINE__, sub_path, res);
goto rec_create_file_end;
}
}
os_printf("mkdir %s err, create rec dir\r\n", sub_path);
void *rec_dir = osal_opendir(main_path);
if (!rec_dir) {
res = osal_fmkdir(main_path);
if (res != FR_OK) {
os_printf("%s %d\tmkdir %s fail, res: %d\r\n", __FUNCTION__, __LINE__, main_path, res);
goto rec_create_file_end;
} else {
res = osal_fmkdir(sub_path);
if (res != FR_OK) {
os_printf("%s %d\tmkdir %s fail, res: %d\r\n", __FUNCTION__, __LINE__, sub_path, res);
goto rec_create_file_end;
}
}
} else {
osal_closedir(rec_dir);
os_printf("%s %d\tmkdir %s fail, res: %d\r\n", __FUNCTION__, __LINE__, sub_path, res);
goto rec_create_file_end;
}
}
os_printf("mkdir %s\r\n", sub_path);
} else {
osal_closedir(sub_dir);
}
if (changeflag) {
char old_filepath[64];
char *name = get_file_name(node);
dir_path = get_file_dir(*loop);
os_sprintf(old_filepath, "%s/%s", dir_path, name);
res = osal_rename(old_filepath, file_path);
if (res != FR_OK) {
os_printf("rename file %s err, res: %d\r\n", old_filepath, res);
if (sd_cap < LOOP_REMAIN_CAP) {
if(res == FR_DENIED) {
res = osal_unlink(old_filepath);
if(res != FR_OK) {
os_printf("%s %d\tunlink file %s fail, res: %d\r\n", __FUNCTION__, __LINE__, old_filepath, res);
goto rec_create_file_end;
} else {
os_printf("unlink file %s\r\n", old_filepath);
res = osal_fatfsfree("0:", NULL, &sd_cap);
if(res != FR_OK) {
os_printf("%s %d\tfatfsfree err, res: %d\r\n", __FUNCTION__, __LINE__, res);
goto rec_create_file_end;
}
}
}
os_printf("%s %d\tsd_cap: %d\r\n", __FUNCTION__, __LINE__, sd_cap);
free_file_node(node);
node = NULL;
goto rec_create_file_get_node;
}
} else {
os_printf("rename file %s to %s\r\n", old_filepath, file_path);
}
gen_thumb_path(name, thumb_path, sizeof(thumb_path));
res = osal_unlink(thumb_path);
if (res != FR_OK) {
os_printf("unlink thumb_path %s err, res: %d\r\n", thumb_path, res);
} else {
os_printf("unlink thumb_path: %s\r\n", thumb_path);
}
free_file_node(node);
node = NULL;
char *min_file = get_min_file(*loop);
if (min_file && (os_strcmp(file_name, min_file) < 0)) {
list = get_err_dir_list(*loop);
free_file_list(*loop);
*loop = NULL;
os_printf("%s %d\tfree_file_list\r\n", __FUNCTION__, __LINE__);
}
}
fp = osal_fopen(file_path, "a+");
rec_create_file_end:
if(node) {
free_file_node(node);
node = NULL;
}
return fp;
}
void rec_loop_free(void **loop)
{
if(*loop) {
free_list(*loop);
free_file_list(*loop);
*loop = NULL;
}
}

View File

@@ -0,0 +1,30 @@
#ifndef __FILE_PROCESS_H__
#define __FILE_PROCESS_H__
#include "basic_include.h"
struct file_process;
typedef void *(*create_file)(struct file_process *file_process, char *file_name, char *file_path, uint32_t file_size);
typedef void (*loop_free)(void **loop);
typedef void (*lock_file)(char *file_name, char *file_path);
typedef int32_t (*record_callback)(struct file_process *file_process);
struct file_process
{
void *loop;
char *rec_path;
char *ext_name;
create_file create_file;
loop_free loop_free;
lock_file lock_file;
record_callback start_encode; //param代表模式
record_callback end_encode; //param代表录制完毕后的返回码
uint32_t frame_time;
uint32_t param;
};
void *rec_create_file(struct file_process *file_process, char *file_name, char *file_path, uint32_t file_size);
void rec_loop_free(void **loop);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,43 @@
#ifndef _RECORDER_VIIDURE_H
#define _RECORDER_VIIDURE_H
#include "basic_include.h"
#include "file_process.h"
typedef struct msi *(*create_msi_func)(const char *mp4_msi_name, uint8_t srcID, uint8_t filter_type, uint8_t rec_time,
uint32_t audio_encode, struct file_process *file_process, uint8_t mode);
typedef uint8_t (*get_video_status)(void);
struct media_s
{
const char *rtsp_url; //rtsp的地址的后缀地址
const char *tran_mode; //传输方式
};
struct cam_cfg {
struct msi *msi;
const char *msi_name;
struct msi *src_msi;
const char *src_msi_name;
struct msi *aac_msi;
uint8_t srcID;
uint8_t filter_type;
uint8_t mode;
uint8_t mask;
uint8_t type; // 0:mp4, 1:avi
uint8_t src_type;
const char *rec_path;
const char *img_path;
uint8_t enable;
struct media_s media;
struct file_process file_process;
create_msi_func create_func;
get_video_status get_status;
};
void rec_open(void);
void rec_close(void);
int config_Viidure(int port);
#endif