|
@@ -0,0 +1,200 @@
|
|
|
+<?php
|
|
|
+//--------------------------------------------------------------------
|
|
|
+// $Id: index.php,v 0.7 2008/07/24 18:46:16 tmerkel Exp $
|
|
|
+// Copyright 2008 Frubar Network (drscream@frubar.net | wiedi@frubar.net)
|
|
|
+//--------------------------------------------------------------------
|
|
|
+
|
|
|
+/*
|
|
|
+ * information:
|
|
|
+ * - vlc under gentoo is compiled with the following useflags:
|
|
|
+ * X a52 aac aalib alsa avahi bidi dbus dts dvb dvd esd ffmpeg flac
|
|
|
+ * gnutls hal httpd libgcrypt mmx modplug mp3 mpeg musepack musicbrainz
|
|
|
+ * ncurses ogg opengl png pvr qt4 samba sdl shout sse stream taglib
|
|
|
+ * truetype upnp v4l v4l2 vcd vcdx vlm vorbis xml xv
|
|
|
+ * - apache must in the same group that the dvb device, for example
|
|
|
+ * video and audio.
|
|
|
+ * - the channels.dvb must be in the following format (the first is the
|
|
|
+ * line number :P ):
|
|
|
+ * 1: # generated by tmerkel
|
|
|
+ * 2: info:channel name:frequency:orientation:unknown:symbols:unused:unused:channel
|
|
|
+ * 3: TV :Das Erste :11836 :h :0 :27500 :101 :102 :28106
|
|
|
+ * example line:
|
|
|
+ * 4: TV:Das Erste:11836:h:0:27500:101:102:28106
|
|
|
+ *
|
|
|
+ */
|
|
|
+
|
|
|
+define( 'NL', "\n" );
|
|
|
+
|
|
|
+/*
|
|
|
+ * functions
|
|
|
+ */
|
|
|
+function rmnl( $in ) {
|
|
|
+ return str_replace("\n", "", $in);
|
|
|
+}
|
|
|
+
|
|
|
+function init( $station = 0 ) {
|
|
|
+ $channels = array();
|
|
|
+ $chandb[0] = file('channels.dvb');
|
|
|
+ $chandb[1] = count($chandb[0]);
|
|
|
+
|
|
|
+ foreach( $chandb[0] as $chan ) {
|
|
|
+ $channels[] = rmnl(explode(':', $chan));
|
|
|
+ }
|
|
|
+
|
|
|
+ for( $s = 0; $chandb[1] >= $s; $s++ ) {
|
|
|
+ $channels[$s]['channel'] = $channels[$s][8];
|
|
|
+ $channels[$s]['frequency'] = $channels[$s][2] . '000';
|
|
|
+ $channels[$s]['symbols'] = $channels[$s][5] . '000';
|
|
|
+
|
|
|
+ if($channels[$s][3] == 'v')
|
|
|
+ $channels[$s]['voltage'] = 13;
|
|
|
+ else
|
|
|
+ $channels[$s]['voltage'] = 18;
|
|
|
+ }
|
|
|
+
|
|
|
+ if( $station > 0 )
|
|
|
+ return $channels[$station];
|
|
|
+ else
|
|
|
+ return $channels;
|
|
|
+}
|
|
|
+
|
|
|
+function inerr( $error, $text ) {
|
|
|
+ if ( $error ) {
|
|
|
+ echo $text; exit();
|
|
|
+ } else {
|
|
|
+ echo $text;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function channelname( $station, $channels ) {
|
|
|
+ return $channels[$station][1];
|
|
|
+}
|
|
|
+
|
|
|
+function vlc_status( ) {
|
|
|
+ // proccess check
|
|
|
+ $pid = file_get_contents('vlc.pid');
|
|
|
+ if( $pid )
|
|
|
+ $s['s'] = true;
|
|
|
+ else
|
|
|
+ $s['s'] = false;
|
|
|
+
|
|
|
+ if( $s['s'] ) {
|
|
|
+ $tuned = file_get_contents('tuning.dat');
|
|
|
+ $s['i'] = $tuned;
|
|
|
+ $s['p'] = $pid;
|
|
|
+ }
|
|
|
+ return $s;
|
|
|
+}
|
|
|
+
|
|
|
+function exec_vlc( $station, $cmd_http ) {
|
|
|
+ $status = vlc_status();
|
|
|
+ if( $status['s'] ) {
|
|
|
+ exec( 'kill -9 '.(int)$status['p'] );
|
|
|
+ sleep(2); // waiting for the kill
|
|
|
+ }
|
|
|
+ shell_exec( 'env -i bash -c '.escapeshellarg($cmd_http) );
|
|
|
+ file_put_contents( 'tuning.dat', $station );
|
|
|
+ $status = vlc_status();
|
|
|
+ if( $status['s'] )
|
|
|
+ return true;
|
|
|
+ else
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+function playlist( $channels ) {
|
|
|
+ header('Content-type: application/xspf+xml');
|
|
|
+ header('Content-Disposition: attachment; filename="tv.xspf"');
|
|
|
+
|
|
|
+ echo '<?xml version="1.0" encoding="UTF-8"?>' . NL
|
|
|
+ . '<playlist version="1" xmlns="http://xspf.org/ns/0/">' . NL
|
|
|
+ . '<trackList>' . NL
|
|
|
+ . '<track><location>http://'.$_SERVER[HTTP_HOST].':8080</location><title>Last Tuned</title></track>';
|
|
|
+
|
|
|
+ foreach( $channels as $num => $c ) {
|
|
|
+ if( $c[0] != 'TV' && $c[0] != 'RA' ) continue;
|
|
|
+ echo '<track><location>http://'.$_SERVER[HTTP_HOST].'/frutv/?station=' . $num
|
|
|
+ . '&playlist=true</location><title>' . $c[0]
|
|
|
+ . ': ' . htmlspecialchars(utf8_encode($c[1])). '</title></track>'.NL;
|
|
|
+ }
|
|
|
+
|
|
|
+ echo '</trackList></playlist>';
|
|
|
+ exit();
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * parameters
|
|
|
+ */
|
|
|
+function cmd( $channel, $frequency, $voltage, $symbols ) {
|
|
|
+ $cmd_http = '/usr/bin/vlc -d --pidfile vlc.pid --ts-es-id-pid'
|
|
|
+ . ' --program ' . $channel
|
|
|
+ . ' --dvb-frequency=' . $frequency
|
|
|
+ . ' --dvb-adapter=1'
|
|
|
+ . ' dvb:// -I telnet telnet-password=asdfjedn3jdsw3jd'
|
|
|
+ . ' --dvb-voltage=' . $voltage
|
|
|
+ . ' --dvb-srate=' . $symbols
|
|
|
+ . ' --sout \'#duplicate{dst="standard{access'
|
|
|
+ . '=http,mux=ts,url=:8080/tv},select="program=' . $channel . '"}\' ';
|
|
|
+ // . ' --sout \'#duplicate{dst="transcode{acodec=mp3, vcodec=mp4v,vb=2000,ab=128,vt=800000,keyint=80}:standard{access'
|
|
|
+ // . '=http,mux=ts,url=:8080/tv}",select="program=' . $channel . '"}\' ';
|
|
|
+
|
|
|
+ return $cmd_http;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+ * main
|
|
|
+ */
|
|
|
+// param
|
|
|
+$playlist = $_GET['playlist'];
|
|
|
+$station = (int)$_GET['station'];
|
|
|
+
|
|
|
+$channels = init( $station );
|
|
|
+
|
|
|
+if( $station > 0 ) {
|
|
|
+ $cmd = cmd( $channels['channel'],
|
|
|
+ $channels['frequency'],
|
|
|
+ $channels['voltage'],
|
|
|
+ $channels['symbols']);
|
|
|
+ $status = exec_vlc( $station, $cmd );
|
|
|
+
|
|
|
+ if( isset($playlist) ) {
|
|
|
+ sleep(5); // fix for a slow machine, slow dvb card...
|
|
|
+ header( 'Location: http://'.$_SERVER[HTTP_HOST].':8080/', true, 303 );
|
|
|
+ } elseif( $status )
|
|
|
+ header( 'Location: http://'.$_SERVER[HTTP_HOST].'/frutv/' );
|
|
|
+}
|
|
|
+elseif( isset($playlist) ) {
|
|
|
+ playlist( $channels );
|
|
|
+}
|
|
|
+else {
|
|
|
+ $status = vlc_status();
|
|
|
+ $channelname = channelname( $status['i'], $channels );
|
|
|
+ $channelname = ( $channelname ) ? 'currrent channel: '.$channelname : '';
|
|
|
+
|
|
|
+ // default channel list
|
|
|
+ echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'.NL
|
|
|
+ .'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'.NL
|
|
|
+ .'<html xmlns="http://www.w3.org/1999/xhtml">'.NL
|
|
|
+ .' <head>'.NL
|
|
|
+ .' <title>FruTV</title>'.NL
|
|
|
+ .' <meta http-equiv="content-type" content="text/html; charset=utf-8" />'.NL
|
|
|
+ .' <link rel="stylesheet" type="text/css" href="frutv.css" />'.NL
|
|
|
+ .' <link rel="shortcut icon" type="image/png" href="frutv_ico.png" />'.NL
|
|
|
+ .' </head>'.NL
|
|
|
+ .' <body>'.NL;
|
|
|
+ echo ' <h1><img src="frutv.png" /> <span class="orange_h1">Fru</span>TV</h1>'.NL
|
|
|
+ .' <hr />'.NL
|
|
|
+ .' <h2>Channel List</h2>'.NL
|
|
|
+ .' '.$channelname.'<br /><br />'.NL
|
|
|
+ .' <a href="?playlist">» playlist</a><br /><br />'.NL;
|
|
|
+
|
|
|
+ foreach($channels as $num => $c) {
|
|
|
+ if($c[0] != 'TV' && $c[0] != 'RA') continue;
|
|
|
+ echo ' '.$c[0] . ' <a href="?station=' . $num . '">' . $c[1] . '</a><br />'.NL;
|
|
|
+ }
|
|
|
+ echo ' </body>'.NL
|
|
|
+ .'</html>';
|
|
|
+}
|
|
|
+
|
|
|
+?>
|