📄 lqt_codecfile.c
字号:
/******************************************************************************* lqt_codecfile.c libquicktime - A library for reading and writing quicktime/avi/mp4 files. http://libquicktime.sourceforge.net Copyright (C) 2002 Heroine Virtual Ltd. Copyright (C) 2002-2007 Members of the libquicktime project. Modified by Napoleon E. Cornejo May 4, 2007, San Salvador, El Salvador - Validated user home directory in create_filename() This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*******************************************************************************/ /* * Codec file handling */#include "lqt_private.h"#include "lqt_codecinfo_private.h"#include <unistd.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <limits.h>#define LOG_DOMAIN "codecfile"/* * The keywords are defined globaly, so they are automatically * the same in reading and writing functions */static const char * begin_codec_key = "BeginCodec: ";static const char * end_codec_key = "EndCodec";/* * Start string for parameter definition: * These 2 strings (for en- and decoding MUST have the same length) */static const char * begin_parameter_e_key = "BeginParameterE: ";static const char * begin_parameter_d_key = "BeginParameterD: ";static const char * end_parameter_key = "EndParameter";static const char * long_name_key = "LongName: ";static const char * description_key = "Description: ";static const char * type_key = "Type: ";/* Types for codecs */static const char * type_audio = "Audio";static const char * type_video = "Video";/* Codec direction */static const char * direction_key = "Direction: ";static const char * direction_encode = "Encode";static const char * direction_decode = "Decode";static const char * direction_both = "Both";static const char * num_fourccs_key = "NumFourccs: ";static const char * fourccs_key = "Fourccs: ";static const char * num_wav_ids_key = "NumWavIds: ";static const char * wav_ids_key = "WavIds: ";static const char * compatibility_key = "Compatibility: ";/* Module filename and module index */static const char * module_filename_key = "ModuleFilename: ";static const char * module_index_key = "ModuleIndex: ";static const char * module_file_time_key = "FileTime: ";static const char * gettext_domain_key = "GettextDomain";static const char * gettext_directory_key = "GettextDirectory";/* Types for parameters */static const char * type_int = "Integer";static const char * type_float = "Float";static const char * type_string = "String";static const char * type_stringlist = "Stringlist";static const char * type_section = "Section";static const char * help_string_key = "HelpString: ";static const char * num_digits_key = "NumDigits";static const char * num_encoding_parameters_key = "NumEncodingParameters: ";static const char * num_decoding_parameters_key = "NumDecodingParameters: ";static const char * value_key = "Value: ";static const char * min_value_key = "ValueMin: ";static const char * max_value_key = "ValueMax: ";static const char * real_name_key = "RealName: ";static const char * num_options_key = "NumOptions: ";static const char * option_key = "Options: ";static const char * label_key = "OptionLabels: ";/* Codec order */static const char * audio_order_key = "AudioOrder: ";static const char * video_order_key = "VideoOrder: ";#define READ_BUFFER_SIZE 2048#define CHECK_KEYWORD(key) (!strncmp(line, key, strlen(key)))static char filename_buffer[PATH_MAX];static void create_filename() { /* Obtain the home directory */ char * fdir; /* First look for a system-wide codec file if available. If not look into users home */ fdir = getenv("LQT_CODEC_FILE"); if (fdir == NULL ) { lqt_log(NULL, LQT_LOG_DEBUG, LOG_DOMAIN, "no system-wide codec file. Looking in user's home."); fdir = getenv("HOME"); strcpy(filename_buffer, fdir); strcat(filename_buffer, "/.libquicktime_codecs"); } else strcpy(filename_buffer, fdir); }static char * __lqt_strdup(const char * string) { char * ret = malloc(strlen(string)+1); strcpy(ret, string); return ret; }static void read_parameter_value(char * pos, lqt_parameter_value_t * ret, lqt_parameter_type_t type) { switch(type) { case LQT_PARAMETER_INT: ret->val_int = atoi(pos); break; case LQT_PARAMETER_FLOAT: ret->val_float = strtod(pos, (char**)0); break; case LQT_PARAMETER_STRING: case LQT_PARAMETER_STRINGLIST: ret->val_string = __lqt_strdup(pos); break; case LQT_PARAMETER_SECTION: break; } }static char * convert_help_string(char * str) { char * ret; char * src_pos, *dst_pos; ret = malloc(strlen(str)+1); src_pos = str; dst_pos = ret; while(*src_pos != '\0') { if((src_pos[0] == '\\') && (src_pos[1] == 'n')) { *dst_pos = '\n'; src_pos += 2; dst_pos++; } else { *dst_pos = *src_pos; src_pos++; dst_pos++; } } *dst_pos = '\0'; free(str); return ret; }static void read_parameter_info(FILE * input, lqt_parameter_info_t * info, char * line) { char * pos; int options_read = 0; int labels_read = 0; /* First, get the name */ pos = line + strlen(begin_parameter_e_key); info->name = __lqt_strdup(pos); while(1) { fgets(line, READ_BUFFER_SIZE-1, input); if(feof(input)) break; pos = strchr(line, '\n'); if(pos) *pos = '\0'; /* Now, go through the syntax */ if(CHECK_KEYWORD(type_key)) { pos = line + strlen(type_key); if(!strcmp(pos, type_int)) { info->type = LQT_PARAMETER_INT; /* * We set them here for the case, they are not set after * (which can happen for min and max) */ info->val_default.val_int = 0; info->val_min.val_int = 0; info->val_max.val_int = 0; } if(!strcmp(pos, type_float)) { info->type = LQT_PARAMETER_FLOAT; /* * We set them here for the case, they are not set after * (which can happen for min and max) */ info->val_default.val_float = 0; info->val_min.val_float = 0; info->val_max.val_float = 0; info->num_digits = 1; } /* * Important: type_stringlist must be checked * BEFORE type_string */ else if(!strcmp(pos, type_stringlist)) { info->type = LQT_PARAMETER_STRINGLIST; info->val_default.val_string = (char*)0; } else if(!strcmp(pos, type_string)) { info->type = LQT_PARAMETER_STRING; info->val_default.val_string = (char*)0; } else if(!strcmp(pos, type_section)) { info->type = LQT_PARAMETER_SECTION; info->val_default.val_string = (char*)0; } } else if(CHECK_KEYWORD(real_name_key)) { pos = line + strlen(real_name_key); info->real_name = __lqt_strdup(pos); } else if(CHECK_KEYWORD(value_key)) { pos = line + strlen(value_key); read_parameter_value(pos, &(info->val_default), info->type); } else if(CHECK_KEYWORD(min_value_key)) { pos = line + strlen(min_value_key); if(info->type == LQT_PARAMETER_INT) info->val_min.val_int = atoi(pos); else if(info->type == LQT_PARAMETER_FLOAT) info->val_min.val_float = strtod(pos, (char**)0); } else if(CHECK_KEYWORD(max_value_key)) { pos = line + strlen(max_value_key); if(info->type == LQT_PARAMETER_INT) info->val_max.val_int = atoi(pos); else if(info->type == LQT_PARAMETER_FLOAT) info->val_max.val_float = strtod(pos, (char**)0); } else if(CHECK_KEYWORD(num_options_key)) { pos = line + strlen(num_options_key); info->num_stringlist_options = atoi(pos); info->stringlist_options = calloc(info->num_stringlist_options, sizeof(char*)); info->stringlist_labels = calloc(info->num_stringlist_options, sizeof(char*)); } else if(CHECK_KEYWORD(option_key)) { pos = line + strlen(option_key); info->stringlist_options[options_read] = __lqt_strdup(pos); options_read++; } else if(CHECK_KEYWORD(label_key)) { pos = line + strlen(label_key); info->stringlist_labels[labels_read] = __lqt_strdup(pos); labels_read++; } else if(CHECK_KEYWORD(help_string_key)) { pos = line + strlen(help_string_key); info->help_string = __lqt_strdup(pos); info->help_string = convert_help_string(info->help_string); } else if(CHECK_KEYWORD(num_digits_key)) { pos = line + strlen(num_digits_key); info->num_digits = atoi(pos); } else if(CHECK_KEYWORD(end_parameter_key)) break; } }static void read_codec_info(FILE * input, lqt_codec_info_t * codec, char * line) { char * pos, *rest; int i; int encoding_parameters_read = 0; int decoding_parameters_read = 0; uint32_t tmp_fourcc; /* First, get the name */ pos = line + strlen(begin_codec_key); codec->name = __lqt_strdup(pos); while(1) { fgets(line, READ_BUFFER_SIZE-1, input); if(feof(input)) break; pos = strchr(line, '\n'); if(pos) *pos = '\0'; /* Long name */ if(CHECK_KEYWORD(long_name_key)) { pos = line + strlen(long_name_key); codec->long_name = __lqt_strdup(pos); } /* Description */ else if(CHECK_KEYWORD(description_key)) { pos = line + strlen(description_key); codec->description = __lqt_strdup(pos); } /* Type */ else if(CHECK_KEYWORD(type_key)) { pos = line + strlen(type_key); if(!strcmp(pos, type_audio)) codec->type = LQT_CODEC_AUDIO; else if(!strcmp(pos, type_video)) codec->type = LQT_CODEC_VIDEO; } /* Direction */ else if(CHECK_KEYWORD(direction_key)) { pos = line + strlen(direction_key); if(!strcmp(pos, direction_encode)) codec->direction = LQT_DIRECTION_ENCODE; else if(!strcmp(pos, direction_decode)) codec->direction = LQT_DIRECTION_DECODE; else if(!strcmp(pos, direction_both)) codec->direction = LQT_DIRECTION_BOTH; } /* Compatibility flags */ else if(CHECK_KEYWORD(compatibility_key)) { pos = line + strlen(compatibility_key); codec->compatibility_flags = strtoul(pos, (char**)0, 16); } /* Module filename */ else if(CHECK_KEYWORD(module_filename_key)) { pos = line + strlen(module_filename_key); codec->module_filename = __lqt_strdup(pos); } /* Gettext domain */ else if(CHECK_KEYWORD(gettext_domain_key)) { pos = line + strlen(gettext_domain_key); codec->gettext_domain = __lqt_strdup(pos); } /* Gettext directory */ else if(CHECK_KEYWORD(gettext_directory_key)) { pos = line + strlen(gettext_directory_key); codec->gettext_directory = __lqt_strdup(pos); } /* Module Index */ else if(CHECK_KEYWORD(module_index_key)) { pos = line + strlen(module_index_key); codec->module_index = atoi(pos); } /* File modification time */ else if(CHECK_KEYWORD(module_file_time_key)) { pos = line + strlen(module_file_time_key); codec->file_time = strtoul(pos, (char**)0, 10); } /* Number of Fourccs */ else if(CHECK_KEYWORD(num_fourccs_key)) { pos = line + strlen(num_fourccs_key); codec->num_fourccs = atoi(pos);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -