Author:
	Brian Quandt
	Heuris Logic
	Copyright Heuris Logic
	quandt@heuris.com

Introduction:
This program is designed create MPEG-1 (11172-1) system streams from
mpeg compressed (11172-2 and 11172-3) video and audio files.  It is 
limited 


Compliation/Installation Instructions:
	- Modify the Makefile to match your system.  If you want 
	all types of messages define one of the DEBUG's.
	- Type "make binary"
	- Put wherever you wish.

Usage:
	cdisys paramfile


Parameter file explanation:

	The parameter file is used to control the behavior of this 
	encoder.  It is line oriented, and therefore it is very important
	for the right parameters to be on the correct line.
	
	Here is a sample param file that would create a multiplexed
	mpeg file suitable for playing back from a 2x cdrom, using
	mode 2 form 2 sectors.


--------------Start of param file, cut here -----------------------
# Sample param file for system encoder, your comments may go on this line
audio.abs 	# Name of the input audio file 
video.vbs 	# Name of the input video file
/tmp/sys.mpg	# Name of the output system file
e0				# hex value for video id, normally e0 (dec 224)
c0				# hex value for audio id, normally c0 (dec 192)
3				# MPEG video M value, ie size between P frames
1152000.0		# Video bit rate
224000.0		# Audio bit rate
0				# bool flag, if set, encoder continues even on EOF of aud/vid
999999			# max number of sectors to create
7056			# muxrate 
21000			# First Audio pts in 90khz clock units
21000			# First Video pts in 90khz clock units
0				# Fixed bitrate flag 1->set, 0->variable bitrate stream
1				# CSPS flag
1				# Audio lock flag 1 or 0
1				# Video lock flag 1 or 0
44100.0			# Audio sample rate
29.97			# Video frame rate
2324			# Number of bytes per pack (CDI = 2324)
2352			# Number of bytes per pack + any DSM related stuff (CDI = 2352)
2312			# Number of bytes per video packet (CDI=2312)
2294			# Number of data bytes per video packet (CDI=2294)
2312			# Number of bytes per audio packet (CDI=2312)
2299			# Number of data bytes per audio packet (CDI=2279, don't include the 20 bytes of nulls here!)
1				# Number of packets per pack (not implemented, fixed to 1, CDI=1)
0				# (0|1) If set then output CDI type headers and audio (20byte) padding
0				# (0|1) If set output Video CD NULLS with audio packs
---------------------End of param file, cut here ----------------------------

	The first line is for any comments you may wish to identify the
	parameter file.

	The next two lines are the audio and video input files that 
	are to be multiplexed into a system stream specified in the 
	following parameter.

	The stream ID for video is specified next as a hexadecimal value.
	Values from 0xE0 to 0xEF are allowed as specified according to 
	ISO 11172-1.  In other words up to 16 video elementary streams
	can be multiplexed into one system stream (but not with this 
	encoder).

	The stream ID for audio allows values from 0xC0 to 0xDF are allowed.
	This allows for as many as 32 seperate audio elementary streams
	to be multiplexed together.

	The number of video frames (plus 1) between 'reference' frames is specified 
	next (more specfically, the 11172-2 parameter of M).  For example,
	if the number of B frames between reference frames is 2 then this
	number is 2+1

	Video bitrate is the encoded 11172-2 video bitrate of the video stream.

	Audio bitrate is the encoded 11172-3 audio bitrate of the audio stream.

	The next parameter is used to control when the encoder stops
	encoding.  If this is set the encoder will continue even after
	the EOF of the elementary streams.  This will result in the encoder
	simply creating padding streams.

	Max number of sectors is used to control how many packs/sectors
	that the encoder can generate.  This can be used to terminate
	the encoder before the EOF of one or more of the elementary streams.

	Muxrate is the number (divided by 50) of bytes that are delivered
	to the system decoder every second.  For example 7056 is equal 
	to 352800 bytes/second, or looking up the specs on cdrom's
	this is what 2x cdroms can actually deliver.

	First audio and video PTS are used by the encoder to 
	determine when each stream should start playback.  If the
	streams are initially in sync, then make sure that these
	values are set to the same value.  If there is a startup
	difference between audio to video then set the audio
	video PTS value to reflect the difference.

	Fixed bitrate, constrained system parameters, audio lock and
	video lock are parameters that come right out of the 11172-1
	specification.  

	Audio sample rate and video sample rate are the next parameters.
	Each parameter is set according to the value actually set 
	within the elementary stream.

	Bytes per pack is the number of bytes that each pack may contain.

	Bytes per pack + DSM, is the total number of bytes that 
	are contained within a "sector".  This value is necessary 
	to account for any 'time' that takes place for sector headers
	and other non-mpeg data.  For example, with CD's a sector
	is actually 2352 bytes, of which only 2324 bytes are used
	for mpeg systems data.  The remaining bytes still take time
	to pass under the read head, so the system encoder uses this
	size to calculate the amount of time this will take.

	The next parameter controls the size of a video packet.  The
	parameter after this one controls how many video bytes
	are copied from the video elementary stream into the video packet.

	The next parameter controls the size of a audio packet.  The
	parameter after this one controls how many audio bytes
	are copied from the audio elementary stream into the audio packet.

	Number of packets per pack controls the max number of packets
	that can be put within a mpeg system pack.  At present this
	is fixed to 1.

	The next parameter is used to put the encoder into a CDI or 
	non-CDI generating mode.  If you are creating CDI/VCD type 
	mpeg files, this should be set to 1.  It will turn on the notion
	of each elementary stream being multiplexed  into its own 
	system stream (albeit still producing 1 muxed file).

	The last parameter controls the generation of Video CD NULLS.
	If set the encoder will output 20 NULLS after each audio packet.
	This is a requirment of Video CD's.   Many CD burning software
	packages put the NULLS on the file when burning to the disk.
	If using these types of software, set this to 0.  The philips
	verifier assumes that the NULLS are left off for verification, 
	and only placed in the stream when acutally burned to disc.

	
Bugs:
	The buffering model is not completely accurate and can produce 
	minor overflow/underflow errors when multiplexing long runs.

	Access Unit (AU) detection is not 100% reliable on audio AU's
	due to the small size of a syncword.  A heuristic is used 
	to reduce the odds of mismatching an audio AU, however, the
	chances are not zero.

	Upon termination of an elementary stream this code will 
	just tack on a ISO end code.  There are requirments (non-ISO) such
	as video CD or CDI that really want the EOF to happen on 
	an access unit boundary for all elementary streams being multiplexed.



