活动介绍

#if LIBVC_ON static char op_fname_inp_libpics[256] = "\0"; /* bitstream of libpics */ static char op_fname_out_libpics[256] = "\0"; /* reconstructed yuv of libpics */ #endif #if LIB_PIC_ERR_TOL unsigned int bs_real_size = 0; #endif typedef enum _STATES { STATE_DECODING, STATE_BUMPING #if LIB_PIC_ERR_TOL , STATE_LIBPIC_COLLECTING #endif } STATES;

时间: 2025-07-21 17:57:10 浏览: 3
<think>我们正在处理一个C语言项目中的条件编译和枚举类型定义。代码片段展示了几个条件编译块和一个枚举定义。 1. 首先,在条件编译指令`#if LIBVC_ON`下,定义了两个静态字符数组,用于存储libpics的输入和输出文件名。 2. 接着,在条件编译指令`#if LIB_PIC_ERR_TOL`下,定义了一个无符号整数变量`bs_real_size`。 3. 然后,定义了一个枚举类型`_STATES`(通常枚举类型名建议不要以下划线开头,但这里我们按照原样),其中包含了两个基本状态:`STATE_DECODING`和`STATE_BUMPING`,并且根据`LIB_PIC_ERR_TOL`是否定义,可能添加第三个状态`STATE_LIBPIC_COLLECTING`。 我们将详细解释这些代码,并展示一个完整的例子,包括如何根据不同的宏定义来使用这些变量和枚举。 注意:条件编译允许我们在编译时根据宏定义的情况包含或排除代码。这在跨平台或不同配置的项目中非常常见。 下面我们将编写一个示例程序,展示如何根据不同的宏定义来使用这些变量和枚举状态。</think>## 条件编译与枚举状态设计详解 ### 代码分析 ```c #if LIBVC_ON static char op_fname_inp_libpics[256] = "\0"; /* bitstream of libpics */ static char op_fname_out_libpics[256] = "\0"; /* reconstructed yuv of libpics */ #endif #if LIB_PIC_ERR_TOL unsigned int bs_real_size = 0; #endif typedef enum _STATES { STATE_DECODING, STATE_BUMPING #if LIB_PIC_ERR_TOL , STATE_LIBPIC_COLLECTING #endif } STATES; ``` ### 代码功能解析 #### 1. 条件编译变量定义 ```mermaid graph TD A[LIBVC_ON宏] -->|已定义| B[定义libpics相关文件路径] A -->|未定义| C[不定义相关变量] D[LIB_PIC_ERR_TOL宏] -->|已定义| E[定义bs_real_size变量] D -->|未定义| F[不定义该变量] ``` - **`#if LIBVC_ON`**: - `op_fname_inp_libpics`:libpics输入文件路径(256字符缓冲区) - `op_fname_out_libpics`:libpics输出文件路径 - **`#if LIB_PIC_ERR_TOL`**: - `bs_real_size`:用于错误容忍处理的比特流实际大小 #### 2. 枚举状态设计 ```mermaid graph LR A[STATE_DECODING] --> 解码处理 B[STATE_BUMPING] --> 碰撞处理 C{是否定义 LIB_PIC_ERR_TOL} -->|是| D[添加STATE_LIBPIC_COLLECTING] C -->|否| E[仅基础状态] ``` - 基础状态: - `STATE_DECODING`:解码状态 - `STATE_BUMPING`:碰撞处理状态 - 条件状态(当`LIB_PIC_ERR_TOL`定义时): - `STATE_LIBPIC_COLLECTING`:libpics数据收集状态 ### 完整状态机实现 ```c #include <stdio.h> #include <string.h> // 模拟配置宏(实际项目中可能由构建系统定义) #define LIBVC_ON #define LIB_PIC_ERR_TOL // 条件变量定义 #if LIBVC_ON static char op_fname_inp_libpics[256] = "input_libpics.dat"; static char op_fname_out_libpics[256] = "output_libpics.yuv"; #endif #if LIB_PIC_ERR_TOL unsigned int bs_real_size = 0; #endif // 状态枚举定义 typedef enum _STATES { STATE_DECODING, STATE_BUMPING #if LIB_PIC_ERR_TOL , STATE_LIBPIC_COLLECTING #endif } STATES; // 状态转换函数 void handle_state(STATES current_state) { switch(current_state) { case STATE_DECODING: printf("Processing decoding state...\n"); #if LIBVC_ON printf("Loading libpics input: %s\n", op_fname_inp_libpics); #endif break; case STATE_BUMPING: printf("Processing bumping state...\n"); break; #if LIB_PIC_ERR_TOL case STATE_LIBPIC_COLLECTING: printf("Collecting libpics data...\n"); #if LIBVC_ON printf("Saving output to: %s\n", op_fname_out_libpics); #endif bs_real_size = 1024; // 示例值 printf("Real bitstream size: %u bytes\n", bs_real_size); break; #endif default: printf("Unknown state!\n"); } } // 状态机处理函数 void process_state_machine() { STATES states[] = { STATE_DECODING, STATE_BUMPING #if LIB_PIC_ERR_TOL , STATE_LIBPIC_COLLECTING #endif }; int num_states = sizeof(states)/sizeof(states[0]); printf("Total states: %d\n", num_states); for (int i = 0; i < num_states; i++) { printf("\n--- State %d ---\n", i+1); handle_state(states[i]); } } int main() { // 初始化配置 #if LIBVC_ON printf("LIBVC_ON enabled\n"); #endif #if LIB_PIC_ERR_TOL printf("LIB_PIC_ERR_TOL enabled\n"); #endif // 运行状态机 process_state_machine(); return 0; } ``` ### 状态机设计详解 #### 1. 状态枚举扩展技巧 ```c // 使用X-Macro技术实现可扩展状态定义 #define STATE_LIST \ X(STATE_DECODING, "Decoding") \ X(STATE_BUMPING, "Bumping") \ X_COND(LIB_PIC_ERR_TOL, STATE_LIBPIC_COLLECTING, "LibPics Collecting") // 定义枚举 typedef enum _STATES { #define X(state, desc) state, #define X_COND(cond, state, desc) #if cond state, #endif STATE_LIST #undef X #undef X_COND } STATES; // 获取状态描述字符串 const char* state_description(STATES s) { switch(s) { #define X(state, desc) case state: return desc; #define X_COND(cond, state, desc) #if cond case state: return desc; #endif STATE_LIST #undef X #undef X_COND default: return "Unknown State"; } } ``` #### 2. 高级状态机实现 ```c #include <stdbool.h> // 状态转换表结构 typedef struct { STATES current; STATES next; bool (*condition)(void); } StateTransition; // 状态处理函数类型 typedef void (*StateHandler)(void); // 状态处理函数映射 StateHandler state_handlers[] = { [STATE_DECODING] = handle_decoding, [STATE_BUMPING] = handle_bumping, #if LIB_PIC_ERR_TOL [STATE_LIBPIC_COLLECTING] = handle_collecting #endif }; // 状态转换表 StateTransition transitions[] = { {STATE_DECODING, STATE_BUMPING, decoding_complete}, {STATE_BUMPING, STATE_DECODING, bumping_complete}, #if LIB_PIC_ERR_TOL {STATE_BUMPING, STATE_LIBPIC_COLLECTING, needs_collection}, {STATE_LIBPIC_COLLECTING, STATE_DECODING, collection_complete} #endif }; // 状态机引擎 void run_state_machine(STATES start_state) { STATES current = start_state; while (1) { // 执行当前状态处理 state_handlers[current](); // 检查状态转换 bool transitioned = false; for (int i = 0; i < sizeof(transitions)/sizeof(transitions[0]); i++) { if (transitions[i].current == current && transitions[i].condition()) { current = transitions[i].next; transitioned = true; printf("Transitioned to: %s\n", state_description(current)); break; } } if (!transitioned) { printf("No valid transition, staying in %s\n", state_description(current)); break; } } } ``` ### 条件编译最佳实践 #### 1. 模块化配置头文件 ```c // config.h #pragma once // 功能开关 #define FEATURE_LIBVC 1 #define FEATURE_ERR_TOL 1 #define FEATURE_ADVANCED 0 // 派生宏 #if FEATURE_LIBVC #define LIBVC_ON #endif #if FEATURE_ERR_TOL #define LIB_PIC_ERR_TOL #endif ``` #### 2. 编译时配置检查 ```c // 确保必要的依赖关系 #if defined(LIB_PIC_ERR_TOL) && !defined(LIBVC_ON) #error "LIB_PIC_ERR_TOL requires LIBVC_ON to be defined" #endif // 检查枚举定义完整性 #ifdef LIB_PIC_ERR_TOL _Static_assert( STATE_LIBPIC_COLLECTING == 2, "Enum order mismatch for LIB_PIC_ERR_TOL" ); #else _Static_assert( STATE_BUMPING == 1, "Enum order mismatch without LIB_PIC_ERR_TOL" ); #endif ``` #### 3. 跨平台状态序列化 ```c // 状态序列化函数 size_t serialize_state(STATES state, char* buffer, size_t size) { const char* names[] = { "DECODING", "BUMPING" #if LIB_PIC_ERR_TOL , "COLLECTING" #endif }; if (state >= sizeof(names)/sizeof(names[0])) { return 0; } size_t len = strlen(names[state]); if (len + 1 > size) { return 0; } strncpy(buffer, names[state], size); return len; } // 状态反序列化函数 STATES deserialize_state(const char* str) { if (strcmp(str, "DECODING") == 0) return STATE_DECODING; if (strcmp(str, "BUMPING") == 0) return STATE_BUMPING; #if LIB_PIC_ERR_TOL if (strcmp(str, "COLLECTING") == 0) return STATE_LIBPIC_COLLECTING; #endif return -1; // 无效状态 } ``` ### 状态机设计模式 ```mermaid stateDiagram-v2 [*] --> STATE_DECODING STATE_DECODING --> STATE_BUMPING: 完成解码 STATE_BUMPING --> STATE_DECODING: 完成碰撞处理 %% 条件状态转换 note right of STATE_BUMPING 当LIB_PIC_ERR_TOL启用时 增加额外转换路径 end note state "条件状态" as cond { STATE_BUMPING --> STATE_LIBPIC_COLLECTING: 需要收集数据 STATE_LIBPIC_COLLECTING --> STATE_DECODING: 收集完成 } %% 条件编译控制 STATE_BUMPING --> cond : if LIB_PIC_ERR_TOL cond --> STATE_DECODING : if LIB_PIC_ERR_TOL ``` ### 完整项目结构示例 ``` video_decoder/ ├── include/ │ ├── config.h // 配置宏定义 │ ├── states.h // 状态枚举定义 │ └── decoder.h // 解码器API ├── src/ │ ├── state_machine.c // 状态机实现 │ ├── libvc_handler.c // LIBVC_ON相关处理 │ ├── error_tolerance.c // LIB_PIC_ERR_TOL相关处理 │ └── main.c // 主程序 ├── CMakeLists.txt // 构建配置 └── config.cmake // CMake配置选项 ``` **CMakeLists.txt 示例**: ```cmake cmake_minimum_required(VERSION 3.10) project(video_decoder) # 配置选项 option(ENABLE_LIBVC "Enable libpics support" ON) option(ENABLE_ERR_TOL "Enable error tolerance" ON) # 添加定义 if(ENABLE_LIBVC) add_definitions(-DLIBVC_ON) endif() if(ENABLE_ERR_TOL) add_definitions(-DLIB_PIC_ERR_TOL) # 确保依赖关系 if(NOT ENABLE_LIBVC) message(FATAL_ERROR "LIB_PIC_ERR_TOL requires LIBVC support") endif() endif() # 包含头文件 include_directories(include) # 添加源文件 add_executable(decoder src/main.c src/state_machine.c src/libvc_handler.c src/error_tolerance.c ) # 条件编译源文件 if(ENABLE_LIBVC) target_sources(decoder PRIVATE src/libvc_handler.c) endif() if(ENABLE_ERR_TOL) target_sources(decoder PRIVATE src/error_tolerance.c) endif() ```
阅读全文

