Example #1
0
 /**
  * Returns the next tag from the open file
  *
  * @throws FLV_CorruptedFileException
  * 
  * @param array $skipTagTypes   The tag types contained in this array won't be examined
  * @return FLV_Tag_Generic or one of its descendants
  */
 function getTag($skipTagTypes = false)
 {
     static $cnt = 0;
     if ($this->eof) {
         return null;
     }
     $hdr = fread($this->fp, self::TAG_HEADER_SIZE);
     if (strlen($hdr) < self::TAG_HEADER_SIZE) {
         $this->eof = true;
         return null;
     }
     /*
             //DEV: Some files seem to don't store this value!
             // check against corrupted files
             $prevTagSize = unpack( 'Nprev', $hdr );     
             if ($prevTagSize['prev'] != $this->lastTagSize)
             {
                 throw( 
                     new FLV_CorruptedFileException(  
                         sprintf(    "Previous tag size check failed. Actual size is %d but defined size is %d",
                                     $this->lastTagSize,
                                     $prevTagSize['prev']
                         )
                     )
                 );
             }
     */
     // Get the tag object by skiping the first 4 bytes which tell the previous tag size
     $tag = FLV_Tag::getTag(substr($hdr, 4));
     // Read at most MAX_TAG_BODY_SIZE bytes of the body
     $bytesToRead = min(self::MAX_TAG_BODY_SIZE, $tag->size);
     $tag->setBody(fread($this->fp, $bytesToRead));
     // Check if the tag body has to be processed
     if (is_array($skipTagTypes) && !in_array($tag->type, $skipTagTypes)) {
         $tag->analyze();
     }
     // If the tag was skipped or the body size was larger than MAX_TAG_BODY_SIZE
     if ($tag->size > $bytesToRead) {
         fseek($this->fp, $tag->size - $bytesToRead, SEEK_CUR);
     }
     $this->lastTagSize = $tag->size + self::TAG_HEADER_SIZE - 4;
     return $tag;
 }
 /**
  * Returns the next tag from the open file
  * 
  * @param array $skipTagTypes	The tag types contained in this array won't be examined
  *
  * @return object				FLV_Tag_Generic or one of its descendants
  */
 function getTag($skipTagTypes = false)
 {
     if ($this->eof) {
         return NULL;
     }
     $hdr = fread($this->_fh, $this->TAG_HEADER_SIZE);
     if (strlen($hdr) < $this->TAG_HEADER_SIZE) {
         $this->eof = true;
         return NULL;
     }
     // check against corrupted files
     $prevTagSize = unpack('Nprev', $hdr);
     //		if ($prevTagSize['prev'] != $this->_lastTagSize) die("<br>Previous tag size check failed. Actual size is ".$this->_lastTagSize." but defined size is ".$prevTagSize['prev']);
     // Get the tag object by skiping the first 4 bytes which tell the previous tag size
     $tag = FLV_Tag::getTag(substr($hdr, 4));
     // Read at most MAX_TAG_BODY_SIZE bytes of the body
     $bytesToRead = min($this->MAX_TAG_BODY_SIZE, $tag->size);
     $tag->setBody(fread($this->_fh, $bytesToRead));
     // Check if the tag body has to be processed
     if (is_array($skipTagTypes) && !in_array($tag->type, $skipTagTypes) || !$skipTagTypes) {
         $tag->analyze();
     }
     // If the tag was skipped or the body size was larger than MAX_TAG_BODY_SIZE
     if ($tag->size > $bytesToRead) {
         fseek($this->_fh, $tag->size - $bytesToRead, SEEK_CUR);
     }
     $this->_lastTagSize = $tag->size + $this->TAG_HEADER_SIZE - 4;
     $tag->start = $this->getTagOffset();
     $tag->end = ftell($this->_fh);
     return $tag;
 }