示例#1
0
文件: dvb.c 项目: 0xheart0/vlc
/* http://www.linuxtv.org/vdrwiki/index.php/Syntax_of_channels.conf or not...
 * Read the dvb-apps source code for reference. */
static input_item_t *ParseLine(char *line)
{
    char *str, *end;

    line += strspn(line, " \t\r"); /* skip leading white spaces */
    if (*line == '#')
        return NULL; /* skip comments */

    /* Extract channel cute name */
    char *name = strsep(&line, ":");
    assert(name != NULL);
    EnsureUTF8(name);

    /* Extract central frequency */
    str = strsep(&line, ":");
    if (str == NULL)
        return NULL;
    unsigned long freq = strtoul(str, &end, 10);
    if (*end)
        return NULL;

    /* Extract tuning parameters */
    str = strsep(&line, ":");
    if (str == NULL)
        return NULL;

    char *mrl;

    if (!strcmp(str, "h") || !strcmp(str, "v"))
    {   /* DVB-S */
        char polarization = toupper(*str);

        /* TODO: sat no. */
        str = strsep(&line, ":");
        if (str == NULL)
            return NULL;

        /* baud rate */
        str = strsep(&line, ":");
        if (str == NULL)
            return NULL;

        unsigned long rate = strtoul(str, &end, 10);
        if (*end || rate > (ULONG_MAX / 1000u))
            return NULL;
        rate *= 1000;

        if (asprintf(&mrl,
                     "dvb-s://frequency=%"PRIu64":polarization=%c:srate=%lu",
                     freq * UINT64_C(1000000), polarization, rate) == -1)
            mrl = NULL;
    }
    else
    if (!strncmp(str, "INVERSION_", 10))
    {   /* DVB-C or DVB-T */
        int inversion;

        str += 10;
        if (strcmp(str, "AUTO"))
            inversion = -1;
        else if (strcmp(str, "OFF"))
            inversion = 0;
        else if (strcmp(str, "ON"))
            inversion = 1;
        else
            return NULL;

        str = strsep(&line, ":");
        if (str == NULL)
            return NULL;

        if (strncmp(str, "BANDWIDTH_", 10))
        {   /* DVB-C */
            unsigned long rate = strtoul(str, &end, 10);
            if (*end)
                return NULL;

            str = strsep(&line, ":");
            const char *fec = ParseFEC(str);
            str = strsep(&line, ":");
            const char *mod = ParseModulation(str);
            if (fec == NULL || mod == NULL)
                return NULL;

            if (asprintf(&mrl, "dvb-c://frequency=%lu:inversion:%d:srate=%lu:"
                         "fec=%s:modulation=%s", freq, inversion, rate, fec,
                         mod) == -1)
                mrl = NULL;
        }
        else
        {   /* DVB-T */
            unsigned bandwidth = atoi(str + 10);

            str = strsep(&line, ":");
            const char *hp = ParseFEC(str);
            str = strsep(&line, ":");
            const char *lp = ParseFEC(str);
            str = strsep(&line, ":");
            const char *mod = ParseModulation(str);
            if (hp == NULL || lp == NULL || mod == NULL)
                return NULL;

            str = strsep(&line, ":");
            if (str == NULL || strncmp(str, "TRANSMISSION_MODE_", 18))
                return NULL;
            int xmit = atoi(str);
            if (xmit == 0)
                xmit = -1; /* AUTO */

            str = strsep(&line, ":");
            const char *guard = ParseGuard(str);
            if (guard == NULL)
                return NULL;

            str = strsep(&line, ":");
            if (str == NULL || strncmp(str, "HIERARCHY_", 10))
                return NULL;
            str += 10;
            int hierarchy = atoi(str);
            if (!strcmp(str, "AUTO"))
                hierarchy = -1;

            if (asprintf(&mrl, "dvb-t://frequency=%lu:inversion=%d:"
                         "bandwidth=%u:code-rate-hp=%s:code-rate-lp=%s:"
                         "modulation=%s:transmission=%d:guard=%s:"
                         "hierarchy=%d", freq, inversion, bandwidth, hp, lp,
                         mod, xmit, guard, hierarchy) == -1)
                mrl = NULL;
        }
    }
    else
    {   /* ATSC */
        const char *mod = ParseModulation(str);
        if (mod == NULL)
            return NULL;

        if (asprintf(&mrl, "atsc://frequency=%lu:modulation=%s", freq,
                     mod) == -1)
            mrl = NULL;
    }

    if (unlikely(mrl == NULL))
        return NULL;

    /* Video PID (TODO? set video track) */
    strsep(&line, ":");
    /* Audio PID (TODO? set audio track) */
    strsep(&line, ":");
    /* Extract SID */
    str = strsep(&line, ":");
    if (str == NULL)
    {
        free(mrl);
        return NULL;
    }
    unsigned long sid = strtoul(str, &end, 10);
    if (*end || sid > 65535)
    {
        free(mrl);
        return NULL;
    }

    char sid_opt[sizeof("program=65535")];
    snprintf(sid_opt, sizeof(sid_opt), "program=%lu", sid);

    input_item_t *item = input_item_NewCard(mrl, name);
    free(mrl);
    if (item != NULL)
        input_item_AddOption(item, sid_opt, 0);
    return item;
}
示例#2
0
static list expandtransition(struct trans_object *trans_el, struct net_object *net, struct net_object *unf_net)
{
  struct trans_object *unf_trans;
  bool Found;
  struct lisp_object *lisp;
  struct arc_object *arc, *new_arc, *prev_arc;
  guard_exprPTR g;  
  arcPTR *parsedArcs;
  operandPTR op;
  list arcs, l=NULL, curr=NULL;
  int i, j, noarc, otd, vtd;
  multisetPTR p_MS;
  AssignmentPTR gamma;
  status state;
  char *new_var;
  
 init_list(&gListParsedArcs);
 init_list(&YACCParsedVarList);

 
 #if DEBUG_UNFOLD
   printf("Expand transition %s\n\n", trans_el->tag);
 #endif
 
  new_var = FreeVarName();

  for (arc = trans_el->arcs, noarc = 0; arc != NULL; arc = arc->next, noarc++);
                
  parsedArcs = (arcPTR *) Ecalloc( noarc , sizeof(arcPTR));
   
  init_list(&YACCParsedVarList);   

  i = 0; 
  for( arc = trans_el->arcs; arc != NULL; arc = arc->next){
      
   init_list(&l);
   
   if((find_key(gListDomain, (generic_ptr) (arc->place)->tag , CmpDomainName, &l))==OK) 
   {      
     YACCparsedDomain = ((DomainObjPTR) DATA(l));
     Found = FALSE;
     if ( arc->color != NULL ) {
       for ( lisp = net->lisps; lisp != NULL; lisp = lisp->next){       
         if(lisp->type=='f' && (strcmp(arc->color, lisp->tag)==0)) {
	   parsedArcs[i++]= ParseArc(lisp->text);
	   Found = TRUE;
	 }   
       }
       if(Found == FALSE){
        parsedArcs[i++]= ParseArc(arc->color);
	Found = TRUE;
       }
     }
     else if(Found == FALSE && arc->lisp != NULL)
       parsedArcs[i++]= ParseArc(arc->lisp->text);
     else
       parsedArcs[i++]= ParseNoColoredArc(arc, new_var);
   }
   else
     Error(UNDEF_DOM_ERR, "DefTransitions", (arc->place)->tag);
    
  }
   
 
  g = ParseGuard(trans_el, net);      
  create_assignment(&gamma, YACCParsedVarList); 
  
  
  otd = atoi(opt_list[OPT_ORIZ_TRANS_DISPLACEMENT].arg_val);
  vtd = atoi(opt_list[OPT_VERT_TRANS_DISPLACEMENT].arg_val);
  
  l = NULL;
  j = 0;
  init_list(&l);
  for(state = first_assignment(gamma) ; state != ERROR ; j++) {
    #if DEBUG_UNFOLD      
      printf("Assignment %s\n%",print_assignment(gamma));
    #endif
    if(eval_guard_expr(g, gamma) == TRUE){
      unf_trans = unfolding_transition(trans_el, j, gamma, &(unf_net->rpars));      
      unf_trans->center.x += j*otd;
      unf_trans->center.y += j*vtd;
      head_insert(&l, (generic_ptr) unf_trans);
    
      
      i = 0; 
      for( arc = trans_el->arcs; arc != NULL; arc = arc->next)
      {
        #if DEBUG_UNFOLD
          printf("Arc %s \n", PrintArcExpression(parsedArcs[i]));
	#endif        
	
	
	eval_arc(parsedArcs[i], gamma, &p_MS);	
        
		
	arcs = expand_arc(arc, p_MS, parsedArcs[i++]->domain->create_place, unf_net);
// 	destroy_multiset(p_MS);
	curr = NULL;
	while ( (curr = list_iterator(arcs, curr)) != NULL )
	{
	  new_arc = (struct arc_object *) DATA(curr);          
          if(unf_trans->arcs == NULL)
            unf_trans->arcs = new_arc;
          else
            prev_arc->next = new_arc;
          prev_arc = new_arc; 
         
	}
// 	destroy(&arcs, NULL);
      }
            
    } 
    state = next_assignment(gamma);
  }  
  
  return(l);
}