packages/web/353/camogmgui/camogmgui2.php

Go to the documentation of this file.
00001 <?php
00002 /*!***************************************************************************
00003 *! FILE NAME  : camogmgui.php
00004 *! DESCRIPTION: GUI for the camogm recorder
00005 *! Copyright (C) 2008 Elphel, Inc
00006 *! -----------------------------------------------------------------------------**
00007 *!
00008 *!  This program is free software: you can redistribute it and/or modify
00009 *!  it under the terms of the GNU General Public License as published by
00010 *!  the Free Software Foundation, either version 3 of the License, or
00011 *!  (at your option) any later version.
00012 *!
00013 *!  This program is distributed in the hope that it will be useful,
00014 *!  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 *!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 *!  GNU General Public License for more details.
00017 *!
00018 *!  You should have received a copy of the GNU General Public License
00019 *!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 *! -----------------------------------------------------------------------------**
00021 *!  $Log: camogmgui2.php,v $
00022 *!  Revision 1.1.1.1  2008/11/27 20:04:03  elphel
00023 *!
00024 *!
00025 *!  Revision 1.1  2008/11/21 02:46:33  elphel
00026 *!  added camogmgui
00027 *!
00028 *!
00029 *!  Revision 1.""  2008/07/30 Sebastian Pichelhofer
00030 *!  some stability improvements
00031 *!
00032 *!  Revision 1.1  2008/07/25 Sebastian Pichelhofer
00033 *!  added custom commands form and color tags for better overview of current development status
00034 *!
00035 *!  Revision 1.0  2008/07/08 Sebastian Pichelhofer
00036 *!  initial revision with basic interface
00037 *!
00038 */
00039         $reload = false;
00040         // save the "Prompt for filename after recording" checkbox state in a cookie
00041         if (isset($_POST['settings_format']))
00042         {
00043                 setcookie("prompt_filename", $_POST['prompt_filename'], time()+3600*24*7);
00044                 $prompt_filename = $_POST['prompt_filename'];
00045         }
00046         else
00047         {
00048                 $prompt_filename = $_COOKIE['prompt_filename'];
00049         }
00050                 
00051         $pipe = "/var/state/camogm.state";
00052         $cmd_pipe = "/var/state/camogm_cmd";
00053         $mode = 0777;
00054    
00055         if(!file_exists($pipe)) {
00056                 // create the pipe
00057                 umask(0);
00058                 if(!posix_mkfifo($pipe,$mode))
00059                         echo "Error creating pipe!";
00060         } else {
00061                 unlink($pipe);
00062                 umask(0);
00063                 if(!posix_mkfifo($pipe,$mode))
00064                         echo "Error creating pipe!";
00065         }
00066 
00067         // is camogm running
00068         $camogm_running = false;
00069         exec('ps | grep "camogm"', $arr); 
00070         function low_daemon($v)
00071         {
00072                 return (substr($v, -1) != ']');
00073         }
00074         
00075         $p = (array_filter($arr, "low_daemon"));
00076         $check = implode("<br />",$p);
00077         
00078         if (strstr($check, "camogm /var/state/camogm_cmd"))
00079                 $camogm_running = true;
00080         else
00081                 $camogm_running = false;
00082 
00083         // if camogm is not running start it 
00084         if (!$camogm_running)
00085         {
00086                 header("Refresh: 1; url=".$_SERVER['PHP_SELF']);
00087                 echo "<html><head>";
00088                 echo "<script language=\"JavaScript\" src=\"camogmgui.js\"></script>";
00089                 echo "</head><body onLoad=\"reload();\">";
00090                 echo "<h1>starting camogm</h1><br>page will reload automatically in a few moments<br></body></html>";
00091                 exit;
00092         }
00093         
00094         if ($camogm_running) {
00095                 $fcmd = fopen($cmd_pipe, "w"); // "w+" prevents the script from crashing at this point in some cases?
00096         }
00097                 
00098         // any settings to be set?
00099         if (isset($_POST['settings_format'])){
00100                 switch($_POST['container']){
00101                         case'ogm':
00102                                 $container = $_POST['container'];
00103                                 break;
00104                         case'jpg':
00105                                 $container = $_POST['container'];
00106                                 break;
00107                         case'mov':
00108                                 $container = $_POST['container'];
00109                                 break;
00110                         default:
00111                                 $container = "mov";
00112                                 break;
00113                 }
00114                 if ($camogm_running) {
00115                         fprintf($fcmd, "format=%s;\n", $container);
00116 
00117                         $prefix = $_POST['prefix'];
00118                         fprintf($fcmd, "prefix=%s;\n", $prefix);
00119                         setcookie("directory", $prefix); // save as cookie so we can get prefered record directory even after camera reboot
00120                 }
00121         }
00122         
00123         if (isset($_POST['advanced_settings'])) {
00124                 if ($camogm_running) {
00125         
00126                         if ($_POST['fps_reduce'] == "frameskip") // we can only either skip frames or seconds
00127                                 fprintf($fcmd, "frameskip=%s; ", $_POST['frameskip']);
00128                         else
00129                                 fprintf($fcmd, "timelapse=%s;\n", $_POST['timelapse']);
00130         
00131                         fprintf($fcmd, "timescale=%s; ", $_POST['timescale']);
00132                         
00133                         if ($_POST['exif'] == "yes")
00134                                 fprintf($fcmd, "exif=1 ; ");
00135                         else
00136                                 fprintf($fcmd, "exif=0 ; ");
00137                 }       
00138         }
00139         
00140         // set max file size to 2GB
00141         $max_size = 2*1024*1024*1024;
00142         if ($camogm_running)
00143                         fprintf($fcmd, "length=".$max_size.";\n");
00144 
00145         //set max record time to 1 year
00146         $max_record_time = 365*24*60*60;
00147         if ($camogm_running)
00148                         fprintf($fcmd, "duration=".$max_record_time.";\n");
00149         
00150         // Get XML data for init
00151         if ($camogm_running) {
00152                 fprintf($fcmd, "xstatus=%s;\n", $pipe);
00153                 fclose($fcmd);
00154                 $xml_status = file_get_contents($pipe);
00155 
00156                 require_once('xml_simple.php');
00157                 function parse_array($element) 
00158                 {
00159                     global $logdata, $logindex;
00160                     foreach ($element as $header => $value) 
00161                         {
00162                         if (is_array($value)) 
00163                                 {
00164                             parse_array($value);
00165                             $logindex++;
00166                         } else 
00167                                 {
00168                             $logdata[$logindex][$header] = $value;
00169                         }
00170                     }
00171                 }
00172         
00173                 $parser =& new xml_simple('UTF-8');
00174                 $request = $parser->parse($xml_status);
00175         
00176                 // catch errors
00177                 $error_code = 0;
00178                 if (!$request) {
00179                     $error_code = 1;
00180                     echo("XML error: ".$parser->error);
00181                 }
00182         
00183                 $logdata = array();
00184                 $logindex = 0;
00185                 parse_array($parser->tree);
00186                 
00187                 // load xml tags
00188                 $xml_format = substr($logdata[0]['format'], 1, strlen($logdata[0]['format'])-2);
00189                 $xml_state = substr($logdata[0]['state'], 1, strlen($logdata[0]['state'])-2);
00190                 $xml_directory = substr($logdata[0]['prefix'], 1, strlen($logdata[0]['prefix'])-2);
00191                 $xml_compressor_state = substr($logdata[0]['compressor_state'], 1, strlen($logdata[0]['compressor_state'])-2);
00192                 $xml_file_length = substr($logdata[0]['file_length'], 0, strlen($logdata[0]['file_length'])); // file size in bytes
00193                 $xml_file_duration = substr($logdata[0]['file_duration'], 0, strlen($logdata[0]['file_duration']));
00194                 $xml_frame_number = substr($logdata[0]['frame_number'], 0, strlen($logdata[0]['frame_number']));
00195                 $xml_res_x = substr($logdata[0]['frame_width'], 0, strlen($logdata[0]['frame_width']));
00196                 $xml_res_y = substr($logdata[0]['frame_height'], 0, strlen($logdata[0]['frame_height']));
00197                 
00198                 
00199                 //advanced settings
00200                 $xml_timescale = substr($logdata[0]['timescale'], 0, strlen($logdata[0]['timescale']));
00201                 $xml_frameskip = substr($logdata[0]['frames_skip'], 0, strlen($logdata[0]['frames_skip']));
00202                 $xml_timelapse = substr($logdata[0]['seconds_skip'], 0, strlen($logdata[0]['seconds_skip']));
00203                 $xml_exif = substr($logdata[0]['exif'], 0, strlen($logdata[0]['exif']));
00204                 $xml_split_size = substr($logdata[0]['max_length'], 0, strlen($logdata[0]['max_length']));
00205                 $xml_split_length = substr($logdata[0]['max_duration'], 0, strlen($logdata[0]['max_duration']));
00206                 
00207                 
00208                 if ($xml_directory == "") // load directory cookie if nothing has been set
00209                         if (isset($_COOKIE['directory']))
00210                                 $xml_directory = $_COOKIE['directory'];
00211                                 
00212                 if ($xml_format == "'none'") // use quicktime mov as default if no container format has been selected
00213                         fprintf($fcmd, "format=mov;");
00214         }
00215         
00216         // GUI
00217         ?>
00218         <html>
00219         <head>
00220     <title>HDD / CF Recorder</title>
00221         <link href="camogmgui2.css" rel="stylesheet" type="text/css" media="screen">
00222     <link href="SpryTabbedPanels.css" rel="stylesheet" type="text/css">
00223     <script src="SpryTabbedPanels.js" type="text/javascript"></script>
00224         <script src="camogmgui.js" type="text/javascript"></script>
00225         </head>
00226         <body onLoad="init();">
00227     <div id="sitecoloumn">
00228         <div id="header">HDD / CF Recorder</div>
00229         <div id="files">
00230             <div id="files_header">
00231                 device: <span id="mounted_devices">loading ...</span><br>
00232                 <div id="file_browser_commands">
00233                 <table cellpadding="0" cellspacing="0" border="0">
00234                 <tr>
00235                         <td width="105"><a href="#" id="refresh_file_list" onClick="list_files();"><img src="images/reload.png" border="0" style="bottom:-2px; position:relative;"> reload</a></td>
00236                   <td width="105"><a href="#" id="mount_hdd_button" onClick="mount_hdd();">mount</a></td>
00237                   <td width="105"><a href="#" id="create_webshare_button" onClick="create_webshare();">create webshare</a></td>
00238                 </tr>
00239                 </table>
00240                 </div>
00241           </div>
00242             <span id="filelist">nothing mounted.</span><br>
00243             <div id="files_footer">
00244                     remaining free space: <span id="hdd_rem">loading ...</span>            </div>    
00245       </div>
00246         <div id="record" >
00247             <a href="#" onClick="toggle_recording();"><span id="record_text"><img src="images/record.gif" style="position:relative; bottom:-5px;"> RECORD</span></a>
00248         </div>
00249         <div id="TabbedPanels1" class="TabbedPanels">
00250           <ul class="TabbedPanelsTabGroup">
00251                           <? 
00252                           if (($xml_compressor_state != "running") || (!$camogm_running))
00253                 echo  "<li class=\"TabbedPanelsTabAlert\" tabindex=\"0\">Status</li>";
00254               else
00255                 echo "<li class=\"TabbedPanelsTab\" tabindex=\"0\">Status</li>";
00256               ?>
00257               <li class="TabbedPanelsTab" tabindex="1">Format</li>
00258               <li class="TabbedPanelsTab" tabindex="2">Sound</li>
00259               <li class="TabbedPanelsTab" tabindex="3">Advanced</li>
00260           </ul>
00261           <div class="TabbedPanelsContentGroup">
00262             <div class="TabbedPanelsContent">
00263             <!-- Status -->
00264             <?
00265                         echo "Compressor: ";
00266                         if ($xml_compressor_state != "running") {
00267                                 echo "<span class=\"alert\">not running!</span>";
00268                                 echo " <a href=\"#\" OnClick=\"start_compressor(this); window.location.reload();\">start compressor</a>";       
00269                         }
00270                         else
00271                                 echo "<span class=\"green\"> running</span>";
00272                         echo "<br>";
00273                         
00274                         echo "Camogm: ";
00275                         if (!$camogm_running) {
00276                                 echo "<span class=\"alert\">NOT running!</span>";
00277                                 echo " <input name=\"camogm_start\" type=\"button\" value=\"start camogm\" >";  
00278                         }
00279                         else
00280                                 echo "<span class=\"green\"> running</span>";
00281                         ?>
00282                         <br>
00283                         <br>
00284             Recording: <span id="ajax_state"><? echo $xml_state; ?></span><br>
00285             <br>
00286             <table class="state_table" border="0px" cellpadding="0px" cellspacing="0px">
00287                 <tr><td width="120px">Filename:</td><td id="ajax_file_name">-</td></tr>
00288                 <tr><td>Image Resolution:</td><td id="ajax_res"><? echo $xml_res_x." x ".$xml_res_y; ?></td></tr>        
00289                 <tr><td>Framerate:</td><td id="ajax_fps">-</td></tr>
00290                 <tr><td>Record Time:</td><td id="ajax_file_duration">-</td></tr>
00291                 <tr><td>File Size:</td><td id="ajax_file_length">-</td></tr>
00292                 <tr><td>Data Rate:</td><td id="ajax_data_rate">-</td></tr>  
00293                 <tr><td>Data Rate:</td><td id="ajax_data_rate2">-</td></tr>           
00294             </table>
00295             </div>
00296             <div class="TabbedPanelsContent">
00297             <!-- Format -->
00298                 <form method="POST">
00299                     <b>Format:</b><br>
00300                     <?
00301                     if ($xml_format == "ogm")
00302                         echo "<input type=\"radio\" name=\"container\" value=\"ogm\" checked> Ogg Media Stream<br>";
00303                     else
00304                         echo "<input type=\"radio\" name=\"container\" value=\"ogm\"> Ogg Media Stream<br>";
00305                     if ($xml_format == "mov")
00306                                 echo "<input type=\"radio\" name=\"container\" value=\"mov\" checked> Apple Quicktime Movie<br>";
00307                     else
00308                         echo "<input type=\"radio\" name=\"container\" value=\"mov\"> Apple Quicktime Movie<br>";
00309                     if ($xml_format == "jpeg")
00310                         echo "<input type=\"radio\" name=\"container\" value=\"jpg\" checked> JPEG Sequence<br>";
00311                     else
00312                         echo "<input type=\"radio\" name=\"container\" value=\"jpg\"> JPEG Sequence<br>";
00313                     ?>
00314                     <br>
00315                     Directory: <input id="directory" type="text" onChange="DirectoryChanged();" name="prefix" value="<? echo $xml_directory; ?>"> <a id="use_dir" href="#" id="use_mounted_hdd_button" onClick="use_mount();">use /var/hdd/</a><br>
00316                     <br>
00317                     <input id="filename_prompt" name="prompt_filename" type="checkbox" value="yes" <? if ($prompt_filename == "yes") echo "checked"; ?>> Prompt for filename after recording<br>                     
00318                     <input name="settings_format" type="submit" value="OK">
00319                                 </form>
00320             </div>
00321             <div class="TabbedPanelsContent">
00322                     <!-- Sound -->
00323                 Audio Recording:<br>
00324                 <div class="small">requires optional soundcard</div>
00325                 <form method="POST">
00326                 <input type="checkbox" name="audio_check" disabled onchange="update_audio_form(document.getElementById('form1'))"> Record Audio<br>
00327                 Sample Rate: 
00328                 <select name="audio_sample_rate" disabled>
00329                     <option selected>44100</option>
00330                     <option>22050</option>
00331                     <option>11025</option>
00332                 </select><br>
00333                 Channels: 
00334                 <select  name="audio_channels" disabled>
00335                     <option selected>stereo</option>
00336                     <option>mono</option>
00337                 </select><br>
00338                 <INPUT name="settings_sound" type="submit" value="OK">
00339                 </form>
00340             </div>
00341             <div class="TabbedPanelsContent">
00342             <!-- Advanced -->
00343             <form method="POST">
00344                                 <b>Time Settings:</b><br>
00345                 <table cellpadding="3px" cellspacing="0px;">
00346                 <tr><td>Timescale:</td><td><input id="timescale" type="text" name="timescale" size="6" value="<? echo $xml_timescale; ?>"></td><td><span class="small">currently only works for Quicktime *.mov - values > 1.0 make the video play back slower than recorded (slow motion), values < 1.0 make the playback faster (time lapse video).</span></td></tr>
00347                 <tr><td><input id="fps_reduce_frameskip" name="fps_reduce" type="radio" value="frameskip" <? if ($xml_frameskip != 0) echo "checked"; ?> onChange="update_fps_reduce(this);"> Frameskip:</td><td><input id="frameskip_id" type="text" name="frameskip" size="4" value="<? echo $xml_frameskip; ?>" <? if($xml_frameskip == "0") echo "disabled"; ?>></td><td><span class="small">reduces framerate and skips every n frames.</span></td></tr>
00348                 <tr><td width="100px;"><input id="fps_reduce_timelapse" name="fps_reduce" type="radio" value="timelapse" <? if ($xml_timelapse != 0) echo "checked"; ?> onChange="update_fps_reduce(this);"> Timelapse:</td><td><input size="4" id="timelapse_id" type="text" name="timelapse" value="<? echo $xml_timelapse; ?>" <? if($xml_timelapse == "0") echo "disabled"; ?>></td><td><span class="small">reduces framerate and waits n seconds between recording single frames.</span></td></tr>
00349                 <tr><td></td></tr>
00350                 <tr><td>Save EXIF data</td><td><input name="exif" type="checkbox" value="yes" <? if ($xml_exif == "\"yes\"") echo "checked";?>></td></tr>
00351                 <tr><td>Split Size:</td><td><input name="exif" type="text" size="10" value="<? echo $xml_split_size; ?>" ></td><td>Bytes</td></tr>
00352                 <tr><td>Split Length:</td><td><input name="exif" type="text" size="10" value="<? echo $xml_split_length; ?>"></td><td>Seconds</td></tr>
00353                 </table>
00354                 <INPUT name="advanced_settings" type="submit" value="OK">
00355                 </div>  
00356             </form>
00357             </div>        
00358           </div>
00359         </div>
00360     </div>
00361     <br><br><br><br><br><br><br>
00362         <script type="text/javascript">
00363     <!--
00364     var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
00365     //-->
00366     </script>
00367 </body>

Generated on Fri Nov 28 00:06:24 2008 for elphel by  doxygen 1.5.1