コード例 #1
0
ファイル: fy.c プロジェクト: AndTH/GCA
void savePosition(unsigned char pos, unsigned int stepnr) {
  unsigned char hb = (unsigned char)(stepnr / 256 );
  unsigned char lb = (unsigned char)(stepnr % 256 );
  unsigned char idx = (pos-1) * 2;
  saveByte(idx, hb);
  saveByte(idx+1, lb);
}
コード例 #2
0
ファイル: Entity.cpp プロジェクト: hasyimibhar/gag
void Entity::save(std::ofstream& file)
{
	saveByte(file, getCode()[0]);
	saveByte(file, getCode()[1]);

	unsigned char posBuffer[4];

   PackInteger32(posBuffer, int(position_.x));
   for (int i = 0; i < 4; i++)
      saveByte(file, posBuffer[i]);

	PackInteger32(posBuffer, int(position_.y));
   for (int i = 0; i < 4; i++)
      saveByte(file, posBuffer[i]);
}
コード例 #3
0
ファイル: MagStripe.cpp プロジェクト: Yelp/kegmate
void MagStripe::decode() {
  int sentinal = findStartSentinal();
  int i = 0;
  int k = 0;
  uint8_t thisByte[5];

  for (int j = sentinal; j < MAGSTRIPE_BUFFER_SIZE - sentinal; j = j + 1) {
    thisByte[i] = _buffer[j];
    i++;
    if (i % 5 == 0) {
      i = 0;
      if (thisByte[0] == 0 & thisByte[1] == 0 & thisByte[2] == 0 & thisByte[3] == 0 & thisByte[4] == 0) {
        break;
      }
      uint8_t value = saveByte(thisByte);
      // TODO(johnb): Do some validation. Maybe return false if there wasn't an end sentinel.
      if (value == '?') break; // End sentinel
    }
  }
#if MAGSTRIPE_DEBUG 
  Serial.print("Stripe_Data:");
  for (k = 0; k < _dataSize; k = k + 1) {
    Serial.print(_cardData[k]);
  }
  Serial.println("");
#endif
}
コード例 #4
0
ファイル: bitlash-eeprom.c プロジェクト: GIRA/Physical-Etoys
// write id:value, unless value is empty, in which case we erase the id
void writeMacro(char *id) {
	eraseentry(id);

	// we need to know the macro value length to allocate space for it
	// we don't realistically have enough buffer space handy to parse it into
	// so this is a two-pass operation: first we measure the text, then on
	// the second pass we stuff it into the eeprom
	//
	// measure length of macro value
	// we get here with inchar = first char of macro and fetchptr one past that
	//
	char *fetchmark = --fetchptr;		// back up and mark first char of macro text
	primec();							// re-prime
	expval = 0;							// zero the count
	parsestring(&countByte);			// now expval is the macro value length
	if (!expval) return;				// empty string? we're done
	
	int addr = findhole(strlen(id) + expval + 2);	// longjmps on fail
	if (addr >= 0) {
		saveString(addr, id);

		// reset parse context
		fetchptr = fetchmark;
		primec();

		expval = addr + strlen(id) + 1;		// set up address for saveByte
		parsestring(&saveByte);
		saveByte(0);
	}
}
コード例 #5
0
unsigned H264or5VideoStreamParser::parse() {
    static int aaaa = 0  ;
    aaaa++;
    qDebug()<<"H264or5VideoStreamParser::parse() {  868   aaaa" <<aaaa;
  try {
    // The stream must start with a 0x00000001:
    if (!fHaveSeenFirstStartCode) {
      // Skip over any input bytes that precede the first 0x00000001:
      u_int32_t first4Bytes;
      while ((first4Bytes = test4Bytes()) != 0x00000001) {
	get1Byte(); setParseState(); // ensures that we progress over bad data
      }
      skipBytes(4); // skip this initial code
      
      setParseState();
      fHaveSeenFirstStartCode = True; // from now on
    }
    
    if (fOutputStartCodeSize > 0 && curFrameSize() == 0 && !haveSeenEOF()) {
      // Include a start code in the output:
      save4Bytes(0x00000001);
    }

    // Then save everything up until the next 0x00000001 (4 bytes) or 0x000001 (3 bytes), or we hit EOF.
    // Also make note of the first byte, because it contains the "nal_unit_type": 
    if (haveSeenEOF()) {
      // We hit EOF the last time that we tried to parse this data, so we know that any remaining unparsed data
      // forms a complete NAL unit, and that there's no 'start code' at the end:
      unsigned remainingDataSize = totNumValidBytes() - curOffset();
#ifdef DEBUG
      unsigned const trailingNALUnitSize = remainingDataSize;
#endif
      while (remainingDataSize > 0) {
	u_int8_t nextByte = get1Byte();
	if (!fHaveSeenFirstByteOfNALUnit) {
	  fFirstByteOfNALUnit = nextByte;
	  fHaveSeenFirstByteOfNALUnit = True;
	}
	saveByte(nextByte);
	--remainingDataSize;
      }

#ifdef DEBUG
      if (fHNumber == 264) {
	u_int8_t nal_ref_idc = (fFirstByteOfNALUnit&0x60)>>5;
	u_int8_t nal_unit_type = fFirstByteOfNALUnit&0x1F;
	fprintf(stderr, "Parsed trailing %d-byte NAL-unit (nal_ref_idc: %d, nal_unit_type: %d (\"%s\"))\n",
		trailingNALUnitSize, nal_ref_idc, nal_unit_type, nal_unit_type_description_h264[nal_unit_type]);
      } else { // 265
	u_int8_t nal_unit_type = (fFirstByteOfNALUnit&0x7E)>>1;
	fprintf(stderr, "Parsed trailing %d-byte NAL-unit (nal_unit_type: %d (\"%s\"))\n",
		trailingNALUnitSize, nal_unit_type, nal_unit_type_description_h265[nal_unit_type]);
      }
#endif

      (void)get1Byte(); // forces another read, which will cause EOF to get handled for real this time
      return 0;
    } else {
コード例 #6
0
unsigned MPEG4VideoStreamParser::parseVisualObject() {
#ifdef DEBUG
  fprintf(stderr, "parsing VisualObject\n");
#endif
  // Note that we've already read the VISUAL_OBJECT_START_CODE
  save4Bytes(VISUAL_OBJECT_START_CODE);

  // Next, extract the "visual_object_type" from the next 1 or 2 bytes:
  u_int8_t nextByte = get1Byte(); saveByte(nextByte);
  Boolean is_visual_object_identifier = (nextByte&0x80) != 0;
  u_int8_t visual_object_type;
  if (is_visual_object_identifier) {
#ifdef DEBUG
    fprintf(stderr, "visual_object_verid: 0x%x; visual_object_priority: 0x%x\n", (nextByte&0x78)>>3, (nextByte&0x07));
#endif
    nextByte = get1Byte(); saveByte(nextByte);
    visual_object_type = (nextByte&0xF0)>>4;
  } else {
コード例 #7
0
static void saveOrLoadByte(uint8 &b) {
	switch (_saveOrLoadMode) {
	case kSaveMode:
		saveByte(b);
		break;
	case kLoadMode:
		b = loadByte();
		break;
	}
}
コード例 #8
0
ファイル: fy.c プロジェクト: AndTH/GCA
void initPositions(void) {
  waitMS(100);

  if( getPosition(choice) == 0 || getPosition(choice) == 0xFFFF ) {
    unsigned char i;

    for( i = 1; i <= MAX_TRACKS; i++ ) {
        // not initialized before
        savePosition(i, initpos);
    }
    // default power off step motor
    saveByte(ADDR_KEEPPOWER, KEEPPOWER_OFF);
  }
  // always set the calibration position
  savePosition(choice, initpos);
}
コード例 #9
0
unsigned H264VideoStreamParser::parseNALUnit()
{

    u_int32_t test = test4Bytes();
    int numBytes = 0;
    while (test != 0x00000001)
    {
        saveByte(get1Byte());
        numBytes++;
        test = test4Bytes();
    }
	//skipBytes(8);


    return curFrameSize();
}
コード例 #10
0
unsigned MPEG4VideoStreamParser
::parseVisualObjectSequence(Boolean haveSeenStartCode) {
#ifdef DEBUG
  fprintf(stderr, "parsing VisualObjectSequence\n");
#endif
  usingSource()->startNewConfig();
  u_int32_t first4Bytes;
  if (!haveSeenStartCode) {
    while ((first4Bytes = test4Bytes()) != VISUAL_OBJECT_SEQUENCE_START_CODE) {
#ifdef DEBUG
      fprintf(stderr, "ignoring non VS header: 0x%08x\n", first4Bytes);
#endif
      get1Byte(); setParseState(PARSING_VISUAL_OBJECT_SEQUENCE);
          // ensures we progress over bad data
    }
    first4Bytes = get4Bytes();
  } else {
    // We've already seen the start code
    first4Bytes = VISUAL_OBJECT_SEQUENCE_START_CODE;
  }
  save4Bytes(first4Bytes);

  // The next byte is the "profile_and_level_indication":
  u_int8_t pali = get1Byte();
#ifdef DEBUG
  fprintf(stderr, "profile_and_level_indication: %02x\n", pali);
#endif
  saveByte(pali);
  usingSource()->fProfileAndLevelIndication = pali;

  // Now, copy all bytes that we see, up until we reach
  // a VISUAL_OBJECT_START_CODE:
  u_int32_t next4Bytes = get4Bytes();
  while (next4Bytes != VISUAL_OBJECT_START_CODE) {
    saveToNextCode(next4Bytes);
  }

  setParseState(PARSING_VISUAL_OBJECT);

  // Compute this frame's presentation time:
  usingSource()->computePresentationTime(fTotalTicksSinceLastTimeCode);

  // This header forms part of the 'configuration' information:
  usingSource()->appendToNewConfig(fStartOfFrame, curFrameSize());

  return curFrameSize();
}
コード例 #11
0
unsigned H264VideoStreamParser::parse() {
  try {
    // The stream must start with a 0x00000001:
    if (!fHaveSeenFirstStartCode) {
      // Skip over any input bytes that precede the first 0x00000001:
      u_int32_t first4Bytes;
      while ((first4Bytes = test4Bytes()) != 0x00000001) {
	get1Byte(); setParseState(); // ensures that we progress over bad data
      }
      skipBytes(4); // skip this initial code
      
      setParseState();
      fHaveSeenFirstStartCode = True; // from now on
    }
    
    if (fOutputStartCodeSize > 0 && curFrameSize() == 0 && !haveSeenEOF()) {
      // Include a start code in the output:
      save4Bytes(0x00000001);
    }

    // Then save everything up until the next 0x00000001 (4 bytes) or 0x000001 (3 bytes), or we hit EOF.
    // Also make note of the first byte, because it contains the "nal_unit_type": 
    if (haveSeenEOF()) {
      // We hit EOF the last time that we tried to parse this data, so we know that any remaining unparsed data
      // forms a complete NAL unit, and that there's no 'start code' at the end:
      unsigned remainingDataSize = totNumValidBytes() - curOffset();
#ifdef DEBUG
      unsigned const trailingNALUnitSize = remainingDataSize;
#endif
      while (remainingDataSize > 0) {
	u_int8_t nextByte = get1Byte();
	if (!fHaveSeenFirstByteOfNALUnit) {
	  fFirstByteOfNALUnit = nextByte;
	  fHaveSeenFirstByteOfNALUnit = True;
	}
	saveByte(nextByte);
	--remainingDataSize;
      }

#ifdef DEBUG
      u_int8_t nal_ref_idc = (fFirstByteOfNALUnit&0x60)>>5;
      u_int8_t nal_unit_type = fFirstByteOfNALUnit&0x1F;
      fprintf(stderr, "Parsed trailing %d-byte NAL-unit (nal_ref_idc: %d, nal_unit_type: %d (\"%s\"))\n",
	      trailingNALUnitSize, nal_ref_idc, nal_unit_type, nal_unit_type_description[nal_unit_type]);
#endif

      (void)get1Byte(); // forces another read, which will cause EOF to get handled for real this time
      return 0;
    } else {
      u_int32_t next4Bytes = test4Bytes();
      if (!fHaveSeenFirstByteOfNALUnit) {
	fFirstByteOfNALUnit = next4Bytes>>24;
	fHaveSeenFirstByteOfNALUnit = True;
      }
      while (next4Bytes != 0x00000001 && (next4Bytes&0xFFFFFF00) != 0x00000100) {
	// We save at least some of "next4Bytes".
	if ((unsigned)(next4Bytes&0xFF) > 1) {
	  // Common case: 0x00000001 or 0x000001 definitely doesn't begin anywhere in "next4Bytes", so we save all of it:
	  save4Bytes(next4Bytes);
	  skipBytes(4);
	} else {
	  // Save the first byte, and continue testing the rest:
	  saveByte(next4Bytes>>24);
	  skipBytes(1);
	}
	setParseState(); // ensures forward progress
	next4Bytes = test4Bytes();
      }
      // Assert: next4Bytes starts with 0x00000001 or 0x000001, and we've saved all previous bytes (forming a complete NAL unit).
      // Skip over these remaining bytes, up until the start of the next NAL unit:
      if (next4Bytes == 0x00000001) {
	skipBytes(4);
      } else {
	skipBytes(3);
      }
    }
コード例 #12
0
/// Process data received by UART 
///
void simpleBinary::processSerial()
{
    while (serial->available() > 0) 
    {
      int data = serial->read();

      serbuf[serbuflen++] = data;
    }

    if(serbuflen > 3)
    {
      receiveTime = millis();
       
      if(serbuf[0] == _uartAddress)    
      {
        int address;
        char crc;
        
        switch(serbuf[1])
        {
          //new data
          case (char)0xD0:  
            if(serbuf[2] == 0x01)
            {
               //force all output data as new through user function
               forceAllNewData();
            }
            if(serbuf[2] == 0x00 || serbuf[2] == 0x01)
            {
               crc = CRC8::evalCRC(serbuf,3);

               if(crc != serbuf[3])
                  sendWrongData(crc);
                else
                  checkNewData();
            }   
            else
              sendUnknownData();              

            serbuflen = 0;                       
            break;
          //read data  
          case (char)0xD1: 
            if(serbuflen < 5)
              break;
              
            address =  serbuf[2] | (serbuf[3] << 8);
            
            crc = CRC8::evalCRC(serbuf,4);

            if(crc != serbuf[4])
               sendWrongData(crc);
            else
               readData(address);            

            serbuflen = 0;           
            break;
          //write byte
          case (char)0xDA:
            if(serbuflen < 6)
              break;
            //address
            address = serbuf[2] | (serbuf[3] << 8);
            //crc check
            crc = CRC8::evalCRC(serbuf,5);
            if(serbuf[5] != crc)
              sendWrongData(crc);
            else         
            {
              //check address
              if(!checkAddress(address))
                sendInvalidAddress();               
              //write data into memory
              if(saveByte(address,serbuf+4))
                sendOK();
              else
                sendSavingError();
            }
            //clear buffer
            serbuflen = 0;                                                           
            break;
          //write word
          case (char)0xDB:
            if(serbuflen < 7)
              break;

            //address 
            address = serbuf[2] | (serbuf[3] << 8);
            //crc check
            crc = CRC8::evalCRC(serbuf,6);
            if(serbuf[6] != crc)
              sendWrongData(crc);
            else       
            {
              //check address
              if(!checkAddress(address))
                sendInvalidAddress();                 
              //write data into memory
              if(saveWord(address,serbuf+4))
                sendOK();
              else
                sendSavingError();              
            }
            //clear buffer
            serbuflen = 0;            
            break;
          //write dword
          case (char)0xDC:
          case (char)0xDD:
            if(serbuflen < 9)
              break;

            //address
            address = serbuf[2] | (serbuf[3] << 8);
            //crc check
            crc = CRC8::evalCRC(serbuf,8);
            if(serbuf[8] != crc)
              sendWrongData(crc);
            else
            {
              //check address
              if(!checkAddress(address))
                sendInvalidAddress();
              //write data into memory
              if(saveDword(address,serbuf+4))
                sendOK();
              else
                sendSavingError();  
            }
            //clear buffer
            serbuflen = 0;             
            break;
          //write array
          case (char)0xDE:
            if(serbuflen < 6)
              break;
            
            int datalen;
            datalen = (serbuf[4] | (serbuf[5] << 8));
            //correct packet length check
            if(serbuflen < 7 + datalen)
              break;

            //address
            address = serbuf[2] | (serbuf[3] << 8);
            //crc check
            crc = CRC8::evalCRC(serbuf,6+datalen);
            if(serbuf[7+datalen] != crc)
              sendWrongData(crc);
            else            
            {
              //check address
              if(!checkAddress(address))
                sendInvalidAddress();
              char *pData = serbuf + 6;
              //write data into memory              
              if(saveArray(address,pData, datalen))
                sendOK();
              else
                sendSavingError();              
            }
            //clear buffer
            serbuflen = 0;               
            break;                        
          default:
            serbuflen = 0;
            sendUnknownData();
            break;            
         }
      }
      else
      {
        serbuflen = 0;
        return;
      }
    }
}
コード例 #13
0
unsigned H264VideoStreamParser::parse() {
  try {
    // The stream must start with a 0x00000001:
    if (!fHaveSeenFirstStartCode) {
      // Skip over any input bytes that precede the first 0x00000001:
      u_int32_t first4Bytes;
      while ((first4Bytes = test4Bytes()) != 0x00000001) {
	get1Byte(); setParseState(); // ensures that we progress over bad data
      }
      skipBytes(4); // skip this initial code
      
      setParseState();
      fHaveSeenFirstStartCode = True; // from now on
    }
    
    if (fOutputStartCodeSize > 0) {
      // Include a start code in the output:
      save4Bytes(0x00000001);
    }

    // Then save everything up until the next 0x00000001 (4 bytes) or 0x000001 (3 bytes), or we hit EOF.
    // Also make note of the first byte, because it contains the "nal_unit_type": 
    if (haveSeenEOF()) {
      // We hit EOF the last time that we tried to parse this data, so we know that any remaining unparsed data
      // forms a complete NAL unit, and that there's no 'start code' at the end:
      unsigned remainingDataSize = totNumValidBytes() - curOffset();
      while (remainingDataSize > 0) {
	saveByte(get1Byte());
	--remainingDataSize;
      }

      if (!fHaveSeenFirstByteOfNALUnit) {
	// There's no remaining NAL unit.
	(void)get1Byte(); // forces another read, which will cause EOF to get handled for real this time
	return 0;
      }
#ifdef DEBUG
      fprintf(stderr, "This NAL unit (%d bytes) ends with EOF\n", curFrameSize()-fOutputStartCodeSize);
#endif
    } else {
      u_int32_t next4Bytes = test4Bytes();
      if (!fHaveSeenFirstByteOfNALUnit) {
	fFirstByteOfNALUnit = next4Bytes>>24;
	fHaveSeenFirstByteOfNALUnit = True;
      }
      while (next4Bytes != 0x00000001 && (next4Bytes&0xFFFFFF00) != 0x00000100) {
	// We save at least some of "next4Bytes".
	if ((unsigned)(next4Bytes&0xFF) > 1) {
	  // Common case: 0x00000001 or 0x000001 definitely doesn't begin anywhere in "next4Bytes", so we save all of it:
	  save4Bytes(next4Bytes);
	  skipBytes(4);
	} else {
	  // Save the first byte, and continue testing the rest:
	  saveByte(next4Bytes>>24);
	  skipBytes(1);
	}
	setParseState(); // ensures forward progress
	next4Bytes = test4Bytes();
      }
      // Assert: next4Bytes starts with 0x00000001 or 0x000001, and we've saved all previous bytes (forming a complete NAL unit).
      // Skip over these remaining bytes, up until the start of the next NAL unit:
      if (next4Bytes == 0x00000001) {
	skipBytes(4);
      } else {
	skipBytes(3);
      }
    }

    u_int8_t nal_ref_idc = (fFirstByteOfNALUnit&0x60)>>5;
    u_int8_t nal_unit_type = fFirstByteOfNALUnit&0x1F;
    fHaveSeenFirstByteOfNALUnit = False; // for the next NAL unit that we parse
#ifdef DEBUG
    fprintf(stderr, "Parsed %d-byte NAL-unit (nal_ref_idc: %d, nal_unit_type: %d (\"%s\"))\n",
	    curFrameSize()-fOutputStartCodeSize, nal_ref_idc, nal_unit_type, nal_unit_type_description[nal_unit_type]);
#endif

    switch (nal_unit_type) {
      case 6: { // Supplemental enhancement information (SEI)
	analyze_sei_data();
	// Later, perhaps adjust "fPresentationTime" if we saw a "pic_timing" SEI payload??? #####
	break;
      }
      case 7: { // Sequence parameter set
	// First, save a copy of this NAL unit, in case the downstream object wants to see it:
	usingSource()->saveCopyOfSPS(fStartOfFrame + fOutputStartCodeSize, fTo - fStartOfFrame - fOutputStartCodeSize);

	// Parse this NAL unit to check whether frame rate information is present:
	unsigned num_units_in_tick, time_scale, fixed_frame_rate_flag;
	analyze_seq_parameter_set_data(num_units_in_tick, time_scale, fixed_frame_rate_flag);
	if (time_scale > 0 && num_units_in_tick > 0) {
	  usingSource()->fFrameRate = time_scale/(2.0*num_units_in_tick);
#ifdef DEBUG
	  fprintf(stderr, "Set frame rate to %f fps\n", usingSource()->fFrameRate);
	  if (fixed_frame_rate_flag == 0) {
	    fprintf(stderr, "\tWARNING: \"fixed_frame_rate_flag\" was not set\n");
	  }
#endif
	} else {
#ifdef DEBUG
	  fprintf(stderr, "\tThis \"Sequence Parameter Set\" NAL unit contained no frame rate information, so we use a default frame rate of %f fps\n", usingSource()->fFrameRate);
#endif
	}
	break;
      }
      case 8: { // Picture parameter set
	// Save a copy of this NAL unit, in case the downstream object wants to see it:
	usingSource()->saveCopyOfPPS(fStartOfFrame + fOutputStartCodeSize, fTo - fStartOfFrame - fOutputStartCodeSize);
      }
    }

    usingSource()->setPresentationTime();
#ifdef DEBUG
    unsigned long secs = (unsigned long)usingSource()->fPresentationTime.tv_sec;
    unsigned uSecs = (unsigned)usingSource()->fPresentationTime.tv_usec;
    fprintf(stderr, "\tPresentation time: %lu.%06u\n", secs, uSecs);
#endif

    // If this NAL unit is a VCL NAL unit, we also scan the start of the next NAL unit, to determine whether this NAL unit
    // ends the current 'access unit'.  We need this information to figure out when to increment "fPresentationTime".
    // (RTP streamers also need to know this in order to figure out whether or not to set the "M" bit.)
    Boolean thisNALUnitEndsAccessUnit = False; // until we learn otherwise 
    if (haveSeenEOF()) {
      // There is no next NAL unit, so we assume that this one ends the current 'access unit':
      thisNALUnitEndsAccessUnit = True;
    } else {
      Boolean const isVCL = nal_unit_type <= 5 && nal_unit_type > 0; // Would need to include type 20 for SVC and MVC #####
      if (isVCL) {
	u_int32_t first4BytesOfNextNALUnit = test4Bytes();
	u_int8_t firstByteOfNextNALUnit = first4BytesOfNextNALUnit>>24;
	u_int8_t next_nal_ref_idc = (firstByteOfNextNALUnit&0x60)>>5;
	u_int8_t next_nal_unit_type = firstByteOfNextNALUnit&0x1F;
	if (next_nal_unit_type >= 6) {
	  // The next NAL unit is not a VCL; therefore, we assume that this NAL unit ends the current 'access unit':
#ifdef DEBUG
	  fprintf(stderr, "\t(The next NAL unit is not a VCL)\n");
#endif
	  thisNALUnitEndsAccessUnit = True;
	} else {
	  // The next NAL unit is also a VCL.  We need to examine it a little to figure out if it's a different 'access unit'.
	  // (We use many of the criteria described in section 7.4.1.2.4 of the H.264 specification.)
	  Boolean IdrPicFlag = nal_unit_type == 5;
	  Boolean next_IdrPicFlag = next_nal_unit_type == 5;
	  if (next_IdrPicFlag != IdrPicFlag) {
	    // IdrPicFlag differs in value
#ifdef DEBUG
	    fprintf(stderr, "\t(IdrPicFlag differs in value)\n");
#endif
	    thisNALUnitEndsAccessUnit = True;
	  } else if (next_nal_ref_idc != nal_ref_idc && next_nal_ref_idc*nal_ref_idc == 0) {
	    // nal_ref_idc differs in value with one of the nal_ref_idc values being equal to 0
#ifdef DEBUG
	    fprintf(stderr, "\t(nal_ref_idc differs in value with one of the nal_ref_idc values being equal to 0)\n");
#endif
	    thisNALUnitEndsAccessUnit = True;
	  } else if ((nal_unit_type == 1 || nal_unit_type == 2 || nal_unit_type == 5)
		     && (next_nal_unit_type == 1 || next_nal_unit_type == 2 || next_nal_unit_type == 5)) {
	    // Both this and the next NAL units begin with a "slice_header".
	    // Parse this (for each), to get parameters that we can compare:
	    
	    // Current NAL unit's "slice_header":
	    unsigned frame_num, pic_parameter_set_id, idr_pic_id;
	    Boolean field_pic_flag, bottom_field_flag;
	    analyze_slice_header(fStartOfFrame + fOutputStartCodeSize, fTo, nal_unit_type,
				 frame_num, pic_parameter_set_id, idr_pic_id, field_pic_flag, bottom_field_flag);
	    
	    // Next NAL unit's "slice_header":
#ifdef DEBUG
	    fprintf(stderr, "    Next NAL unit's slice_header:\n");
#endif
	    u_int8_t next_slice_header[NUM_NEXT_SLICE_HEADER_BYTES_TO_ANALYZE];
	    testBytes(next_slice_header, sizeof next_slice_header);
	    unsigned next_frame_num, next_pic_parameter_set_id, next_idr_pic_id;
	    Boolean next_field_pic_flag, next_bottom_field_flag;
	    analyze_slice_header(next_slice_header, &next_slice_header[sizeof next_slice_header], next_nal_unit_type,
				 next_frame_num, next_pic_parameter_set_id, next_idr_pic_id, next_field_pic_flag, next_bottom_field_flag);
	    
	    if (next_frame_num != frame_num) {
	      // frame_num differs in value
#ifdef DEBUG
	      fprintf(stderr, "\t(frame_num differs in value)\n");
#endif
	      thisNALUnitEndsAccessUnit = True;
	    } else if (next_pic_parameter_set_id != pic_parameter_set_id) {
	      // pic_parameter_set_id differs in value
#ifdef DEBUG
	      fprintf(stderr, "\t(pic_parameter_set_id differs in value)\n");
#endif
	      thisNALUnitEndsAccessUnit = True;
	    } else if (next_field_pic_flag != field_pic_flag) {
	      // field_pic_flag differs in value
#ifdef DEBUG
	      fprintf(stderr, "\t(field_pic_flag differs in value)\n");
#endif
	      thisNALUnitEndsAccessUnit = True;
	    } else if (next_bottom_field_flag != bottom_field_flag) {
	      // bottom_field_flag differs in value
#ifdef DEBUG
	      fprintf(stderr, "\t(bottom_field_flag differs in value)\n");
#endif
	      thisNALUnitEndsAccessUnit = True;
	    } else if (next_IdrPicFlag == 1 && next_idr_pic_id != idr_pic_id) {
	      // IdrPicFlag is equal to 1 for both and idr_pic_id differs in value
	      // Note: We already know that IdrPicFlag is the same for both.
#ifdef DEBUG
	      fprintf(stderr, "\t(IdrPicFlag is equal to 1 for both and idr_pic_id differs in value)\n");
#endif
	      thisNALUnitEndsAccessUnit = True;
	    }
	  }
	}
      }
    }
	
    if (thisNALUnitEndsAccessUnit) {
#ifdef DEBUG
      fprintf(stderr, "*****This NAL unit ends the current access unit*****\n");
#endif
      usingSource()->fPictureEndMarker = True;
      ++usingSource()->fPictureCount;

      // Note that the presentation time for the next NAL unit will be different:
      struct timeval& nextPT = usingSource()->fNextPresentationTime; // alias
      nextPT = usingSource()->fPresentationTime;
      double nextFraction = nextPT.tv_usec/1000000.0 + 1/usingSource()->fFrameRate;
      unsigned nextSecsIncrement = (long)nextFraction;
      nextPT.tv_sec += (long)nextSecsIncrement;
      nextPT.tv_usec = (long)((nextFraction - nextSecsIncrement)*1000000);
    }
    setParseState();

    return curFrameSize();
  } catch (int /*e*/) {
コード例 #14
0
ファイル: fy.c プロジェクト: AndTH/GCA
/*
 * setup service to define the track positions
 * control remains in this function as long as the setup button is active
 */
void setup(void) {
  confirm(5);

  // start with position mid
  stepnr = initpos;
  choice = MAX_TRACKS / 2 + 1;
  updateDisplay();

  pulswidth = MAX_PULSWIDTH;
  power = POWER_ON;
  waitMS(100);

  curtrack = choice;

  while( buttonSetup == BUTTON_ON ) {
    waitMS(10);

    if( buttonRight == BUTTON_ON && buttonLeft == BUTTON_ON ) {
      saveByte( ADDR_KEEPPOWER, readByte(ADDR_KEEPPOWER) ? KEEPPOWER_OFF:KEEPPOWER_ON );
      confirm(3);
      while( buttonRight == BUTTON_ON && buttonLeft == BUTTON_ON );
    }

    while( stepnr < MAX_STEPS && buttonLeft == BUTTON_OFF && buttonRight == BUTTON_ON ) {
      // turn right; end position is not reached
      stepnr++;
      oneStep(STEP_RIGHT);
    };

    while( stepnr > 0 && buttonLeft == BUTTON_ON && buttonRight == BUTTON_OFF ) {
      // turn left; start position is not reached
      stepnr--;
      oneStep(STEP_LEFT);
    };

    // check if the buttonSave is pressed
    if( buttonSave == BUTTON_ON ) {
      // save the new position in eeprom
      savePosition( choice, stepnr);
      confirm(1);

      choice++;
      if( choice > MAX_TRACKS )
        choice = 1;
      curtrack = choice;
      updateDisplay();

      while( buttonSave == BUTTON_ON )
        waitMS(10);
    }

    // check if the buttonNext is pressed
    if( buttonNext == BUTTON_ON ) {
      confirm(1);

      choice++;
      if( choice > MAX_TRACKS )
        choice = 1;
      curtrack = choice;
      updateDisplay();

      while( buttonNext == BUTTON_ON )
        waitMS(10);
    }

  } // end while

  if( !readByte(ADDR_KEEPPOWER) )
    power = POWER_OFF;  /* power off step motor */
}