本文整理汇总了Java中javax.media.Buffer.setFormat方法的典型用法代码示例。如果您正苦于以下问题:Java Buffer.setFormat方法的具体用法?Java Buffer.setFormat怎么用?Java Buffer.setFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.media.Buffer
的用法示例。
在下文中一共展示了Buffer.setFormat方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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++;
}
}
示例3: 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.byteArray) ||
((byte[])outdata).length < maxDataLength) {
outdata = new byte[maxDataLength];
buffer.setData(outdata);
}
if (videoData) {
buffer.setFormat( rgbFormat );
buffer.setTimeStamp( (long) (seqNo * (1000 / frameRate) * 1000000) );
int lineNo = (seqNo * 2) % size.height;
int chunkStart = lineNo * size.width * 3;
System.arraycopy(data, chunkStart,
outdata, 0,
maxDataLength - (chunkStart));
if (chunkStart != 0) {
System.arraycopy(data, 0,
outdata, maxDataLength - chunkStart,
chunkStart);
}
} else {
buffer.setFormat( audioFormat );
buffer.setTimeStamp( 1000000000 / 8 );
for (int i = 0; i < 1000; i++) {
((byte[])outdata)[i] = (byte) (Math.sin(i / freq) * 32);
freq = (freq + 0.01);
if (freq > 10.0)
freq = 2.0;
}
}
buffer.setSequenceNumber( seqNo );
buffer.setLength(maxDataLength);
buffer.setFlags(0);
buffer.setHeader( null );
seqNo++;
}
}
示例4: doneAllStreams
import javax.media.Buffer; //导入方法依赖的package包/类
void doneAllStreams() {
Buffer buffer = new Buffer();
updateTime();
buffer.setEOM(true);
for (int i = 0; i < outputStreams.length; i++) {
buffer.setFormat(outputStreams[i].getFormat());
outputStreams[i].pushData(buffer);
}
connected = false;
}
示例5: read
import javax.media.Buffer; //导入方法依赖的package包/类
public void read(Buffer buffer) {
//System.err.println("entering read");
synchronized (this) {
while (!dataPending) {
try {
wait();
} catch (InterruptedException ie) {
}
}
}
//System.err.println("... in read");
// Swap
Object data = buffer.getData();
Format format = buffer.getFormat();
Object header = buffer.getHeader();
buffer.setData(pendingBuffer.getData());
buffer.setFormat(pendingBuffer.getFormat());
buffer.setHeader(pendingBuffer.getHeader());
buffer.setTimeStamp(pendingBuffer.getTimeStamp());
buffer.setFlags(pendingBuffer.getFlags() | Buffer.FLAG_NO_SYNC);
buffer.setLength(pendingBuffer.getLength());
buffer.setOffset(pendingBuffer.getOffset());
buffer.setSequenceNumber(pendingBuffer.getSequenceNumber());
pendingBuffer.setData(data);
pendingBuffer.setFormat(format);
pendingBuffer.setHeader(header);
dataPending = false;
synchronized (this) {
notifyAll();
}
}
示例6: read
import javax.media.Buffer; //导入方法依赖的package包/类
/**
* This is called from the Processor to read a frame worth of video data.
*/
public void read(Buffer buffer) throws IOException
{
buffer.setOffset(0);
// Check if we've finished all the frames
if (endOfStream())
{
buffer.setEOM(true);
buffer.setLength(0);
}
else
{
checkAppContext();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BufferedImage frame = this.frameGenerator.renderImageAt(this.framesPath[this.imageIndex],
this.imageIndex == this.framesPath.length - 1);
ImageIO.write(frame, "JPEG", outputStream);
byte[] data = outputStream.toByteArray();
buffer.setData(data);
buffer.setLength(data.length);
buffer.setFormat(this.format);
buffer.setFlags(buffer.getFlags() | Buffer.FLAG_KEY_FRAME);
final int progressionValue = this.imageIndex++;
EventQueue.invokeLater(new Runnable()
{
public void run()
{
progressModel.setValue(progressionValue);
}
});
}
}
示例7: read
import javax.media.Buffer; //导入方法依赖的package包/类
public void read(Buffer buffer) throws IOException {
if (recordingStream.isFinished()) {
System.out.println("Done reading all images.");
buffer.setEOM(true);
buffer.setOffset(0);
buffer.setLength(0);
return;
}
RenderedImage newImage = recordingStream.readFrame();
if (newImage != null) {
image = newImage;
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(outputStream);
ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
writer.setOutput(ios);
ImageWriteParam iwp = writer.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionType("JPEG");
iwp.setCompressionQuality(1);
writer.write(null, new IIOImage(image, null, null), iwp);
writer.dispose();
byte[] data = outputStream.toByteArray();
nextImage++;
System.out.println("Processing frame: " + nextImage);
buffer.setData(data);
buffer.setOffset(0);
buffer.setLength(data.length);
buffer.setFormat(format);
buffer.setFlags(buffer.getFlags() | Buffer.FLAG_KEY_FRAME);
}
示例8: process
import javax.media.Buffer; //导入方法依赖的package包/类
@Override
public int process(Buffer input, Buffer output) {
//System.err.println("ZMBVDecoder " + input.getTimeStamp());
if (input.isDiscard()) {
output.setDiscard(true);
return BUFFER_PROCESSED_OK;
}
if (input.isEOM()) {
output.setEOM(true);
output.setData(null);
return BUFFER_PROCESSED_OK;
}
output.copy(input);
output.setFormat(outputFormat);
output.setData(pixels);
output.setOffset(0);
output.setLength(pixels.length);
//if (input.)
byte[] inDat = (byte[]) input.getData();
int[] swap = prevPixels;
prevPixels = pixels;
pixels = swap;
// Detect if frames were skipped
long sequenceNumber = input.getSequenceNumber();
boolean framesWereSkipped = (sequenceNumber != previousSequenceNumber + 1);
boolean isKeyframe = state.decode(inDat, input.getOffset(), input.getLength(), pixels, prevPixels, outputFormat.getSize().width, outputFormat.getSize().height,
framesWereSkipped);
if (framesWereSkipped && !isKeyframe) {
output.setDiscard(true);
} else {
previousSequenceNumber = sequenceNumber;
}
setFlag(output, Buffer.FLAG_KEY_FRAME, isKeyframe);
return BUFFER_PROCESSED_OK;
}
示例9: process
import javax.media.Buffer; //导入方法依赖的package包/类
public int process(Buffer inputBuffer, Buffer outputBuffer){
// == prolog
if (isEOM(inputBuffer) ) {
propagateEOM(outputBuffer);
return BUFFER_PROCESSED_OK;
}
byte [] inBuffer = (byte[])inputBuffer.getData();
int inLength = inputBuffer.getLength();
int inOffset = inputBuffer.getOffset();
int samplesNumber = inLength;
AudioFormat af = (AudioFormat) inputBuffer.getFormat();
if (enabled) {
int shiftZero = 0;
int shiftOne = 8;
if (af.getEndian() == AudioFormat.BIG_ENDIAN) {
shiftZero = 8;
shiftOne = 0;
}
// == main
int spa = ((int) af.getSampleRate() * af.getChannels()) / nPowersPerSec;
long npa = 1000000000L / nPowersPerSec;
long timeStamp = inputBuffer.getTimeStamp(); // in nanos
float average = 0;
long cspa = 0;
for (int i = 0; i < inLength; i += 2) {
short sample = (short)
(((0xFF & inBuffer[inOffset + i]) << shiftZero) |
((0xFF & inBuffer[inOffset + i + 1]) << shiftOne));
float normal = (float) sample;
average = average + normal * normal;
cspa++;
if (cspa == spa) {
cspa = 0;
average = (float) Math.sqrt((average / spa)) / 32768;
push(timeStamp, average);
timeStamp += npa;
average = 0;
}
}
}
// == epilog
inputBuffer.setData(outputBuffer.getData());
outputBuffer.setFormat(af);
outputBuffer.setData(inBuffer);
outputBuffer.setLength(inLength);
outputBuffer.setOffset(inOffset);
outputBuffer.setTimeStamp(inputBuffer.getTimeStamp());
outputBuffer.setFlags(inputBuffer.getFlags());
return BUFFER_PROCESSED_OK;
}
示例10: read
import javax.media.Buffer; //导入方法依赖的package包/类
/**
* This is called from the Processor to read a frame worth
* of video data.
*/
public void read(Buffer buf) throws IOException {
// Check if we've finished all the frames.
if (nextImage >= images.size()) {
// We are done. Set EndOfMedia.
System.err.println("Done reading all images.");
buf.setEOM(true);
buf.setOffset(0);
buf.setLength(0);
ended = true;
return;
}
String imageFile = (String)images.elementAt(nextImage);
nextImage++;
System.err.println(" - reading image file: " + imageFile);
// Open a random access file for the next image.
RandomAccessFile raFile;
raFile = new RandomAccessFile(imageFile, "r");
byte data[] = null;
// Check the input buffer type & size.
if (buf.getData() instanceof byte[])
data = (byte[])buf.getData();
// Check to see the given buffer is big enough for the frame.
if (data == null || data.length < raFile.length()) {
data = new byte[(int)raFile.length()];
buf.setData(data);
}
// Read the entire JPEG image from the file.
raFile.readFully(data, 0, (int)raFile.length());
System.err.println(" read " + raFile.length() + " bytes.");
buf.setOffset(0);
buf.setLength((int)raFile.length());
buf.setFormat(format);
buf.setFlags(buf.getFlags() | Buffer.FLAG_KEY_FRAME);
// Close the random access file.
raFile.close();
}
示例11: process
import javax.media.Buffer; //导入方法依赖的package包/类
public int process(Buffer inBuffer, Buffer outBuffer) {
int outputDataLength = ((VideoFormat)outputFormat).getMaxDataLength();
validateByteArraySize(outBuffer, outputDataLength);
outBuffer.setLength(outputDataLength);
outBuffer.setFormat(outputFormat);
outBuffer.setFlags(inBuffer.getFlags());
byte [] inData = (byte[]) inBuffer.getData();
byte [] outData = (byte[]) outBuffer.getData();
RGBFormat vfIn = (RGBFormat) inBuffer.getFormat();
Dimension sizeIn = vfIn.getSize();
int pixStrideIn = vfIn.getPixelStride();
int lineStrideIn = vfIn.getLineStride();
int iw = sizeIn.width;
int ih = sizeIn.height;
int cx = iw/2;
int cy = ih/2;
int ip = 0;
int op = 0;
int x, y;
double vsin, vcos, ratio;
if ( outData.length < iw*ih*3 ) {
System.out.println("the buffer is not full");
return BUFFER_PROCESSED_FAILED;
}
// System.out.println("count = " + count);
vsin = sinTable[count];
vcos = cosTable[count];
ratio = 1.0;//rateTable[count];
// System.out.println("vsin = " + vsin + " vcos = " + vcos);
for ( int j = -cy; j < ih-cy; j++ )
for ( int i = -cx; i < iw-cx; i++ ) {
x = (int)((vcos * i - vsin * j)*ratio + cx + 0.5);
y = (int)((vsin * i + vcos * j)*ratio + cy + 0.5);
if ( x < 0 || x >= iw || y < 0 || y >= ih) {
outData[op++] = 0;
outData[op++] = 0;
outData[op++] = 0;
} else {
ip = lineStrideIn * y + x * pixStrideIn;
outData[op++] = inData[ip++];
outData[op++] = inData[ip++];
outData[op++] = inData[ip++];
}
}
count ++;
if ( count >= num )
count = 0;
return BUFFER_PROCESSED_OK;
}
示例12: read
import javax.media.Buffer; //导入方法依赖的package包/类
/**
* This is called from the Processor to read a frame worth
* of video data.
*/
public void read(Buffer buf) throws IOException {
// Check if we've finished all the frames.
if (JPGImages.finished) {
// We are done. Set EndOfMedia.
System.err.println("Done reading all images.");
System.err.println("Frames: " + JPGImages.totalPics);
System.err.println("Missed frames: " +
(JPGImages.sentPics - JPGImages.totalPics));
buf.setEOM(true);
buf.setOffset(0);
buf.setLength(0);
ended = true;
return;
}
float time1 = seqNo * (1000 / frameRate) * 1000000;
long time = (long) time1;
buf.setTimeStamp(time);
buf.setSequenceNumber(seqNo++);
byte[] picBytes = JPGImages.readNode(); // read the next image in line
// in the DataList.
byte data[] = null;
// int data[] = new int[picBytes.length / 4];
// Read the entire JPEG image from the file.
data = picBytes;
/* The commented out code below is remains from a
* failed attempt to include avi output. The code is
* left in the source like this as a reminder to the
* author
*/
// int dataCnt = 0;
// int mult;
// for (int cnt = 0; cnt < data.length; cnt ++) {
// mult = 256*256*256;
// for (int loopCnt = 0; loopCnt < 4; loopCnt++) {
// data[picCnt] += picBytes[dataCnt++] * mult;
// mult /= 256;
// }
// }
buf.setData(data);
buf.setOffset(0);
buf.setLength((int) picBytes.length);
buf.setFormat(format);
buf.setFlags(buf.getFlags() | buf.FLAG_KEY_FRAME);
}
示例13: read
import javax.media.Buffer; //导入方法依赖的package包/类
public void read(Buffer buffer) throws IOException {
synchronized (this) {
// {
Object outdata = buffer.getData();
if (rateChanged || outdata == null
|| !(outdata.getClass() == Format.intArray)
|| ((int[]) outdata).length < maxDataLength) {
outdata = new int[maxDataLength];
buffer.setData(outdata);
// System.out.println("rateChanged is: "+rateChanged+" and framerate is: "
// + frameRate);
rateChanged = false;
}
buffer.setFormat(rgbFormat);
if (!everChanged) {
timeStamp = (long) (seqNo * (1000 / frameRate) * 1000000);
} else {
if (rateChanged2) {
OldStampCons = timeStamp;
rateChanged2 = false;
}
timeStamp = OldStampCons
+ (long) (seqNo * (1000 / frameRate) * 1000000);
// System.out.println("timeStamp is: " + timeStamp);
}
/*
* if (rateChanged2 && everChanged) { timeStamp = timeStamp + (long)
* (seqNo * (1000 / frameRate) * 1000000);
* System.out.println("timeStamp is: " + timeStamp); rateChanged2
* ++; } else { timeStamp = (long) (seqNo * (1000 / frameRate) *
* 1000000); System.out.println("timeStamp is: " + timeStamp); }
*/
// buffer.setTimeStamp( (long) (seqNo * (1000 / frameRate) *
// 1000000) );
buffer.setTimeStamp(timeStamp);
// System.out.println("timeStamp is: " + timeStamp);
// System.out.println("framerate is: " + frameRate);
int ww = width;
// ww = ww+1;
// x = x+1;
// y = y+1;
// height = height+1;
// System.out.println("width is: "+width);
BufferedImage bi = robot.createScreenCapture(new Rectangle(x, y,
width, height));
// bi.getRGB(0, 0, width, height,
// (int[])outdata, 0, width);
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++;
}
}