FileDocCategorySizeDatePackage
DePacketizer.javaAPI DocJMF 2.1.1e5821Mon May 12 12:20:46 BST 2003com.sun.media.codec.video.jpeg

DePacketizer

public class DePacketizer extends BasicCodec

Fields Summary
private VideoFormat
inputFormat
private JPEGFormat
outputFormat
private int
decimation
private int
quality
private RTPDePacketizer
rtpdp
int
DEFAULT_WIDTH
int
DEFAULT_HEIGHT
Constructors Summary
public DePacketizer()

    
    
    // Initialize default formats.
     
    
        inputFormats = new Format[] { new VideoFormat(VideoFormat.JPEG_RTP) };
        outputFormats = new Format[] { new VideoFormat(VideoFormat.JPEG) };
    
Methods Summary
public synchronized voidclose()

	rtpdp = null;
	super.close();
    
public voidfinalize()

        close();
    
protected javax.media.FormatgetInputFormat()

        return inputFormat;
    
public java.lang.StringgetName()

        return "JPEG DePacketizer";
    
protected javax.media.FormatgetOutputFormat()

        return outputFormat;
    
public javax.media.Format[]getSupportedOutputFormats(javax.media.Format in)

        if (in == null)
            return outputFormats;

        // Make sure the input is JPEG video format
        if (matches(in, inputFormats) == null)
            return new Format[0];
        
        Format out [] = new Format[1];
        out[0] = makeJPEGFormat(in);
        return out;
    
private final javax.media.format.JPEGFormatmakeJPEGFormat(javax.media.Format in)

	VideoFormat vf = (VideoFormat)in;
	return new JPEGFormat((vf.getSize() != null ? vf.getSize() : 
			       new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT)),
			      VideoFormat.NOT_SPECIFIED,
			      Format.byteArray,
			      vf.getFrameRate(), 
			      quality,
			      decimation);
    
public voidopen()

        if (inputFormat == null || outputFormat == null)
            throw new ResourceUnavailableException("Incorrect formats set on JPEG converter");
	rtpdp = new RTPDePacketizer();
	super.open();
    
public synchronized intprocess(javax.media.Buffer inBuffer, javax.media.Buffer outBuffer)

        if (isEOM(inBuffer)) {
            propagateEOM(outBuffer);
            return BUFFER_PROCESSED_OK;
        }
        if (inBuffer.isDiscard()) {
            updateOutput(outBuffer, outputFormat, 0, 0);
            outBuffer.setDiscard(true);
            return OUTPUT_BUFFER_NOT_FILLED;
        }

        // if the encoding is JPEG_RTP, send this packet over to the
        // depacketizer, which will do all the work for you. If the
        // depacketizer has not finished constructing a frame, dont
        // send it for decoding and just return. If the depacketizer
        // has finished constructing an entire frame, send it to the
        // decoder after getting a handle over the decimation and
        // quality from the depacketizer.


        int retVal = rtpdp.process(inBuffer, outBuffer);

        // return any value from the depacketizer except,
        // BUFFER_PROCESSED_OK, which indicates a complete frame
        // is ready for decoding
        if (retVal != BUFFER_PROCESSED_OK) {
            return retVal;
        }

        // at this time, the inBuffer contains a complete JPEG
        // frame of format JPEG
        int type = rtpdp.getType();
        int q = rtpdp.getQuality();

        // compute thje outputFormat only if the type has changed
        // or this is the first time.
        if (type != decimation || q != quality) {
            decimation = type;
	    quality = q;
            outputFormat = makeJPEGFormat(inBuffer.getFormat());
	}
	outBuffer.setFormat(outputFormat);

	// the following code fragment has been removed since the RTPDePacketizer
	// now uses the outBuffer for frame assembly.
	
	/*
        byte [] inData = (byte[]) inBuffer.getData();
        byte [] outData = (byte[]) outBuffer.getData();

        if (outData == null || outData.length < inData.length) {
            outData = new byte[inData.length];
            outBuffer.setData(outData);
        }
	*/
	// Neither copying or setting the data is optimal.
	// We'll need to rewrite RTPDePacketizer to reuse the array.
	// -ivg
	//System.arraycopy((byte[])inData, 0, (byte[])outData, 0, inBuffer.getLength());
	/*
	outBuffer.setData(inData);
        
        outBuffer.setLength(inBuffer.getLength());
	*/
	
	outBuffer.setOffset(0);
	
        outBuffer.setTimeStamp(inBuffer.getTimeStamp());
	
        inBuffer.setLength(0);

	outBuffer.setFlags(outBuffer.getFlags() | Buffer.FLAG_KEY_FRAME);

        return BUFFER_PROCESSED_OK;
    
public voidreset()

        // Anything to do?
    
public javax.media.FormatsetInputFormat(javax.media.Format input)

        inputFormat = (VideoFormat) input;
	if (opened) {
	    outputFormat = makeJPEGFormat(inputFormat);
	}
        return input;
    
public javax.media.FormatsetOutputFormat(javax.media.Format output)

	if (!(output instanceof VideoFormat)) return null;
        outputFormat = makeJPEGFormat(output);
        return outputFormat;