相关推荐

unsigned char * bs_buf5 = NULL; #endif #if MULTI_LAYER_FRAMEWORK DEC id[MAX_LAYER] = { NULL, NULL }; DEC_CDSC cdsc[MAX_LAYER]; #else DEC id = NULL; DEC_CDSC cdsc; #endif COM_BITB bitb; COM_IMGB * imgb; DEC_STAT stat; int ret; COM_CLK clk_beg, clk_tot; int bs_cnt, pic_cnt; int bs_size = 0, bs_read_pos = 0; int width, height; FILE * fp_bs = NULL; #if LIB_PIC_ERR_TOL int libpic_num_patch = 0; int *libpic_bs_size = NULL; unsigned char * libpic_bs_buf = NULL; int num_nalu = 0; int collect_libpic_state = 0; unsigned int libpic_addr = 0; #endif #if SVAC_AI_SEG_EXT fp_seg = fopen("dec_aiseg.bin", "wb"); #endif #if ENC_DEC_TRACE fp_trace = NULL; #endif #if CU_LEVEL_PRIVACY unsigned int libpic_addr_privacy = 0; int *libpic_bs_size_privacy = NULL; unsigned char * libpic_bs_buf_privacy = NULL; int num_nalu_privacy = 0; #endif #if LINUX signal(SIGSEGV, handler); // install our handler #endif #if DECODING_TIME_TEST clk_beg = com_clk_get(); #endif /* parse options */ ret = com_args_parse_all(argc, argv, options); if(ret != 0) { if(ret > 0) v0print("-%c argument should be set\n", ret); print_usage(); return -1; } /* open input bitstream */ fp_bs = fopen(op_fname_inp, "rb"); if(fp_bs == NULL) { v0print("ERROR: cannot open bitstream file = %s\n", op_fname_inp); print_usage(); return -1; } if(op_flag[OP_FLAG_FNAME_OUT]) { /* remove decoded file contents if exists */ FILE * fp; #if MULTI_LAYER_FRAMEWORK fp = fopen(op_fname_out[0], "wb"); #else fp = fopen(op_fname_out, "wb"); #endif if(fp == NULL) { v0print("ERROR: cannot create a decoded file\n"); print_usage(); return -1; } fclose(fp); } #if MULTI_LAYER_FRAMEWORK if (op_flag[OP_FLAG_FNAME_OUT1]) { /* remove decoded file contents if exists */ FILE* fp; fp = fopen(op_fname_out[1], "wb"); if (fp == NULL) { v0print("ERROR: cannot create a EL decoded file\n"); print_usage(); return -1; } fclose(fp); } #endif bs_buf = malloc(MAX_BS_BUF); if(bs_buf == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } bs_buf2 = malloc(MAX_BS_BUF); if (bs_buf2 == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } #if SVAC_UD_MD5_STREAM bs_buf5 = malloc(MAX_BS_BUF); if (bs_buf5 == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } bitb.addr3 = bs_buf5; bitb.addr3_beg = bs_buf5; bs_buf4 = malloc(MAX_BS_BUF); if (bs_buf4 == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } unsigned char * buf4_p = bs_buf4; unsigned char * buf4_beg = bs_buf4; #endif #if CU_LEVEL_PRIVACY unsigned char *bs_buf3 = malloc(MAX_BS_BUF); if (bs_buf3 == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } #endif #if LIBVC_ON #if MULTI_LAYER_FRAMEWORK LibVCData libvc_data[MAX_LAYER]; for (int i = 0; i < MAX_LAYER; i++) { init_libvcdata(&libvc_data[i]); } #else LibVCData libvc_data; init_libvcdata(&libvc_data); #endif if (op_flag[OP_FLAG_FNAME_INP_LIBPICS]) { #if MULTI_LAYER_FRAMEWORK int err; for (int i = 0; i < MAX_LAYER; i++) { err = decode_libpics(&cdsc[i], &libvc_data[i]); if (err) { v0print("Error when decode lib pic!"); return -1; } libvc_data[i].is_libpic_prepared = 1; } #else int err = decode_libpics(&cdsc, &libvc_data); if (err) { v0print("Error when decode lib pic!"); return -1; } libvc_data.is_libpic_prepared = 1; #endif } #endif #if MULTI_LAYER_FRAMEWORK for (int i = 0; i < MAX_LAYER; i++) { id[i] = dec_create(&cdsc[i], NULL); dec_setlayer(id[i],i); if (id[i] == NULL) { v0print("ERROR: cannot create decoder\n"); return -1; } } #else id = dec_create(&cdsc, NULL); if(id == NULL) { v0print("ERROR: cannot create decoder\n"); return -1; } #endif #if LIBVC_ON #if MULTI_LAYER_FRAMEWORK for (int i = 0; i < MAX_LAYER; i++) { set_livcdata_dec(id[i], &libvc_data[i]); } #else set_livcdata_dec(id, &libvc_data); #endif #endif #if MULTI_LAYER_FRAMEWORK for (int i = 0; i < MAX_LAYER; i++) { if (set_extra_config(id[i])) { v0print("ERROR: cannot set extra configurations\n"); return -1; } } #else if (set_extra_config(id)) { v0print("ERROR: cannot set extra configurations\n"); return -1; } #endif pic_cnt = 0; clk_tot = 0; bs_cnt = 0; width = height = 0; #if MULTI_LAYER_FRAMEWORK for (int i = 0; i < MAX_LAYER; i++) { g_CountDOICyCleTime[i] = 0; // initialized the number . g_DOIPrev[i] = 0; } #else g_CountDOICyCleTime = 0; // initialized the number . g_DOIPrev = 0; #endif #if CU_LEVEL_PRIVACY int bs_buf3_size = 0; #endif while (1) { #if MULTI_LAYER_FRAMEWORK int nal_layer_id = 0; #endif if (state == STATE_DECODING) { bs_size = read_a_bs(fp_bs, &bs_read_pos, bs_buf, bs_buf2 #if CU_LEVEL_PRIVACY , bs_buf3, &bs_buf3_size #endif #if SVAC_UD_MD5_STREAM , &bitb #endif ); if (bs_size <= 0) { state = STATE_BUMPING; v1print("bumping process starting...\n"); continue; } bs_read_pos += bs_size; bitb.addr = bs_buf; #if CU_LEVEL_PRIVACY bitb.addr2 = bs_buf3; bitb.ssize2 = bs_buf3_size; bitb.ssize = bs_size - bs_buf3_size; #else bitb.ssize = bs_size; #endif bitb.bsize = MAX_BS_BUF; #if MULTI_LAYER_FRAMEWORK nal_layer_id = (bs_buf[4] >> 1) & 0x07; if (nal_layer_id == 0) { v1print("BL---[%4d]-th BS (%07dbytes) --> ", bs_cnt++, bs_size); } else { v1print("EL---[%4d]-th BS (%07dbytes) --> ", bs_cnt++, bs_size); } #else v1print("[%4d]-th BS (%07dbytes) --> ", bs_cnt++, bs_size); #endif #if LIB_PIC_ERR_TOL #if SVAC_PROGRESSIVE // 7 6 5 4 3 & 2 // temporal_nesting library_picture_enable library_stream duplicate_sqh library_picture_mode_index int library_picture_enable = bs_buf[7] & 0x40; int library_stream_flag = bs_buf[7] & 0x20; int library_picture_mode_index = (bs_buf[7] >> 2) & 3; #else // 7 6 5 4 3 2 1 & 0 // progressive_sequence field_coded_sequence temporal_nesting library_picture_enable library_stream duplicate_sqh library_picture_mode_index int library_picture_enable = bs_buf[7] & 0x10; int library_picture_enable_flag = bs_buf[7] & 8; #if EMULATION_PREVENT_BUGFIX int library_picture_mode_index = bs_buf[7] & 3; #else int library_picture_mode_index = ((bs_buf[7] & 1) << 1) + (bs_buf[8] >> 7); #endif #endif if (bs_buf[3] == SVAC_SPS && library_stream_flag && library_picture_mode_index == 0) { if (libpic_bs_buf == NULL) { libpic_bs_buf = malloc(MAX_BS_BUF); if (libpic_bs_buf == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } } if (libpic_bs_size == NULL) { libpic_bs_size = malloc(sizeof(int) * 260); if (libpic_bs_size == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } } #if CU_LEVEL_PRIVACY if (libpic_bs_buf_privacy == NULL) { libpic_bs_buf_privacy = malloc(MAX_BS_BUF); if (libpic_bs_buf_privacy == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } } if (libpic_bs_size_privacy == NULL) { libpic_bs_size_privacy = malloc(sizeof(int) * 260); if (libpic_bs_size_privacy == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } } num_nalu_privacy = 0; #endif memcpy(libpic_bs_buf, bs_buf, bs_real_size); state = STATE_LIBPIC_COLLECTING; libpic_bs_size[0] = bs_real_size; collect_libpic_state = 1; num_nalu = 1; libpic_addr = bs_real_size; #if SVAC_UD_MD5_STREAM unsigned int tmp_bs_size = (unsigned int)((unsigned char *)bitb.addr3 - (unsigned char *)bitb.addr3_beg); memcpy(buf4_p, bitb.addr3_beg, tmp_bs_size); buf4_p = buf4_p + tmp_bs_size; bitb.addr3 = (unsigned char *)bitb.addr3_beg; #endif continue; } else if (bs_buf[3] == SVAC_SPS && library_picture_enable && library_stream_flag == 0 && library_picture_mode_index == 0) { libpic_addr = 0; #if CU_LEVEL_PRIVACY libpic_addr_privacy = 0; #endif #if SVAC_UD_MD5_STREAM bitb.addr3_beg = buf4_beg; buf4_beg = bs_buf5; unsigned char * tmp_p = buf4_p; buf4_p = bitb.addr3; bitb.addr3 = tmp_p; #endif for (int i = 0; i < num_nalu; i++) { #if !DECODING_TIME_TEST clk_beg = com_clk_get(); #endif /* main decoding block */ bitb.addr = libpic_bs_buf + libpic_addr; bitb.ssize = libpic_bs_size[i] - 4; bitb.bsize = MAX_BS_BUF; libpic_addr += libpic_bs_size[i]; #if CU_LEVEL_PRIVACY if (i >= num_nalu - num_nalu_privacy) { bitb.addr2 = libpic_bs_buf_privacy + libpic_addr_privacy; bitb.ssize2 = libpic_bs_size_privacy[i - num_nalu + num_nalu_privacy] + 4 ; libpic_addr_privacy += libpic_bs_size_privacy[i - num_nalu + num_nalu_privacy]; } #endif #if MULTI_LAYER_FRAMEWORK ret = dec_cnk((DEC_CTX*)id[0], &bitb, &stat); #else ret = dec_cnk((DEC_CTX*)id, &bitb, &stat); #endif if (stat.ctype == COM_CT_SEQ_END) { state = STATE_BUMPING; v1print("bumping process starting...\n"); continue; } if (COM_FAILED(ret)) { v0print("failed to decode bitstream\n"); return -1; } #if !DECODING_TIME_TEST clk_tot += com_clk_from(clk_beg); #endif print_stat(&stat, ret); } #if SVAC_UD_MD5_STREAM bitb.addr3_beg = buf4_beg; bitb.addr3 = buf4_p; buf4_beg = bs_buf4; buf4_p = bs_buf4; #endif num_nalu = 0; libpic_addr = 0; bitb.addr = bs_buf; bitb.ssize = bs_size; bitb.bsize = MAX_BS_BUF; } #endif #if !DECODING_TIME_TEST clk_beg = com_clk_get(); #endif /* main decoding block */ #if MULTI_LAYER_FRAMEWORK if (nal_layer_id == 0) { DEC_CTX* ctx_t = (DEC_CTX*)id[0]; ctx_t->ctx_e = id[1]; ret = dec_cnk((DEC_CTX*)id[0], &bitb, &stat); } else { DEC_CTX* ctx_e = (DEC_CTX*)id[nal_layer_id]; assert(ctx_e->layer_id == nal_layer_id); if (!ctx_e->init_sps_pps) { DEC_CTX* ctx_b = (DEC_CTX*)id[0]; ctx_e->ctx_b =id[ctx_b->info.sqh.ref_layer_id[nal_layer_id]]; COM_SQH* sqh_e = &ctx_e->info.sqh; COM_SQH* sqh_b = &ctx_b->info.sqh; memcpy(sqh_e, sqh_b, sizeof(COM_SQH)); COM_PIC_PARA_SET* pps_e = &ctx_e->info.pps[0]; memcpy(pps_e, ctx_b->info.pps, sizeof(COM_PIC_PARA_SET)); #if LIBVC_ON ctx_e->dpm.libvc_data->is_libpic_processing = sqh_b->library_stream_flag; ctx_e->dpm.libvc_data->library_picture_enable_flag = sqh_b->library_picture_enable_flag; #endif #if HIGH_LEVEL_PRIVACY COM_PRIVACY* pri_e = &ctx_e->ctx_privacy_data; COM_PRIVACY* pri_b = &ctx_b->ctx_privacy_data; memcpy(pri_e, pri_b, sizeof(COM_PRIVACY)); #endif } ret = dec_cnk((DEC_CTX*)id[nal_layer_id], &bitb, &stat); } #else ret = dec_cnk((DEC_CTX*)id, &bitb, &stat); #endif if (stat.ctype == COM_CT_SEQ_END) { state = STATE_BUMPING; v1print("bumping process starting...\n"); continue; } if (COM_FAILED(ret)) { v0print("failed to decode bitstream\n"); return -1; } #if !DECODING_TIME_TEST clk_tot += com_clk_from(clk_beg); #endif print_stat(&stat, ret); } #if LIB_PIC_ERR_TOL if (state == STATE_LIBPIC_COLLECTING) { bs_size = read_a_bs(fp_bs, &bs_read_pos, bs_buf, bs_buf2 #if CU_LEVEL_PRIVACY , bs_buf3, &bs_buf3_size #endif #if SVAC_UD_MD5_STREAM , &bitb #endif ); if (bs_size <= 0) { state = STATE_BUMPING; v1print("bumping process starting...\n"); continue; } bs_read_pos += bs_size; bitb.addr = bs_buf; bitb.ssize = bs_size; bitb.bsize = MAX_BS_BUF; #if CU_LEVEL_PRIVACY bitb.addr2 = bs_buf3; bitb.ssize2 = bs_buf3_size; #endif v1print("[%4d]-th BS (%07dbytes) --> ", bs_cnt++, bs_size); if (bs_buf[3] == SVAC_PPS && collect_libpic_state == 1) { memcpy(libpic_bs_buf + libpic_addr, bs_buf, bs_real_size); libpic_bs_size[num_nalu++] = bs_real_size; collect_libpic_state = 2; libpic_addr += bs_real_size; #if SVAC_UD_MD5_STREAM unsigned int tmp_bs_size = (unsigned int)((unsigned char *)bitb.addr3 - (unsigned char *)bitb.addr3_beg); memcpy(buf4_p, bitb.addr3_beg, tmp_bs_size); buf4_p = buf4_p + tmp_bs_size; bitb.addr3 = (unsigned char *)bitb.addr3_beg; #endif continue; } else if (bs_buf[3] == SVAC_PH && collect_libpic_state == 2) { memcpy(libpic_bs_buf + libpic_addr, bs_buf, bs_real_size); libpic_bs_size[num_nalu++] = bs_real_size; collect_libpic_state = 3; libpic_addr += bs_real_size; #if SVAC_UD_MD5_STREAM unsigned int tmp_bs_size = (unsigned int)((unsigned char *)bitb.addr3 - (unsigned char *)bitb.addr3_beg); memcpy(buf4_p, bitb.addr3_beg, tmp_bs_size); buf4_p = buf4_p + tmp_bs_size; bitb.addr3 = (unsigned char *)bitb.addr3_beg; #endif continue; } else if (bs_buf[3] == SVAC_CRR_DL) { memcpy(libpic_bs_buf + libpic_addr, bs_buf, bs_real_size); libpic_bs_size[num_nalu++] = bs_real_size; assert(collect_libpic_state == 3 || collect_libpic_state == 4); libpic_addr += bs_real_size; #if SVAC_UD_MD5_STREAM unsigned int tmp_bs_size = (unsigned int)((unsigned char *)bitb.addr3 - (unsigned char *)bitb.addr3_beg); memcpy(buf4_p, bitb.addr3_beg, tmp_bs_size); buf4_p = buf4_p + tmp_bs_size; bitb.addr3 = (unsigned char *)bitb.addr3_beg; #endif #if CU_LEVEL_PRIVACY memcpy(libpic_bs_buf_privacy + libpic_addr_privacy, bs_buf3, bs_buf3_size); libpic_bs_size_privacy[num_nalu_privacy++] = bs_buf3_size; libpic_addr_privacy += bs_buf3_size; #endif if (collect_libpic_state == 3) collect_libpic_state = 4; else if (collect_libpic_state == 4) { state = STATE_DECODING; } continue; } else if (bs_buf[3] == SVAC_CRR_L) { memcpy(libpic_bs_buf + libpic_addr, bs_buf, bs_real_size); libpic_bs_size[num_nalu++] = bs_real_size; assert(collect_libpic_state == 3 || collect_libpic_state == 4); libpic_addr += bs_real_size; #if CU_LEVEL_PRIVACY memcpy(libpic_bs_buf_privacy + libpic_addr_privacy, bs_buf3, bs_buf3_size); libpic_bs_size_privacy[num_nalu_privacy++] = bs_buf3_size; libpic_addr_privacy += bs_buf3_size; #endif #if SVAC_UD_MD5_STREAM unsigned int tmp_bs_size = (unsigned int)((unsigned char *)bitb.addr3 - (unsigned char *)bitb.addr3_beg); memcpy(buf4_p, bitb.addr3_beg, tmp_bs_size); buf4_p = buf4_p + tmp_bs_size; bitb.addr3 = (unsigned char *)bitb.addr3_beg; #endif if (collect_libpic_state == 3) { state = STATE_DECODING; } continue; } else if (bs_buf[3] == SVAC_SPS && (bs_buf[7] & 16) && (bs_buf[7] & 8) == 0) { v0print("ERROR: not recieve enough libpic NALU\n"); return -1; } #if !DECODING_TIME_TEST clk_beg = com_clk_get(); #endif /* main decoding block */ #if MULTI_LAYER_FRAMEWORK ret = dec_cnk((DEC_CTX*)id[0], &bitb, &stat); #else ret = dec_cnk((DEC_CTX*)id, &bitb, &stat); #endif if (stat.ctype == COM_CT_SEQ_END) { state = STATE_BUMPING; v1print("bumping process starting...\n"); continue; } if (COM_FAILED(ret)) { v0print("failed to decode bitstream\n"); return -1; } #if !DECODING_TIME_TEST clk_tot += com_clk_from(clk_beg); #endif print_stat(&stat, ret); } #endif if (stat.fnum >= 0 || state == STATE_BUMPING) { #if MULTI_LAYER_FRAMEWORK ret = dec_pull_frm((DEC_CTX*)id[nal_layer_id], &imgb, state); #else ret = dec_pull_frm((DEC_CTX*)id, &imgb, state); #endif if (ret == COM_ERR_UNEXPECTED) { v1print("bumping process completed\n"); if (bs_size <= 0) { goto END; } else { state = STATE_DECODING; } } else if (COM_FAILED(ret)) { v0print("failed to pull the decoded image\n"); return -1; } } else { imgb = NULL; } if (imgb) { width = imgb->width[0]; height = imgb->height[0]; #if LIB_PIC_MIXBIN #if MULTI_LAYER_FRAMEWORK if (!((DEC_CTX*)id[0])->info.sqh.library_stream_flag #else if (!((DEC_CTX*)id)->info.sqh.library_stream_flag #endif #if LIBPIC_DISPLAY #if MULTI_LAYER_FRAMEWORK || (((DEC_CTX*)id[0])->info.sqh.library_stream_flag && ((DEC_CTX*)id[0])->info.sqh.library_picture_mode_index == 1) #else || (((DEC_CTX*)id)->info.sqh.library_stream_flag && ((DEC_CTX*)id)->info.sqh.library_picture_mode_index == 1) #endif #endif ) { #endif #if MULTI_LAYER_FRAMEWORK if (op_flag[OP_FLAG_FNAME_OUT] && nal_layer_id == 0) { write_dec_img(id[0], op_fname_out[0], imgb, ((DEC_CTX*)id[0])->info.bit_depth_internal); } if (op_flag[OP_FLAG_FNAME_OUT1] && nal_layer_id == 1) { write_dec_img(id[1], op_fname_out[1], imgb, ((DEC_CTX*)id[1])->info.bit_depth_internal); } #else if (op_flag[OP_FLAG_FNAME_OUT]) { write_dec_img(id, op_fname_out, imgb, ((DEC_CTX*)id)->info.bit_depth_internal); } #endif imgb->release(imgb); pic_cnt++; #if LIB_PIC_MIXBIN } else if (op_flag[OP_FLAG_FNAME_OUT_LIBPICS]) { #if MULTI_LAYER_FRAMEWORK write_dec_img(id[0], op_fname_out_libpics, imgb, ((DEC_CTX*)id[0])->info.bit_depth_internal); #else write_dec_img(id, op_fname_out_libpics, imgb, ((DEC_CTX*)id)->info.bit_depth_internal); #endif } #endif } } END: #if DECODING_TIME_TEST clk_tot += com_clk_from(clk_beg); #endif v1print("===========================================================\n"); v1print("Resolution (decoding) = %d x %d\n", width, height); #if MULTI_LAYER_FRAMEWORK v1print("BL Resolution (output) = %d x %d\n", ((DEC_CTX*)id[0])->info.sqh.horizontal_size[0], ((DEC_CTX*)id[0])->info.sqh.vertical_size[0]); v1print("EL1 Resolution (output) = %d x %d\n", ((DEC_CTX*)id[0])->info.sqh.horizontal_size[1], ((DEC_CTX*)id[0])->info.sqh.vertical_size[1]); #else v1print("Resolution (output) = %d x %d\n", ((DEC_CTX *)id)->info.sqh.horizontal_size, ((DEC_CTX *)id)->info.sqh.vertical_size); #endif v1print("Processed BS count = %d\n", bs_cnt); v1print("Decoded frame count = %d\n", pic_cnt); if(pic_cnt > 0) { v1print("total decoding time = %d msec,", (int)com_clk_msec(clk_tot)); v1print(" %.3f sec\n", (float)(com_clk_msec(clk_tot) /1000.0)); v1print("Average decoding time for a frame = %d msec\n", (int)com_clk_msec(clk_tot)/pic_cnt); v1print("Average decoding speed = %.3f frames/sec\n", ((float)pic_cnt*1000)/((float)com_clk_msec(clk_tot))); } v1print("===========================================================\n"); if (op_flag[OP_FLAG_USE_PIC_SIGN] && pic_cnt > 0) { v1print("Decode Match: 1 (HASH)\n"); #if SVAC_UD_MD5_STREAM #if MULTI_LAYER_FRAMEWORK if (((DEC_CTX *)id[0])->stream_sign_check_flag) #else if (((DEC_CTX *)id)->stream_sign_check_flag) #endif v1print("Stream Decode Match: 1 (HASH)\n"); #endif v1print("===========================================================\n"); } #if MULTI_LAYER_FRAMEWORK for (int i = 0; i < MAX_LAYER; i++) { if (id[i]) dec_delete(id[i]); } #else if(id) dec_delete(id); #endif if(fp_bs) fclose(fp_bs); if(bs_buf) free(bs_buf); if (bs_buf2) { free(bs_buf2); bs_buf2 = NULL; } #if CU_LEVEL_PRIVACY if (bs_buf3) { free(bs_buf3); bs_buf3 = NULL; } #endif #if SVAC_UD_MD5_STREAM if (bs_buf5) { free(bs_buf5); bs_buf5 = NULL; } if (bs_buf4) { free(bs_buf4); bs_buf4 = NULL; } #endif #if LIBVC_ON #if MULTI_LAYER_FRAMEWORK for (int i = 0; i < MAX_LAYER; i++) { delete_libvcdata(&libvc_data[i]); } #else delete_libvcdata(&libvc_data); #endif #endif #if ENC_DEC_TRACE if( fp_trace ) { fclose( fp_trace ); fp_trace = NULL; } #endif #if SVAC_AI_SEG_EXT if (fp_seg) { fclose(fp_seg); fp_seg = NULL; } #endif return 0; }对这段代码做注释

