当前位置: 首页>>代码示例>>Java>>正文


Java Buffer.setLength方法代码示例

本文整理汇总了Java中javax.media.Buffer.setLength方法的典型用法代码示例。如果您正苦于以下问题:Java Buffer.setLength方法的具体用法?Java Buffer.setLength怎么用?Java Buffer.setLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.media.Buffer的用法示例。


在下文中一共展示了Buffer.setLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
	}
 
开发者ID:champtar,项目名称:fmj-sourceforge-mirror,代码行数:18,代码来源:FrameAccess.java

示例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++;
}
   }
 
开发者ID:champtar,项目名称:fmj-sourceforge-mirror,代码行数:22,代码来源:LiveStream.java

示例3: 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);
			
		}
	}

}
 
开发者ID:champtar,项目名称:fmj-sourceforge-mirror,代码行数:35,代码来源:QTParser.java

示例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.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++;
}
   }
 
开发者ID:champtar,项目名称:fmj-sourceforge-mirror,代码行数:39,代码来源:LiveStream.java

示例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();
    }
}
 
开发者ID:champtar,项目名称:fmj-sourceforge-mirror,代码行数:35,代码来源:SuperGlueDataSource.java

示例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);
			}
		});
	}
}
 
开发者ID:valsr,项目名称:SweetHome3D,代码行数:36,代码来源:VideoPanel.java

示例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);
   }
 
开发者ID:openwarrior,项目名称:java-screen-recorder,代码行数:41,代码来源:PlayerSourceStream.java

示例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;
}
 
开发者ID:pojosontheweb,项目名称:selenium-utils,代码行数:40,代码来源:ZMBVDecoder.java

示例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;
   }
 
开发者ID:champtar,项目名称:fmj-sourceforge-mirror,代码行数:57,代码来源:PowerMeter.java

示例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();
}
 
开发者ID:champtar,项目名称:fmj-sourceforge-mirror,代码行数:53,代码来源:JpegImagesToMovie.java

示例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;
    
}
 
开发者ID:champtar,项目名称:fmj-sourceforge-mirror,代码行数:61,代码来源:RotationEffect.java

示例12: readFrame

import javax.media.Buffer; //导入方法依赖的package包/类
@Override
public void readFrame(Buffer buffer)
{
    synchronized (OGG_SYNC_OBJ)
    {
        try
        {
            nextAudioBuffer(); // TODO: this often generates discard
                               // buffers, we could be smarter about it.
                               // Same for video.
        } catch (IOException e)
        {
            buffer.setLength(0);
            buffer.setDiscard(true);
            throw new RuntimeException(e); // TODO: how to handle?
        }

        /* If playback has begun, top audio buffer off immediately. */
        if (stateflag == 0)
        {
            buffer.setEOM(eomAudio);
            buffer.setLength(0);
            if (!eomAudio)
                buffer.setDiscard(true);

            return;
        } else
        {
            if (audiobuf_ready == 0)
            {
                buffer.setEOM(eomAudio);
                buffer.setLength(0);
                if (!eomAudio)
                    buffer.setDiscard(true);
                // System.out.println("Generated discard buffer: ");
                return;
            } else
            {
                // convert from short array to byte array. TODO:
                // inefficient, should just store in byte array to begin
                // with.
                final byte[] data = new byte[audiobuf.length * 2];
                for (int i = 0; i < audiobuf.length; ++i)
                {
                    // little-endian:
                    data[i * 2] = (byte) (audiobuf[i] & 0xff);
                    data[i * 2 + 1] = (byte) ((audiobuf[i] >> 8) & 0xff);
                }

                buffer.setData(data);
                buffer.setLength(data.length);
                buffer.setOffset(0);
                buffer.setEOM(false);
                buffer.setDiscard(false);
                buffer.setTimeStamp(System.currentTimeMillis()); // TODO

                // System.out.println("Generated audio buffer: " +
                // data.length);

                audiobuf_fill = 0;
                audiobuf_ready = 0;

            }
        }
    }
}
 
开发者ID:champtar,项目名称:fmj-sourceforge-mirror,代码行数:67,代码来源:JavaOggParser.java

示例13: 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);

    }
 
开发者ID:jimmyfm,项目名称:krut,代码行数:59,代码来源:ImageSourceStream.java

示例14: 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++;
	}
}
 
开发者ID:mloobo,项目名称:Dolphin-Streaming-Server,代码行数:57,代码来源:StreamPantalla.java

示例15: decode

import javax.media.Buffer; //导入方法依赖的package包/类
public void decode(DataInputExt inputStream, DataComponent blockComponent) throws CDMException
{
    int frameSize = -1;

    try
    {
        // read frame size
        frameSize = inputStream.readInt();
        //System.out.println("Frame size = " + frameSize);
        if (frameSize <= 0)
            throw new CDMException("Invalid block size: " + frameSize);
        
        // read frame to memory buffer
        if (frameData == null || frameData.length < frameSize)
            frameData = new byte[frameSize];
        inputStream.readFully(frameData, 0, frameSize);
        Buffer buffer = new Buffer();
        buffer.setData(frameData);
        buffer.setLength(frameSize);
        
        // decode mpeg into RGB
        Buffer rgbFrame = new Buffer();
        mpegDecoder.process(buffer, rgbFrame);
        
        // write RGB values in datablock
        if (rgbFrame.getData() != null)
        {
            int[] rgbData = (int[])rgbFrame.getData();
            for (int p=0; p<rgbData.length; p++)
            {
                blockComponent.getData().setByteValue(p*3, (byte)rgbData[p]);
                blockComponent.getData().setByteValue(p*3 + 1, (byte)(rgbData[p] >> 8));
                blockComponent.getData().setByteValue(p*3 + 2, (byte)(rgbData[p] >> 16));
            }
        }
    }
    catch (IOException e)
    {
        throw new CDMException("Error when decoding " + frameSize + "B block for " + blockComponent.getName(), e);
    }
}
 
开发者ID:sensiasoft,项目名称:lib-swe-common,代码行数:42,代码来源:MPEG2StreamDecoder.java


注:本文中的javax.media.Buffer.setLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。