コード例 #1
0
ファイル: parse-dvb.c プロジェクト: gitpan/Linux-DVB-DVBT
/* ----------------------------------------------------------------------- */
static void parse_nit_desc_1(unsigned char *desc, int dlen,
			     char *dest, int max)
{
    int i,t,l;

    if (dvb_debug>1)
		fprintf(stderr,
			"parse_nit_desc_1()\n");

    for (i = 0; i < dlen; i += desc[i+1] +2) {
	t = desc[i];
	l = desc[i+1];

    if (dvb_debug>1)
		fprintf_timestamp(stderr,
			"ts [nit1]: t 0x%02x   l %d\n",
			t, l);

	switch (t) {
	case 0x40:
	    mpeg_parse_psi_string((char*)desc+i+2, l, dest, max);
	    break;
	}
    }
}
コード例 #2
0
ファイル: parse-dvb.c プロジェクト: gitpan/Linux-DVB-DVBT
//	network_information_section(){
//		table_id	8	uimsbf
//		section_syntax_indicator	1	bslbf
//		reserved_future_use	1	bslbf
//		reserved	2	bslbf
//		section_length	12	uimsbf
//		
//		network_id	16	uimsbf
//		reserved	2	bslbf
//		version_number	5	uimsbf
//		current_next_indicator	1	bslbf
//		section_number	8	uimsbf
//		last_section_number	8	uimsbf
//		
//		reserved_future_use	4	bslbf
//		network_descriptors_length	12	uimsbf
//		for(i=0;i<N;i++){
//			descriptor()
//		}
//		reserved_future_use	4	bslbf
//		transport_stream_loop_length	12	uimsbf
//		for(i=0;i<N;i++){
//			transport_stream_id	16	uimsbf
//			original_network_id	16	uimsbf
//			reserved_future_use	4	bslbf
//			transport_descriptors_length	12	uimsbf
//			for(j=0;j<N;j++){
//				descriptor()
//			}
//		}
//		CRC_32	32	rpchof
//	}
int mpeg_parse_psi_nit(struct psi_info *info, unsigned char *data, int verbose, int tuned_freq)
{
    struct psi_stream *stream;
    char network[PSI_STR_MAX] = "";
    int id,version,current,len;
    int j,dlen,tsid;


    len     = mpeg_getbits(data,12,12) + 3 - 4;
    id      = mpeg_getbits(data,24,16);		/* network_id */
    version = mpeg_getbits(data,42,5);
    current = mpeg_getbits(data,47,1);

    if (!current)
    	return len+4;

    if (0 /* info->id == id */ && info->nit_version == version)
    	return len+4;
    info->nit_version = version;

    j = 80;
    dlen = mpeg_getbits(data,68,12);
    parse_nit_desc_1(data + j/8, dlen, network, sizeof(network));

    if (verbose>1) {
		fprintf_timestamp(stderr,
			"ts [nit]: id %3d ver %2d [%d/%d] #",
			id, version,
			mpeg_getbits(data,48, 8),
			mpeg_getbits(data,56, 8));
		mpeg_dump_desc(data + j/8, dlen);
		fprintf(stderr,"\n");
    }
    j += 16 + 8*dlen;

    while (j < len*8) {
    	tsid = mpeg_getbits(data,j,16);
        dlen = mpeg_getbits(data,j+36,12);
		j += 48;
		
		stream = psi_stream_get(info, tsid, id, 1);	
		
		stream->updated = 1;
		if (network)
			strcpy(stream->net, network);
		parse_nit_desc_2(data + j/8, dlen, stream, tuned_freq);
		if (verbose > 2) {
			fprintf(stderr,"   tsid %3d #", tsid);
			mpeg_dump_desc(data + j/8, dlen);
			fprintf(stderr,"\n");
		}
		j += 8*dlen;
    }

    if (verbose > 2)
    	fprintf(stderr,"\n");

    return len+4;
}
コード例 #3
0
ファイル: audit_log.c プロジェクト: VonRosenchild/build-test
static
int init_new_log_file()
{
  if (audit_log_handler == HANDLER_FILE)
  {
    audit_handler_file_config_t opts;
    opts.name= audit_log_file;
    opts.rotate_on_size= audit_log_rotate_on_size;
    opts.rotations= audit_log_rotations;
    opts.sync_on_write= audit_log_strategy == SYNCHRONOUS;
    opts.use_buffer= audit_log_strategy < SEMISYNCHRONOUS;
    opts.buffer_size= audit_log_buffer_size;
    opts.can_drop_data= audit_log_strategy == PERFORMANCE;
    opts.header= audit_log_header;
    opts.footer= audit_log_footer;

    log_handler= audit_handler_file_open(&opts);
    if (log_handler == NULL)
    {
      fprintf_timestamp(stderr);
      fprintf(stderr, "Cannot open file %s. ", audit_log_file);
      perror("Error: ");
      return(1);
    }
  }
  else
  {
    audit_handler_syslog_config_t opts;
    opts.facility= audit_log_syslog_facility_codes[audit_log_syslog_facility];
    opts.ident= audit_log_syslog_ident;
    opts.priority= audit_log_syslog_priority_codes[audit_log_syslog_priority];
    opts.header= audit_log_header;
    opts.footer= audit_log_footer;

    log_handler= audit_handler_syslog_open(&opts);
    if (log_handler == NULL)
    {
      fprintf_timestamp(stderr);
      fprintf(stderr, "Cannot open syslog. ");
      perror("Error: ");
      return(1);
    }
  }

  return(0);
}
コード例 #4
0
ファイル: parse-dvb.c プロジェクト: gitpan/Linux-DVB-DVBT
/* ----------------------------------------------------------------------- */
int mpeg_parse_psi_sdt(struct psi_info *info, unsigned char *data, int verbose, int tuned_freq)
{
    static const char *running[] = {
	[ 0       ] = "undefined",
	[ 1       ] = "not running",
	[ 2       ] = "starts soon",
	[ 3       ] = "pausing",
	[ 4       ] = "running",
	[ 5 ... 8 ] = "reserved",
    };
    struct psi_program *pr;
    int tsid,pnr,version,current;
    int j,len,dlen,run,ca;

    len     = mpeg_getbits(data,12,12) + 3 - 4;
    tsid    = mpeg_getbits(data,24,16);
    version = mpeg_getbits(data,42,5);
    current = mpeg_getbits(data,47,1);
    if (!current)
    	return len+4;
    if (info->tsid == tsid && info->sdt_version == version)
    	return len+4;
    info->sdt_version = version;

    if (verbose>1)
		fprintf_timestamp(stderr,
			"ts [sdt]: tsid %d ver %2d [%d/%d]\n",
			tsid, version,
			mpeg_getbits(data,48, 8),
			mpeg_getbits(data,56, 8));

    j = 88;
    while (j < len*8) {
		pnr  = mpeg_getbits(data,j,16);
		run  = mpeg_getbits(data,j+24,3);
		ca   = mpeg_getbits(data,j+27,1);
		dlen = mpeg_getbits(data,j+28,12);
		if (verbose > 2) {
			fprintf(stderr,"   (freq=%d) pnr %3d ca %d %s #",
				tuned_freq, pnr, ca, running[run]);
			mpeg_dump_desc(data+j/8+5,dlen);
			fprintf(stderr,"\n");
		}
		pr = psi_program_get(info, tsid, pnr, tuned_freq, 1);
		parse_sdt_desc(data+j/8+5,dlen,pr,tuned_freq, verbose);
		pr->running = run;
		pr->ca      = ca;
		j += 40 + dlen*8;
    }
    if (verbose > 2)
    	fprintf(stderr,"\n");
    return len+4;
}
コード例 #5
0
ファイル: audit_log.c プロジェクト: VonRosenchild/build-test
static
int reopen_log_file()
{
  if (log_handler != NULL)
  {
    if (audit_handler_flush(log_handler))
    {
      fprintf_timestamp(stderr);
      fprintf(stderr, "Cannot open file %s. ", audit_log_file);
      perror("Error: ");
      return(1);
    }
  }

  return(0);
}
コード例 #6
0
ファイル: audit_log.c プロジェクト: VonRosenchild/build-test
static
void audit_log_write(const char *buf, size_t len)
{
  static int write_error= 0;

  if (log_handler != NULL)
  {
    if (audit_handler_write(log_handler, buf, len) < 0)
    {
      if (!write_error)
      {
        write_error= 1;
        fprintf_timestamp(stderr);
        fprintf(stderr, "Error writing to file %s. ", audit_log_file);
        perror("Error: ");
      }
    }
    else
    {
      write_error= 0;
    }
  }
}
コード例 #7
0
ファイル: parse-dvb.c プロジェクト: gitpan/Linux-DVB-DVBT
/* ----------------------------------------------------------------------- */
static void parse_nit_desc_2(unsigned char *desc, int dlen,
			     struct psi_stream *stream, int tuned_freq)
{
    static char *bw[4] = {
	[ 0 ] = "8",
	[ 1 ] = "7",
	[ 2 ] = "6",
	[ 3 ] = "5",
    };
    static char *co_t[4] = { 
	[ 0 ] = "0",	/* QPSK */
	[ 1 ] = "16",
	[ 2 ] = "64",
    };
    static char *co_c[16] = {
	[ 0 ] = "0",
	[ 1 ] = "16",
	[ 2 ] = "32",
	[ 3 ] = "64",
	[ 4 ] = "128",
	[ 5 ] = "256",
    };
    static char *hi[4] = {
	[ 0 ] = "0",
	[ 1 ] = "1",
	[ 2 ] = "2",
	[ 3 ] = "4",
    };
    static char *ra_t[8] = {
	[ 0 ] = "12",
	[ 1 ] = "23",
	[ 2 ] = "34",
	[ 3 ] = "56",
	[ 4 ] = "78",
    };
    static char *ra_sc[8] = {
	[ 1 ] = "12",
	[ 2 ] = "23",
	[ 3 ] = "34",
	[ 4 ] = "56",
	[ 5 ] = "78",
    };
    static char *gu[4] = {
	[ 0 ] = "32",
	[ 1 ] = "16",
	[ 2 ] = "8",
	[ 3 ] = "4",
    };
    static char *tr[3] = {
	[ 0 ] = "2",
	[ 1 ] = "8",
	[ 2 ] = "4",
    };
    static char *po[4] = {
	[ 0 ] = "H",
	[ 1 ] = "V",
	[ 2 ] = "L",  // circular left
	[ 3 ] = "R",  // circular right
    };
    unsigned int freq,rate,fec;
    int i,j, t,l;

