public function testReadWrite()
 {
     /* byte-image of a valid flv header */
     $bytes = 'FLV' . chr(1) . chr(5) . chr(0) . chr(0) . chr(0) . chr(9);
     /* preparing mock streams */
     $inputStub = $this->getMock('Yamdi_InputStream', array(), array(''), '', false, false);
     $inputStub->expects($this->any())->method('read')->will($this->returnValue($bytes));
     $outputMock = $this->getMock('Yamdi_OutputStream', array(), array(''), '', false, false);
     $outputMock->expects($this->once())->method('write')->with($this->equalTo($bytes))->will($this->returnValue(strlen($bytes)));
     /* reading tag */
     $tag = new Yamdi_FlvFileHeader();
     $tag->read($inputStub);
     $this->assertEquals($tag->signature, 'FLV');
     $this->assertEquals($tag->version, 1);
     $this->assertEquals($tag->flags, 5);
     $this->assertEquals($tag->headersize, 9);
     /* writing tag */
     $tag->write($outputMock);
 }
 public function testReadWrite()
 {
     /* byte image of a valid flv header */
     $bytes = 'FLV' . chr(1) . chr(5) . chr(0) . chr(0) . chr(0) . chr(9);
     /* preparing mock streams */
     $inputStream = new MockYamdi_InputStream();
     $inputStream->setReturnValue('read', $bytes);
     $outputStream = new MockYamdi_OutputStream();
     $outputStream->setReturnValue('write', strlen($bytes));
     $outputStream->expect('write', array($bytes));
     /* reading tag */
     $tag = new Yamdi_FlvFileHeader();
     $tag->read($inputStream);
     $this->assertEqual($tag->signature, 'FLV');
     $this->assertEqual($tag->version, 1);
     $this->assertEqual($tag->flags, 5);
     $this->assertEqual($tag->headersize, 9);
     /* writing tag */
     $tag->write($outputStream);
 }
Beispiel #3
0
 protected function write($filename)
 {
     /*
      * File to write
      */
     $stream = new Yamdi_OutputStream($filename);
     if (!$this->header->isValid()) {
         throw new Exception('Must read an flv file before writing it');
     }
     /*
      * Writing preamble tags
      */
     $this->header->write($stream);
     $this->zeroTagSize->write($stream);
     $this->writeMetaBlock($stream);
     $this->writeMediaBlocks($stream);
     $stream->close();
 }
 /**
  * @deprecated 
  */
 public function testMetadataWriteback()
 {
     /*
      * File to read 
      */
     $stream = new Yamdi_InputStream(dirname(__FILE__) . '/../trailer_2.flv');
     /*
      * Constant header
      */
     $header = new Yamdi_FlvFileHeader();
     $header->read($stream);
     $this->assertEqual(true, $header->isValid());
     /*
      * Constant size of zero tag
      */
     $zeroTagSize = new Yamdi_FlvTagSize();
     $zeroTagSize->read($stream);
     $this->assertEqual(0, $zeroTagSize->size);
     // allways 0
     /*
      * First tag (should be meta)
      */
     $tag = new Yamdi_FlvTag();
     $tag->read($stream);
     $this->assertTrue($tag->isMeta());
     $metadata = new Yamdi_FlvMetadataBody();
     $tagBody = $tag->readTagBody($stream);
     $metadata->read($tagBody);
     $this->assertEqual(strlen($tagBody), strlen($metadata->write()));
     /*
      * Cleanup
      */
     $stream->close();
 }