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

DePacketizer

public class DePacketizer extends BasicCodec

Fields Summary
private VideoFormat
inputFormat
private VideoFormat
outputFormat
private RTPDePacketizer
rtpdp
Constructors Summary
public DePacketizer()

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

	rtpdp = null;
    
public voidfinalize()

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

        return inputFormat;
    
public java.lang.StringgetName()

        return "MPEG Video 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 MPEG video format
        if (matches(in, inputFormats) == null)
            return new Format[0];
        
        Format out [] = new Format[1];
        out[0] = makeMPEGFormat(in);
        return out;
    
private final javax.media.format.VideoFormatmakeMPEGFormat(javax.media.Format in)

	VideoFormat vf = (VideoFormat)in;
	return new VideoFormat(VideoFormat.MPEG,
			vf.getSize(),
			VideoFormat.NOT_SPECIFIED,
			Format.byteArray,
			vf.getFrameRate());
    
public voidopen()

        if (inputFormat == null || outputFormat == null)
            throw new ResourceUnavailableException(
			"Incorrect formats set on MPEG video depacketizer");
	rtpdp = new RTPDePacketizer();
    
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 MPEG_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.


        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 outBuffer contains a complete MPEG
        // frame of format MPEG

        // get the outputFormat from the buffer only if this is the first time.
        if (outputFormat == null) {
            outputFormat = (VideoFormat) outBuffer.getFormat();
        }

        return BUFFER_PROCESSED_OK;
    
public voidreset()

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

        inputFormat = (VideoFormat) input;
        return input;
    
public javax.media.FormatsetOutputFormat(javax.media.Format output)

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