    if (dvb_debug>1)
		fprintf(stderr,
			"parse_nit_desc_2()\n");

    for (i = 0; i < dlen; i += desc[i+1] +2) 
    {
	t = desc[i];
	l = desc[i+1];

    if (dvb_debug>1)
		fprintf_timestamp(stderr,
			"ts [nit2]: t 0x%02x   l %d\n",
			t, l);


	switch (t) {
	case 0x43: /* dvb-s */
	    freq = mpeg_getbits(desc+i+2,  0, 32);
	    rate = mpeg_getbits(desc+i+2, 56, 28);
	    fec  = mpeg_getbits(desc+i+2, 85,  3);
	    stream->frequency     = unbcd(freq)    * 10;
	    stream->symbol_rate   = unbcd(rate*16) * 10;
	    stream->fec_inner     = ra_sc[fec];
	    stream->polarization  = po[   mpeg_getbits(desc+i+2, 49, 2) ];
	    break;
	    
	case 0x44: /* dvb-c */
	    freq = mpeg_getbits(desc+i+2,  0, 32);
	    rate = mpeg_getbits(desc+i+2, 56, 28);
	    fec  = mpeg_getbits(desc+i+2, 85,  3);
	    stream->frequency     = unbcd(freq)    * 100;
	    stream->symbol_rate   = unbcd(rate*16) * 10;
	    stream->fec_inner     = ra_sc[fec];
	    stream->constellation = co_c[ mpeg_getbits(desc+i+2, 52, 4) ];
	    break;
	    
	    
	case 0x5a: /* dvb-t */
		// terrestrial_delivery_system_descriptor

		//	centre_frequency 32 bslbf
		//	bandwidth 3 bslbf
		//	priority 1 bslbf
		//	Time_Slicing_indicator 1 bslbf
		//	MPE-FEC_indicator 1 bslbf
		//	reserved_future_use 2 bslbf
		//	constellation 2 bslbf
		//	hierarchy_information 3 bslbf
		//	code_rate-HP_stream 3 bslbf
		//	code_rate-LP_stream 3 bslbf
		//	guard_interval 2 bslbf
		//	transmission_mode 2 bslbf
		//	other_frequency_flag 1 bslbf
		//	reserved_future_use 32 bslbf

	    stream->frequency     = mpeg_getbits(desc+i+2,  0, 32) * 10;
	    stream->bandwidth     = bw[   mpeg_getbits(desc+i+2, 33, 2) ];
	    stream->constellation = co_t[ mpeg_getbits(desc+i+2, 40, 2) ];
	    stream->hierarchy     = hi[   mpeg_getbits(desc+i+2, 43, 2) ];
	    stream->code_rate_hp  = ra_t[ mpeg_getbits(desc+i+2, 45, 3) ];
	    stream->code_rate_lp  = ra_t[ mpeg_getbits(desc+i+2, 48, 3) ];
	    stream->guard         = gu[   mpeg_getbits(desc+i+2, 51, 2) ];
	    stream->transmission  = tr[   mpeg_getbits(desc+i+2, 54, 1) ];
	    stream->other_freq    = mpeg_getbits(desc+i+2, 55, 1);

if (dvb_debug>2)
	fprintf(stderr,
		"#@f terrestrial_delivery_system_descriptor: TSID %d freq=%d (other=%d) bw=%d (%s MHz) const=%d (%s) hier=%d (%s) rate hi=%d  (%s) rate lo=%d (%s) guard=%d (%s) tr=%d (%s) : up=%d tuned=%d\n",
		stream->tsid,
		stream->frequency,
		stream->other_freq,
		mpeg_getbits(desc+i+2, 33, 2),
		stream->bandwidth,
		mpeg_getbits(desc+i+2, 40, 2),
		stream->constellation,
		mpeg_getbits(desc+i+2, 43, 2),
		stream->hierarchy,
		mpeg_getbits(desc+i+2, 45, 3),
		stream->code_rate_hp,
		mpeg_getbits(desc+i+2, 48, 3),
		stream->code_rate_lp,
		mpeg_getbits(desc+i+2, 51, 2),
		stream->guard,
		mpeg_getbits(desc+i+2, 54, 1),
		stream->transmission,
		stream->updated, stream->tuned
		);
		
// Test where broadcast centre freq is invalid
#ifdef TEST_INVALID_CENTRE

		// mangle the real centre freq
		stream->frequency = stream->tsid ;

#endif


#ifdef TEST_MULTIFREQ

		// mangle the real centre freq
		stream->frequency = stream->tsid ;
		
	    // create freq list from table
		{
		int idx = (stream->tsid & 0xf000) >> 12 ;
		int num_freqs = other_freqs[idx][0] ;
    	unsigned int freq_index ;

if (dvb_debug>1)
	fprintf(stderr,
		"frequency_list_descriptor: num freqs=%d\n",
		num_freqs);
		
	    	
	    	stream->freq_list_len = num_freqs ;
	    	stream->freq_list = malloc(num_freqs * sizeof(int)) ;
	    	memset(stream->freq_list, 0, num_freqs * sizeof(int)) ;
		    for (freq_index=0; freq_index < num_freqs; ++freq_index) 
		    {
			int freq = other_freqs[idx][freq_index+1];
		
			    if (dvb_debug>1)
					fprintf(stderr,
						"frequency_list_descriptor: freq[%d]=%d\n",
						freq_index, freq);
	
				stream->freq_list[freq_index] = freq ;
		    }
	    
		}
#endif

if (dvb_debug > 1)
{
	fprintf(stderr,
		"terrestrial_delivery_system_descriptor:: Freq=%d\n",
		stream->frequency);
	
}
	    break;

	case 0x62: /* freq list */
		{
		unsigned int coding_type ;
		int num_freqs ;
	 
		//	frequency_list_descriptor(){
		//		descriptor_tag 8 uimsbf
		//		descriptor_length 8 uimsbf
		//		reserved_future_use 6 bslbf
		//		coding_type 2 bslbf
		//		for (i=0;I<N;i++){
		//			centre_frequency 32 uimsbf
		//		}
		//	}
		//	Table 54: Coding type values
		//	Coding_type Delivery system
		//	00 			not defined
		//	01 			satellite
		//	10 			cable
		//	11 			terrestrial

	    j = 0;
	    coding_type = mpeg_getbits(desc+i+2,  j+6, 2) ;
	    j+=8 ;
	    
	    num_freqs = (l - 1) / 4 ;

if (dvb_debug>1)
	fprintf(stderr,
		"frequency_list_descriptor: num freqs=%d\n",
		num_freqs);
		
	    if ((coding_type == 3) && (num_freqs > 0))
	    {
	    	unsigned int freq_index=0 ;
	    	
	    	stream->freq_list_len = num_freqs ;
	    	stream->freq_list = malloc(num_freqs * sizeof(int)) ;
	    	memset(stream->freq_list, 0, num_freqs * sizeof(int)) ;
		    while (j < l*8) 
		    {
			int freq ;
		
				freq = mpeg_getbits(desc+i+2,  j, 32) * 10 ;
		
			    if (dvb_debug>1)
					fprintf(stderr,
						"frequency_list_descriptor: freq[%d]=%d\n",
						freq_index, freq);
	
				stream->freq_list[freq_index++] = freq ;
		
				j += 32;
		    }
	    }
	    
		}
	    break;

#ifndef TEST_MULTIFREQ
	    
	case 0x83 : /* LCN */

	    j = 0;
	    while (j < l*8) 
	    {
		int sid, visible, lcn ;
	    struct prog_info  *pinfo;
		
	
			//	service_id 16 uimsbf
			//	visible_service_flag 1 bslbf
			//	reserved 5 bslbf
			//	logical_channel_number 10 uimsbf	
			sid			= mpeg_getbits(desc+i+2,  j, 16) ;
			visible		= mpeg_getbits(desc+i+2,  j+17, 1) ;
			lcn 		= mpeg_getbits(desc+i+2,  j+22, 10) ;
	
		    if (dvb_debug>1)
				fprintf(stderr,
					"#@p LCN: service_id=%d (0x%04x)  visible=%d  lcn=%d (0x%03x)\n",
					sid, sid, visible, lcn, lcn);
					
			pinfo = prog_info_get(stream, sid, 1) ;
			pinfo->visible = visible ;
			pinfo->lcn = lcn ;
	
			j += 32;
	    }

		break ;
#endif

		
	case 0x41:  /* service list descriptor */
	
		//service_list_descriptor(){
		//	descriptor_tag 8 uimsbf
		//	descriptor_length 8 uimsbf
		//	for (i=0;i<N;I++){
		//		service_id 16 uimsbf
		//		service_type 8 uimsbf
		//	}
		//}
	
	    j = 0;
	    while (j < l*8) 
	    {
		int sid, service_type ;
	    struct prog_info  *pinfo;
	
			sid				= mpeg_getbits(desc+i+2,  j, 16) ;
			service_type	= mpeg_getbits(desc+i+2,  j+17, 8) ;
	
		    if (dvb_debug>1)
				fprintf(stderr,
					"service_list_descriptor: service_id=%d (0x%04x)  service_type=%d (0x%02x)\n",
					sid, sid, service_type, service_type);

			pinfo = prog_info_get(stream, sid, 1) ;
			pinfo->service_type = service_type ;
	
			j += 24;
	    }
		break ;	
		
	}
    }
    return;
}