~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to api/lib/Module/Movies.php

  • Committer: V. Keith Hughitt
  • Date: 2009-03-26 19:20:57 UTC
  • Revision ID: hughitt1@kore-20090326192057-u0x8rf8sf5lmmnwh
nightly build 03-26-2009: Using alpha-channel JPEG 2000 dataset

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php 
2
 
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
 
/**
4
 
 * Helioviewer Movies Module class definition
5
 
 * 
6
 
 * PHP version 5
7
 
 * 
8
 
 * @category Configuration
9
 
 * @package  Helioviewer
10
 
 * @author   Keith Hughitt <keith.hughitt@nasa.gov>
11
 
 * @author   Jaclyn Beck <jabeck@nmu.edu>
12
 
 * @license  http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License 1.1
13
 
 * @link     http://launchpad.net/helioviewer.org
14
 
 */
15
 
require_once 'interface.Module.php';
16
 
 
17
 
/**
18
 
 * Movie generation and display.
19
 
 * 
20
 
 * @category Configuration
21
 
 * @package  Helioviewer
22
 
 * @author   Keith Hughitt <keith.hughitt@nasa.gov>
23
 
 * @author   Jaclyn Beck <jabeck@nmu.edu>
24
 
 * @license  http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License 1.1
25
 
 * @link     http://launchpad.net/helioviewer.org
26
 
 *
27
 
 */
28
 
class Module_Movies implements Module
29
 
