#!/oracle/app/oracle/product/7.3.3/bin/oraperl

##### set Oracle's variables #####
$ENV{'ORACLE_HOME'}='/oracle/app/oracle/product/7.3.3';
$ENV{'ORACLE_SID'}='rabbit';
$orauser="vod";
$orapass="vod";

#### set web server address ####
$WSA = "http://clarissa.npac.syr.edu/vod";
$PROJDIR="/project/K136/VOD";



($clipid,$serverid) =  split(/\&/,$ENV{'QUERY_STRING'});


$lda = &ora_login('', $orauser, $orapass);
$ora_long=32760;
$csr = &ora_open($lda," select FRSFILE, ACCESSLEVEL, BITRATE, FRAMERATE, DOWNLD,
			ENCODING, LENGTH, FILESIZE
                        from CLIPTABLE where CLIPID=$clipid");
($frsvariable, $access, $bitrate, $framerate, $downld, $enc, $len, $filsiz) 
 = &ora_fetch($csr);
$frsvariable =~ s/NPAC\s+/NVS/g;

&ora_close($csr);
$csr = &ora_open($lda," select IPADDRESS from SERVERTABLE 
                 where SERVERID=$serverid");
($server) = &ora_fetch($csr);
&ora_close($csr);
$csr = &ora_open($lda," select FILENAME from CLIPSERVER 
                 where SERVERID=$serverid and CLIPID=$clipid");
($fname) = &ora_fetch($csr);
&ora_close($csr);
&ora_logoff($lda);
 
#
# Set up metafile variables
#
$fz = $filsiz;
$ln = $len;
$framm = 0;
if( $fz eq "" ) {$fz = "2048000"}
if( $ln eq "" ) {$ln = "5000"}
if( $bitrate eq "" ) {$bitrate = "1500"}
if( $framerate eq "" ) {$framerate = "30"}
if( $access eq "" ) {$access = "ALL"}
if( $downld eq "" ) {$downld = "NO"}

print "Content-type: vod/nvs\n\n";

print "NVSID\n";		# file id string
print "ServerIP=$server\n";             # server IP
print "Filename=$fname\n";              # filename
print "Offset=$framm\n";		# playback offset in frames
print "Filesize=$fz\n";             	# file size in bytes
print "Length=$ln\n";			# length of the clip in frames
print "Codec=$enc\n";			# encoding
print "Bitrate=$bitrate\n";		# bitrate
print "Framerate=$framerate\n";		# framerate
print "Access=$access\n";		# access level
print "Download=$downld\n";		# download
print "$frsvariable\n";		# FRS table
