[Red5commits] [1564] io code moved to main red5 server repository

jbauch luke at codegent.com
Wed Jan 24 10:56:12 EST 2007


io code moved to main red5 server repository


Timestamp: 11/22/06 16:21:40 EST (2 months ago) 
Change: 1564 
Author: jbauch

Files (see diff or trac for details): 
java/server/trunk/src/org/red5
java/server/trunk/src/org/red5/io
java/server/trunk/test/CuePointNavPointTest.flv
java/server/trunk/test/CuePointTest.flv
java/server/trunk/test/org/red5/server/io/test
java/server/trunk/test/test.flv
java/server/trunk/test/test_cue.flv
java/server/trunk/test/test_cue1.flv
java/server/trunk/test/test_cue3.flv


Trac: http://mirror1.cvsdude.com/trac/osflash/red5/changeset/1564

Index: /java/server/trunk/test/org/red5/server/io/test/MetaDataTest.java
===================================================================
--- /java/server/trunk/test/org/red5/server/io/test/MetaDataTest.java (revision 581)
+++ /java/server/trunk/test/org/red5/server/io/test/MetaDataTest.java (revision 581)
@@ -0,0 +1,89 @@
+package org.red5.server.io.test;
+
+/*
+ * * RED5 Open Source Flash Server - http://www.osflash.org/red5
+ * 
+ * Copyright © 2006 by respective authors. All rights reserved.
+ * 
+ * This library is free software; you can redistribute it and/or modify it under the 
+ * terms of the GNU Lesser General Public License as published by the Free Software 
+ * Foundation; either version 2.1 of the License, or (at your option) any later 
+ * version. 
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License along 
+ * with this library; if not, write to the Free Software Foundation, Inc., 
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
+ * 
+ * @author The Red5 Project (red5 at osflash.org)
+ * @author Dominick Accattato (daccattato at gmail.com)
+ */
+
+import org.red5.io.flv.meta.MetaData;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+
+/**
+ * MetaData TestCase
+ * 
+ * @author The Red5 Project (red5 at osflash.org)
+ * @author daccattato (daccattato at gmail.com)
+ * @version 0.3
+ */
+public class MetaDataTest extends TestCase {
+	MetaData data;
+	
+	public MetaDataTest() {
+		data = new MetaData();
+	}
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+		
+		data.setCanSeekToEnd(true);
+		data.setDuration(7.347);
+		data.setframeRate(15);
+		data.setHeight(333);
+		data.setVideoCodecId(4);
+		data.setVideoDataRate(400);
+		data.setWidth(300);
+	}
+	
+	public void tearDown() {
+		data = null;
+	}
+	
+	public void testCanSeekToEnd() {
+		Assert.assertEquals(true, data.getCanSeekToEnd());
+	}	
+	
+	public void testDuration() {
+		Assert.assertEquals(7.347, data.getDuration(), 0);
+	}
+	
+	public void testFrameRate() {
+		Assert.assertEquals(15, data.getframeRate());
+	}	
+		
+	public void testHeight() {		
+		Assert.assertEquals(333, data.getHeight());
+	}		
+	
+	public void testVideoCodecId() {
+		Assert.assertEquals(4, data.getVideoCodecId());
+	}	
+	
+	public void testVideoDataRate() {
+		Assert.assertEquals(400, data.getVideoDataRate());
+	}	
+	
+	public void testWidth() {
+		Assert.assertEquals(400, data.getVideoDataRate());
+	}	
+	
+}
Index: /java/server/trunk/test/org/red5/server/io/test/MockIOTest.java
===================================================================
--- /java/server/trunk/test/org/red5/server/io/test/MockIOTest.java (revision 228)
+++ /java/server/trunk/test/org/red5/server/io/test/MockIOTest.java (revision 228)
@@ -0,0 +1,50 @@
+package org.red5.server.io.test;
+
+/*
+ * RED5 Open Source Flash Server - http://www.osflash.org/red5
+ * 
+ * Copyright © 2006 by respective authors. All rights reserved.
+ * 
+ * This library is free software; you can redistribute it and/or modify it under the 
+ * terms of the GNU Lesser General Public License as published by the Free Software 
+ * Foundation; either version 2.1 of the License, or (at your option) any later 
+ * version. 
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License along 
+ * with this library; if not, write to the Free Software Foundation, Inc., 
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
+ * 
+ * @author The Red5 Project (red5 at osflash.org)
+ * @author Luke Hubbard, Codegent Ltd (luke at codegent.com)
+ */
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.red5.io.mock.Input;
+import org.red5.io.mock.Mock;
+import org.red5.io.mock.Output;
+
+public class MockIOTest extends AbstractIOTest {
+
+	protected List list;
+	
+	void setupIO() {
+		list = new LinkedList();
+		in = new Input(list);
+		out = new Output(list);
+	}
+	
+	void dumpOutput() {
+		System.out.println(Mock.listToString(list));
+	}
+
+	void resetOutput() {
+		setupIO();
+	}
+
+}
Index: /java/server/trunk/test/org/red5/server/io/test/SimpleJavaBean.java
===================================================================
--- /java/server/trunk/test/org/red5/server/io/test/SimpleJavaBean.java (revision 205)
+++ /java/server/trunk/test/org/red5/server/io/test/SimpleJavaBean.java (revision 205)
@@ -0,0 +1,46 @@
+package org.red5.server.io.test;
+
+/*
+ * RED5 Open Source Flash Server - http://www.osflash.org/red5
+ * 
+ * Copyright © 2006 by respective authors. All rights reserved.
+ * 
+ * This library is free software; you can redistribute it and/or modify it under the 
+ * terms of the GNU Lesser General Public License as published by the Free Software 
+ * Foundation; either version 2.1 of the License, or (at your option) any later 
+ * version. 
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License along 
+ * with this library; if not, write to the Free Software Foundation, Inc., 
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
+ * 
+ * @author The Red5 Project (red5 at osflash.org)
+ * @author Luke Hubbard, Codegent Ltd (luke at codegent.com)
+ */
+
+public class SimpleJavaBean {
+
+	private String nameOfBean = "jeff";
+
+	public String getNameOfBean() {
+		return nameOfBean;
+	}
+
+	public void setNameOfBean(String nameOfBean) {
+		this.nameOfBean = nameOfBean;
+	}
+	
+	public boolean equals(Object obj){
+		if(obj instanceof SimpleJavaBean){
+			SimpleJavaBean sjb = (SimpleJavaBean) obj;
+			return sjb.getNameOfBean() == sjb.getNameOfBean();
+		}
+		return false;
+	}
+	
+
+}
Index: /java/server/trunk/test/org/red5/server/io/test/MetaDataInjectionTest.java
===================================================================
--- /java/server/trunk/test/org/red5/server/io/test/MetaDataInjectionTest.java (revision 581)
+++ /java/server/trunk/test/org/red5/server/io/test/MetaDataInjectionTest.java (revision 581)
@@ -0,0 +1,198 @@
+package org.red5.server.io.test;
+
+/*
+ * RED5 Open Source Flash Server - http://www.osflash.org/red5
+ * 
+ * Copyright © 2006 by respective authors. All rights reserved.
+ * 
+ * This library is free software; you can redistribute it and/or modify it under the 
+ * terms of the GNU Lesser General Public License as published by the Free Software 
+ * Foundation; either version 2.1 of the License, or (at your option) any later 
+ * version. 
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License along 
+ * with this library; if not, write to the Free Software Foundation, Inc., 
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
+ * 
+ * @author The Red5 Project (red5 at osflash.org)
+ * @author Dominick Accattato (daccattato at gmail.com)
+ * @author Luke Hubbard, Codegent Ltd (luke at codegent.com)
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.util.TreeSet;
+
+import junit.framework.TestCase;
+
+import org.apache.mina.common.ByteBuffer;
+import org.red5.io.amf.Output;
+import org.red5.io.flv.IFLV;
+import org.red5.io.flv.IFLVService;
+import org.red5.io.flv.IReader;
+import org.red5.io.flv.ITag;
+import org.red5.io.flv.IWriter;
+import org.red5.io.flv.impl.FLVService;
+import org.red5.io.flv.impl.Tag;
+import org.red5.io.flv.meta.MetaCue;
+import org.red5.io.flv.meta.IMetaCue;
+import org.red5.io.flv.meta.ICueType;
+import org.red5.io.object.Deserializer;
+import org.red5.io.object.Serializer;
+
+/**
+ * @author The Red5 Project (red5 at osflash.org)
+ * @author daccattato(daccattato at gmail.com)
+ * @version 0.3
+ */
+public class MetaDataInjectionTest extends TestCase {
+
+	private IFLVService service;
+	
+	/**
+	 * SetUp is called before each test
+	 * @return void
+	 */
+	public void setUp() {
+		service = new FLVService();
+		service.setSerializer(new Serializer());
+		service.setDeserializer(new Deserializer());
+	}
+	
+	/**
+	 * Test MetaData injection
+	 * @throws IOException
+	 */
+	public void testMetaDataInjection() throws IOException {
+		File f = new File("tests/test_cue1.flv");
+		
+		if(f.exists()) {			
+			f.delete();
+		}
+		
+		// Create new file
+		f.createNewFile();
+		
+		// Use service to grab FLV file
+		IFLV flv = service.getFLV(f);
+		
+		// Grab a writer for writing a new FLV
+		IWriter writer = flv.writer();
+		
+		// Create a reader for testing
+		File readfile = new File("tests/test_cue.flv");
+		IFLV readflv = service.getFLV(readfile);
+		
+		// Grab a reader for reading a FLV in
+		IReader reader = readflv.reader();
+		
+		// Inject MetaData
+		writeTagsWithInjection(reader, writer);	
+		
+	}
+
+	/**
+	 * Write FLV tags and inject Cue Points
+	 * @param reader
+	 * @param writer
+	 * @throws IOException
+	 */
+	private void writeTagsWithInjection(IReader reader, IWriter writer) throws IOException {
+				
+		IMetaCue cp = new MetaCue();
+		cp.setName("cue_1");
+		cp.setTime(0.01);
+		cp.setType(ICueType.EVENT);
+		
+		IMetaCue cp1 = new MetaCue();
+		cp1.setName("cue_1");
+		cp1.setTime(2.01);
+		cp1.setType(ICueType.EVENT);	
+
+		// Place in TreeSet for sorting
+		TreeSet ts = new TreeSet();
+		ts.add(cp);
+		ts.add(cp1);
+		
+		int cuePointTimeStamp = getTimeInMilliseconds(ts.first());		
+		
+		ITag tag = null;
+		ITag injectedTag = null;
+		
+		while(reader.hasMoreTags()) {
+			tag = reader.readTag();
+			
+			if(tag.getDataType() != Tag.TYPE_METADATA) {
+				//injectNewMetaData();
+			} else {
+				//in
+			}
+			
+			// if there are cuePoints in the TreeSet
+			if(!ts.isEmpty()) {
+	
+				// If the tag has a greater timestamp than the
+				// cuePointTimeStamp, then inject the tag
+				while(tag.getTimestamp() > cuePointTimeStamp) {
+					
+					injectedTag = (ITag) injectMetaData(ts.first(), tag);
+					writer.writeTag(injectedTag);					
+					tag.setPreviousTagSize((injectedTag.getBodySize() + 11));
+					
+					// Advance to the next CuePoint
+					ts.remove(ts.first());
+				
+					if(ts.isEmpty()) {
+						break;						
+					}
+					
+					cuePointTimeStamp = getTimeInMilliseconds(ts.first());
+				}										
+			}
+			
+			writer.writeTag(tag);
+			
+		}
+	}		
+
+	/**
+	 * Injects metadata (Cue Points) into a tag
+	 * @param cue
+	 * @param writer
+	 * @param tag
+	 * @return ITag tag
+	 */
+	private ITag injectMetaData(Object cue, ITag tag) {
+		
+		IMetaCue cp = (MetaCue) cue;
+		Output out = new Output(ByteBuffer.allocate(1000));
+		Serializer ser = new Serializer();		
+		ser.serialize(out,"onCuePoint");
+		ser.serialize(out,cp);
+				
+		ByteBuffer tmpBody = out.buf().flip();		
+		int tmpBodySize = out.buf().limit();	
+		int tmpPreviousTagSize = tag.getPreviousTagSize();
+		byte tmpDataType = ((byte)(ITag.TYPE_METADATA));
+		int tmpTimestamp = getTimeInMilliseconds(cp);
+								
+		return new Tag(tmpDataType, tmpTimestamp, tmpBodySize, tmpBody, tmpPreviousTagSize);
+		
+	}
+	
+	/**
+	 * Returns a timestamp in milliseconds
+	 * @param object
+	 * @return int time
+	 */
+	private int getTimeInMilliseconds(Object object) {
+		IMetaCue cp = (MetaCue) object;		
+		return (int) (cp.getTime() * 1000.00);
+		
+	}
+	
+}
Index: /java/server/trunk/test/org/red5/server/io/test/CircularRefBean.java
===================================================================
--- /java/server/trunk/test/org/red5/server/io/test/CircularRefBean.java (revision 205)
+++ /java/server/trunk/test/org/red5/server/io/test/CircularRefBean.java (revision 205)
@@ -0,0 +1,43 @@
+package org.red5.server.io.test;
+
+/*
+ * RED5 Open Source Flash Server - http://www.osflash.org/red5
+ * 
+ * Copyright © 2006 by respective authors. All rights reserved.
+ * 
+ * This library is free software; you can redistribute it and/or modify it under the 
+ * terms of the GNU Lesser General Public License as published by the Free Software 
+ * Foundation; either version 2.1 of the License, or (at your option) any later 
+ * version. 
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License along 
+ * with this library; if not, write to the Free Software Foundation, Inc., 
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
+ * 
+ * @author The Red5 Project (red5 at osflash.org)
+ * @author Luke Hubbard, Codegent Ltd (luke at codegent.com)
+ */
+
+public class CircularRefBean extends SimpleJavaBean {
+
+	private CircularRefBean refToSelf;
+	
+	public CircularRefBean(){
+		super();
+	}
+
+	public CircularRefBean getRefToSelf() {
+		return refToSelf;
+	}
+
+	public void setRefToSelf(CircularRefBean refToSelf) {
+		this.refToSelf = refToSelf;
+	}
+	
+	
+
+}
Index: /java/server/trunk/test/org/red5/server/io/test/MetaServiceTest.java
===================================================================
--- /java/server/trunk/test/org/red5/server/io/test/MetaServiceTest.java (revision 607)
+++ /java/server/trunk/test/org/red5/server/io/test/MetaServiceTest.java (revision 607)
@@ -0,0 +1,93 @@
+package org.red5.server.io.test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.red5.io.flv.IFLV;
+import org.red5.io.flv.impl.FLV;
+import org.red5.io.flv.impl.FLVService;
+import org.red5.io.flv.meta.ICueType;
+import org.red5.io.flv.meta.IMetaCue;
+import org.red5.io.flv.meta.MetaCue;
+import org.red5.io.flv.meta.MetaData;
+import org.red5.io.flv.meta.MetaService;
+import org.red5.io.flv.meta.Resolver;
+import org.red5.io.object.Deserializer;
+import org.red5.io.object.Serializer;
+
+import junit.framework.TestCase;
+
+public class MetaServiceTest extends TestCase {
+
+	private FLVService service;
+	private MetaService metaService;
+
+	protected void setUp() throws Exception {
+		super.setUp();
+				
+		// Create a FLV Service
+		service = new FLVService();
+		
+		// Create a Meta Service
+		metaService = new MetaService();
+		metaService.setSerializer(new Serializer());
+		metaService.setDeserializer(new Deserializer());
+		metaService.setResolver(new Resolver());
+	}
+	
+	/**
+	 * Test writing meta data
+	 * @throws IOException
+	 */
+	public void testWrite() throws IOException {		
+
+		// Get MetaData to embed
+		MetaData meta = createMeta();
+		// Read in a FLV file for reading tags
+		// set the MetaService
+		// set the MetaData
+		File tmp = new File("tests/test.flv");
+		IFLV flv = service.getFLV(tmp);
+		flv.setMetaService(metaService);
+		flv.setMetaData(meta);
+		
+	}
+
+	/**
+	 * Create some test Metadata for insertion
+	 * @return MetaData meta
+	 */
+	private MetaData createMeta() {
+		
+		IMetaCue metaCue[] = new MetaCue[2];
+		
+	  	IMetaCue cp = new MetaCue();
+		cp.setName("cue_1");
+		cp.setTime(0.01);
+		cp.setType(ICueType.EVENT);
+		
+		IMetaCue cp1 = new MetaCue();
+		cp1.setName("cue_2");
+		cp1.setTime(0.03);
+		cp1.setType(ICueType.EVENT);
+		
+		// add cuepoints to array
+		metaCue[0] = cp;
+		metaCue[1] = cp1;		
+		
+		MetaData meta = new MetaData();
+		meta.setMetaCue(metaCue);
+		meta.setCanSeekToEnd(true);
+		meta.setDuration(300);
+		meta.setframeRate(15);
+		meta.setHeight(400);
+		meta.setWidth(300);
+		
+		return meta;
+		
+	}
+	
+
+}
Index: /java/server/trunk/test/org/red5/server/io/test/TestJavaBean.java
===================================================================
--- /java/server/trunk/test/org/red5/server/io/test/TestJavaBean.java (revision 205)
+++ /java/server/trunk/test/org/red5/server/io/test/TestJavaBean.java (revision 205)
@@ -0,0 +1,80 @@
+package org.red5.server.io.test;
+
+/*
+ * RED5 Open Source Flash Server - http://www.osflash.org/red5
+ * 
+ * Copyright © 2006 by respective authors. All rights reserved.
+ * 
+ * This library is free software; you can redistribute it and/or modify it under the 
+ * terms of the GNU Lesser General Public License as published by the Free Software 
+ * Foundation; either version 2.1 of the License, or (at your option) any later 
+ * version. 
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License along 
+ * with this library; if not, write to the Free Software Foundation, Inc., 
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
+ * 
+ * @author The Red5 Project (red5 at osflash.org)
+ * @author Luke Hubbard, Codegent Ltd (luke at codegent.com)
+ */
+
+import java.util.Date;
+
+public class TestJavaBean {
+
+	private byte testByte = 65;
+	private int testPrimitiveNumber = 3;
+	private Integer testNumberObject = new Integer(33);
+	private String testString = "red5 rocks!";
+	private Date testDate = new Date();
+	private Boolean testBooleanObject = Boolean.FALSE;
+	private boolean testBoolean = true;
+	
+	public byte getTestByte() {
+		return testByte;
+	}
+	public void setTestByte(byte testByte) {
+		this.testByte = testByte;
+	}
+	public boolean isTestBoolean() {
+		return testBoolean;
+	}
+	public void setTestBoolean(boolean testBoolean) {
+		this.testBoolean = testBoolean;
+	}
+	public Boolean getTestBooleanObject() {
+		return testBooleanObject;
+	}
+	public void setTestBooleanObject(Boolean testBooleanObject) {
+		this.testBooleanObject = testBooleanObject;
+	}
+	public Date getTestDate() {
+		return testDate;
+	}
+	public void setTestDate(Date testDate) {
+		this.testDate = testDate;
+	}
+	public Integer getTestNumberObject() {
+		return testNumberObject;
+	}
+	public void setTestNumberObject(Integer testNumberObject) {
+		this.testNumberObject = testNumberObject;
+	}
+	public int getTestPrimitiveNumber() {
+		return testPrimitiveNumber;
+	}
+	public void setTestPrimitiveNumber(int testPrimitiveNumber) {
+		this.testPrimitiveNumber = testPrimitiveNumber;
+	}
+	public String getTestString() {
+		return testString;
+	}
+	public void setTestString(String testString) {
+		this.testString = testString;
+	}
+	
+}
Index: /java/server/trunk/test/org/red5/server/io/test/CuePointInjectionTest.java
===================================================================
--- /java/server/trunk/test/org/red5/server/io/test/CuePointInjectionTest.java (revision 581)
+++ /java/server/trunk/test/org/red5/server/io/test/CuePointInjectionTest.java (revision 581)
@@ -0,0 +1,236 @@
+package org.red5.server.io.test;
+
+/*
+ * RED5 Open Source Flash Server - http://www.osflash.org/red5
+ * 
+ * Copyright © 2006 by respective authors. All rights reserved.
+ * 
+ * This library is free software; you can redistribute it and/or modify it under the 
+ * terms of the GNU Lesser General Public License as published by the Free Software 
+ * Foundation; either version 2.1 of the License, or (at your option) any later 
+ * version. 
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License along 
+ * with this library; if not, write to the Free Software Foundation, Inc., 
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
+ * 
+ * @author The Red5 Project (red5 at osflash.org)
+ * @author Dominick Accattato (daccattato at gmail.com)
+ * @author Luke Hubbard, Codegent Ltd (luke at codegent.com)
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.Vector;
+
+import org.apache.mina.common.ByteBuffer;
+import org.red5.io.amf.AMF;
+import org.red5.io.amf.Output;
+import org.red5.io.flv.IFLV;
+import org.red5.io.flv.IFLVService;
+import org.red5.io.flv.impl.FLVService;
+import org.red5.io.flv.IReader;
+import org.red5.io.flv.ITag;
+import org.red5.io.flv.impl.Tag;
+import org.red5.io.flv.meta.MetaCue;
+import org.red5.io.flv.meta.IMetaCue;
+import org.red5.io.flv.meta.ICueType;
+import org.red5.io.flv.meta.MetaData;
+import org.red5.io.flv.IWriter;
+import org.red5.io.object.Deserializer;
+import org.red5.io.object.Serializer;
+import org.red5.io.utils.IOUtils;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author The Red5 Project (red5 at osflash.org)
+ * @author daccattato(daccattato at gmail.com)
+ * @version 0.3
+ */
+public class CuePointInjectionTest extends TestCase {
+
+	private IFLVService service;
+	
+	/**
+	 * SetUp is called before each test
+	 * @return void
+	 */
+	public void setUp() {
+		service = new FLVService();
+		service.setSerializer(new Serializer());
+		service.setDeserializer(new Deserializer());
+	}
+	
+	/**
+	 * Test MetaData injection
+	 * @throws IOException
+	 */
+	public void testCuePointInjection() throws IOException {
+		File f = new File("tests/test_cue1.flv");
+		
+		if(f.exists()) {			
+			f.delete();
+		}
+		
+		// Create new file
+		f.createNewFile();
+		
+		// Use service to grab FLV file
+		IFLV flv = service.getFLV(f);
+		
+		// Grab a writer for writing a new FLV
+		IWriter writer = flv.writer();
+		
+		// Create a reader for testing
+		File readfile = new File("tests/test_cue.flv");
+		IFLV readflv = service.getFLV(readfile);
+		
+		// Grab a reader for reading a FLV in
+		IReader reader = readflv.reader();
+		
+		// Inject MetaData
+		writeTagsWithInjection(reader, writer);	
+		
+	}
+
+	/**
+	 * Write FLV tags and inject Cue Points
+	 * @param reader
+	 * @param writer
+	 * @throws IOException
+	 */
+	private void writeTagsWithInjection(IReader reader, IWriter writer) throws IOException {
+				
+		IMetaCue cp = new MetaCue();
+		cp.setName("cue_1");
+		cp.setTime(0.01);
+		cp.setType(ICueType.EVENT);
+		
+		IMetaCue cp1 = new MetaCue();
+		cp1.setName("cue_1");
+		cp1.setTime(2.01);
+		cp1.setType(ICueType.EVENT);	
+
+		// Place in TreeSet for sorting
+		TreeSet ts = new TreeSet();
+		ts.add(cp);
+		ts.add(cp1);
+		
+		int cuePointTimeStamp = getTimeInMilliseconds(ts.first());		
+		
+		ITag tag = null;
+		ITag injectedTag = null;
+		
+		while(reader.hasMoreTags()) {
+			tag = reader.readTag();
+			
+			// if there are cuePoints in the TreeSet
+			if(!ts.isEmpty()) {
+	
+				// If the tag has a greater timestamp than the
+				// cuePointTimeStamp, then inject the tag
+				while(tag.getTimestamp() > cuePointTimeStamp) {
+					
+					injectedTag = (ITag) injectCuePoint(ts.first(), tag);
+					writer.writeTag(injectedTag);					
+					tag.setPreviousTagSize((injectedTag.getBodySize() + 11));
+					
+					// Advance to the next CuePoint
+					ts.remove(ts.first());
+				
+					if(ts.isEmpty()) {
+						break;						
+					}
+					
+					cuePointTimeStamp = getTimeInMilliseconds(ts.first());
+				}										
+			}

Note:
Diffs are chopped if more than 25k.
This is to get past the limit on the mailing list.



More information about the Red5commits mailing list