diff options
author | TheTroll <trolldev@gmail.com> | 2010-03-17 13:20:30 +0100 |
---|---|---|
committer | TheTroll <trolldev@gmail.com> | 2010-03-17 13:20:30 +0100 |
commit | d890fd4beb74429626b3d49b008b645889f8bbe0 (patch) | |
tree | eddc7877f449636d923f1ffdecaf460dc5d75017 | |
parent | 2699eecff7856183c6f0ef45a5e1eab2cf92d6e0 (diff) | |
download | istreamdev-d890fd4beb74429626b3d49b008b645889f8bbe0.tar.gz istreamdev-d890fd4beb74429626b3d49b008b645889f8bbe0.tar.bz2 |
Implemented startBroacast
PHP files cleanup
-rwxr-xr-x[-rw-r--r--] | bin/backend.php | 44 | ||||
-rwxr-xr-x | bin/files.php | 172 | ||||
-rwxr-xr-x[-rw-r--r--] | bin/firephp.php | 0 | ||||
-rwxr-xr-x | bin/istream.sh | 39 | ||||
-rwxr-xr-x | bin/jsonapi.php | 77 | ||||
-rwxr-xr-x | bin/session.php | 118 | ||||
-rwxr-xr-x | bin/streaminfo.php | 54 | ||||
-rwxr-xr-x[-rw-r--r--] | bin/svdrp.php | 0 | ||||
-rwxr-xr-x | bin/vdr.php | 111 | ||||
-rw-r--r-- | ram/session1/stream.m3u8 | 2 | ||||
-rw-r--r-- | ram/session1/thumb.png | bin | 1809 -> 0 bytes | |||
-rw-r--r-- | ram/session2/stream.m3u8 | 2 | ||||
-rw-r--r-- | ram/session2/thumb.png | bin | 1809 -> 0 bytes | |||
-rw-r--r-- | ram/session3/stream.m3u8 | 2 | ||||
-rwxr-xr-x | ram/session3/thumb.png | bin | 6123 -> 0 bytes |
15 files changed, 527 insertions, 94 deletions
diff --git a/bin/backend.php b/bin/backend.php index c7ff4db..eed0cfd 100644..100755 --- a/bin/backend.php +++ b/bin/backend.php @@ -7,39 +7,43 @@ if (file_exists('../config.php')) else include ('../config_default.php'); include ('./utils.php'); +include ('./files.php'); +include ('./streaminfo.php'); include ('./vdr.php'); +include ('./session.php'); +include ('./jsonapi.php'); $action=$_REQUEST['action']; switch ($action) { case ("getGlobals"): - $tree = getGlobals(); - print $tree; - break; + $tree = getGlobals(); + print $tree; + break; case ("getTvCat"): - $tree = getTvCat(); - print $tree; - break; + $tree = getTvCat(); + print $tree; + break; case ("getFullChanList"): - $tree = getFullChanList(); - print $tree; - break; + $tree = getFullChanList(); + print $tree; + break; case ("getTvChan"): - $tree = GetTvChan($_REQUEST['cat']); - print $tree; - break; + $tree = GetTvChan($_REQUEST['cat']); + print $tree; + break; case ("getChanInfo"): - $tree = getChanInfo($_REQUEST['chan']); - print $tree; - break; + $tree = getChanInfo($_REQUEST['chan']); + print $tree; + break; case ("getRecInfo"): $tree = file_get_contents("textfiles/getRecInfo.txt"); - print $tree; + print $tree; break; case ("getVidInfo"): @@ -54,11 +58,9 @@ switch ($action) break; case ("startBroadcast"): - $type = $_REQUEST['type']; - $url = $_REQUEST['url']; - $tree = file_get_contents("textfiles/startBroadcast-" . $type . ".txt"); - print $tree; - break; + $tree = startBroadcast($_REQUEST['type'], $_REQUEST['url'], $_REQUEST['mode']); + print $tree; + break; case ("stopBroadcast"): $tree = file_get_contents("textfiles/stopBroadcast.txt"); diff --git a/bin/files.php b/bin/files.php new file mode 100755 index 0000000..7dc5baf --- /dev/null +++ b/bin/files.php @@ -0,0 +1,172 @@ +<?php + +$audiotypes='mp3 aac wav '; + +function mediagetinfostream($stream) +{ + // Get info + $getid3 = new getID3; + $fileinfo = $getid3->analyze($stream); + + $title = "Media:"; + $info = "Duration: <i>" .sec2hms($fileinfo['playtime_seconds']) ."</i><br>"; + if ($fileinfo['fileformat']) + $info .= "Format: <i>" .$fileinfo['fileformat'] ."</i><br>"; + if ($fileinfo['video']['codec']) + $info .= "Video: <i>" .$fileinfo['video']['codec'] ."</i><br>"; + if ($fileinfo['audio']['codec']) + $info .= "Audio: <i>" .$fileinfo['audio']['codec'] ."</i><br>"; + if ($fileinfo['video']['resolution_x']) + $info .= "Resolution: <i>" .$fileinfo['video']['resolution_x'] ."x" .$fileinfo['video']['resolution_y'] ."</i><br>"; + + return array($title, $info); +} + +function mediagentb($stream, $dest) +{ + global $ffmpegpath; + + // Get info + $getid3 = new getID3; + $fileinfo = $getid3->analyze($stream); + + exec("rm " .$dest); + $path = dirname($stream); + + if (file_exists(substr($stream, 0, -4) .".tbn")) + $file = substr($stream, 0, -4) .".tbn"; + else if (file_exists($path ."/poster.jpg")) + $file = $path ."/poster.jpg"; + else if (file_exists($path ."/folder.jpg")) + $file = $path ."/folder.jpg"; + else + $file = ""; + + $resx = 180; + $resy = 100; + + if ($file) + { + $getid3 = new getID3; + $fileinfo = $getid3->analyze($file); + } + + if ($fileinfo['video']['resolution_y'] && $fileinfo['video']['resolution_x']) + { + if ($fileinfo['video']['resolution_y'] < $fileinfo['video']['resolution_x']) + { + $resx = 180; + $resy = round(($fileinfo['video']['resolution_y'] * 180) / $fileinfo['video']['resolution_x']); + } + else + { + $resx = round (($fileinfo['video']['resolution_x'] * 100) / $fileinfo['video']['resolution_y']); + $resy = 100; + } + } + + if ($file) + exec("cp \"" .$file ."\" ram/stream-tb-tmp.jpg; " .$ffmpegpath ." -y -i ram/stream-tb-tmp.jpg -s " .$resx ."x" .$resy ." " .$dest ." ; rm ram/stream-tb-tmp.jpg"); + else + exec($ffmpegpath ." -y -i \"" .$stream ."\" -an -ss 00:00:05.00 -r 1 -vframes 1 -s " .$resx ."x" .$resy ." -f mjpeg " .$dest); + + if (!file_exists($dest)) + exec('cp logos/nologoMEDIA.png ' .$dest); +} + +function mediagetwidth($file) +{ + + $getid3 = new getID3; + $fileinfo = $getid3->analyze($file); + + return $fileinfo['video']['resolution_x']; +} + +function mediagettype($file) +{ + global $videotypes, $audiotypes; + + // Get file extension + $fileext = end(explode(".", $file)); + $file = str_replace("\\'", "'", $file); + + if (is_dir($file)) + return 3; + else if (preg_match("$/$", $fileext)) + return 0; + else if (preg_match("/" .$fileext ." /", $videotypes)) + return 'tv'; + else if (preg_match("/" .$fileext ." /", $audiotypes)) + return 'rec'; + else + return 'vid'; +} + +function mediadirhasaudio($dir) +{ + global $audiotypes; + + $audioextarray = explode(' ', $audiotypes); + + foreach ($audioextarray as $num => $audioext) + { + if (glob($dir .'*.' .$audioext)) + return 1; + } + + return 0; +} + +function mediagetmusicinfo($file ="") +{ + // Get info + $getid3 = new getID3; + $fileinfo = $getid3->analyze($file); + + $name = $fileinfo['tags']['id3v2']['title'][0]; + if ($name == "") + { + $name = $fileinfo['tags']['id3v1']['title'][0]; + if ($name == "") + { + $name = $fileinfo['filename']; + if ($name == "") + $name = "unknown"; + } + } + + if (!is_utf8($name)) + $name = utf8_encode($name); + + $duration = $fileinfo['playtime_string']; + + return array ($name, $duration); +} + +function generatelogo($type, $name, $dest) +{ + switch ($type) + { + case 'tv': + $channoslash = preg_replace("$/$", " ", $name); + $logopath = "logos/" .$channoslash .".png"; + if (!file_exists($logopath)) + $logopath = "logos/nologoTV.png"; + exec("cp \"" .$logopath ."\" " .$dest); + break; + case 'rec': + $channoslash = preg_replace("$/$", " ", $name); + $logopath = "logos/" .$channoslash .".png"; + if (!file_exists($logopath)) + $logopath = "logos/nologoREC.png"; + exec("cp \"" .$logopath ."\" " .$dest); + break; + case 'vid': + // Generate TB + mediagentb($name, $dest); + break; + } +} + +?> diff --git a/bin/firephp.php b/bin/firephp.php index 0533028..0533028 100644..100755 --- a/bin/firephp.php +++ b/bin/firephp.php diff --git a/bin/istream.sh b/bin/istream.sh new file mode 100755 index 0000000..6c0985f --- /dev/null +++ b/bin/istream.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +STREAM=$1 +VRATE=$2 +ARATE=$3 +ACHANNELS=$4 +XY=$5 +HTTP_PATH="$6ram/" + +SEGDUR=10 # Length of Segments produced (between 10 and 30) +SEGWIN=$7 # Amount of Segments to produce +FFPATH=$8 +SEGMENTERPATH=$9 +SESSION=${10} + +if [ $# -eq 0 ] +then +echo "Format is : ./istream.sh source video_rate audio_rate audio_channels 480x320 httppath segments_number ffmpeg_path segmenter_path" +exit 1 +fi + +############################################################# +# start dumping the TS via Streamdev into a pipe for ffmpeg +# and store baseline 3.0 mpegts to outputfile +# sending it to the segmenter via a PIPE +############################################################## + +cd ../ram/$SESSION + +2> /dev/null rm stream*.ts + +# Shutdown FTP +/usr/local/bin/fwnoftp + +2> /dev/null $FFPATH -i "$STREAM" -deinterlace -f mpegts -acodec libmp3lame -ab $ARATE -ac $ACHANNELS -s $XY -vcodec libx264 -b $VRATE -flags +loop \ + -cmp \+chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -keyint_min 25 \ + -sc_threshold 40 -i_qfactor 0.71 -bt $VRATE -maxrate $VRATE -bufsize $VRATE -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 \ + -qmin 10 -qmax 51 -qdiff 4 -level 30 -g 30 -async 2 -threads 4 - | \ +$SEGMENTERPATH - $SEGDUR stream stream.m3u8 $HTTP_PATH$SESSION/ $SEGWIN & diff --git a/bin/jsonapi.php b/bin/jsonapi.php new file mode 100755 index 0000000..35ec623 --- /dev/null +++ b/bin/jsonapi.php @@ -0,0 +1,77 @@ +<?php + +function getGlobals() +{ + global $vdrstreamdev, $vdrrecpath, $mediasource; + + $ret = array(); + $ret['streamdev_server'] = $vdrstreamdev; + $ret['rec_path'] = $vdrrecpath; + $ret['video_path'] = "/mnt/media/Video/"; + $ret['audio_path'] = "/mnt/media/Music/"; + + return json_encode($ret); +} + +function getTvCat() +{ + $ret = array(); + $ret['categories'] = vdrgetcategories(); + + return json_encode($ret); +} + +function getFullChanList() +{ + $catlist = array(); + + // Get all categories + $categories = vdrgetcategories(); + + // For all categories + $count = count($categories); + for ($i = 0; $i < $count; $i++) + { + $tmpcat = array(); + + $tmpcat['name'] = $categories[$i]['name']; + $tmpcat['channel'] = vdrgetchannels($tmpcat['name'], 0); + + $catlist[] = $tmpcat; + } + + $ret = array(); + $ret['category'] = $catlist; + + return json_encode($ret); +} + +function getTvChan($cat) +{ + $ret = array(); + $ret['channel'] = vdrgetchannels($cat, 1); + + return json_encode($ret); +} + +function getChanInfo($channum) +{ + $ret = array(); + + $info = array(); + $ret['program'] = vdrgetchaninfo($channum); + + return json_encode($ret); +} + +function startBroadcast($type, $url, $mode) +{ + $ret = array(); + + $ret['session'] = sessioncreate($type, $url, $mode); + + return json_encode($ret); +} + + +?> diff --git a/bin/session.php b/bin/session.php new file mode 100755 index 0000000..8b998d2 --- /dev/null +++ b/bin/session.php @@ -0,0 +1,118 @@ +<?php + +function sessioncreate($type, $url, $mode) +{ + global $httppath, $ffmpegpath, $segmenterpath, $quality; + + // Get a free session + $i=0; + for ($i=0; $i<1000; $i++) + { + $session = "session" .$i; + if (!file_exists('../ram/' .$session)) + break; + } + + // Default + $qparams = $quality[0]; + + // Get parameters + foreach ($quality as $qn => $qp) + { + if ($qn == $mode) + { + $qparams = $qp; + break; + } + } + + // Create session + exec('mkdir ../ram/' .$session); + $url = str_replace("\\'", "'", $url); + switch ($type) + { + case 'tv': + $cmd = "export SHELL=\"/bin/sh\";printf \"./istream.sh \\\"" .$url ."\\\" " .$qparams ." " .$httppath ." 2 " .$ffmpegpath ." " .$segmenterpath ." " .$session ." \" | at now"; + break; + case 'rec': + $cmd = "export SHELL=\"/bin/sh\";printf \"cat \\\"" .$url ."\\\"/0* | ./istream.sh - " .$qparams ." " .$httppath ." 1260 " .$ffmpegpath ." " .$segmenterpath ." " .$session ." \" | at now"; + break; + case 'vid': + $cmd = "export SHELL=\"/bin/sh\";printf \"./istream.sh \\\"" .$url ."\\\" " .$qparams ." " .$httppath ." 1260 " .$ffmpegpath ." " .$segmenterpath ." " .$session ." \" | at now"; + break; + default: + $cmd = ""; + } + + $cmd = str_replace('%', '%%', $cmd); + exec ('echo "' .$cmd .'" > /tmp/a'); + exec ($cmd); + + // Extract $channame if needed + switch ($type) + { + case 'tv': + $urlarray = explode("/", $url); + $channum = $urlarray[count($urlarray)-1]; + $channame = vdrgetchanname($channum); + break; + case 'rec': + list($channame, $title, $desc) = vdrgetrecinfo($url); + break; + default: + $channame = ""; + break; + } + + // Write streaminfo + writeinfostream($session, $type, $mode, $url, $channame); + + // Create logo + if ($type == 'vid') + generatelogo($type, $url, '../ram/' .$session .'/logo.png'); + else + generatelogo($type, $channame, '../ram/' .$session .'/logo.png'); + + return $session; +} + +function sessiondelete($session) +{ + if ($session == 'all') + { + $dir_handle = @opendir('../ram/'); + if ($dir_handle) + { + while ($session = readdir($dir_handle)) + { + if($session == "." || $session == ".." || $session == 'lost+found') + continue; + + if (!is_dir('../ram/' .$session)) + continue; + + // Get info + list($type, $mode, $url, $channame) = readinfostream($session); + + if ($type) + sessiondeletesingle($session); + } + } + } + else + return sessiondeletesingle($session); +} + +function sessiondeletesingle($session) +{ + $ram = "../ram/" .$session ."/"; + + // Get segmenter PID if any + if (file_exists($ram ."segmenter.pid")) + $cmd = "/usr/local/bin/fw;kill `cat " .$ram ."segmenter.pid`; rm " .$ram ."segmenter.pid; "; + + $cmd .= "rm -rf " .$ram; + exec ($cmd); +} + +?> diff --git a/bin/streaminfo.php b/bin/streaminfo.php new file mode 100755 index 0000000..f102226 --- /dev/null +++ b/bin/streaminfo.php @@ -0,0 +1,54 @@ +<?php + +/* + Types: + 0 : Not running + tv : VDR live + rec : VDR recording + vid : Media +*/ + +function writeinfostream($session, $type, $mode, $url, $channame) +{ + $ram = "../ram/" .$session ."/"; + + $infofile = fopen($ram ."streaminfo", 'w'); + + fwrite($infofile, "type=" .$type ."\n"); + fwrite($infofile, "mode=" .$mode ."\n"); + fwrite($infofile, "url=" .$url ."\n"); + fwrite($infofile, "channame=" .$channame ."\n"); + + fclose($infofile); +} + + +function readinfostream($session) +{ + $ram = "../ram/" .$session ."/"; + + if (!file_exists($ram ."streaminfo")) + return array(0); + + $infofile = fopen($ram ."streaminfo", 'r'); + if (!$infofile) + return array(0); + + while ($line = fgets($infofile, 1024)) + { + if (!strncmp($line, "type=", strlen("type="))) + $type = substr($line, strlen("type="), -1); + else if (!strncmp($line, "mode=", strlen("mode="))) + $mode = substr($line, strlen("mode="), -1); + else if (!strncmp($line, "url=", strlen("url="))) + $url = substr($line, strlen("url="), -1); + else if (!strncmp($line, "channame=", strlen("channame="))) + $channame = substr($line, strlen("channame="), -1); + } + + fclose($infofile); + + return array($type, $mode, $url, $channame); +} + +?> diff --git a/bin/svdrp.php b/bin/svdrp.php index 401d6d5..401d6d5 100644..100755 --- a/bin/svdrp.php +++ b/bin/svdrp.php diff --git a/bin/vdr.php b/bin/vdr.php index fc03c12..0b401a8 100755 --- a/bin/vdr.php +++ b/bin/vdr.php @@ -1,73 +1,6 @@ <?php include ('./svdrp_old.php'); -function getGlobals() -{ - global $vdrstreamdev, $vdrrecpath, $mediasource; - - $ret = array(); - $ret['streamdev_server'] = $vdrstreamdev; - $ret['rec_path'] = $vdrrecpath; - $ret['video_path'] = "/mnt/media/Video/"; - $ret['audio_path'] = "/mnt/media/Music/"; - - return json_encode($ret); -} - -function getTvCat() -{ - $ret = array(); - $ret['categories'] = vdrgetcategories(); - - return json_encode($ret); -} - -function getFullChanList() -{ - $catlist = array(); - - // Get all categories - $categories = vdrgetcategories(); - - // For all categories - $count = count($categories); - for ($i = 0; $i < $count; $i++) - { - $tmpcat = array(); - - $tmpcat['name'] = $categories[$i]['name']; - $tmpcat['channel'] = vdrgetchannels($tmpcat['name'], 0); - - $catlist[] = $tmpcat; - } - - $ret = array(); - $ret['category'] = $catlist; - - return json_encode($ret); -} - -function getTvChan($cat) -{ - $ret = array(); - $ret['channel'] = vdrgetchannels($cat, 1); - - return json_encode($ret); -} - -function getChanInfo($channum) -{ - $ret = array(); - - $info = array(); - $ret['program'] = vdrgetchaninfo($channum); - - return json_encode($ret); -} - - -/********************* LOCAL ************************/ - function vdrsendcommand($cmd) { global $svdrpip, $svdrpport; @@ -325,7 +258,51 @@ function vdrgetchanepg($channum, $now) return array($time, $title, $desc); } +function vdrgetrecinfo($rec) +{ + $infofile = $rec ."/info"; + if (file_exists($infofile)) + $info= file_get_contents($infofile); + else + { + $infofile = $rec ."/info.vdr"; + if (file_exists($infofile)) + $info= file_get_contents($infofile); + else + $info=""; + } + + $allepg = explode("\n", $info); + $epgtitle=""; + $epgdesc=""; + + // For all epg + $count = count($allepg); + for ($i = 0; $i < $count; $i++) + { + // Now find T or C + if(ereg("^C", $allepg[$i])) + { + $channame = substr($allepg[$i], 2); + $channames = explode(" ", $channame); + $channame = substr($channame, strlen($channames[0])+1); + } + else if(ereg("^T", $allepg[$i])) + $epgtitle=substr($allepg[$i], 2); + else if(ereg("^D", $allepg[$i])) + $epgdesc=substr($allepg[$i], 2); + } + + // Convert if needed + if (!is_utf8($epgtitle)) + $epgtitle = utf8_encode($epgtitle); + if (!is_utf8($epgdesc)) + $epgdesc = utf8_encode($epgdesc); + + + return array($channame, epgtitle, $epgdesc); +} diff --git a/ram/session1/stream.m3u8 b/ram/session1/stream.m3u8 deleted file mode 100644 index e3f9509..0000000 --- a/ram/session1/stream.m3u8 +++ /dev/null @@ -1,2 +0,0 @@ -#TEST -http://alib.hd.free.fr/istreamdev2/ram/session0/stream1.ts diff --git a/ram/session1/thumb.png b/ram/session1/thumb.png Binary files differdeleted file mode 100644 index 56b1a74..0000000 --- a/ram/session1/thumb.png +++ /dev/null diff --git a/ram/session2/stream.m3u8 b/ram/session2/stream.m3u8 deleted file mode 100644 index e3f9509..0000000 --- a/ram/session2/stream.m3u8 +++ /dev/null @@ -1,2 +0,0 @@ -#TEST -http://alib.hd.free.fr/istreamdev2/ram/session0/stream1.ts diff --git a/ram/session2/thumb.png b/ram/session2/thumb.png Binary files differdeleted file mode 100644 index 56b1a74..0000000 --- a/ram/session2/thumb.png +++ /dev/null diff --git a/ram/session3/stream.m3u8 b/ram/session3/stream.m3u8 deleted file mode 100644 index e3f9509..0000000 --- a/ram/session3/stream.m3u8 +++ /dev/null @@ -1,2 +0,0 @@ -#TEST -http://alib.hd.free.fr/istreamdev2/ram/session0/stream1.ts diff --git a/ram/session3/thumb.png b/ram/session3/thumb.png Binary files differdeleted file mode 100755 index 92d077a..0000000 --- a/ram/session3/thumb.png +++ /dev/null |