Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
285 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,10 @@ | |
*.jar | ||
*.war | ||
*.ear | ||
.idea | ||
*.iml | ||
|
||
examples/target | ||
isoparser/target | ||
isoparser/aac-sample.mp4 | ||
isoparser/ac3-sample.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
muxer/src/main/java/org/mp4parser/muxer/FileDataSourceViaHeapImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package org.mp4parser.muxer; | ||
|
||
import com.googlecode.mp4parser.util.Logger; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.channels.FileChannel; | ||
import java.nio.channels.WritableByteChannel; | ||
|
||
import static com.googlecode.mp4parser.util.CastUtils.l2i; | ||
|
||
|
||
public class FileDataSourceViaHeapImpl implements DataSource { | ||
private static Logger LOG = Logger.getLogger(FileDataSourceViaHeapImpl.class); | ||
FileChannel fc; | ||
String filename; | ||
|
||
|
||
public FileDataSourceViaHeapImpl(File f) throws FileNotFoundException { | ||
this.fc = new FileInputStream(f).getChannel(); | ||
this.filename = f.getName(); | ||
} | ||
|
||
public FileDataSourceViaHeapImpl(String f) throws FileNotFoundException { | ||
File file = new File(f); | ||
this.fc = new FileInputStream(file).getChannel(); | ||
this.filename = file.getName(); | ||
} | ||
|
||
|
||
public FileDataSourceViaHeapImpl(FileChannel fc) { | ||
this.fc = fc; | ||
this.filename = "unknown"; | ||
} | ||
|
||
public FileDataSourceViaHeapImpl(FileChannel fc, String filename) { | ||
this.fc = fc; | ||
this.filename = filename; | ||
} | ||
|
||
public synchronized int read(ByteBuffer byteBuffer) throws IOException { | ||
return fc.read(byteBuffer); | ||
} | ||
|
||
public synchronized long size() throws IOException { | ||
return fc.size(); | ||
} | ||
|
||
public synchronized long position() throws IOException { | ||
return fc.position(); | ||
} | ||
|
||
public synchronized void position(long nuPos) throws IOException { | ||
fc.position(nuPos); | ||
} | ||
|
||
public synchronized long transferTo(long startPosition, long count, WritableByteChannel sink) throws IOException { | ||
return fc.transferTo(startPosition, count, sink); | ||
} | ||
|
||
public synchronized ByteBuffer map(long startPosition, long size) throws IOException { | ||
ByteBuffer bb = ByteBuffer.allocate(l2i(size)); | ||
fc.read(bb, startPosition); | ||
return (ByteBuffer) bb.rewind(); | ||
} | ||
|
||
public void close() throws IOException { | ||
fc.close(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return filename; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.