本文整理汇总了Java中javax.media.Buffer类的典型用法代码示例。如果您正苦于以下问题:Java Buffer类的具体用法?Java Buffer怎么用?Java Buffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Buffer类属于javax.media包,在下文中一共展示了Buffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import javax.media.Buffer; //导入依赖的package包/类
/**
* Description of the Method
*
* @param buffer Description of the Parameter
* @return Description of the Return Value
*/
public int process(Buffer buffer) {
//Graphics2D g2d = (Graphics2D) comp.getGraphics();
//Rectangle r = ((javax.swing.JViewport) comp.getParent()).getViewRect();
//if (g2d != null) {
// if (lastImage == null) {
lastImage = bufferToImage(buffer);
// }
// int w = r.width;
// int h = (int) (w * 3 / 4.0);
// int yy = (int) (r.height / 2 - h / 2);
//g2d.drawImage(lastImage, r.x, yy, r.width, h, null);
// // g2d.dispose();
//}
return BUFFER_PROCESSED_OK;
}
示例2: process
import javax.media.Buffer; //导入依赖的package包/类
public int process(Buffer in, Buffer out) {
// This is the "Callback" to access individual frames.
accessFrame(in);
// Swap the data between the input & output.
Object data = in.getData();
in.setData(out.getData());
out.setData(data);
// Copy the input attributes to the output
out.setFormat(in.getFormat());
out.setLength(in.getLength());
out.setOffset(in.getOffset());
return BUFFER_PROCESSED_OK;
}
示例3: validateByteArraySize
import javax.media.Buffer; //导入依赖的package包/类
byte[] validateByteArraySize(Buffer buffer,int newSize) {
Object objectArray=buffer.getData();
byte[] typedArray;
if (objectArray instanceof byte[]) { // is correct type AND not null
typedArray=(byte[])objectArray;
if (typedArray.length >= newSize ) { // is sufficient capacity
return typedArray;
}
byte[] tempArray=new byte[newSize]; // re-alloc array
System.arraycopy(typedArray,0,tempArray,0,typedArray.length);
typedArray = tempArray;
} else {
typedArray = new byte[newSize];
}
buffer.setData(typedArray);
return typedArray;
}
示例4: read
import javax.media.Buffer; //导入依赖的package包/类
public void read(Buffer buffer) throws IOException {
synchronized (this) {
Object outdata = buffer.getData();
if (outdata == null || !(outdata.getClass() == Format.intArray) ||
((int[])outdata).length < maxDataLength) {
outdata = new int[maxDataLength];
buffer.setData(outdata);
}
buffer.setFormat( rgbFormat );
buffer.setTimeStamp( (long) (seqNo * (1000 / frameRate) * 1000000) );
BufferedImage bi = robot.createScreenCapture(
new Rectangle(x, y, width, height));
bi.getRGB(0, 0, width, height,
(int[])outdata, 0, width);
buffer.setSequenceNumber( seqNo );
buffer.setLength(maxDataLength);
buffer.setFlags(Buffer.FLAG_KEY_FRAME);
buffer.setHeader( null );
seqNo++;
}
}
示例5: process
import javax.media.Buffer; //导入依赖的package包/类
private static int process(Buffer outBuffer) {
int ret = BUFFER_PROCESSED_OK;
try {
if (log.isDebugEnabled()) {
log.debug("process - buffer - ts: {} format: {} length: {}", outBuffer.getTimeStamp(), outBuffer.getFormat(), outBuffer.getLength());
}
// pull out the bytes in to a properly sized array
int encLength = outBuffer.getLength();
log.debug("Encoded video - offset: {} length: {}", outBuffer.getOffset(), encLength);
byte[] data = new byte[encLength];
System.arraycopy((byte[]) outBuffer.getData(), 0, data, 0, encLength);
// check for decoder OK
if (ret == BUFFER_PROCESSED_OK) {
// http://www.cs.columbia.edu/~hgs/rtp/faq.html#timestamp-computed
long timestamp = System.currentTimeMillis() - startTs;
log.debug("Video timestamp: {} ms", timestamp);
// get the NALU
int nalsProcessed = processNals(data, timestamp);
log.debug("NALU processed: {}", nalsProcessed);
}
} catch (Throwable t) {
log.error("Exception in video render", t);
}
return ret;
}
示例6: readHeader
import javax.media.Buffer; //导入依赖的package包/类
/** Reads the image header.
* Does nothing if the header has already been loaded.
*/
private void readHeader() throws IOException {
if (image == null) {
ImageReader r = new JPEGImageReader(getOriginatingProvider());
Object in = getInput();
if (in instanceof Buffer) {
Buffer buffer = (Buffer) in;
in=buffer.getData();
}
if (in instanceof byte[]) {
r.setInput(new MemoryCacheImageInputStream(AVIBMPDIB.prependDHTSeg((byte[]) in)));
} else if (in instanceof ImageInputStream) {
r.setInput(AVIBMPDIB.prependDHTSeg((ImageInputStream) in));
} else {
r.setInput(AVIBMPDIB.prependDHTSeg((InputStream) in));
}
image = r.read(0);
}
}
示例7: bufferReceived
import javax.media.Buffer; //导入依赖的package包/类
/**
* The transcriber can be used as a {@link ReceiveStreamBufferListener}
* to listen for new audio packets coming in through a MediaDevice. It will
* try to filter them based on the SSRC of the packet. If the SSRC does not
* match a participant added to the transcribed, an exception will be thrown
* <p>
* Note that this code is run in a Thread doing audio mixing and only
* has 20 ms for each frame
*
* @param receiveStream the stream from which the audio was received
* @param buffer the containing the audio as well as meta-data
*/
@Override
public void bufferReceived(ReceiveStream receiveStream, Buffer buffer)
{
if (!isTranscribing())
{
logger.trace("Receiving audio while not transcribing");
return;
}
long ssrc = receiveStream.getSSRC() & 0xffffffffL;
Participant p = participants.get(ssrc);
if (p != null)
{
logger.trace("Gave audio to buffer");
p.giveBuffer(buffer);
}
else
{
logger.warn("Reading from SSRC " + ssrc + " while it is " +
"not known as a participant");
}
}
示例8: getFrame
import javax.media.Buffer; //导入依赖的package包/类
public BufferedImage getFrame(int index) {
if (getState() != READY || index < 0 || index > getFrameCount()) {
return null;
}
_framePositioningControl.seek(index);
Buffer buffer = _frameGrabbingControl.grabFrame();
Image img = new BufferToImage((VideoFormat) buffer.getFormat())
.createImage(buffer);
// image creation may also fail!
if (img != null) {
BufferedImage bi = new BufferedImage(img.getWidth(null),
img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bi.createGraphics();
g.drawImage(img, 0, 0, null);
return bi;
}
return null;
}
示例9: mute
import javax.media.Buffer; //导入依赖的package包/类
/**
* Replaces the media data contained in a specific <tt>Buffer</tt> with a
* compatible representation of silence.
*
* @param buffer the <tt>Buffer</tt> the data contained in which is to be
* replaced with silence
*/
public static void mute(Buffer buffer)
{
Object data = buffer.getData();
if (data != null)
{
Class<?> dataClass = data.getClass();
final int fromIndex = buffer.getOffset();
final int toIndex = fromIndex + buffer.getLength();
if (Format.byteArray.equals(dataClass))
Arrays.fill((byte[]) data, fromIndex, toIndex, (byte) 0);
else if (Format.intArray.equals(dataClass))
Arrays.fill((int[]) data, fromIndex, toIndex, 0);
else if (Format.shortArray.equals(dataClass))
Arrays.fill((short[]) data, fromIndex, toIndex, (short) 0);
buffer.setData(data);
}
}
示例10: process
import javax.media.Buffer; //导入依赖的package包/类
/**
* Updates the image to be drawn on the graphics context.
*
* @param buffer the RAW image data.
* @param size the dimension of the image in the buffer.
*/
void process(Buffer buffer, Dimension size)
{
if (mis == null || !this.size.equals(size))
{
this.size = size;
mis =
new MemoryImageSource(size.width, size.height,
(int[]) buffer.getData(), buffer.getOffset(), size.width);
}
else
{
mis.newPixels((int[]) buffer.getData(), ColorModel.getRGBdefault(),
buffer.getOffset(), size.width);
}
this.repaint();
}
示例11: process
import javax.media.Buffer; //导入依赖的package包/类
public int process(Buffer buffer) {
Graphics2D g2d = (Graphics2D) this.getGraphics();
if(g2d != null) {
if(lastImage == null) lastImage = bufferToImage(buffer);
g2d.drawImage(lastImage, 0, 0, this.getWidth(),this.getHeight(), null);
//g2d.dispose();
}
return BUFFER_PROCESSED_OK;
}
示例12: bufferToImage
import javax.media.Buffer; //导入依赖的package包/类
/**
* Description of the Method
*
* @param buffer Description of the Parameter
* @return Description of the Return Value
*/
public BufferedImage bufferToImage(Buffer buffer) {
RGBFormat format = (RGBFormat) buffer.getFormat();
int rMask;
int gMask;
int bMask;
Object data = buffer.getData();
DirectColorModel dcm;
rMask = format.getRedMask();
gMask = format.getGreenMask();
bMask = format.getBlueMask();
int[] masks = new int[3];
masks[0] = rMask;
masks[1] = gMask;
masks[2] = bMask;
DataBuffer db = new DataBufferInt((int[]) data,
format.getLineStride() *
format.getSize().height);
SampleModel sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT,
format.getLineStride(),
format.getSize().height,
masks);
WritableRaster wr = Raster.createWritableRaster(sm, db, new Point(0, 0));
dcm = new DirectColorModel(24, rMask, gMask, bMask);
return new BufferedImage(dcm, wr, true, null);
}
示例13: grabFrame
import javax.media.Buffer; //导入依赖的package包/类
/**
* Description of the Method
*
* @return Description of the Return Value
*/
public Buffer grabFrame() {
Buffer buf = null;
if (lastImage != null) {
buf = ImageToBuffer.createBuffer(lastImage, (float) 0);
}
return buf;
}
示例14: readFrame
import javax.media.Buffer; //导入依赖的package包/类
@Override
public void readFrame(Buffer buffer)
{
synchronized (QT_SYNC_OBJ)
{
BufferedImage bi;
try
{
qtSnapper.next();
bi = qtSnapper.getFrame();
} catch (QTException e)
{
throw new RuntimeException(e); // TODO: how to handle.
}
if (bi != null)
{
final Buffer b = ImageToBuffer.createBuffer(bi, format.getFrameRate());
buffer.setData(b.getData());
buffer.setLength(b.getLength());
buffer.setOffset(b.getOffset());
buffer.setEOM(false);
buffer.setDiscard(false);
buffer.setTimeStamp((qtSnapper.getFrameTime() * 1000000000L) / qtSnapper.getTimeScale());
} else
{
buffer.setEOM(true);
buffer.setLength(0);
}
}
}
示例15: read
import javax.media.Buffer; //导入依赖的package包/类
public void read(Buffer buffer) throws IOException {
// Wait for data to be available
// Doesn't get used much because the transferData
// call is made when data IS available. And most
// Processors/Players read the data in the same
// thread that called transferData, although that's
// not a safe assumption to make
if (!dataAvailable) {
synchronized (bufferLock) {
while (!dataAvailable && !terminate) {
try {
bufferLock.wait(1000);
} catch (InterruptedException ie) {
}
}
}
}
if (dataAvailable) {
synchronized (bufferLock) {
// Copy the buffer attributes, but swap the data
// attributes so that no extra copy is made.
buffer.copy(cbuffer, true);
dataAvailable = false;
}
}
return;
}