forked from caprica/vlcj
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use native direct ByteBuffer instead of Java heap buffer.
This removes one full-frame memory copy.
- Loading branch information
Showing
10 changed files
with
116 additions
and
110 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
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
54 changes: 54 additions & 0 deletions
54
src/main/java/uk/co/caprica/vlcj/player/direct/ByteBufferFactory.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,54 @@ | ||
package uk.co.caprica.vlcj.player.direct; | ||
|
||
import sun.nio.ch.DirectBuffer; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
|
||
/** | ||
* Factory for creating property aligned native byte buffers. | ||
*/ | ||
public class ByteBufferFactory { | ||
|
||
/** | ||
* Alignment suitable for use by LibVLC video callbacks. | ||
*/ | ||
private static final int LIBVLC_ALIGNMENT = 32; | ||
|
||
/** | ||
* Allocate a properly aligned native byte buffer, suitable for use by the LibVLC video | ||
* callbacks. | ||
* | ||
* @param capacity size of the buffer | ||
* @return aligned byte buffer | ||
*/ | ||
public static ByteBuffer allocateAlignedBuffer(int capacity) { | ||
return allocateAlignedBuffer(capacity, LIBVLC_ALIGNMENT); | ||
} | ||
|
||
/** | ||
* Allocate a property aligned native byte buffer. | ||
* <p></p> | ||
* Original credit: http://psy-lob-saw.blogspot.co.uk/2013/01/direct-memory-alignment-in-java.html | ||
* | ||
* @param capacity size of the buffer | ||
* @param alignment alignment | ||
* @return aligned byte buffer | ||
*/ | ||
public static ByteBuffer allocateAlignedBuffer(int capacity, int alignment) { | ||
ByteBuffer result; | ||
ByteBuffer buffer = ByteBuffer.allocateDirect(capacity + alignment); | ||
long address = ((DirectBuffer) buffer).address(); | ||
if ((address & (alignment - 1)) == 0) { | ||
buffer.limit(capacity); | ||
result = buffer.slice().order(ByteOrder.nativeOrder()); | ||
} | ||
else { | ||
int newPosition = (int) (alignment - (address & (alignment - 1))); | ||
buffer.position(newPosition); | ||
buffer.limit(newPosition + capacity); | ||
result = buffer.slice().order(ByteOrder.nativeOrder()); | ||
} | ||
return result; | ||
} | ||
} |
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
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
74 changes: 0 additions & 74 deletions
74
src/main/java/uk/co/caprica/vlcj/player/direct/RenderCallbackAdapter.java
This file was deleted.
Oops, something went wrong.
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