Example #1
0
int getVBRHeader(struct vbrHeader *head,unsigned char *buf, struct frame *fr) 
{
    int ssize;

    if(fr->lay != 3)
	return 0;

    if(fr->lsf)
	ssize = (fr->stereo == 1) ? 9 : 17;
    else
	ssize = (fr->stereo == 1) ? 17 : 32;


    buf += ssize;

    if(( buf[0] != 'X' ) || ( buf[1] != 'i' ) ||
       ( buf[2] != 'n' ) || ( buf[3] != 'g' ) ) 
	return 0;
    buf+=4;
    
    head->flags = get32bits(buf);
    buf+=4;
    
    if(head->flags & VBR_FRAMES_FLAG) {
	head->frames = get32bits(buf);
	buf += 4;
    }

    if(head->flags & VBR_BYTES_FLAG) {
	head->bytes  = get32bits(buf); 
	buf += 4;
    }

    if(head->flags & VBR_TOC_FLAG) {
	memcpy(head->toc,buf,100);
	buf += 100;
    }

    if(head->flags & VBR_SCALE_FLAG) {
	head->scale = get32bits(buf);
	buf += 4;
    }

    wxLogDebug("Found XING %04lx\n",head->flags);

    return 1;

}
Example #2
0
void * DLL_FUNC jpl_init_ephemeris( const char *ephemeris_filename,
                          char nam[][6], double *val)
{
   unsigned i, j;
   long de_version;
   char title[84];
   FILE *ifile = fopen( ephemeris_filename, "rb");
   struct jpl_eph_data *rval;
   struct jpl_eph_data temp_data;
   char header[JPL_HEADER_SIZE];

   init_err_code = 0;
   temp_data.ifile = ifile;
   if( !ifile)
      init_err_code = JPL_INIT_FILE_NOT_FOUND;
   else if( fread( title, 84, 1, ifile) != 1)
      init_err_code = JPL_INIT_FREAD_FAILED;
   else if( fseek( ifile, 2652L, SEEK_SET))
      init_err_code = JPL_INIT_FSEEK_FAILED;
   else if( fread( header, JPL_HEADER_SIZE, 1, ifile) != 1)
      init_err_code = JPL_INIT_FREAD2_FAILED;

   temp_data.ephem_start = get_double( header);
   temp_data.ephem_end   = get_double( header + 8);
   temp_data.ephem_step  = get_double( header + 16);
   temp_data.ncon        = get32bits( header + 24);
   temp_data.au          = get_double( header + 28);
   temp_data.emrat       = get_double( header + 36);
   for( i = 0; i < 40; i++)
      temp_data.ipt[i / 3][i % 3] = get32bits( header + 44 + i * 4);

   if( init_err_code)
      {
      if( ifile)
         fclose( ifile);
      return( NULL);
      }

   de_version = atoi( title + 26);

          /* A small piece of trickery:  in the binary file,  data is stored */
          /* for ipt[0...11],  then the ephemeris version,  then the         */
          /* remaining ipt[12] data.  A little switching is required to get  */
          /* the correct order. */
   temp_data.ipt[12][0] = temp_data.ipt[12][1];
   temp_data.ipt[12][1] = temp_data.ipt[12][2];
   temp_data.ipt[12][2] = temp_data.ipt[13][0];
   temp_data.ephemeris_version = de_version;


   temp_data.swap_bytes = (temp_data.ncon > 65536L);
   if( temp_data.swap_bytes)     /* byte order is wrong for current platform */
      {
      swap_64_bit_val( &temp_data.ephem_start, 1);
      swap_64_bit_val( &temp_data.ephem_end, 1);
      swap_64_bit_val( &temp_data.ephem_step, 1);
      swap_32_bit_val( &temp_data.ncon);
      swap_64_bit_val( &temp_data.au, 1);
      swap_64_bit_val( &temp_data.emrat, 1);
      }

            /* It's a little tricky to tell if an ephemeris really has  */
            /* TT-TDB data (with offsets in ipt[13][] and ipt[14][]).   */
            /* Essentially,  we read the data and sanity-check it,  and */
            /* zero it if it "doesn't add up" correctly.                */
            /*    Also:  certain ephems I've generated with ncon capped */
            /* at 400 have no TT-TDB data.  So if ncon == 400,  don't   */
            /* try to read such data;  you may get garbage.             */
   if( de_version >= 430 && temp_data.ncon != 400)
      {
         /* If there are 400 or fewer constants,  data for ipt[13][0...2] */
         /* immediately follows that for ipt[12][0..2];  i.e.,  we don't  */
         /* need to fseek().  Otherwise,  we gotta skip 6*(n_constants-400) */
         /* bytes. */
      if( temp_data.ncon > 400)
         fseek( ifile, (size_t)( temp_data.ncon - 400) * 6, SEEK_CUR);
      if( fread( &temp_data.ipt[13][0], sizeof( int32_t), 6, ifile) != 6)
         init_err_code = JPL_INIT_FREAD5_FAILED;
      }
   else                 /* mark header data as invalid */
      temp_data.ipt[13][0] = (uint32_t)-1;

   if( temp_data.swap_bytes)     /* byte order is wrong for current platform */
      for( j = 0; j < 3; j++)
         for( i = 0; i < 15; i++)
            swap_32_bit_val( &temp_data.ipt[i][j]);

   if( temp_data.ipt[13][0] !=       /* if these don't add up correctly, */
          temp_data.ipt[12][0] + temp_data.ipt[12][1] * temp_data.ipt[12][2] * 3
    || temp_data.ipt[14][0] !=       /* zero them out (they've garbage data) */
          temp_data.ipt[13][0] + temp_data.ipt[13][1] * temp_data.ipt[13][2] * 3)
      {     /* not valid pointers to TT-TDB data */
      for( i = 13; i < 15; i++)
         for( j = 0; j < 3; j++)
            temp_data.ipt[i][j] = 0;
      }

         /* A sanity check:  if the earth-moon ratio is outside reasonable */
         /* bounds,  we must be looking at a wrong or corrupted file.      */
         /* In DE-102,  emrat = 81.3007;  in DE-405/406, emrat = 81.30056. */
         /* Those are the low and high ranges.  We'll allow some slop in   */
         /* case the earth/moon mass ratio changes:                        */
   if( temp_data.emrat > 81.3008 || temp_data.emrat < 81.30055)
      init_err_code = JPL_INIT_FILE_CORRUPT;

   if( init_err_code)
      {
      fclose( ifile);
      return( NULL);
      }

         /* Once upon a time,  the kernel size was determined from the */
         /* DE version.  This was not a terrible idea,  except that it */
         /* meant that when the code faced a new version,  it broke.   */
         /* Now we use some logic to compute the kernel size.          */
   temp_data.kernel_size = 4;
   for( i = 0; i < 15; i++)
      temp_data.kernel_size +=
             2 * temp_data.ipt[i][1] * temp_data.ipt[i][2] * dimension( i);
// for( i = 0; i < 13; i++)
//    temp_data.kernel_size +=
//                     temp_data.ipt[i][1] * temp_data.ipt[i][2] * ((i == 11) ? 4 : 6);
//       /* ...and then add in space required for the TT-TDB data : */
// temp_data.kernel_size += temp_data.ipt[14][1] * temp_data.ipt[14][2] * 2;
   temp_data.recsize = temp_data.kernel_size * 4L;
   temp_data.ncoeff = temp_data.kernel_size / 2L;

               /* Rather than do two separate allocations,  everything     */
               /* we need is allocated in _one_ chunk,  then parceled out. */
               /* This looks a little weird,  but it simplifies error      */
               /* handling and cleanup.                                    */
   rval = (struct jpl_eph_data *)calloc( sizeof( struct jpl_eph_data)
                        + temp_data.recsize, 1);
   if( !rval)
      {
      init_err_code = JPL_INIT_MEMORY_FAILURE;
      fclose( ifile);
      return( NULL);
      }
   memcpy( rval, &temp_data, sizeof( struct jpl_eph_data));
   rval->iinfo.posn_coeff[0] = 1.0;
            /* Seed a bogus value here.  The first and subsequent calls to */
            /* 'interp' will correct it to a value between -1 and +1.      */
   rval->iinfo.posn_coeff[1] = -2.0;
   rval->iinfo.vel_coeff[0] = 0.0;
   rval->iinfo.vel_coeff[1] = 1.0;
   rval->curr_cache_loc = (uint32_t)-1;
          /* The 'cache' data is right after the 'jpl_eph_data' struct: */
   rval->cache = (double *)( rval + 1);
               /* If there are more than 400 constants,  the names of       */
               /* the extra constants are stored in what would normally     */
               /* be zero-padding after the header record.  However,        */
               /* older ephemeris-reading software won't know about that.   */
               /* So we store ncon=400,  then actually check the names to   */
               /* see how many constants there _really_ are.  Older readers */
               /* will just see 400 names and won't know about the others.  */
               /* But on the upside,  they won't crash.                     */
   if( rval->ncon == 400)
      {
      char buff[7];

      buff[6] = '\0';
      fseek( ifile, START_400TH_CONSTANT_NAME, SEEK_SET);
      while( fread( buff, 6, 1, ifile) && strlen( buff) == 6)
         rval->ncon++;
      }

   if( val)
      {
      fseek( ifile, rval->recsize, SEEK_SET);
      if( fread( val, sizeof( double), (size_t)rval->ncon, ifile)
                        != (size_t)rval->ncon)
         init_err_code = JPL_INIT_FREAD3_FAILED;
      else if( rval->swap_bytes)     /* gotta swap the constants,  too */
         swap_64_bit_val( val, rval->ncon);
      }

   if( !init_err_code && nam)
      {
      fseek( ifile, 84L * 3L, SEEK_SET);   /* just after the 3 'title' lines */
      for( i = 0; i < rval->ncon && !init_err_code; i++)
         {
         if( i == 400)
            fseek( ifile, START_400TH_CONSTANT_NAME, SEEK_SET);
         if( fread( nam[i], 6, 1, ifile) != 1)
            init_err_code = JPL_INIT_FREAD4_FAILED;
         }
      }
   return( rval);
}
Example #3
0
/**
   This function permits to get from the NAL unit additional parameters. 
   VUI parameters are not required for constructing the luma and chroma samples by teh decoding process.
   
   @param data The NAL unit.
   @param position The current position in the NAL.
   */
