Skip to content

Commit

Permalink
Applied some of the submitted code from issue #220 to support non-key…
Browse files Browse the repository at this point in the history
…frame seek.

git-svn-id: http://red5.googlecode.com/svn/java/server/trunk@4380 1b6495e4-3631-0410-8e05-8f51eee8b9cc
  • Loading branch information
mondain committed Jun 11, 2012
1 parent 0425822 commit 101a8b5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,10 @@
</copy>
<!-- zip the source instead of copying verbatim -->
<zip destfile="${dist.dir}/src.zip" basedir="${src.dir}" level="9"/>
<!-- move to the expected directory for windows installer -->
<move todir="${dist.dir}.java6">
<fileset dir="${dist.dir}"/>
</move>
</target>
<target name="dist-archive" depends="dist-installer" description="Create archive file for distribution">
<touch>
Expand Down
4 changes: 2 additions & 2 deletions src/org/red5/io/flv/impl/FLVReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -836,12 +836,12 @@ public static int getDuration(File flvFile) {
long flvLength = Math.max(flvFile.length(), flv.length());
log.debug("File length: {}", flvLength);
if (flvLength > 13) {
flv.seek(flvLength - 4);
flv.seek(flvLength - (4 + 1));
int lastTagSize = flv.readInt();
log.debug("Last tag size: {}", lastTagSize);
if (lastTagSize > 0 && (lastTagSize < flvLength)) {
// jump right to where tag timestamp would be
flv.seek(flvLength - lastTagSize);
flv.seek(flvLength - (lastTagSize + 1));
// grab timestamp as a regular int
duration = flv.readInt();
// adjust value to match extended timestamp
Expand Down
2 changes: 1 addition & 1 deletion src/org/red5/server/api/Red5.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*
* @author The Red5 Project (red5@osflash.org)
* @author Luke Hubbard (luke@codegent.com)
* @author Paul Gregoire (mondain@gmail.com)
* @author Paul Gregoire (mondain@gmail.com)
*/
public final class Red5 {

Expand Down
15 changes: 11 additions & 4 deletions src/org/red5/server/stream/provider/FileProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,21 @@ public synchronized int seek(int ts) {
reader.position(Long.MAX_VALUE);
return (int) keyFrameMeta.duration;
}
int frame = 0;
int frame = -1;
for (int i = 0; i < keyFrameMeta.positions.length; i++) {
if (keyFrameMeta.timestamps[i] > ts) {
frame = i;
break;
}
frame = i;
}
reader.position(keyFrameMeta.positions[frame]);
return keyFrameMeta.timestamps[frame];

if(frame > -1){
reader.position(keyFrameMeta.positions[frame]);
return keyFrameMeta.timestamps[frame];
} else {
// Seek at or beyond EOF
reader.position(Long.MAX_VALUE);
return (int) keyFrameMeta.duration;
}
}
}

0 comments on commit 101a8b5

Please sign in to comment.