{
30
 
    /**
31
 
     * API Request parameters
32
 
     * 
33
 
     * @var mixed
34
 
     */
35
 
    private $_params;
36
 
 
37
 
    /**
38
 
     * Movie module constructor
39
 
     * 
40
 
     * @param mixed &$params API request parameters
41
 
     */
42
 
    public function __construct(&$params)
43
 
    {
44
 
        $this->_params = $params;
45
 
        $this->execute();
46
 
    }
47
 
 
48
 
    /**
49
 
     * execute 
50
 
     *
51
 
     * @return void
52
 
     */
53
 
    public function execute()
54
 
    {
55
 
        if ($this->validate()) {
56
 
            $this->{$this->_params['action']}();
57
 
        }
58
 
    }
59
 
 
60
 
    /**
61
 
     * validate
62
 
     * 
63
 
     * @return bool Returns true if input parameters are valid
64
 
     */
65
 
    public function validate()
66
 
    {
67
 
        switch($this->_params['action'])
68
 
        {
69
 
        case "buildMovie":
70
 
            $expected = array(
71
 
                "required" => array('startDate', 'zoomLevel', 'numFrames', 'frameRate', 'timeStep', 'quality'),
72
 
                "dates"    => array('startDate'),
73
 
                "ints"     => array('zoomLevel, numFrames, frameRate, timeStep, quality')
74
 
            );
75
 
            break;
76
 
        case "playMovie":
77
 
            // Temporarily disabled. 
78
 
            // TODO: Before re-enabling, validate file input.
79
 
            // Allow only filename specification.
80
 
            return false;
81
 
        default:
82
 
            break;
83
 
        }
84
 
        
85
 
        // Check input
86
 
        if (isset($expected)) {
87
 
            Validation_InputValidator::checkInput($expected, $this->_params);
88
 
        }
89
 
        
90
 
        return true;
91
 
    }
92
 
 
93
 
    /**
94
 
     * printDoc
95
 
     * 
96
 
     * @return void
97
 
     */
98
 
    public static function printDoc()
99
 
    {
100
 
 
101
 
    }
102
 
    
103
 
    
104
 
    /**
105
 
     * buildMovie
106
 
     * 
107
 
     * All possible parameters: startDate, zoomLevel, numFrames, frameRate, 
108
 
     * timeStep, layers, imageSize ("x,y"), filename, edges, sharpen, format.
109
 
     * 
110
 
     * API example: http://localhost/helioviewer/api/index.php?action=buildMovie
111
 
     *     &startDate=1041465600&zoomLevel=13&numFrames=20&frameRate=8
112
 
     *     &timeStep=86400&layers=SOH,EIT,EIT,304,1,100x0,1034,0,1034,-230,-215
113
 
     *     /SOH,LAS,0C2,0WL,1,100x0,1174,28,1110,-1,0
114
 
     *     &imageSize=588,556&filename=example&sharpen=false&edges=false
115
 
     * 
116
 
     * Note that filename does NOT have the . extension on it. The reason for 
117
 
     * this is that in the media settings pop-up dialog, there is no way of 
118
 
     * knowing ahead of time whether the image is a .png, .tif, .flv, etc,
119
 
     * and in the case of movies, the file is both a .flv and .mov/.asf/.mp4
120
 
     * 
121
 
     * @return void
122
 
     */
123
 
    public function buildMovie () 
124
 
    {
125
 
        include_once 'lib/Movie/HelioviewerMovie.php';
126
 
 
127
 
        // Required parameters
128
 
        $startDate = $this->_params['startDate'];
129
 
        $zoomLevel = $this->_params['zoomLevel'];
130
 
        $numFrames = $this->_params['numFrames'];
131
 
        $frameRate = $this->_params['frameRate'];
132
 
        $timeStep  = $this->_params['timeStep'];
133
 
        $quality   = $this->_params['quality'];
134
 
           
135
 
        // Layerstrings are separated by "/"
136
 
        $layerStrings = explode("/", $this->_params['layers']);
137
 
 
138
 
        $imageCoords = explode(",", $this->_params['imageSize']);
139
 
        $imageSize   = array(
140
 
            "width"  => $imageCoords[0],
141
 
            "height" => $imageCoords[1]
142
 
        );
143
 
        $filename    = $this->_params['filename'];      
144
 
        $hqFormat    = $this->_params['format'];
145
 
        //$hqFormat = "mp4";
146
 
        
147
 
        // Optional parameters
148
 
        $options = array();
149
 
        $options['enhanceEdges'] = $this->_params['edges']   || false;
150
 
        $options['sharpen']      = $this->_params['sharpen'] || false;    
151
 
                
152
 
        //Check to make sure values are acceptable
153
 
        try {
154
 
            //Limit number of layers to three
155
 
            if (strlen($this->_params['layers']) == 0) {
156
 
                $msg = "Invalid layer choices! You must specify 1-3 command-separate layernames.";
157
 
                throw new Exception($msg);
158
 
            }
159
 
 
160
 
            //Limit number of frames
161
 
            if (($numFrames < 10) || ($numFrames > HV_MAX_MOVIE_FRAMES)) {
162
 
                $msg = "Invalid number of frames. Number of frames should be " .
163
 
                "at least 10 and no more than " . HV_MAX_MOVIE_FRAMES . ".";
164
 
                throw new Exception($msg);
165
 
            }
166
 
 
167
 
            $layers = $this->_formatLayerStrings($layerStrings);
168
 
 
169
 
            $movie = new Movie_HelioviewerMovie(
170
 
                $layers, $startDate, $zoomLevel, $numFrames, $frameRate, 
171
 
                $hqFormat, $options, $timeStep, $imageSize, $filename, $quality
172
 
            );
173
 
            $movie->buildMovie();
174
 
 
175
 
        } catch(Exception $e) {
176
 
            echo 'Error: ' .$e->getMessage();
177
 
            exit();
178
 
        }
179
 
 
180
 
        return 1;
181
 
    }
182
 
    
183
 
    /**
184
 
     * Gets the movie url and loads it into MC Mediaplayer 
185
 
     * 
186
 
     * @return void
187
 
     */
188
 
    public function playMovie () 
189
 
    {
190
 
        $url = $this->_params['url'];
191
 
        $width  = $this->_params['width'];
192
 
        $height = $this->_params['height'];
193
 
 
194
 
        ?>
195
 
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
196
 
            "http://www.w3.org/TR/html4/strict.dtd">
197
 
        <html>
198
 
        <head>
199
 
            <title>Helioviewer.org QuickMovie</title>
200
 
        </head>
201
 
        <body style="background-color: black; color: #FFF;">
202
 
            <!-- MC Media Player -->
203
 
            <div style="text-align: center;">
204
 
                <script type="text/javascript">
205
 
                    playerFile = "http://www.mcmediaplayer.com/public/mcmp_0.8.swf";
206
 
                    fpFileURL = "<?php print $url?>";
207
 
                    fpButtonSize = "48x48";
208
 
                    fpAction = "play";
209
 
                    cpHidePanel = "mouseout";
210
 
                    cpHideDelay = "1";
211
 
                    defaultEndAction = "repeat";
212
 
                    playerSize = "<?php print $width . 'x' . $height?>";
213
 
                </script>
214
 
                <script type="text/javascript"
215
 
                    src="http://www.mcmediaplayer.com/public/mcmp_0.8.js"></script>
216
 
                <!-- / MC Media Player -->
217
 
            </div>
218
 
            <br>
219
 
        </body>
220
 
        </html>
221
 
        <?php
222
 
    }
223
 
}
 
 
b'\\ No newline at end of file'