Esempio n. 1
0
int main( int argc, char *argv[]){
	int  mode = 0;
	int  status = ISDC_OK ;
	char inDol[PIL_LINESIZE]    = "";
	int  numrows = 1;
	fitsfile *fPtr              = NULL;

	/* Executable initialisation */
	mode = CommonInit(COMPONENT_NAME,COMPONENT_VERSION,argc,argv);
	if(mode != ISDC_SINGLE_MODE ){
		RILlogMessage(NULL,Error_1,"CommonInit: mode = %d ", mode); 
		mode=CommonExit(mode);
	}    
	
	status = get_parameters(inDol, &numrows, status);

	RILlogMessage ( NULL, Log_1, "About to add %d rows to %s.", numrows, inDol );

	if ( ! fits_open_file ( &fPtr, inDol, READWRITE, &status) ) {
		RILlogMessage ( NULL, Log_1, "inDol opened." );
/*		status = fits_insert_rows (fPtr, (fPtr->Fptr)->numrows, numrows, &status); */
/*		if ( fits_insert_rows (fPtr, (fPtr->Fptr)->numrows, numrows, &status) ) {	*/
		if ( fits_insert_rows (fPtr, 0, numrows, &status) ) {
			RILlogMessage ( NULL, Log_1, "fits_insert_rows failed." );
		}
		fits_close_file(fPtr, &status);
		RILlogMessage ( NULL, Log_1, "inDol closed." );
	} else {
		RILlogMessage ( NULL, Log_1, "inDol open failed." );
	}

	mode = CommonExit(status);
	return(mode); 
}
Esempio n. 2
0
void getAccessUnit( BsBitStream*      bitStream ,  BsBitBuffer* AUBuffer,unsigned int *AUIndex, unsigned long *totalLength, ES_DESCRIPTOR *es)
{
  unsigned long  index,length,AUStartFlag,AUEndFlag,dummy;
  unsigned long  seq_number;
  
  /* read default AL-PDU header */
  BsGetBit(bitStream,&index,8);
  BsGetBit(bitStream,&length,8);
  *totalLength += length;

  if (es->ALConfigDescriptor.useAccessUnitStartFlag.value)
    BsGetBit(bitStream,&AUStartFlag,1);
  if (AUStartFlag!=1) CommonExit(-1,"error in getAccessUnit");

  if (es->ALConfigDescriptor.useAccessUnitEndFlag.value)
    BsGetBit(bitStream,&AUEndFlag,1);

  if (es->ALConfigDescriptor.seqNumLength.value > 0)
    BsGetBit(bitStream,&seq_number,es->ALConfigDescriptor.seqNumLength.value);
  else
    BsGetBit(bitStream,&dummy,6);  /*6 padding bits (alm) */

  *AUIndex = index;
  
  if (AUStartFlag!=1) CommonExit(-1,"Error  AL-PDU header ");
#if 0  
  BsGetBuffer( bitStream, AUBuffer,length*8);    
#else
  BsGetBufferAppend( bitStream, AUBuffer,1,length*8);    
#endif
  while (AUEndFlag!=1) {
    BsGetBit(bitStream,&index,8);

    if (*AUIndex != index) 
      CommonExit(-1,"FlexMux index error");

    BsGetBit(bitStream,&length,8);
    *totalLength += length;

    if (es->ALConfigDescriptor.useAccessUnitStartFlag.value)
      BsGetBit(bitStream,&AUStartFlag,1);
    if (AUStartFlag==1) CommonExit(-1,"error in getAccessUnit");

    if (es->ALConfigDescriptor.useAccessUnitEndFlag.value)
      BsGetBit(bitStream,&AUEndFlag,1);

    if (es->ALConfigDescriptor.seqNumLength.value > 0)
      BsGetBit(bitStream,&seq_number,es->ALConfigDescriptor.seqNumLength.value);
    else
      BsGetBit(bitStream,&dummy,6);  /*6 padding bits (alm) */

    BsGetBufferAppend( bitStream, AUBuffer,1,length*8);    
  }  
}
Esempio n. 3
0
int resolve_host(char *host, SOCKADDR_IN *sck_addr, unsigned short remote_port)
{
    HOSTENT *hp;

    if (isalpha(host[0]))
    {
        /* server address is a name */
        hp = gethostbyname(host);
    }
    else
    {
        unsigned long addr;
        /* Convert nnn.nnn address to a usable one */
        addr = inet_addr(host);
        hp = gethostbyaddr((char *)&addr, 4, AF_INET);
    }

    if (hp == NULL)
    {
        char tmp[128];
        wsprintf(tmp, "Error resolving host address [%s]!\n", host);
        CommonExit(tmp);
        return -1;
    }

    ZeroMemory(sck_addr, sizeof(SOCKADDR_IN));
    sck_addr->sin_family = AF_INET;
    sck_addr->sin_port = htons(remote_port);
    CopyMemory(&sck_addr->sin_addr, hp->h_addr, hp->h_length);

    return 0;
}
Esempio n. 4
0
void DecLpcFrame (
  BsBitBuffer *bitBuf,		/* in: bit stream frame */
  float **sampleBuf,		/* out: audio frame samples */
				/*     sampleBuf[numChannel][frameNumSample] */
  int *usedNumBit)		/* out: num bits used for this frame */
{
  CommonExit(1,"DecLpcFrame: dummy");
}
Esempio n. 5
0
void DecLpcInitNew (
  char *decPara,                   /* in: decoder parameter string     */
  FRAME_DATA*  fD,
  LPC_DATA*    lpcData,
  int layer
  )             /* out: decoder delay (num samples) */
{
  CommonExit(1,"DecLpcInitNew: dummy");
}
Esempio n. 6
0
void DecLpcInit (
  int numChannel,		/* in: num audio channels */
  float fSample,		/* in: sampling frequency [Hz] */
  float bitRate,		/* in: total bit rate [bit/sec] */
  char *decPara,		/* in: decoder parameter string */
  BsBitBuffer *bitHeader,	/* in: header from bit stream */
  int *frameNumSample,		/* out: num samples per frame */
  int *delayNumSample)		/* out: decoder delay (num samples) */
{
  CommonExit(1,"DecLpcInit: dummy");
}
Esempio n. 7
0
void subSampl(float * inBuff, float * outBuff,int factor,int *noOfSampl)
{
  int i ;
  if ((*noOfSampl%6)!= 0)
    CommonExit(-1,"\n Error in downsampling");
  else
    *noOfSampl = *noOfSampl/6;

  for (i=0;i< *noOfSampl;i++){
    outBuff[i]=inBuff[i * factor];
  }
}
Esempio n. 8
0
FIR_FILT *initFirLowPass(float stopBand,int taps)
{
  FIR_FILT *filter;
  
  filter = (FIR_FILT*)malloc(sizeof(FIR_FILT));
  filter->filtLength=taps;
  filter->memoryPtr = (float*)malloc(sizeof(float)*(taps+1));
  filter->writeIdx =0 ;
  filter->readIdx = taps;
  if ((stopBand == 48000/4000)&& (taps == 120))
    filter->filtPtr=fir48_4_120;
  else 
    CommonExit(-1,"\nthis filter is not yet defined in fir_filt.c");
  
  return filter;
    

}
Esempio n. 9
0
void initESDescr( ES_DESCRIPTOR **es)
{

  *es = NULL;
  *es = (ES_DESCRIPTOR*) malloc(sizeof(ES_DESCRIPTOR));
  

  if (*es==NULL) CommonExit(-1,"no mem");

  memset (*es, 0, sizeof (ES_DESCRIPTOR)) ;

  (*es)->ESNumber.length=5;

  (*es)->streamDependence.length=1;
  (*es)->URLFlag.length=1;
  (*es)->extensFlag.length=1;
  (*es)->dependsOn_Es_number.length=5;

  (*es)->DecConfigDescr.profileAndLevelIndication.length=8 ;
  (*es)->DecConfigDescr.streamType.length=6 ;
  (*es)->DecConfigDescr.upsteam.length=1 ;
  (*es)->DecConfigDescr.specificInfoFlag.length=1 ;
  (*es)->DecConfigDescr.bufferSizeDB.length=24 ;
  (*es)->DecConfigDescr.maxBitrate.length=32 ;
  (*es)->DecConfigDescr.avgBitrate.length=32 ;
  (*es)->DecConfigDescr.specificInfoLength.length=8 ;
  (*es)->DecConfigDescr.audioSpecificConfig.audioDecoderType.length=3 ;
  (*es)->DecConfigDescr.audioSpecificConfig.samplingFreqencyIndex.length= 4;
  (*es)->DecConfigDescr.audioSpecificConfig.channelConfiguration.length=4 ;
  (*es)->ALConfigDescriptor.useAccessUnitStartFlag.length = 1;
  (*es)->ALConfigDescriptor.useAccessUnitEndFlag.length = 1;
  (*es)->ALConfigDescriptor.useRandomAccessPointFlag.length = 1;
  (*es)->ALConfigDescriptor.usePaddingFlag.length = 1;
  (*es)->ALConfigDescriptor.seqNumLength.length = 4;

}
Esempio n. 10
0
void DecLpcFree (void)
{
  CommonExit(1,"DecLpcFree: dummy");
}
Esempio n. 11
0
int CmdLineEval (
  int argc,			/* in: num command line args */
  char *argv[],			/* in: command line args */
  CmdLinePara *paraList,	/* in: parameter info list */
				/*     or NULL */
  CmdLineSwitch *switchList,	/* in: switch info list */
				/*     or NULL */
  int setDefault,		/* in: 0 = leave switch used flags and args */
				/*         unchanged */
				/*     1 = init switch used flags and args */
				/*         with defaultValue */
  char **progNamePtr)		/* out: program name */
				/*      or NULL */
				/* returns: */
				/*  0=OK  1=help switch  2=error */
{
  char *progName;
  char *tmpProgName;
  int i;
  int minusFlag;
  char *minusChar;
  CmdLinePara *paraPtr;
  CmdLineSwitch *switchPtr;
  int tmpVarArgIdx[MAX_TOKEN_NUM];
  int count;  
  int *varArgIdx;

  /* extract program name from argv[0] if command line mode */
  if (progNamePtr != NULL) {
    progName = StripPath(argv[0]);
    if ((tmpProgName=strchr(progName,'.'))!=NULL)
      *tmpProgName = '\0';
    *progNamePtr = progName;
    CommonProgName(progName);
  }
  else	/* progNamePtr==NULL */
    progName = NULL;

  /* set minusFlag if switches are preceded by '-' */
  minusFlag = (progNamePtr!=NULL || paraList!=NULL);
  minusChar = (minusFlag) ? "-" : "";
    
  if (CLdebugLevel >= 1)
    printf("CmdLineEval: argc=%d  mode=%s  minusChar=\"%s\"\n",
	   argc,(progNamePtr!=NULL)?"cmd line":"token list",minusChar);

  if (setDefault) {
    /* reset switch used flags and evaluate default values */
    switchPtr = switchList;
    while (switchPtr != NULL && switchPtr->switchName != NULL) {
      if (switchPtr->argument != NULL) {
	if (switchPtr->usedFlag != NULL)
	  *((int*)switchPtr->usedFlag) = 0;
	if (switchPtr->format == NULL)
	  *((int*)switchPtr->argument) = 0;
	else
	  if (switchPtr->defaultValue != NULL) {
	    if (strcmp(switchPtr->format,"%s") == 0)
	      *((char**)switchPtr->argument) = switchPtr->defaultValue;
	    else
	      if (sscanf(switchPtr->defaultValue,switchPtr->format,
			 switchPtr->argument) != 1) {
		CommonWarning("CmdLineEval: "
			      "switch %s%s default argument format error",
			      minusChar,switchPtr->switchName);
		return 2;
	      }
	  }
      }
      switchPtr++;
    }
  }

  /* scan arguments  */
  i = (progNamePtr==NULL) ? 0 : 1;	/* skip program name */
					/* if command line mode */
  paraPtr = paraList;
  count = 0;

  while (i < argc) {
    if ((*argv[i] == '-' && *(argv[i]+1) != '\0') ||
	(minusFlag == 0 && *argv[i] != '\0')) {
      /* evaluate cmdline switch */
      switchPtr = switchList;
      while (switchPtr != NULL && switchPtr->switchName != NULL) {
	if (strcmp(argv[i]+minusFlag,switchPtr->switchName) == 0) {
	  /* switchList entry found */
	  if (switchPtr->argument == NULL) {
	    /* help switch found */
	    return 1;
	  }
	  if (switchPtr->format != NULL) {
	    /* read switch argument */
	    if (++i >= argc) {
	      CommonWarning("CmdLineEval: switch %s%s has no argument",
			    minusChar,switchPtr->switchName);
	      return 2;
	    }
	    else
	      if (strcmp(switchPtr->format,"%s") == 0)
		*((char**)switchPtr->argument) = argv[i];
	      else
		if (sscanf(argv[i],switchPtr->format,switchPtr->argument)
		    != 1) {
		  CommonWarning("CmdLineEval: "
				"switch %s%s argument format error",
				minusChar,switchPtr->switchName);
		  return 2;
		}
	  }
	  else
	    /* switch without argument */
	    *((int*)switchPtr->argument) = 1;
	  /* set switch used flag */
	  if (switchPtr->usedFlag != NULL)
	    *((int*)switchPtr->usedFlag) = 1;
	  break;	/* while (switchPtr ...) */
	}
	switchPtr++;
      }		/* while (switchPtr ...) */

      if (switchPtr == NULL || switchPtr->switchName == NULL) {
	CommonWarning("CmdLineEval: switch %s unknown",argv[i]);
	return 2;
      }
    }

    else {	/* if (*argv[i] == '-' && ...) */
      /* evaluate cmdline argument */
      if (paraPtr == NULL || paraPtr->argument == NULL) {
	CommonWarning("CmdLineEval: too many arguments",argv[i]);
	return 2;
      }
      if (paraPtr->format == NULL) {
	/* variable length argument list */
	if (count+1 >= MAX_TOKEN_NUM) {
	  CommonWarning("CmdLineEval: argument list %s too long",
			paraPtr->help);
	  return 2;
	}
	tmpVarArgIdx[count++] = i;
      }
      else {
	if (strcmp(paraPtr->format,"%s") == 0)
	  *((char**)paraPtr->argument) = argv[i];
	else
	  if (sscanf(argv[i],paraPtr->format,paraPtr->argument) != 1) {
	    CommonWarning("CmdLineEval: argument %s format error",
			  paraPtr->help);
	    return 2;
	  }
	paraPtr++;
      }
    }
    
    i++;
  }		/* while (i < argc) */
    
  if (paraPtr != NULL && paraPtr->argument != NULL &&
      paraPtr->format == NULL) {
    /* variable length argument list */
    if ((varArgIdx = (int*)malloc((count+1)*sizeof(int))) == NULL)
      CommonExit(1,"CmdLineEval: memory allocation error (varArgIdx)");
    for (i=0; i<count; i++)
      varArgIdx[i] = tmpVarArgIdx[i];
    varArgIdx[count] = -1;
    *((int**)paraPtr->argument) = varArgIdx;
    paraPtr++;
  }

  if (paraPtr != NULL && paraPtr->argument != NULL) {
    CommonWarning("CmdLineEval: argument %s is missing",
		  paraPtr->help);
    return 2;
  }

  return 0;
}
Esempio n. 12
0
int  nextAccessUnit( BsBitStream*      bitStream ,                      
                     unsigned int*     layer, 
                     FRAME_DATA*       frameData
                     )
{
  unsigned long index, dummy,AUStartFlag,AUEndFlag,AUIndex;
  unsigned long length;
  unsigned long  seq_number;
  ES_DESCRIPTOR*  es;
  BsBitBuffer*    AUBuffer  ;

  /* read default AL-PDU header */
  /* suppose trivial streammap table: index 0 = layer 0 ; index 1 = layer 1 etc.*/ 
  BsGetBit(bitStream,&index,8);
  *layer = index;
  AUIndex = index;
  BsGetBit(bitStream,&length,8);
  es = frameData->od->ESDescriptor[index];

  AUBuffer = frameData->layer[index].bitBuf  ;

  if (es->ALConfigDescriptor.useAccessUnitStartFlag.value)
    if (BsGetBit(bitStream,&AUStartFlag,1)== -1) {
      return -1;
    };
  if (AUStartFlag!=1) CommonExit(-1,"error in getAccessUnit");

  if (es->ALConfigDescriptor.useAccessUnitEndFlag.value)
    BsGetBit(bitStream,&AUEndFlag,1);

  if (es->ALConfigDescriptor.seqNumLength.value > 0)
    BsGetBit(bitStream,&seq_number,es->ALConfigDescriptor.seqNumLength.value);
  else
    BsGetBit(bitStream,&dummy,6);  /*6 padding bits (alm) */
  
  if (AUStartFlag!=1) CommonExit(-1,"Error  AL-PDU header ");
  if (AUBuffer!=0 ) {
    if ((AUBuffer->size - AUBuffer->numBit) > (long)length*8 )  {
      BsGetBufferAppend( bitStream, AUBuffer,1,length*8);    
      frameData->layer[AUIndex].NoAUInBuffer++;/* each decoder must decrease this by the number of decoded AU */
    }  else {
      BsGetSkip(bitStream,length*8);
      CommonWarning ("flexmux input buffer overflow for layer %d ; skiping next AU",index);
    }
  } else {
    BsGetSkip(bitStream,length*8);
  }
  while (AUEndFlag!=1) {
    BsGetBit(bitStream,&index,8);

    if (AUIndex != index) 
      CommonExit(-1,"FlexMux index error");

    BsGetBit(bitStream,&length,8);

    if (es->ALConfigDescriptor.useAccessUnitStartFlag.value)
      BsGetBit(bitStream,&AUStartFlag,1);
    if (AUStartFlag==1) CommonExit(-1,"error in getAccessUnit");

    if (es->ALConfigDescriptor.useAccessUnitEndFlag.value)
      BsGetBit(bitStream,&AUEndFlag,1);

    if (es->ALConfigDescriptor.seqNumLength.value > 0)
      BsGetBit(bitStream,&seq_number,es->ALConfigDescriptor.seqNumLength.value);
    else
      BsGetBit(bitStream,&dummy,6);  /*6 padding bits (alm) */

    if (AUBuffer!=0 ) {
      if ((AUBuffer->size - AUBuffer->numBit) > (long)length*8 )  {
        BsGetBufferAppend( bitStream, AUBuffer,1,length*8);    
      }  else {
        BsGetSkip(bitStream,length*8);
        CommonWarning ("flexmux input buffer overflow for layer %d ; skiping next AU",index);
      }
    } else {
      BsGetSkip(bitStream,length*8);
    }

  }  
  return 0;
}
Esempio n. 13
0
void  advanceESDescr ( BsBitStream* bitStream, 
                       ES_DESCRIPTOR *es, 
                       int WriteFlag) 
{
  
  BsRWBitWrapper(bitStream,&(es->ESNumber.value),es->ESNumber.length,WriteFlag);
  
  BsRWBitWrapper(bitStream, &(es->streamDependence.value),es->streamDependence.length,WriteFlag);
  
  BsRWBitWrapper(bitStream, &(es->URLFlag.value),  es->URLFlag.length,WriteFlag);

  if (es->streamDependence.value != 0) {
    BsRWBitWrapper(bitStream, &(es->dependsOn_Es_number.value),  es->dependsOn_Es_number.length,WriteFlag);
  }

  BsRWBitWrapper(bitStream, &(es->extensFlag.value),  es->extensFlag.length,WriteFlag);

  BsRWBitWrapper(bitStream, &(es->DecConfigDescr.profileAndLevelIndication.value),  es->DecConfigDescr.profileAndLevelIndication.length,WriteFlag);
  BsRWBitWrapper(bitStream, &(es->DecConfigDescr.streamType.value) ,  es->DecConfigDescr.streamType.length,WriteFlag) ;
  BsRWBitWrapper(bitStream, &(es->DecConfigDescr.upsteam.value) ,  es->DecConfigDescr.upsteam.length,WriteFlag) ;
  BsRWBitWrapper(bitStream, &(es->DecConfigDescr.specificInfoFlag.value) ,  es->DecConfigDescr.specificInfoFlag.length,WriteFlag) ;
  BsRWBitWrapper(bitStream, &(es->DecConfigDescr.bufferSizeDB.value) ,  es->DecConfigDescr.bufferSizeDB.length,WriteFlag) ;

  BsRWBitWrapper(bitStream, &(es->DecConfigDescr.maxBitrate.value) ,  es->DecConfigDescr.maxBitrate.length,WriteFlag) ;
  BsRWBitWrapper(bitStream, &(es->DecConfigDescr.avgBitrate.value) ,  es->DecConfigDescr.avgBitrate.length,WriteFlag) ;

  BsRWBitWrapper(bitStream, &(es->DecConfigDescr.specificInfoLength.value) ,  es->DecConfigDescr.specificInfoLength.length,WriteFlag) ;
  BsRWBitWrapper(bitStream, &(es->DecConfigDescr.audioSpecificConfig.audioDecoderType.value),  
                 es->DecConfigDescr.audioSpecificConfig.audioDecoderType.length,WriteFlag) ;
  
  BsRWBitWrapper(bitStream, &(es->DecConfigDescr.audioSpecificConfig.samplingFreqencyIndex.value),  
                 es->DecConfigDescr.audioSpecificConfig.samplingFreqencyIndex.length,WriteFlag);
  BsRWBitWrapper(bitStream, &(es->DecConfigDescr.audioSpecificConfig.channelConfiguration.value),  
                 es->DecConfigDescr.audioSpecificConfig.channelConfiguration.length,WriteFlag);


  switch (es->DecConfigDescr.audioSpecificConfig.audioDecoderType.value)
    {
    case GA :
      initTFspecConf ( &(es->DecConfigDescr.audioSpecificConfig.specConf.TFSpecificConfig));
      advanceTFspecConf(bitStream,&(es->DecConfigDescr.audioSpecificConfig.specConf.TFSpecificConfig),WriteFlag);
      break;
    case CELP :
      initCelpSpecConf (&(es->DecConfigDescr.audioSpecificConfig.specConf.celpSpecificConfig)); 
      advanceCelpSpecConf(bitStream,&(es->DecConfigDescr.audioSpecificConfig.specConf.celpSpecificConfig),WriteFlag);
      break;
    case HVXC:	/* AI 990616 */
      initHvxcSpecConf (&(es->DecConfigDescr.audioSpecificConfig.specConf.hvxcSpecificConfig)); 
      advanceHvxcSpecConf(bitStream,&(es->DecConfigDescr.audioSpecificConfig.specConf.hvxcSpecificConfig),WriteFlag);
      break;
    default :
      CommonExit(-1,"audioDecoderType not implemented");
      break;
    }

  BsRWBitWrapper(bitStream, &(es->ALConfigDescriptor.useAccessUnitStartFlag.value),es->ALConfigDescriptor.useAccessUnitStartFlag.length,WriteFlag);

  BsRWBitWrapper(bitStream, &(es->ALConfigDescriptor.useAccessUnitEndFlag.value),es->ALConfigDescriptor.useAccessUnitEndFlag.length,WriteFlag);

  BsRWBitWrapper(bitStream, &(es->ALConfigDescriptor.useRandomAccessPointFlag.value),es->ALConfigDescriptor.useRandomAccessPointFlag.length,WriteFlag);

  BsRWBitWrapper(bitStream, &(es->ALConfigDescriptor.usePaddingFlag.value),es->ALConfigDescriptor.usePaddingFlag.length,WriteFlag);

  BsRWBitWrapper(bitStream, &(es->ALConfigDescriptor.seqNumLength.value),es->ALConfigDescriptor.seqNumLength.length,WriteFlag);
}
Esempio n. 14
0
static void GetProgConfig( BsBitStream* bitstream, ADIF_INFO* adifInfo )
{
  
  unsigned long data;
  int i, tmp;


  /* Instance Tag */
  BsGetBit( bitstream, &data, 4 );
 
 
  /* profile */
  BsGetBit( bitstream, &data, 2 );
  tmp = (int)data;
  if ( CheckProfile(tmp) )
    CommonExit(1,"Illegal profile");

  adifInfo->profile = tmp;


  /* Sampling frequency index */
  BsGetBit( bitstream, &data, 4 );
  tmp = GetSamplingRate((int)data); 
  if ( !tmp )
    CommonExit(1,"Illegal frequency index");

  adifInfo->samplingRate = tmp;


  /* number of front channel elements: 
     only one element (SCE or CPE) is supported */
  BsGetBit( bitstream, &data, 4 );
  if ( data != 1)
    CommonExit(1,"Unsupported number of front channels");

  /* number of side channel elements (not supported) */
  BsGetBit( bitstream, &data, 4 );
  if ( data )
    CommonExit(1,"Unsupported channel element");    

  /* number of back channel elements (not supported) */
  BsGetBit( bitstream, &data, 4 );
  if ( data )
    CommonExit(1,"Unsupported channel element");    
  
  /* number of LFE channel elements (not supported) */
  BsGetBit( bitstream, &data, 2 );
  if ( data )
    CommonExit(1,"Unsupported channel element");    
  
  /* number of data elements (not supported) */
  BsGetBit( bitstream, &data, 3 );
  if ( data )
    CommonExit(1,"Unsupported channel element");    
  
  /* number of coupling channel elements (not supported) */
  BsGetBit( bitstream, &data, 4 );
  if ( data )
    CommonExit(1,"Unsupported channel element");    
  

  /* mono mixdown present */
  BsGetBit( bitstream, &data, 1 );
  if ( data )
    BsGetBit( bitstream, &data, 4 );

  /* stereo mixdown present */
  BsGetBit( bitstream, &data, 1 );
  if ( data )
    BsGetBit( bitstream, &data, 4 );

  /* matrix mixdown index present */
  BsGetBit( bitstream, &data, 1 );
  if ( data ) {
    BsGetBit( bitstream, &data, 2 );
    BsGetBit( bitstream, &data, 1 );
  }

  /* we only have to parse one front channel element */
  BsGetBit( bitstream, &data, 1 );
  if ( !data )
    adifInfo->numChannels = 1; /* single channel */
  else 
    adifInfo->numChannels = 2; /* channel pair */

  /* instance tag */
  BsGetBit( bitstream, &data, 4 );
  adifInfo->elementTag = (int)data;

  /* The other channel elements should be parsed here !! */

  /* byte allignment */
  data = BsCurrentBit( bitstream );
  tmp = ((int)data)%8;
  if ( tmp )
    BsGetSkip( bitstream, 8 - tmp );

  /* Comment field */
  BsGetBit( bitstream, &data, 8 );
  tmp = (int)data;

  for (i=0; i<tmp; i++) {
    BsGetBit( bitstream, &data, 8 );
    adifInfo->commentField[i] = (char)data;
  }
  adifInfo->commentField[i] = '\0';

}
Esempio n. 15
0
int GetAdifHeader( BsBitStream* bitstream, ADIF_INFO* adifInfo )
{

  int i;
  int ADIF_present = 0;
  unsigned long data;
  BsBitBuffer* bitBuffer;

  const char ADIF_ID[] = "ADIF";
  const int ADIF_ID_LEN = 32;

  bitBuffer = BsAllocBuffer( ADIF_ID_LEN );

  /* Check if ADIF ID is present */
  BsGetBufferAhead( bitstream, bitBuffer, ADIF_ID_LEN );

  if ( !strncmp( (char*)bitBuffer->data, ADIF_ID, strlen(ADIF_ID))) {

    /* skip ADIF_ID from bitstream */
    BsGetSkip( bitstream, ADIF_ID_LEN );

    /* copyright_id_present bit */
    BsGetBit( bitstream, &data, 1);
    i = 0;
    if( data ) {
      while (i<9) {
        BsGetBit( bitstream, &data, 8 );
        adifInfo->copyrightId[i++] = (char)data;
      }
    }
    
    adifInfo->copyrightId[i] = '\0';

    /* original_copy bit */
    BsGetBit( bitstream, &data, 1);
    adifInfo->origCopy = (int)data;
    
    /* home bit */
    BsGetBit( bitstream, &data, 1);
    adifInfo->home = (int)data;

    /* bitstream_type bit (0: constant rate, 1: variable rate) */
    BsGetBit( bitstream, &data, 1);
    adifInfo->varRateOn = (int)data;

    /* bitrate */
    BsGetBit( bitstream, &data, 23 );
    adifInfo->bitrate = (int)data;

    /* num_pce's */
    BsGetBit( bitstream, &data, 4 );

    if ( data )
      CommonExit(1, "Only one PCE supported");

    /* buffer fullness */
    if ( !adifInfo->varRateOn ) {
      BsGetBit( bitstream, &data, 20);
      adifInfo->bitresFullnes = (int)data;
    }

    /* parse program config element */
    GetProgConfig( bitstream, adifInfo );

    ADIF_present = 1;
  }

  BsFreeBuffer( bitBuffer );

  return ADIF_present;
}
Esempio n. 16
0
int http_file_open(char *url, FILE_STREAM *fs)
{
    SOCKET sck;
    SOCKADDR_IN host;
    char server[1024], file[1024], request[1024], *temp = NULL, *tmpfile = NULL;
    int i, j, port = 80, bytes_recv, http_code;

    /* No winsock, no streaming */
    if(!winsock_init)
    {
        return -1;
    }

    url += 7; // Skip over http://

    /* Extract data from the URL */
    for(i=0; url[i] != '/' && url[i] != ':' && url[i] != 0; i++);

    ZeroMemory(server, 1024);
    CopyMemory(server, url, i);

    if(url[i] == ':')
    {
        /* A certain port was specified */
        port = atol(url + (i + 1));
    }

    for(; url[i] != '/' && url[i] != 0; i++);

    ZeroMemory(file, 1024);

    CopyMemory(file, url + i, lstrlen(url));

    /* END OF URL PARSING */

    /* Create a TCP/IP socket */
    sck = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

    if(sck == INVALID_SOCKET)
    {
        CommonExit("Error creating TCP/IP new socket");
        return -1;
    }

    /* Resolve the host address (turn www.blah.com into an IP) */
    if(resolve_host(server, &host, (unsigned short)port))
    {
        CommonExit("Error resolving host address");
        CloseTCP(sck);
        return -1;
    }

    /* Connect to the server */
    if(connect(sck, (SOCKADDR *)&host, sizeof(SOCKADDR)) == SOCKET_ERROR)
    {
        CommonExit("Error connecting to remote server");
        CloseTCP(sck);
        return -1;
    }

	tmpfile = calloc(1, (strlen(file) * 3) + 1);

	/* Encode URL */
	for(i=0, j=0; i < (int)strlen(file); i++)
	{
		if((unsigned char)file[i] <= 31 || (unsigned char)file[i] >= 127)
		{
			/* encode ASCII-control characters */
			wsprintf(tmpfile + j, "%%%X", (unsigned char)file[i]);
			j += 3;
			continue;
		}
		else
		{
			switch(file[i])
			{
				/* encode characters that could confuse some servers */
				case ' ':
				case '"':
				case '>':
				case '<':
				case '#':
				case '%':
				case '{':
				case '}':
				case '|':
				case '\\':
				case '^':
				case '~':
				case '[':
				case ']':
				case '`':

				wsprintf(tmpfile + j, "%%%X", (unsigned char)file[i]);
				j += 3;
				continue;
			}
		}
		
		tmpfile[j] = file[i];
		j++;
	}

    wsprintf(request, "GET %s\r\n\r\n", tmpfile);

	free(tmpfile);

    /* Send the request */
    if(send(sck, request, lstrlen(request), 0) <= 0)
    {
        /* Error sending data */
        CloseTCP(sck);
        return -1;
    }

    ZeroMemory(request, 1024);

    /* Send the request */
    if((bytes_recv = recv(sck, request, 1024, 0)) <= 0)
    {
        /* Error sending data */
        CloseTCP(sck);
        return -1;
    }

    if(StringComp(request,"HTTP/1.", 7) != 0)
    {
        /* Invalid header */
        CloseTCP(sck);
        return -1;
    }

    http_code = atol(request + 9);

    if(http_code < 200 || http_code > 299)
    {
        /* HTTP error */
        CloseTCP(sck);
        return -1;
    }

	// Search for a length field
	fs->http_file_length = 0;

    /* Limit search to only 20 loops */
    if((temp = strstr(request, "Content-Length: ")) != NULL)
    {
		/* Has a content-length field, copy into structure */
		fs->http_file_length = atol(temp + 16);
	}

    /* Copy the handle data into the structure */
    fs->inetStream = sck;

    /* Copy any excess data beyond the header into the filestream buffers */
	temp = strstr(request, "\r\n\r\n");

	if(temp)
	{
		temp += 4;
	}

    if(temp - request < bytes_recv)
    {
        memcpy(fs->data, temp, (temp - request) - bytes_recv);
        fs->buffer_length = (temp - request) - bytes_recv;
        fs->buffer_offset = 0;
    }

    return 0;
}