/**
        \fn getPacket
*/
uint8_t ADM_audioStreamDCA::getPacket(uint8_t *obuffer,uint32_t *osize, uint32_t sizeMax,uint32_t *nbSample,uint64_t *dts)
{
#define ADM_LOOK_AHEAD DTS_HEADER_SIZE // Need 10 bytes...
uint8_t data[ADM_LOOK_AHEAD];
uint32_t offset;
ADM_DCA_INFO info;
    while(1)
    {
        // Do we have sync ?
        if(needBytes(ADM_LOOK_AHEAD)==false) 
        {
            ADM_warning("DCA: Not sync found in buffer\n");
            return false;
        }
            
        // Peek
        peek(ADM_LOOK_AHEAD,data);
        // Search start seq
        if(buffer[start]!=0x7F || buffer[start+1]!=0xFE)
        {
            read8();
            continue;
        }
        if(buffer[start+2]!=0x80 || buffer[start+3]!=0x1)
        {
            read8();
            read8();
            continue;
        }

        if(false== ADM_DCAGetInfo(buffer+start, limit-start,&info,&offset))
        {
            read8();
            read8();
            read8();
            read8();
            continue;
        }
        ADM_assert(info.frameSizeInBytes<=sizeMax);
        if(needBytes(info.frameSizeInBytes)==false)
        {
            ADM_warning("DCA: Not enough data\n");
            return false;
        }
        *osize=info.frameSizeInBytes;
        read(*osize,obuffer);
        *nbSample=info.samples;
        *dts=lastDts;
        advanceDtsBySample(*nbSample);
        return 1;

    }
}
/**
        \fn getPacket
*/
uint8_t ADM_audioStreamAC3::getPacket(uint8_t *obuffer,uint32_t *osize, uint32_t sizeMax,uint32_t *nbSample,uint64_t *dts)
{
#define ADM_LOOK_AHEAD 6 // Need 6 bytes...
uint8_t data[ADM_LOOK_AHEAD];
int size;
int flags,sample_rate,bit_rate;

    while(1)
    {
        // Do we have sync ?
        if(needBytes(ADM_LOOK_AHEAD)==false) return 0;
        // Peek
        peek(ADM_LOOK_AHEAD,data);
        // Search start seq
        if(buffer[start]!=0x0b || buffer[start+1]!=0x77)
        {
            read8();
            continue;
        }
        // 
        size= ADM_a52_syncinfo (buffer+start, &flags, &sample_rate, &bit_rate);
        
        if(!size)
        {
            read8();
            continue;
        }
        
        ADM_assert(size<=sizeMax);
        if(needBytes(size)==false)
        {
            return false;
        }
        *osize=size;
        read(size,obuffer);
        *nbSample=256*6;
        *dts=lastDts;
        advanceDtsBySample(*nbSample);
        return 1;
            
    }
}
Esempio n. 3
0
int Forward(void *p){
  int *forwarding;
  int realSize = 0;
  char *class_gc_map;
  if (p>=(void*)heap.from && p<(void*)heap.from+heap.size ){
    forwarding= (int*)p+3;
    if ( *forwarding>=(int)heap.to && *forwarding<(int)heap.to+heap.size ){
      return *forwarding;
    }else{
      *forwarding=(int)heap.toNext;
      if( 0 == *((int*)p+1 )){            //object
        class_gc_map=(char*)(*(int*)(*((int*)p)));   // the fields map
        realSize = needBytes(strlen(class_gc_map));
        memcpy(heap.toNext,p,realSize);
      }else{ //array
    	realSize = needBytes(*((int*)p +2));
        memcpy(heap.toNext,p,realSize);
      }
      heap.toNext = heap.toNext + realSize;
    }
    return *forwarding;
  }
  return (int)p;
}
Esempio n. 4
0
// Try to allocate an array object in the "from" space of the Java
// heap. Read Tiger book chapter 13.3 for details on the
// allocation.
// There are two cases to consider:
//   1. If the "from" space has enough space to hold this array object, then
//      allocation succeeds, return the apropriate address (look at
//      the above figure, be careful);
//   2. if there is no enough space left in the "from" space, then
//      you should call the function "Tiger_gc()" to collect garbages.
//      and after the collection, there are still two sub-cases:
//        a: if there is enough space, you can do allocations just as case 1; 
//        b: if there is still no enough space, you can just issue
//           an error message ("OutOfMemory") and exit.
//           (However, a production compiler will try to expand
//           the Java heap.)
//#define  needBytes(length)  Header + sizeof(int)*length
void *Tiger_new_array (int length){
	 int needSpace = needBytes(length);
  if ( FreeSpace < needSpace ){
      Tiger_gc();
      if ( FreeSpace < needSpace ){
          printf("OutOfMemory\n");
          exit(-1);
      }
    }
      memset(heap.fromFree,0,needSpace);
      int *p =(int*) heap.fromFree;
      heap.fromFree += needSpace;
      p[0] = 0;
      p[1] = 1;
      p[2] = length;
      p[3] = 0;
      return (void*)p;
}
Esempio n. 5
0
static void Tiger_gc (){
	FILE *logfile=fopen("gc_log.txt","a");
    round++;
    struct timeval gc_start,gc_end;
    float gc_time;
    gettimeofday(&gc_start,NULL);
    int preGC = (int)heap.fromFree - (int)heap.from;
//    printf("preGC:%d\n",preGC);
   heap.toNext = heap.to;   //point to vptr
   char *scan = heap.toNext;
   void *prePrev=prev;       // mark the head frame chain
   while(NULL != prev){
   //args forward
    char *args_gc_map = (char*)(*((int*)prev+1));
    int *args=(int*)(*((int*)prev+2));
    int locals_gc_map = *((int*)prev+3);
    int *locals=(int*)prev+4;
//    printf("args_gc_map:%s\n",args_gc_map);
    while('\0' != *args_gc_map){
      if('1' == *args_gc_map){
        *args = Forward((int*)(*args));
      }
      args++;
      args_gc_map++;
    }
  //locals forward
    while(locals_gc_map > 0){
        *locals=Forward((int*)(*locals));
        locals++;
        locals_gc_map--;
    }
    prev=(void*)(*(int*)prev);
  }
  prev=prePrev; //
  while(scan<heap.toNext){
    int scan_size=0;
    if(0==*((int*)scan + 1)){  //object
      int *scan_fields = (int*)scan + 4;
      char *class_gc_map=(char*)(*(int*)(*(int*)scan));
      while( '\0'  !=  *class_gc_map){
        if( '1' == *class_gc_map){
          *scan_fields = Forward((int*)(*scan_fields));
        }
        scan_size++;
        scan_fields++;
        class_gc_map++;
      }
    }else{  //array
      scan_size+=*((int*)scan+2);
    }
    scan = scan + needBytes(scan_size);
  }

  int afterGC = (int)heap.toNext - (int)heap.to;
//  printf("afterGC:%d\n",afterGC);
  //swap heap pointer
  char *swap = heap.from;
  heap.from = heap.to;
  heap.to = swap;
  heap.fromFree = heap.toNext;
  gettimeofday(&gc_end,NULL);
  gc_time = durTime(gc_start,gc_end);
  printf("%d round of GC: %.5f ms, collected %d bytes garbage.\n",round,gc_time ,preGC - afterGC);
 if (Control_logGc){
      char buffer[100];
      sprintf(buffer,"%d round of GC: %.5f ms, collected %d bytes garbage.\n",round,gc_time ,preGC - afterGC);
      //addToLog(buffer);
      fprintf(logfile, "%s\n", buffer);
      fclose(logfile);
 }
}