void vui_parameters ( unsigned char *data, int *position, SPS *sps )
{

    int    overscan_info_present_flag ;
    int    video_signal_type_present_flag ;
    int    bitstream_restriction_flag ;


    int aspect_ratio_info_present_flag = getNbits(data, position, 1);
    if ( aspect_ratio_info_present_flag ) {
       int  aspect_ratio_idc = getNbits(data, position, 8);
        if ( aspect_ratio_idc == Extended_SAR ) {
            getNbits(data, position, 16);//sar_width = 
            getNbits(data, position, 16);// sar_height = 
        }
    }
    //scanner dans ffmpeg mais pas pris en compte
    overscan_info_present_flag = getNbits(data, position, 1);
    if ( overscan_info_present_flag ) 
        getNbits(data, position, 1);// overscan_appropriate_flag =

    video_signal_type_present_flag = getNbits(data, position, 1);
    if ( video_signal_type_present_flag ) {
        getNbits(data, position, 3);//video_format =
        getNbits(data, position, 1);// video_full_range_flag =
        if (getNbits(data, position, 1)) {
           getNbits(data, position, 8);// colour_primaries = 
           getNbits(data, position, 8);// transfer_characteristics =
           getNbits(data, position, 8);//  matrix_coefficients = 
        }
    }

    if (getNbits(data, position, 1)) {
        read_ue(data, position);//chroma_sample_loc_type_top_field =
        read_ue(data, position);// chroma_sample_loc_type_bottom_field =
    }


    //******************************************
    if (getNbits(data, position, 1)) {
       get32bits(data, position);// num_units_in_tick = 
       get32bits(data, position);//time_scale = 
       getNbits(data, position, 1);// fixed_frame_rate_flag =
    }


    sps -> nal_hrd_parameters_present_flag = getNbits(data, position, 1);
    if ( sps -> nal_hrd_parameters_present_flag ) 
        hrd_parameters(data, position,sps);

    sps -> vlc_hrd_parameters_present_flag = getNbits(data, position, 1);
    if ( sps -> vlc_hrd_parameters_present_flag ) 
        hrd_parameters(data, position,sps);

    //scanner dans ffmpeg mais pas pris en compte
    if ( sps -> nal_hrd_parameters_present_flag ||  sps -> vlc_hrd_parameters_present_flag ) 
        getNbits(data, position, 1);//low_delay_hrd_flag = 

    //********************************************
    sps -> pic_present_flag = getNbits(data, position, 1);//  =
    bitstream_restriction_flag = getNbits(data, position, 1);
    if ( bitstream_restriction_flag ) {
        //scanner dans ffmpeg mais pas pris en compte
        getNbits(data, position, 1);// motion_vectors_over_pic_boundaries_flag =
        read_ue(data, position);//max_bytes_per_pic_denom =
        read_ue(data, position);//max_bits_per_mb_denom = 
        read_ue(data, position);//log2_max_mv_length_horizontal = 
        read_ue(data, position);//log2_max_mv_length_vertical =
        //******************************************
        read_ue(data, position);//num_reorder_frames = 
        read_ue(data, position);//max_dec_frame_buffering =
    }
}