/*
* @(#)MpegParser.java 1.50 01/02/27
*
* Licensed Materials - Property of IBM
* "Restricted Materials of IBM"
* 5648-B81
* (c) Copyright IBM Corporation 1998,1999 All Rights Reserved
* US Government Users Restricted Rights - Use, duplication or
* disclosure restricted by GSA ADP Schedule Contract with
* IBM Corporation.
*
*/
package com.ibm.media.parser.video;
import java.security.*;
import java.lang.reflect.Method;
import java.lang.reflect.Constructor;
import java.io.OutputStream; //EE temporary!
import java.io.FileOutputStream; //EE temporary!
import java.io.IOException;
import java.awt.Dimension;
import javax.media.*;
import javax.media.protocol.DataSource;
import javax.media.protocol.SourceStream;
import javax.media.protocol.PullSourceStream;
import javax.media.protocol.Seekable;
import javax.media.protocol.Positionable;
import javax.media.Format;
import javax.media.protocol.ContentDescriptor;
import javax.media.protocol.FileTypeDescriptor;
import javax.media.format.AudioFormat;
import javax.media.format.VideoFormat;
import com.sun.media.format.WavAudioFormat;
import com.sun.media.parser.BasicPullParser;
import com.sun.media.parser.BasicTrack;
import com.sun.media.util.jdk12;
import com.sun.media.util.LoopThread;
import com.sun.media.JMFSecurity;
import com.sun.media.JMFSecurityManager;
import com.sun.media.CircularBuffer;
import com.sun.media.Log;
import com.ms.security.PermissionID;
import com.ms.security.PolicyEngine;
public class MpegParser extends BasicPullParser {
/*
* Temporary fields
*/
/* temporary for saving in output files */
boolean saveOutputFlag = false; //true;
String AoutName = "Audio.mpg";
String VoutName = "Video.mpg";
FileOutputStream aout;
FileOutputStream vout;
/* temporary for throwing all data away */
boolean throwOutputFlag = false; /// true;
/* As long as MPEG audio decoder doesn't exist, the audio track should be
* hidden inside the parser. That's mean that only video tracks are output
* of getTracks, and once in a while the audio buffer should be just flushed.
* There is a similar option to ignore the video data.
*/
boolean hideAudioTracks = false; //true;
boolean hideVideoTracks = false;
/*
* Constants definitions for the MPEG-1 system layer splitter
*/
static final long NO_PTS_VAL = -3333333; /* an arbitray value */
private static final float EPSILON_PTS = 45000; /* which is 0.5 sec in PTS units */
private static final float EPSILON_NS = 500000000; /* which is 0.5 sec in nanoseconds */
/* The nature of MPEG video stream is that I frames usually apears every
* 15 frames. In setPosition, we want to have an I frame before the time
* being setted. This is why we will try to look for time stamp of 0.5 seconds
* earlier (in common frame rates of 24-30 frames per second, 0.5 second will
* probably include an I frame).
*/
private static final long PRE_ROLLING_DELTA_NS = 500000000; /* which is 0.5 sec in nano-seconds */
/* packet/track/stream type */
private static final byte UNKNOWN_TYPE = 0;
private static final byte AUDIO_TYPE = 1;
private static final byte VIDEO_TYPE = 2;
private static final byte SYS11172_TYPE = 3;
/* streams buffer size */
private static final int AUDIO_TRACK_BUF_SIZE = 100000;
private static final int VIDEO_TRACK_BUF_SIZE = 200000;
/* codes definition */
private static final int PACK_START_CODE = 0x000001BA;
private static final int SYSTEM_HEADER_START_CODE = 0x000001BB;
private static final int PACKET_START_CODE_24 = 0x000001; /* 24 bits of 0x000001 */
private static final int END_CODE = 0x000001B9;
private static final int MIN_STREAM_CODE = 0x00BC;
private static final int MAX_STREAM_CODE = 0x00FF;
private static final int PRIVATE_STREAM2_CODE = 0x00BF;
private static final int VIDEO_PICTURE_START_CODE = 0x00000100;
private static final int VIDEO_SEQUENCE_HEADER_CODE = 0x000001B3;
private static final int VIDEO_GROUP_START_CODE = 0x000001B8;
/* streams IDs */
private static final int MAX_AUDIO_STREAMS = 32;
private static final int MAX_VIDEO_STREAMS = 16;
private static final int MAX_NUM_STREAMS = 48;
private static final int MIN_AUDIO_ID = 0;
private static final int MAX_AUDIO_ID = 31;
private static final int MIN_VIDEO_ID = 32;
private static final int MAX_VIDEO_ID = 47;
private static int MAX_TRACKS_SUPPORTED = MAX_NUM_STREAMS;
/*
* Fields
*/
private static ContentDescriptor[] supportedFormat =
new ContentDescriptor[] { new ContentDescriptor("audio.mpeg"),
new ContentDescriptor(FileTypeDescriptor.MPEG),
new ContentDescriptor(FileTypeDescriptor.MPEG_AUDIO)};
private PullSourceStream stream = null;
private TrackList[] trackList = new TrackList[MAX_TRACKS_SUPPORTED];
private Track[] tracks = null;
private Track[] videoTracks = null; /// temporary, for hiding audio tracks
private Track[] audioTracks = null; /// temporary, for hiding video tracks
private int videoCount = 0; /// temporary, for hiding audio tracks
private int audioCount = 0; /// temporary, for hiding video tracks
private int numSupportedTracks = 0;
private int numTracks = 0;
private int numPackets = 0;
private int initTmpBufLen; // a buffer used in the initation phase
private byte[] initTmpStreamBuf;
private byte streamType = UNKNOWN_TYPE; // stream can be of: Unknown/Audio/Video/System11172 type
private long streamContentLength = 0L;
private SystemHeader sysHeader = new SystemHeader();
private boolean sysHeaderSeen = false;
boolean EOMflag = false;
boolean parserErrorFlag = false;
private boolean durationInitialized = false;
private boolean sysPausedFlag = false;
private boolean seekableStreamFlag = false; // can be seeked at least to the beginning
private boolean randomAccessStreamFlag = true; // can be seeked to any location
/* some JMFSecurity stuff */
private static JMFSecurity jmfSecurity = null;
private static boolean securityPrivelege=false;
private Method mSecurity[] = new Method[1];
private Class clSecurity[] = new Class[1];
private Object argsSecurity[][] = new Object[1][0];
private long startLocation = 0;
static {
try {
jmfSecurity = JMFSecurityManager.getJMFSecurity();
securityPrivelege = true;
} catch (SecurityException e) {
}
}
/* Time is managed in few sets of variables (for different types of media),
* each has it's own units:
* durationNs - in nanoseconds
* PTS - is 33 bits of the presentation time stamp value.
* Upon the MPEG standard, it probably should be unsigned,
* but since there are movies with negetive values, we will
* treat the time stamp as SIGNED !!
* AV...Ns - time for Audio/Video only streams, in nanoseconds
* Important: every public method who return time, calculate the time
* relative to the startPTS !
*/
/** content duration in NS **/
private Time durationNs = Duration.DURATION_UNKNOWN;
/** last seek time **/
private Time lastSetPositionTime = new Time(0L);
- 1
- 2
前往页