static COM_ARGS_OPTION options[] = \ { { 'i', "input", ARGS_TYPE_STRING | ARGS_TYPE_MANDATORY, &op_flag[OP_FLAG_FNAME_INP], op_fname_inp, "file name of input bitstream"}, #if MULTI_LAYER_FRAMEWORK { 'o', "output", ARGS_TYPE_STRING, &op_flag[OP_FLAG_FNAME_OUT], op_fname_out[0],"file name of decoded output" }, { 'e', "output1", ARGS_TYPE_STRING, &op_flag[OP_FLAG_FNAME_OUT1], op_fname_out[1],"file name of decoded output" }, #else { 'o', "output", ARGS_TYPE_STRING, &op_flag[OP_FLAG_FNAME_OUT], op_fname_out,"file name of decoded output" }, #endif { 'f', "frames", ARGS_TYPE_INTEGER, &op_flag[OP_FLAG_MAX_FRM_NUM], &op_max_frm_num,"maximum number of frames to be decoded" }, { 's', "signature", COM_ARGS_VAL_TYPE_NONE, &op_flag[OP_FLAG_USE_PIC_SIGN], &op_use_pic_signature,"conformance check using picture signature (HASH)" }, { 'c', "clip_org_size", COM_ARGS_VAL_TYPE_NONE, &op_flag[OP_FLAG_CLIP_ORG_SIZE], &op_clip_org_size,"clip the output size to the original size (the input size at the encoder side)" }, { COM_ARGS_NO_KEY, "output_bit_depth", ARGS_TYPE_INTEGER, &op_flag[OP_FLAG_OUT_BIT_DEPTH], &op_bit_depth_output_cfg, "output bitdepth : 8 / 10 (default: internal bitdepth)" }, #if CU_LEVEL_PRIVACY { 'u', "user_permission", ARGS_TYPE_INTEGER , &op_flag[OP_USER_PERMISSION], &op_user_permission, "decoder user permission: 0 / 1 (default: 0)" }, #endif { 'v', "verbose", ARGS_TYPE_INTEGER, &op_flag[OP_FLAG_VERBOSE], &op_verbose, "verbose level\n" "\t 0: no message\n" "\t 1: frame-level messages (default)\n" "\t 2: all messages\n" }, #if LIBVC_ON { COM_ARGS_NO_KEY, "input_libpics", ARGS_TYPE_STRING, &op_flag[OP_FLAG_FNAME_INP_LIBPICS], op_fname_inp_libpics, "file name of input libpics bitstream" }, { COM_ARGS_NO_KEY, "output_libpics", ARGS_TYPE_STRING, &op_flag[OP_FLAG_FNAME_OUT_LIBPICS], op_fname_out_libpics, "file name of decoded libpics output" }, #endif { 0, "", COM_ARGS_VAL_TYPE_NONE, NULL, NULL, "" } /* termination */ };

int decode_libpics(DEC_CDSC * cdsc, LibVCData* libvc_data) { STATES state_lib = STATE_DECODING; unsigned char * bs_buf_lib = NULL; unsigned char * bs_buf_lib2 = NULL; DEC id_lib = NULL; COM_BITB bitb_lib; COM_IMGB * imgb_lib; DEC_STAT stat_lib; int ret; COM_CLK clk_beg_lib, clk_tot_lib; int bs_cnt_lib, pic_cnt_lib; int bs_size_lib, bs_read_pos_lib = 0; int width_lib, height_lib; FILE * fp_bs_lib = NULL; #if LINUX signal(SIGSEGV, handler); // install our handler #endif #if DECODING_TIME_TEST clk_beg_lib = com_clk_get(); #endif /* open input bitstream */ fp_bs_lib = fopen(op_fname_inp_libpics, "rb"); if (fp_bs_lib == NULL) { v0print("ERROR: cannot open libpics bitstream file = %s\n", op_fname_inp_libpics); print_usage(); return -1; } if (op_flag[OP_FLAG_FNAME_OUT_LIBPICS]) { /* remove decoded file contents if exists */ FILE * fp; fp = fopen(op_fname_out_libpics, "wb"); if (fp == NULL) { v0print("ERROR: cannot create a decoded libpics file\n"); print_usage(); return -1; } fclose(fp); } bs_buf_lib = malloc(MAX_BS_BUF); if (bs_buf_lib == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } bs_buf_lib2 = malloc(MAX_BS_BUF); if (bs_buf_lib2 == NULL) { v0print("ERROR: cannot allocate bit buffer, size2=%d\n", MAX_BS_BUF); return -1; } #if CU_LEVEL_PRIVACY unsigned char *bs_buf_lib3 = malloc(MAX_BS_BUF); if (bs_buf_lib3 == NULL) { v0print("ERROR: cannot allocate bit buffer, size2=%d\n", MAX_BS_BUF); return -1; } #endif #if SVAC_UD_MD5_STREAM unsigned char * bs_buf4 = NULL; unsigned char * bs_buf5 = NULL; bs_buf5 = malloc(MAX_BS_BUF); if (bs_buf5 == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } bitb_lib.addr3 = bs_buf5; bitb_lib.addr3_beg = bs_buf5; bs_buf4 = malloc(MAX_BS_BUF); if (bs_buf4 == NULL) { v0print("ERROR: cannot allocate bit buffer, size=%d\n", MAX_BS_BUF); return -1; } unsigned char * buf4_p = bs_buf4; unsigned char * buf4_beg = bs_buf4; #endif id_lib = dec_create(cdsc, NULL); if (id_lib == NULL) { v0print("ERROR: cannot create decoder\n"); return -1; } set_livcdata_dec(id_lib, libvc_data); if (set_extra_config(id_lib)) { v0print("ERROR: cannot set extra configurations\n"); return -1; } pic_cnt_lib = 0; clk_tot_lib = 0; bs_cnt_lib = 0; width_lib = height_lib = 0; #if CU_LEVEL_PRIVACY int bs_buf3_size = 0; #endif while (1) { if (state_lib == STATE_DECODING) { bs_size_lib = read_a_bs(fp_bs_lib, &bs_read_pos_lib, bs_buf_lib, bs_buf_lib2 #if CU_LEVEL_PRIVACY , bs_buf_lib3, &bs_buf3_size #endif #if SVAC_UD_MD5_STREAM , &bitb_lib #endif ); if (bs_size_lib <= 0) { state_lib = STATE_BUMPING; v1print("bumping process starting...\n"); continue; } bs_read_pos_lib += (bs_size_lib); bitb_lib.addr = bs_buf_lib; bitb_lib.ssize = bs_size_lib; bitb_lib.bsize = MAX_BS_BUF; #if CU_LEVEL_PRIVACY bitb_lib.addr2 = bs_buf_lib3; bitb_lib.ssize2 = bs_buf3_size; #endif #if !DECODING_TIME_TEST clk_beg_lib = com_clk_get(); #endif /* main decoding block */ ret = dec_cnk((DEC_CTX *)id_lib, &bitb_lib, &stat_lib); if (COM_FAILED(ret)) { v0print("failed to decode bitstream\n"); return -1; } #if !DECODING_TIME_TEST clk_tot_lib += com_clk_from(clk_beg_lib); #endif } if (stat_lib.fnum >= 0 || state_lib == STATE_BUMPING) { ret = dec_pull_frm((DEC_CTX *)id_lib, &imgb_lib, state_lib); if (ret == COM_ERR_UNEXPECTED) { v1print("bumping process completed\n"); goto END; } else if (COM_FAILED(ret)) { v0print("failed to pull the decoded image\n"); return -1; } } else { imgb_lib = NULL; } if (imgb_lib) { width_lib = imgb_lib->width[0]; height_lib = imgb_lib->height[0]; if (op_flag[OP_FLAG_FNAME_OUT_LIBPICS]) { write_dec_img(id_lib, op_fname_out_libpics, imgb_lib, ((DEC_CTX *)id_lib)->info.bit_depth_internal); } imgb_lib->release(imgb_lib); pic_cnt_lib++; } } END: #if DECODING_TIME_TEST clk_tot_lib += com_clk_from(clk_beg_lib); #endif libvc_data->num_lib_pic = pic_cnt_lib; #if CU_LEVEL_PRIVACY if (bs_buf_lib3) { free(bs_buf_lib3); bs_buf_lib3 = NULL; } #endif if (id_lib) dec_delete(id_lib); if (fp_bs_lib) fclose(fp_bs_lib); if (bs_buf_lib) free(bs_buf_lib); return 0; } #endif

/*---------------------------------------------------------------------------/ / FatFs - FAT file system module include file R0.09 (C)ChaN, 2011 /----------------------------------------------------------------------------/ / FatFs module is a generic FAT file system module for small embedded systems. / This is a free software that opened for education, research and commercial / developments under license policy of following trems. / / Copyright (C) 2011, ChaN, all right reserved. / / * The FatFs module is a free software and there is NO WARRANTY. / * No restriction on use. You can use, modify and redistribute it for / personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY. / * Redistributions of source code must retain the above copyright notice. / /----------------------------------------------------------------------------*/ #ifndef _FATFS #define _FATFS 6502 /* Revision ID */ #ifdef __cplusplus extern "C" { #endif #include "integer.h" /* Basic integer types */ #include "ffconf.h" /* FatFs configuration options */ #include "HeaderFiles.h" #if _FATFS != _FFCONF #error Wrong configuration file (ffconf.h). #endif /* Definitions of volume management */ #if _MULTI_PARTITION /* Multiple partition configuration */ typedef struct { BYTE pd; /* Physical drive number */ BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */ } PARTITION; extern PARTITION VolToPart[]; /* Volume - Partition resolution table */ #define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive number */ #define LD2PT(vol) (VolToPart[vol].pt) /* Get partition index */ #else /* Single partition configuration */ #define LD2PD(vol) (vol) /* Each logical drive is bound to the same physical drive number */ #define LD2PT(vol) 0 /* Always mounts the 1st partition or in SFD */ #endif /* Type of path name strings on FatFs API */ #if _LFN_UNICODE /* Unicode string */ #if !_USE_LFN #error _LFN_UNICODE must be 0 in non-LFN cfg. #endif #ifndef _INC_TCHAR typedef WCHAR TCHAR; #define _T(x) L ## x #define _TEXT(x) L ## x #endif #else /* ANSI/OEM string */ #ifndef _INC_TCHAR typedef char TCHAR; #define _T(x) x #define _TEXT(x) x #endif #endif /* File system object structure (FATFS) */ typedef struct { BYTE fs_type; /* FAT sub-type (0:Not mounted) */ BYTE drv; /* Physical drive number */ BYTE csize; /* Sectors per cluster (1,2,4...128) */ BYTE n_fats; /* Number of FAT copies (1,2) */ BYTE wflag; /* win[] dirty flag (1:must be written back) */ BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */ WORD id; /* File system mount ID */ WORD n_rootdir; /* Number of root directory entries (FAT12/16) */ #if _MAX_SS != 512 WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */ #endif #if _FS_REENTRANT _SYNC_t sobj; /* Identifier of sync object */ #endif #if !_FS_READONLY DWORD last_clust; /* Last allocated cluster */ DWORD free_clust; /* Number of free clusters */ DWORD fsi_sector; /* fsinfo sector (FAT32) */ #endif #if _FS_RPATH DWORD cdir; /* Current directory start cluster (0:root) */ #endif DWORD n_fatent; /* Number of FAT entries (= number of clusters + 2) */ DWORD fsize; /* Sectors per FAT */ DWORD fatbase; /* FAT start sector */ DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */ DWORD database; /* Data start sector */ DWORD winsect; /* Current sector appearing in the win[] */ BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and Data on tiny cfg) */ } FATFS; /* File object structure (FIL) */ typedef struct { FATFS* fs; /* Pointer to the owner file system object */ WORD id; /* Owner file system mount ID */ BYTE flag; /* File status flags */ BYTE pad1; DWORD fptr; /* File read/write pointer (0 on file open) */ DWORD fsize; /* File size */ DWORD sclust; /* File start cluster (0 when fsize==0) */ DWORD clust; /* Current cluster */ DWORD dsect; /* Current data sector */ #if !_FS_READONLY DWORD dir_sect; /* Sector containing the directory entry */ BYTE* dir_ptr; /* Ponter to the directory entry in the window */ #endif #if _USE_FASTSEEK DWORD* cltbl; /* Pointer to the cluster link map table (null on file open) */ #endif #if _FS_SHARE UINT lockid; /* File lock ID (index of file semaphore table) */ #endif #if !_FS_TINY BYTE buf[_MAX_SS]; /* File data read/write buffer */ #endif } FIL; /* Directory object structure (DIR) */ typedef struct { FATFS* fs; /* Pointer to the owner file system object */ WORD id; /* Owner file system mount ID */ WORD index; /* Current read/write index number */ DWORD sclust; /* Table start cluster (0:Root dir) */ DWORD clust; /* Current cluster */ DWORD sect; /* Current sector */ BYTE* dir; /* Pointer to the current SFN entry in the win[] */ BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */ #if _USE_LFN WCHAR* lfn; /* Pointer to the LFN working buffer */ WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */ #endif } DIR; /* File status structure (FILINFO) */ typedef struct { DWORD fsize; /* File size */ WORD fdate; /* Last modified date */ WORD ftime; /* Last modified time */ BYTE fattrib; /* Attribute */ TCHAR fname[13]; /* Short file name (8.3 format) */ #if _USE_LFN TCHAR* lfname; /* Pointer to the LFN buffer */ UINT lfsize; /* Size of LFN buffer in TCHAR */ #endif } FILINFO; /* File function return code (FRESULT) */ typedef enum { FR_OK = 0, /* (0) Succeeded */ FR_DISK_ERR, /* (1) A hard error occured in the low level disk I/O layer */ FR_INT_ERR, /* (2) Assertion failed */ FR_NOT_READY, /* (3) The physical drive cannot work */ FR_NO_FILE, /* (4) Could not find the file */ FR_NO_PATH, /* (5) Could not find the path */ FR_INVALID_NAME, /* (6) The path name format is invalid */ FR_DENIED, /* (7) Acces denied due to prohibited access or directory full */ FR_EXIST, /* (8) Acces denied due to prohibited access */ FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */ FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */ FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */ FR_NOT_ENABLED, /* (12) The volume has no work area */ FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */ FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */ FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */ FR_LOCKED, /* (16) The operation is rejected according to the file shareing policy */ FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */ FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_SHARE */ FR_INVALID_PARAMETER /* (19) Given parameter is invalid */ } FRESULT; /*--------------------------------------------------------------*/ /* FatFs module application interface */ FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */ FRESULT f_open (FIL*, const TCHAR*, BYTE); /* Open or create a file */ FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */ FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */ FRESULT f_close (FIL*); /* Close an open file object */ FRESULT f_opendir (DIR*, const TCHAR*); /* Open an existing directory */ FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */ FRESULT f_stat (const TCHAR*, FILINFO*); /* Get file status */ FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */ FRESULT f_getfree (const TCHAR*, DWORD*, FATFS**); /* Get number of free clusters on the drive */ FRESULT f_truncate (FIL*); /* Truncate file */ FRESULT f_sync (FIL*); /* Flush cached data of a writing file */ FRESULT f_unlink (const TCHAR*); /* Delete an existing file or directory */ FRESULT f_mkdir (const TCHAR*); /* Create a new directory */ FRESULT f_chmod (const TCHAR*, BYTE, BYTE); /* Change attriburte of the file/dir */ FRESULT f_utime (const TCHAR*, const FILINFO*); /* Change timestamp of the file/dir */ FRESULT f_rename (const TCHAR*, const TCHAR*); /* Rename/Move a file or directory */ FRESULT f_chdrive (BYTE); /* Change current drive */ FRESULT f_chdir (const TCHAR*); /* Change current directory */ FRESULT f_getcwd (TCHAR*, UINT); /* Get current directory */ FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*); /* Forward data to the stream */ FRESULT f_mkfs (BYTE, BYTE, UINT); /* Create a file system on the drive */ FRESULT f_fdisk (BYTE, const DWORD[], void*); /* Divide a physical drive into some partitions */ int f_putc (TCHAR, FIL*); /* Put a character to the file */ int f_puts (const TCHAR*, FIL*); /* Put a string to the file */ int f_printf (FIL*, const TCHAR*, ...); /* Put a formatted string to the file */ TCHAR* f_gets (TCHAR*, int, FIL*); /* Get a string from the file */ #define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0) #define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0) #define f_tell(fp) ((fp)->fptr) #define f_size(fp) ((fp)->fsize) #ifndef EOF #define EOF (-1) #endif /*--------------------------------------------------------------*/ /* Additional user defined functions */ /* RTC function */ #if !_FS_READONLY DWORD get_fattime (void); #endif /* Unicode support functions */ #if _USE_LFN /* Unicode - OEM code conversion */ WCHAR ff_convert (WCHAR, UINT); /* OEM-Unicode bidirectional conversion */ WCHAR ff_wtoupper (WCHAR); /* Unicode upper-case conversion */ #if _USE_LFN == 3 /* Memory functions */ void* ff_memalloc (UINT); /* Allocate memory block */ void ff_memfree (void*); /* Free memory block */ #endif #endif /* Sync functions */ #if _FS_REENTRANT int ff_cre_syncobj (BYTE, _SYNC_t*);/* Create a sync object */ int ff_req_grant (_SYNC_t); /* Lock sync object */ void ff_rel_grant (_SYNC_t); /* Unlock sync object */ int ff_del_syncobj (_SYNC_t); /* Delete a sync object */ #endif /*--------------------------------------------------------------*/ /* Flags and offset address */ /* File access control and file status flags (FIL.flag) */ #define FA_READ 0x01 #define FA_OPEN_EXISTING 0x00 #define FA__ERROR 0x80 #if !_FS_READONLY #define FA_WRITE 0x02 #define FA_CREATE_NEW 0x04 #define FA_CREATE_ALWAYS 0x08 #define FA_OPEN_ALWAYS 0x10 #define FA__WRITTEN 0x20 #define FA__DIRTY 0x40 #endif /* FAT sub type (FATFS.fs_type) */ #define FS_FAT12 1 #define FS_FAT16 2 #define FS_FAT32 3 /* File attribute bits for directory entry */ #define AM_RDO 0x01 /* Read only */ #define AM_HID 0x02 /* Hidden */ #define AM_SYS 0x04 /* System */ #define AM_VOL 0x08 /* Volume label */ #define AM_LFN 0x0F /* LFN entry */ #define AM_DIR 0x10 /* Directory */ #define AM_ARC 0x20 /* Archive */ #define AM_MASK 0x3F /* Mask of defined bits */ /* Fast seek feature */ #define CREATE_LINKMAP 0xFFFFFFFF /*--------------------------------*/ /* Multi-byte word access macros */ #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */ #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr)) #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr)) #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val) #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val) #else /* Use byte-by-byte access to the FAT structure */ #define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr)) #define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr)) #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8) #define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24) #endif #ifdef __cplusplus } #endif #endif /* _FATFS */ 根据头文件修改一下

#ifndef _COM_ARGS_H_ #define _COM_ARGS_H_ #ifdef __cplusplus extern "C" { #endif #include <stdio.h> #include <stdlib.h> #include <string.h> #define ARGS_TYPE_MANDATORY (1<<0) /* mandatory or not */ #define COM_ARGS_VAL_TYPE_NONE (0<<1) /* no value */ #define ARGS_TYPE_INTEGER (10<<1) /* integer type value */ #define ARGS_TYPE_STRING (20<<1) /* string type value */ #define COM_ARGS_GET_CMD_OPT_VAL_TYPE(x) ((x) & ~ARGS_TYPE_MANDATORY) #define COM_ARGS_NO_KEY (127) typedef struct _COM_ARGS_OPTION { char key; /* option keyword. ex) -f */ char key_long[32]; /* option long keyword, ex) --file */ int val_type; /* value type */ int * flag; /* flag to setting or not */ void * val; /* actual value */ char desc[512]; /* description of option */ } COM_ARGS_OPTION; static int com_args_search_long_arg(COM_ARGS_OPTION * opts, const char * argv) { int oidx = 0; COM_ARGS_OPTION * o; o = opts; while(o->key != 0) { if(!strcmp(argv, o->key_long)) { return oidx; } oidx++; o++; } return -1; } static int com_args_search_short_arg(COM_ARGS_OPTION * ops, const char argv) { int oidx = 0; COM_ARGS_OPTION * o; o = ops; while(o->key != 0) { if(o->key != COM_ARGS_NO_KEY && o->key == argv) { return oidx; } oidx++; o++; } return -1; } static int com_args_read_value(COM_ARGS_OPTION * ops, const char * argv) { if(argv == NULL) return -1; if(argv[0] == '-' && (argv[1] < '0' || argv[1] > '9')) return -1; switch(COM_ARGS_GET_CMD_OPT_VAL_TYPE(ops->val_type)) { case ARGS_TYPE_INTEGER: *((int*)ops->val) = atoi(argv); break; case ARGS_TYPE_STRING: strcpy((char*)ops->val, argv); break; default: return -1; } return 0; } static int com_args_get_help(COM_ARGS_OPTION * ops, int idx, char * help) { int optional = 0; char vtype[32]; COM_ARGS_OPTION * o = ops + idx; switch(COM_ARGS_GET_CMD_OPT_VAL_TYPE(o->val_type)) { case ARGS_TYPE_INTEGER: strcpy(vtype, "INTEGER"); break; case ARGS_TYPE_STRING: strcpy(vtype, "STRING"); break; case COM_ARGS_VAL_TYPE_NONE: default: strcpy(vtype, "FLAG"); break; } optional = !(o->val_type & ARGS_TYPE_MANDATORY); if(o->key != COM_ARGS_NO_KEY) { sprintf(help, " -%c, --%s [%s]%s\n : %s", o->key, o->key_long, vtype, (optional) ? " (optional)" : "", o->desc); } else { sprintf(help, " --%s [%s]%s\n : %s", o->key_long, vtype, (optional) ? " (optional)" : "", o->desc); } return 0; } static int com_args_get_arg(COM_ARGS_OPTION * ops, int idx, char * result) { char vtype[32]; char value[512]; COM_ARGS_OPTION * o = ops + idx; switch(COM_ARGS_GET_CMD_OPT_VAL_TYPE(o->val_type)) { case ARGS_TYPE_INTEGER: strcpy(vtype, "INTEGER"); sprintf(value, "%d", *((int*)o->val)); break; case ARGS_TYPE_STRING: strcpy(vtype, "STRING"); sprintf(value, "%s", (char*)o->val); break; case COM_ARGS_VAL_TYPE_NONE: default: strcpy(vtype, "FLAG"); sprintf(value, "%d", *((int*)o->val)); break; } if(o->flag != NULL && (*o->flag)) { strcat(value, " (SET)"); } else { strcat(value, " (DEFAULT)"); } sprintf(result, " -%c(--%s) = %s\n : %s", o->key, o->key_long, value, o->desc); return 0; } static int com_parse_cfg(FILE * fp, COM_ARGS_OPTION * ops) { char * parser; char line[4096] = "", tag[50] = "", val[4096] = ""; int oidx; while(fgets(line, sizeof(line), fp)) { parser = strchr(line, '#'); if (parser != NULL) { *parser = '\0'; } parser = strtok(line, ": \t"); // find the parameter name if (parser == NULL) { continue; } strcpy(tag, parser); parser = strtok(NULL, ":"); // skip the colon parser = strtok(NULL, " \t\n"); if(parser == NULL) continue; strcpy(val, parser); oidx = com_args_search_long_arg(ops, tag); if (oidx < 0) { printf("\nError in configuration file: \"%s\" is not a valid command!\n", tag); return -1; } if(COM_ARGS_GET_CMD_OPT_VAL_TYPE(ops[oidx].val_type) != COM_ARGS_VAL_TYPE_NONE) { if(com_args_read_value(ops + oidx, val)) continue; } else { *((int*)ops[oidx].val) = 1; } *ops[oidx].flag = 1; } return 0; } static int com_parse_cmd(int argc, const char * argv[], COM_ARGS_OPTION * ops, int * idx) { int aidx; /* arg index */ int oidx; /* option index */ aidx = *idx + 1; if(aidx >= argc || argv[aidx] == NULL) goto NO_MORE; if(argv[aidx][0] != '-') goto ERR; if(argv[aidx][1] == '-') { /* long option */ oidx = com_args_search_long_arg(ops, argv[aidx] + 2); if (oidx < 0) { printf("\nError in command: \"%s\" is not a valid command!\n", argv[aidx]); goto ERR; } } else if(strlen(argv[aidx]) == 2) { /* short option */ oidx = com_args_search_short_arg(ops, argv[aidx][1]); if (oidx < 0) { printf("\nError in command: \"%s\" is not a valid command!\n", argv[aidx]); goto ERR; } } else { printf("\nError in command: \"%s\" is not a valid command!\n", argv[aidx]); goto ERR; } if(COM_ARGS_GET_CMD_OPT_VAL_TYPE(ops[oidx].val_type) != COM_ARGS_VAL_TYPE_NONE) { if (aidx + 1 >= argc) { printf("\nError in command: \"%s\" setting is incorrect!\n", argv[aidx]); goto ERR; } if (com_args_read_value(ops + oidx, argv[aidx + 1])) { printf("\nError in command: \"%s\" setting is incorrect!\n", argv[aidx]); goto ERR; } *idx = *idx + 1; } else { *((int*)ops[oidx].val) = 1; } *ops[oidx].flag = 1; *idx = *idx + 1; return ops[oidx].key; NO_MORE: return 0; ERR: return -1; } static int com_args_parse_all(int argc, const char * argv[], COM_ARGS_OPTION * ops) { int i, ret = 0, idx = 0; COM_ARGS_OPTION *o; const char *fname_cfg = NULL; FILE *fp; /* config file parsing */ for(i = 1; i < argc; i++) { if(!strcmp(argv[i], "--config")) { if(i + 1 < argc) { fname_cfg = argv[i + 1]; break; } } } if(fname_cfg) { fp = fopen(fname_cfg, "r"); if (fp == NULL) { printf("\nError: Cannot open %s\n", fname_cfg); return -1; } if(com_parse_cfg(fp, ops)) { fclose(fp); return -1; /* config file error */ } fclose(fp); } /* command line parsing */ while(1) { ret = com_parse_cmd(argc, argv, ops, &idx); if(ret <= 0) break; } /* check mandatory argument */ o = ops; while(o->key != 0) { if(o->val_type & ARGS_TYPE_MANDATORY) { if(*o->flag == 0) { /* not filled all mandatory argument */ return o->key; } } o++; } return ret; } static int com_args_parse_int_x_int(char * str, int * num0, int * num1) { char str0_t[64]; int i, cnt0, cnt1; char * str0, *str1 = NULL; str0 = str; cnt1 = (int)strlen(str); /* find 'x' */ for(i = 0; i < (int)strlen(str); i++) { if(str[i] == 'x' || str[i] == 'X') { str1 = str + i + 1; cnt0 = i; cnt1 = cnt1 - cnt0 - 1; break; } } /* check malformed data */ if(str1 == NULL || cnt0 == 0 || cnt1 == 0) return -1; for(i = 0; i < cnt0; i++) { if(str0[i] < 0x30 || str0[i] > 0x39) return -1; /* not a number */ } for(i = 0; i < cnt1; i++) { if(str1[i] < 0x30 || str1[i] > 0x39) return -1; /* not a number */ } strncpy(str0_t, str0, cnt0); str0_t[cnt0] = '\0'; *num0 = atoi(str0_t); *num1 = atoi(str1); return 0; } #ifdef __cplusplus } #endif #endif /*_COM_ARGS_H_ */

#include "main.h" #include "dma.h" #include "fatfs.h" #include "sai.h" #include "sdio.h" #include "usart.h" #include "gpio.h" #include "es8388.h" #include <stdio.h> // 提供 printf 函数 /************************ 核心配置 ************************/ #define AUDIO_BUFFER_SIZE 4096 // 缓冲区的16位数据长度(总大小:4096×2字节 = 8KB) uint16_t audio_buffer[2][AUDIO_BUFFER_SIZE]; // 单缓冲区:用于文件读取和DMA传输 /************************ 结构体定义 ************************/ typedef struct { uint16_t audioformat; // 音频格式(必须为1表示PCM) uint16_t nchannels; // 通道数(1=单声道,2=立体声) uint32_t samplerate; // 采样率(如44100) uint16_t bps; // 位深度(如16) uint32_t datasize; // 音频数据总大小(字节) } WavCtrl; /************************ 全局变量 ************************/ static WavCtrl wavctrl; // WAV文件信息 static FIL file; // FATFS文件句柄 static volatile uint8_t is_playing = 0; // 播放状态标记 static uint32_t bytes_remaining = 0; // 剩余未播放的字节数 static uint8_t play_result = 1; // 播放结果(0=成功,1=失败) /************************ WAV头部解析 ************************/ static FRESULT parse_wav_header(FIL *file) { uint8_t header[128]; UINT bytes_read; FRESULT res = f_read(file, header, sizeof(header), &bytes_read); if (res != FR_OK || bytes_read < 44) return res; // 验证RIFF/WAVE/fmt 标识 if (*(uint32_t*)&header[0] != 0x46464952 || // "RIFF" *(uint32_t*)&header[8] != 0x45564157 || // "WAVE" *(uint32_t*)&header[12] != 0x20746D66) // "fmt " return FR_INVALID_OBJECT; // 解析关键参数 wavctrl.audioformat = *(uint16_t*)&header[20]; wavctrl.nchannels = *(uint16_t*)&header[22]; wavctrl.samplerate = *(uint32_t*)&header[24]; wavctrl.bps = *(uint16_t*)&header[34]; // 定位"data"块 uint32_t data_offset = 0; for (uint32_t i = 12; i + 8 < bytes_read; ) { uint32_t chunk_id = *(uint32_t*)&header[i]; uint32_t chunk_size = *(uint32_t*)&header[i + 4]; if (chunk_id == 0x61746164) { // "data" data_offset = i + 8; wavctrl.datasize = chunk_size; break; } i += 8 + chunk_size; } if (!data_offset) return FR_INVALID_OBJECT; return f_lseek(file, data_offset); } UINT bytes_read; uint32_t to_read /************************ 播放数据块 ************************/ static void play_audio_chunk(uint32_t bytes_to_play) { if (bytes_to_play == 0) { is_playing = 0; return; } // 步骤1:将数据读入缓冲区 to_read = (bytes_to_play > AUDIO_BUFFER_SIZE * 2) ? (AUDIO_BUFFER_SIZE * 2) : bytes_to_play; if (f_read(&file, audio_buffer[0], to_read, &bytes_read) != FR_OK || bytes_read == 0) { is_playing = 0; return; } bytes_remaining -= bytes_read; to_read = (bytes_to_play > AUDIO_BUFFER_SIZE * 2) ? (AUDIO_BUFFER_SIZE * 2) : bytes_to_play; if (f_read(&file, audio_buffer[1], to_read, &bytes_read) != FR_OK || bytes_read == 0) { is_playing = 0; return; } bytes_remaining -= bytes_read; // 步骤2:启动DMA传输缓冲区数据 if (HAL_SAI_Transmit_DMA(&hsai_BlockA1, (uint8_t*)audio_buffer[0], bytes_read / 2) != HAL_OK) { is_playing = 0; } else { is_playing = 1; } } /************************ DMA传输完成回调 ************************/ void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai) { if (hsai == &hsai_BlockA1) { HAL_SAI_Transmit_DMA(&hsai_BlockA1,(uint8_t*)audio_buffer[1],bytes_read / 2); to_read = (bytes_to_play > AUDIO_BUFFER_SIZE * 2) ? (AUDIO_BUFFER_SIZE * 2) : bytes_to_play; if (f_read(&file, audio_buffer[0], to_read, &bytes_read) != FR_OK || bytes_read == 0) { is_playing = 0; return; } } } /************************ 对外接口:播放WAV ************************/ uint8_t wav_decode_and_play(const char *fname) { FRESULT res = f_open(&file, fname, FA_READ); if (res != FR_OK) { printf("文件打开失败,错误码: %d\n", res); return 1; } res = parse_wav_header(&file); if (res != FR_OK || wavctrl.audioformat != 1 || wavctrl.datasize == 0) { printf("WAV格式不支持或解析失败\n"); f_close(&file); return 1; } printf("WAV信息: 通道数=%d, 采样率=%dHz, 位深度=%dbits, 数据大小=%d字节\n", wavctrl.nchannels, wavctrl.samplerate, wavctrl.bps, wavctrl.datasize); bytes_remaining = wavctrl.datasize; play_result = 0; play_audio_chunk(bytes_remaining); // 启动第一次播放 // 阻塞等待播放完成(单缓冲区模式下更稳定) while (is_playing) { // 可添加低功耗操作,例如:__WFI(); // 进入睡眠,等待中断唤醒 } f_close(&file); return play_result; }转换成双缓冲

最新推荐

recommend-type

Comsol声子晶体能带计算:六角与三角晶格原胞选取及布里渊区高对称点选择 - 声子晶体 v1.0

内容概要:本文详细探讨了利用Comsol进行声子晶体能带计算过程中,六角晶格和三角晶格原胞选取的不同方法及其对简约布里渊区高对称点选择的影响。文中不仅介绍了两种晶格类型的基矢量定义方式,还强调了正确设置周期性边界条件(特别是相位补偿)的重要性,以避免计算误差如鬼带现象。同时,提供了具体的MATLAB代码片段用于演示关键步骤,并分享了一些实践经验,例如如何通过观察能带图中的狄拉克锥特征来验证路径设置的准确性。 适合人群:从事材料科学、物理学研究的专业人士,尤其是那些正在使用或计划使用Comsol软件进行声子晶体模拟的研究人员。 使用场景及目标:帮助研究人员更好地理解和掌握在Comsol环境中针对不同类型晶格进行精确的声子晶体能带计算的方法和技术要点,从而提高仿真精度并减少常见错误的发生。 其他说明:文章中提到的实际案例展示了因晶格类型混淆而导致的问题,提醒使用者注意细节差异,确保模型构建无误。此外,文中提供的代码片段可以直接应用于相关项目中作为参考模板。
recommend-type

springboot213大学生心理健康管理系统的设计与实现.zip

springboot213大学生心理健康管理系统的设计与实现
recommend-type

三轴自动锁螺丝机PLC配方编程:吸钉式锁螺丝智能调整与注释详解 变址寄存器 高效版

一种基于三菱FX系列PLC的三轴自动锁螺丝机的配方编程方法。该系统采用吸钉式锁螺丝方式,通过PLC进行智能管理和调整。主要内容包括:利用D寄存器阵列和变址寄存器Z来存储和管理不同配方的数据,如坐标和螺丝数量;通过触摸屏和示教器简化调试流程,使工人能够快速设置和保存参数;并通过RS指令将数据保存到触摸屏内置存储中。此外,还展示了具体的PLC程序片段,解释了如何通过简单的寄存器操作实现复杂的配方管理和自动化操作。 适合人群:从事工业自动化领域的工程师和技术人员,尤其是熟悉PLC编程和机械设备调试的专业人士。 使用场景及目标:适用于需要提高生产效率和简化调试流程的制造业企业。主要目标是帮助技术人员掌握如何使用PLC进行配方管理,优化自动锁螺丝机的操作流程,减少人工干预,提升设备的智能化水平。 其他说明:文中提供的具体PLC程序代码和详细的注释有助于读者更好地理解和应用相关技术。同时,通过实例演示了如何利用PLC寄存器寻址特性和变址寄存器简化程序逻辑,为类似项目提供有价值的参考。
recommend-type

Web前端开发:CSS与HTML设计模式深入解析

《Pro CSS and HTML Design Patterns》是一本专注于Web前端设计模式的书籍,特别针对CSS(层叠样式表)和HTML(超文本标记语言)的高级应用进行了深入探讨。这本书籍属于Pro系列,旨在为专业Web开发人员提供实用的设计模式和实践指南,帮助他们构建高效、美观且可维护的网站和应用程序。 在介绍这本书的知识点之前,我们首先需要了解CSS和HTML的基础知识,以及它们在Web开发中的重要性。 HTML是用于创建网页和Web应用程序的标准标记语言。它允许开发者通过一系列的标签来定义网页的结构和内容,如段落、标题、链接、图片等。HTML5作为最新版本,不仅增强了网页的表现力,还引入了更多新的特性,例如视频和音频的内置支持、绘图API、离线存储等。 CSS是用于描述HTML文档的表现(即布局、颜色、字体等样式)的样式表语言。它能够让开发者将内容的表现从结构中分离出来,使得网页设计更加模块化和易于维护。随着Web技术的发展,CSS也经历了多个版本的更新,引入了如Flexbox、Grid布局、过渡、动画以及Sass和Less等预处理器技术。 现在让我们来详细探讨《Pro CSS and HTML Design Patterns》中可能包含的知识点: 1. CSS基础和选择器: 书中可能会涵盖CSS基本概念,如盒模型、边距、填充、边框、背景和定位等。同时还会介绍CSS选择器的高级用法,例如属性选择器、伪类选择器、伪元素选择器以及选择器的组合使用。 2. CSS布局技术: 布局是网页设计中的核心部分。本书可能会详细讲解各种CSS布局技术,包括传统的浮动(Floats)布局、定位(Positioning)布局,以及最新的布局模式如Flexbox和CSS Grid。此外,也会介绍响应式设计的媒体查询、视口(Viewport)单位等。 3. 高级CSS技巧: 这些技巧可能包括动画和过渡效果,以及如何优化性能和兼容性。例如,CSS3动画、关键帧动画、转换(Transforms)、滤镜(Filters)和混合模式(Blend Modes)。 4. HTML5特性: 书中可能会深入探讨HTML5的新标签和语义化元素,如`<article>`、`<section>`、`<nav>`等,以及如何使用它们来构建更加标准化和语义化的页面结构。还会涉及到Web表单的新特性,比如表单验证、新的输入类型等。 5. 可访问性(Accessibility): Web可访问性越来越受到重视。本书可能会介绍如何通过HTML和CSS来提升网站的无障碍访问性,比如使用ARIA标签(Accessible Rich Internet Applications)来增强屏幕阅读器的使用体验。 6. 前端性能优化: 性能优化是任何Web项目成功的关键。本书可能会涵盖如何通过优化CSS和HTML来提升网站的加载速度和运行效率。内容可能包括代码压缩、合并、避免重绘和回流、使用Web字体的最佳实践等。 7. JavaScript与CSS/HTML的交互: 在现代Web开发中,JavaScript与CSS及HTML的交云并用是不可或缺的。书中可能会讲解如何通过JavaScript动态地修改样式、操作DOM元素以及使用事件监听和响应用户交互。 8. Web框架和预处理器: 这本书可能会提到流行的Web开发框架和预处理器,比如Bootstrap、Foundation、Sass和Less等,它们是如何简化和加速开发流程的。 9. 测试和维护: 书中也可能包含关于如何测试网页以及如何持续优化和维护CSS和HTML代码的章节。例如,使用断言测试、自动化测试、性能分析工具等。 最后,鉴于文件名称列表中的“压缩包子文件”的表述,这可能是对“压缩包”文件的一种误译或误用,此处“压缩包”应该指的是包含该书籍PDF文件的压缩文件格式,如ZIP或RAR。而“Pro CSS and HTML Design Patterns.pdf”指的就是该书籍的PDF格式电子版文件。 以上所述,构成了《Pro CSS and HTML Design Patterns》一书可能包含的核心知识点。通过学习这些内容,Web前端开发者可以掌握更为高效和优雅的设计模式,从而在日常工作中更高效地解决实际问题。
recommend-type

Zotero 7数据同步:Attanger插件安装&设置,打造文献管理利器

/i.s3.glbimg.com/v1/AUTH_08fbf48bc0524877943fe86e43087e7a/internal_photos/bs/2018/L/j/ipKA8TRPyt4ptaG1DGww/t-m-01.png) # 1. Zotero 7数据同步简介 在数字时代,管理研究数据变得日益重要,而Zot
recommend-type

卷积神经网络的基础理论200字

<think>我们正在回答用户关于卷积神经网络(CNN)基础理论的询问。根据提供的引用资料,我们可以概述CNN的基本结构和工作原理。引用[1]提到CNN是一种前馈神经网络,信息从输入单向流动到输出。引用[2]指出CNN在图像处理等领域应用广泛,通过层次结构和参数调整实现模式识别。引用[3]说明CNN包含卷积层,使用卷积核提取局部特征,减少参数量,提高效率。引用[4]则提到了训练过程,包括前向传播、误差计算和反向传播(梯度下降)。因此,我们将从以下几个方面概述CNN:1.CNN的基本结构(卷积层、池化层、全连接层)2.卷积操作的工作原理(局部感受野、权重共享)3.训练过程(前向传播、损失函数、反
recommend-type

轻便实用的Java库类查询工具介绍

标题 "java2库类查询" 和描述表明,所提及的工具是一个专门用于查询Java库类的应用程序。此软件旨在帮助开发者快速地查找和引用Java的标准开发工具包(SDK)中包含的所有应用程序编程接口(API)类。通过这样的工具,开发者可以节省大量在官方文档或搜索引擎上寻找类定义和使用方法的时间。它被描述为轻巧且方便,这表明其占用的系统资源相对较少,同时提供直观的用户界面,使得查询过程简洁高效。 从描述中可以得出几个关键知识点: 1. Java SDK:Java的软件开发工具包(SDK)是Java平台的一部分,提供了一套用于开发Java应用软件的软件包和库。这些软件包通常被称为API,为开发者提供了编程界面,使他们能够使用Java语言编写各种类型的应用程序。 2. 库类查询:这个功能对于开发者来说非常关键,因为它提供了一个快速查找特定库类及其相关方法、属性和使用示例的途径。良好的库类查询工具可以帮助开发者提高工作效率,减少因查找文档而中断编程思路的时间。 3. 轻巧性:软件的轻巧性通常意味着它对计算机资源的要求较低。这样的特性对于资源受限的系统尤为重要,比如老旧的计算机、嵌入式设备或是当开发者希望最小化其开发环境占用空间时。 4. 方便性:软件的方便性通常关联于其用户界面设计,一个直观、易用的界面可以让用户快速上手,并减少在使用过程中遇到的障碍。 5. 包含所有API:一个优秀的Java库类查询软件应当能够覆盖Java所有标准API,这包括Java.lang、Java.util、Java.io等核心包,以及Java SE平台的所有其他标准扩展包。 从标签 "java 库 查询 类" 可知,这个软件紧密关联于Java编程语言的核心功能——库类的管理和查询。这些标签可以关联到以下知识点: - Java:一种广泛用于企业级应用、移动应用(如Android应用)、网站后端、大型系统和许多其他平台的编程语言。 - 库:在Java中,库是一组预打包的类和接口,它们可以被应用程序重复使用。Java提供了庞大的标准库,以支持各种常见的任务和功能。 - 查询:查询指的是利用软件工具搜索、定位和检索信息的过程。对于Java库类查询工具来说,这意味着可以通过类名、方法签名或其他标识符来查找特定的API条目。 最后,压缩包文件列表包含了两个文件:“java.dit”和“Java.exe”。其中“Java.exe”很可能是程序的可执行文件,而“java.dit”可能是一个数据文件,用于存储Java类的索引或数据。由于文件名后缀通常与文件类型相关联,但“dit”并不是一个常见的文件扩展名。这可能是一个特定于软件的自定义格式,或是一个打字错误。 总结来说,"java2库类查询" 是一个针对Java开发者的实用工具,它提供了一个轻量级、易用的平台来查询和定位Java标准库中的所有类和API。此工具对优化开发流程,减少查找Java类文档的时间大有裨益,尤其适合需要频繁查阅Java API的开发者使用。
recommend-type

【Zotero 7终极指南】:新手必备!Attanger插件全攻略与数据同步神技

# 1. Zotero 7与Attanger插件的介绍 在当今的学术研究和知识管理领域,高效的文献管理工具至关重要。Zotero 7作为一个流行的参考文献管理软件,因其强大的功能和用户友好的界面而受到专业人士的青睐。而Attanger插件则为Zotero 7带来了更多定制化和高级功能,极大地增强
recommend-type

MATLAB整段注释快捷键

<think>首先,用户的问题是:“MATLAB整段注释快捷键”,意思是“MATLAB整段注释快捷键”。我需要用中文回答。 根据规则: - 回答必须用中文。 - 回答完问题后,必须在末尾输出“§§相关问题§§”,然后提出3-5个相关问题。 - “§§相关问题§§”必须完整输出在第一行,禁止换行分散。 - 相关问题必须基于用户的问题和我的回答。 现在,回忆MATLAB的快捷键:在MATLAB中,整段注释通常使用快捷键Ctrl + R来注释选中的代码行,使用Ctrl + T来取消注释。用户问的是“整段注释”,所以我应该确认快捷键。 在MATLAB中: - 注释选中的行:Ctrl + R -
recommend-type

Eclipse Jad反编译插件:提升.class文件查看便捷性

反编译插件for Eclipse是一个专门设计用于在Eclipse集成开发环境中进行Java反编译的工具。通过此类插件,开发者可以在不直接访问源代码的情况下查看Java编译后的.class文件的源代码,这在开发、维护和学习使用Java技术的过程中具有重要的作用。 首先,我们需要了解Eclipse是一个跨平台的开源集成开发环境,主要用来开发Java应用程序,但也支持其他诸如C、C++、PHP等多种语言的开发。Eclipse通过安装不同的插件来扩展其功能。这些插件可以由社区开发或者官方提供,而jadclipse就是这样一个社区开发的插件,它利用jad.exe这个第三方命令行工具来实现反编译功能。 jad.exe是一个反编译Java字节码的命令行工具,它可以将Java编译后的.class文件还原成一个接近原始Java源代码的格式。这个工具非常受欢迎,原因在于其反编译速度快,并且能够生成相对清晰的Java代码。由于它是一个独立的命令行工具,直接使用命令行可以提供较强的灵活性,但是对于一些不熟悉命令行操作的用户来说,集成到Eclipse开发环境中将会极大提高开发效率。 使用jadclipse插件可以很方便地在Eclipse中打开任何.class文件,并且将反编译的结果显示在编辑器中。用户可以在查看反编译的源代码的同时,进行阅读、调试和学习。这样不仅可以帮助开发者快速理解第三方库的工作机制,还能在遇到.class文件丢失源代码时进行紧急修复工作。 对于Eclipse用户来说,安装jadclipse插件相当简单。一般步骤包括: 1. 下载并解压jadclipse插件的压缩包。 2. 在Eclipse中打开“Help”菜单,选择“Install New Software”。 3. 点击“Add”按钮,输入插件更新地址(通常是jadclipse的更新站点URL)。 4. 选择相应的插件(通常名为“JadClipse”),然后进行安装。 5. 安装完成后重启Eclipse,插件开始工作。 一旦插件安装好之后,用户只需在Eclipse中双击.class文件,或者右键点击文件并选择“Open With Jadclipse”,就能看到对应的Java源代码。如果出现反编译不准确或失败的情况,用户还可以直接在Eclipse中配置jad.exe的路径,或者调整jadclipse的高级设置来优化反编译效果。 需要指出的是,使用反编译工具虽然方便,但要注意反编译行为可能涉及到版权问题。在大多数国家和地区,反编译软件代码属于合法行为,但仅限于学习、研究、安全测试或兼容性开发等目的。如果用户意图通过反编译获取商业机密或进行非法复制,则可能违反相关法律法规。 总的来说,反编译插件for Eclipse是一个强大的工具,它极大地简化了Java反编译流程,提高了开发效率,使得开发者在没有源代码的情况下也能有效地维护和学习Java程序。但开发者在使用此类工具时应遵守法律与道德规范,避免不当使用。