config.c
来自「this ebook is for GSM if any one has int」· C语言 代码 · 共 468 行 · 第 1/2 页
C
468 行
#include <fcntl.h>#include <sys/mman.h>#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>#include <stdio.h>#include <stdlib.h>#include <strings.h>#include <string.h>#include <glib/glist.h>#include "config.h"#include "libconf.h"#include "sap.h"#include "output.h"#include "getstream.h"static struct config_s *config;/* Temporary variables for parsing */static struct adapter_s *adapter;static struct output_s *output;static struct input_s *input;static struct stream_s *stream;static struct sap_s *sap;static int cf_adapter_start(struct lc_centry *ce, struct lc_value *val) { adapter=calloc(1, sizeof(struct adapter_s)); adapter->no=val->num; adapter->budgetmode=1; adapter->dvr.stuckinterval=DVR_DEFAULT_STUCKINT; adapter->dvr.buffer.size=DVR_BUFFER_DEFAULT*TS_PACKET_SIZE; config->adapter=g_list_append(config->adapter, adapter); return 1;}static int cf_sap_scope(struct lc_centry *ce, struct lc_value *val) { sap->scope=val->string; return 1; }static int cf_sap_sap_group(struct lc_centry *ce, struct lc_value *val) { sap->group=val->string; return 1; }static int cf_sap_sap_port(struct lc_centry *ce, struct lc_value *val) { sap->port=val->num; return 1; }static int cf_sap_ttl(struct lc_centry *ce, struct lc_value *val) { sap->ttl=val->num; return 1; }static int cf_sap_playgroup(struct lc_centry *ce, struct lc_value *val) { sap->playgroup=val->string; return 1; }static int cf_sap_announce_host(struct lc_centry *ce, struct lc_value *val) { sap->announcehost=val->string; return 1; }static int cf_sap_announce_port(struct lc_centry *ce, struct lc_value *val) { sap->announceport=val->num; return 1; }static int cf_output_remoteport(struct lc_centry *ce, struct lc_value *val) { output->remoteport=val->num; return 1; }static int cf_output_remoteaddr(struct lc_centry *ce, struct lc_value *val) { output->remoteaddr=val->string; return 1; }static int cf_output_localaddr(struct lc_centry *ce, struct lc_value *val) { output->localaddr=val->string; return 1; }static int cf_output_ttl(struct lc_centry *ce, struct lc_value *val) { output->ttl=val->num; return 1; }static int cf_output_url(struct lc_centry *ce, struct lc_value *val) { output->url=val->string; return 1; }static int cf_http_port(struct lc_centry *ce, struct lc_value *val) { config->http_port=val->num; return 1; }static int cf_pipe_filename(struct lc_centry *ce, struct lc_value *val) { output->pipe.filename=val->string; return 1; }static int cf_sap_start(struct lc_centry *ce, struct lc_value *val) { sap=calloc(1, sizeof(struct sap_s)); output->sap=sap; sap->output=output; /* Default values */ sap->ttl=15; return 1;}static int cf_stream_start(struct lc_centry *ce, struct lc_value *val) { stream=calloc(1, sizeof(struct stream_s)); stream->adapter=adapter; adapter->streams=g_list_append(adapter->streams, stream); return 1;}static int cf_input_start(int itype) { input=calloc(1, sizeof(struct input_s)); input->type=itype; stream->input=g_list_append(stream->input, input); input->stream=stream; return 1;}static int cf_input_pid(struct lc_centry *ce, struct lc_value *val) { cf_input_start(INPUT_PID); input->pid.pid=val->num; return 1;}static int cf_input_pnr(struct lc_centry *ce, struct lc_value *val) { cf_input_start(INPUT_PNR); input->pnr.pnr=val->num; input->stream->psineeded=1; return 1;}static int cf_input_full(struct lc_centry *ce, struct lc_value *val) { cf_input_start(INPUT_FULL); return 1;}static int cf_output_start(struct lc_centry *ce, struct lc_value *val, int stype) { output=calloc(1, sizeof(struct output_s)); output->type=stype; output->ttl=15; output->stream=stream; stream->output=g_list_append(stream->output, output); return 1;}static int cf_output_udp_start(struct lc_centry *ce, struct lc_value *val) { return cf_output_start(ce, val, OTYPE_UDP); }static int cf_output_rtp_start(struct lc_centry *ce, struct lc_value *val) { return cf_output_start(ce, val, OTYPE_RTP); }static int cf_output_http_start(struct lc_centry *ce, struct lc_value *val) { return cf_output_start(ce, val, OTYPE_HTTP); }static int cf_output_pipe_start(struct lc_centry *ce, struct lc_value *val) { return cf_output_start(ce, val, OTYPE_PIPE); }struct lc_ventry conf_sap[] = { { "scope", 0, 1, LCV_STRING, 0, NULL, cf_sap_scope }, { "sap-group", 0, 1, LCV_IPV4ADDR, 0, NULL, cf_sap_sap_group }, { "sap-port", 0, 1, LCV_NUM, 0, NULL, cf_sap_sap_port }, { "announce-host", 0, 1, LCV_STRING, 0, NULL, cf_sap_announce_host }, { "announce-port", 0, 1, LCV_NUM, 0, NULL, cf_sap_announce_port }, { "ttl", 0, 1, LCV_NUM, 0, NULL, cf_sap_ttl }, { "playgroup", 0, 1, LCV_STRING, 0, NULL, cf_sap_playgroup }, { NULL, 0, 0, 0, 0, NULL },};struct lc_ventry conf_output_udp[] = { { "local-address", 0, 1, LCV_IPV4ADDR, 0, NULL, cf_output_localaddr }, { "remote-address", 1, 1, LCV_IPADDR, 0, NULL, cf_output_remoteaddr }, { "remote-port", 1, 1, LCV_NUM, 0, NULL, cf_output_remoteport }, { "ttl", 0, 1, LCV_NUM, 0, NULL, cf_output_ttl }, { "sap", 0, 1, LCV_NONE, 0, conf_sap, cf_sap_start }, { NULL, 0, 0, 0, 0, NULL, NULL },};struct lc_ventry conf_output_rtp[] = { { "local-address", 0, 1, LCV_IPV4ADDR, 0, NULL, cf_output_localaddr }, { "remote-address", 1, 1, LCV_IPV4ADDR, 0, NULL, cf_output_remoteaddr }, { "remote-port", 1, 1, LCV_NUM, 0, NULL, cf_output_remoteport }, { "ttl", 0, 1, LCV_NUM, 0, NULL, cf_output_ttl }, { "sap", 0, 1, LCV_NONE, 0, conf_sap, cf_sap_start }, { NULL, 0, 0, 0, 0, NULL },};struct lc_ventry conf_output_http[] = { { "url", 1, 1, LCV_STRING, 0, NULL, cf_output_url }, { NULL, 0, 0, 0, 0, NULL },};struct lc_ventry conf_output_pipe[] = { { "filename", 1, 1, LCV_STRING, 0, NULL, cf_pipe_filename }, { NULL, 0, 0, 0, 0, NULL },};static int cf_stream_name(struct lc_centry *ce, struct lc_value *val) { stream->name=val->string; return 1; }#if 0static int cf_channel_csa_key(struct lc_centry *ce, struct lc_value *val) { char *eptr; uint64_t key; int i, l=strlen(val->string); key=strtoull(val->string, &eptr, 16); /* * Was the string parsed ? * Was the string a number until the end ? * Was the string between 16 and 18 (0x) bytes long ? * */ if (val->string == eptr || (eptr != NULL && eptr[0] != 0x0) || l<16 || l>18) { fprintf(stderr, "config: Invalid csa-key \"%s\" in line %d\n", val->string, ce->vline); return 0; } /* cpu_to_64be anyone ? */ for(i=0;i<8;i++) channel->csakey[i]=(key>>(56-8*i))&0xff; channel->csat=csa_New(); csa_SetCW(channel->csat, channel->csakey, channel->csakey); return 1;};static int cf_channel_csa_length(struct lc_centry *ce, struct lc_value *val) { if (val->num > TS_PACKET_SIZE) { fprintf(stderr, "config: Invalid csa length %ld in line %d. Needs to be between 0 and 188\n", val->num, ce->vline); return 0; } channel->csalength=val->num; return 1;}static int cf_channel_csa(struct lc_centry *ce, struct lc_value *val) { channel->csalength=TS_PACKET_SIZE; return 1; }static struct lc_ventry conf_channel_csa[] = { { "key", 0, 1, LCV_STRING, 0, NULL, cf_channel_csa_key }, { "length", 0, 1, LCV_STRING, 0, NULL, cf_channel_csa_length }, { NULL, 0, 0, 0, 0, NULL },};#endifstatic struct lc_ventry conf_input[] = { { "pid", 0, 0, LCV_NUM, LCO_UNIQ, NULL, cf_input_pid }, { "pnr", 0, 1, LCV_NUM, LCO_UNIQ, NULL, cf_input_pnr }, { "full", 0, 1, LCV_NONE, LCO_UNIQ, NULL, cf_input_full }, { NULL, 0, 0, 0, 0, NULL },};static struct lc_ventry conf_stream[] = { { "name", 1, 1, LCV_STRING, 0, NULL, cf_stream_name }, { "sap", 0, 1, LCV_NONE, 0, conf_sap, cf_sap_start }, { "input", 0, 1, LCV_NONE, 0, conf_input, NULL },
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?