Add H264 pseudo streaming tools

This commit is contained in:
Romain Neutron
2014-02-27 14:14:07 +01:00
parent 7f2be7d9aa
commit a3b941c3ec
28 changed files with 864 additions and 112 deletions

View File

@@ -17,6 +17,8 @@ namespace KonsoleKommander;
* @link www.phraseanet.com
*/
use Alchemy\Phrasea\Command\Plugin\ListPlugin;
use Alchemy\Phrasea\Command\Setup\H264ConfigurationDumper;
use Alchemy\Phrasea\Command\Setup\H264MappingGenerator;
use Alchemy\Phrasea\Core\Version;
use Alchemy\Phrasea\Command\BuildMissingSubdefs;
use Alchemy\Phrasea\Command\CreateCollection;
@@ -98,6 +100,8 @@ $cli->command(new AddPlugin());
$cli->command(new ListPlugin());
$cli->command(new RemovePlugin());
$cli->command(new Configuration());
$cli->command(new H264ConfigurationDumper());
$cli->command(new H264MappingGenerator());
$cli->command(new XSendFileConfigurationDumper());
$cli->command(new XSendFileMappingGenerator());

View File

@@ -137,4 +137,8 @@ xsendfile:
enabled: false
type: nginx
mapping: []
h264-pseudo-streaming:
enabled: false
type: nginx
mapping: []
plugins: []

View File

@@ -0,0 +1,56 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Command\Setup;
use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class H264ConfigurationDumper extends Command
{
public function __construct($name = null)
{
parent::__construct('h264-pseudo-streaming:dump-configuration');
$this->setDescription('Dump the virtual host configuration depending on Phraseanet configuration');
}
/**
* {@inheritdoc}
*/
protected function doExecute(InputInterface $input, OutputInterface $output)
{
$output->writeln('');
if (!$this->container['phraseanet.h264-factory']->isH264Enabled()) {
$output->writeln('H264 pseudo streaming support is <error>disabled</error>');
$ret = 1;
} else {
$output->writeln('H264 pseudo streaming support is <info>enabled</info>');
$ret = 0;
}
try {
$configuration = $this->container['phraseanet.h264-factory']->createMode(true, true)->getVirtualHostConfiguration();
$output->writeln('H264 pseudo streaming configuration seems <info>OK</info>');
$output->writeln($configuration);
} catch (RuntimeException $e) {
$output->writeln('H264 pseudo streaming configuration seems <error>invalid</error>');
$ret = 1;
}
$output->writeln('');
return $ret;
}
}

View File

@@ -0,0 +1,111 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Command\Setup;
use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Http\H264PseudoStreaming\H264Factory;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Yaml;
class H264MappingGenerator extends Command
{
public function __construct($name = null)
{
parent::__construct('h264-pseudo-streaming:generate-mapping');
$this->addOption('write', 'w', null, 'Writes the configuration')
->addOption('enabled', 'e', null, 'Set the enable toggle to `true`')
->addArgument('type', InputArgument::REQUIRED, 'The configuration type, either `nginx` or `apache`')
->setDescription('Generates Phraseanet H264 pseudo streaming mapping configuration depending on databoxes configuration');
}
/**
* {@inheritdoc}
*/
protected function doExecute(InputInterface $input, OutputInterface $output)
{
$paths = $this->extractPath($this->container['phraseanet.appbox']);
foreach ($paths as $path) {
$this->container['filesystem']->mkdir($path);
}
$type = strtolower($input->getArgument('type'));
$enabled = $input->getOption('enabled');
$factory = new H264Factory($this->container['monolog'], true, $type, $this->computeMapping($paths));
$mode = $factory->createMode(true);
$currentConf = isset($this->container['phraseanet.configuration']['h264-pseudo-streaming']) ? $this->container['phraseanet.configuration']['h264-pseudo-streaming'] : array();
$currentMapping = (isset($currentConf['mapping']) && is_array($currentConf['mapping'])) ? $currentConf['mapping'] : array();
$conf = array(
'enabled' => $enabled,
'type' => $type,
'mapping' => array_replace_recursive($mode->getMapping(), $currentMapping),
);
if ($input->getOption('write')) {
$output->write("Writing configuration ...");
$this->container['phraseanet.configuration']['h264-pseudo-streaming'] = $conf;
$output->writeln(" <info>OK</info>");
$output->writeln("");
$output->write("It is now strongly recommended to use <info>h264-pseudo-streaming:dump-configuration</info> command to upgrade your virtual-host");
} else {
$output->writeln("Configuration will <info>not</info> be written, use <info>--write</info> option to write it");
$output->writeln("");
$output->writeln(Yaml::dump(array('h264-pseudo-streaming' => $conf), 4));
}
return 0;
}
private function computeMapping($paths)
{
$paths = array_unique($paths);
$ret = array();
foreach ($paths as $path) {
$ret[$path] = $this->pathsToConf($path);
}
return $ret;
}
private function pathsToConf($path)
{
static $n = 0;
$n++;
return array('mount-point' => 'mp4-videos-'.$n, 'directory' => $path, 'passphrase' => \random::generatePassword(32));
}
private function extractPath(\appbox $appbox)
{
$paths = array();
foreach ($appbox->get_databoxes() as $databox) {
foreach ($databox->get_subdef_structure() as $group => $subdefs) {
if ('video' !== $group) {
continue;
}
foreach ($subdefs as $subdef) {
$paths[] = $subdef->get_path();
}
}
}
return array_filter(array_unique($paths));
}
}

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Core\Provider;
use Alchemy\Phrasea\Core\Event\Subscriber\XSendFileSubscriber;
use Alchemy\Phrasea\Http\H264PseudoStreaming\H264Factory;
use Alchemy\Phrasea\Http\ServeFileResponseFactory;
use Alchemy\Phrasea\Http\XSendFile\XSendFileFactory;
use Silex\Application;
@@ -28,6 +29,14 @@ class FileServeServiceProvider implements ServiceProviderInterface
return XSendFileFactory::create($app);
});
$app['phraseanet.h264-factory'] = $app->share(function ($app) {
return H264Factory::create($app);
});
$app['phraseanet.h264'] = $app->share(function ($app) {
return $app['phraseanet.h264-factory']->createMode(false);
});
$app['phraseanet.file-serve'] = $app->share(function (Application $app) {
return ServeFileResponseFactory::create($app);
});

View File

@@ -9,11 +9,11 @@
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Http\XSendFile;
namespace Alchemy\Phrasea\Http;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
abstract class AbstractXSendFileMode
abstract class AbstractServerMode
{
protected $mapping = array();

View File

@@ -0,0 +1,109 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Http\H264PseudoStreaming;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Http\AbstractServerMode;
use Guzzle\Http\Url;
class Apache extends AbstractServerMode implements H264Interface
{
/**
* @params array $mapping
*
* @throws InvalidArgumentException if mapping is invalid;
*/
public function setMapping(array $mapping)
{
$final = array();
foreach ($mapping as $key => $entry) {
if (!is_array($entry)) {
throw new InvalidArgumentException('H264 pseudo streaming mapping entry must be an array');
}
if (!isset($entry['directory'])) {
throw new InvalidArgumentException('H264 pseudo streaming mapping entry must contain at least a "directory" key');
}
if (!isset($entry['mount-point'])) {
throw new InvalidArgumentException('H264 pseudo streaming mapping entry must contain at least a "mount-point" key');
}
if (!isset($entry['passphrase'])) {
throw new InvalidArgumentException('H264 pseudo streaming mapping entry must contain at least a "passphrase" key');
}
if (false === is_dir(trim($entry['directory'])) || '' === trim($entry['mount-point']) || '' === trim($entry['passphrase'])) {
continue;
}
$final[$key] = array(
'directory' => $this->sanitizePath(realpath($entry['directory'])),
'mount-point' => $this->sanitizeMountPoint($entry['mount-point']),
'passphrase' => trim($entry['passphrase']),
);
}
$this->mapping = $final;
}
/**
* {@inheritdoc}
*/
public function getUrl($pathfile)
{
if (!is_file($pathfile)) {
return null;
}
$pathfile = realpath($pathfile);
foreach ($this->mapping as $entry) {
if (0 !== strpos($pathfile, $entry['directory'])) {
continue;
}
return $this->generateUrl($pathfile, $entry);
}
}
/**
* {@inheritdoc}
*/
public function getVirtualHostConfiguration()
{
$output = "\n";
foreach ($this->mapping as $entry) {
$output .= " Alias ".$entry['mount-point']." \"".$entry['directory']."\"\n";
$output .= "\n";
$output .= " <Location ".$entry['mount-point'].">\n";
$output .= " AuthTokenSecret \"".$entry['passphrase']."\"\n";
$output .= " AuthTokenPrefix ".$entry['mount-point']."\n";
$output .= " AuthTokenTimeout 3600\n";
$output .= " AuthTokenLimitByIp off\n";
$output .= " </Location>\n";
$output .= "\n";
}
return $output;
}
private function generateUrl($pathfile, array $entry)
{
$path = substr($pathfile, strlen($entry['directory']));
$hexTime = dechex(time() + 3600);
$token = md5($entry['passphrase'] . $path . $hexTime);
return Url::factory($entry['mount-point'] .'/'. $token . "/" . $hexTime . $path);
}
}

View File

@@ -0,0 +1,97 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Http\H264PseudoStreaming;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Psr\Log\LoggerInterface;
class H264Factory
{
private $enabled;
private $logger;
private $type;
private $mapping;
/**
* Constructor
*
* @param LoggerInterface $logger
* @param boolean $enabled
* @param string $type
* @param array $mapping
*/
public function __construct(LoggerInterface $logger, $enabled, $type, array $mapping)
{
$this->logger = $logger;
$this->enabled = (Boolean) $enabled;
$this->type = strtolower($type);
$this->mapping = $mapping;
}
/**
* Returns a new instance of H264Interface.
*
* @return H264Interface
*
* @throws InvalidArgumentException if mode type is unknown
*/
public function createMode($throwException = false, $forceMode = false)
{
if (false === $this->enabled && true !== $forceMode) {
return new NullMode();
}
switch ($this->type) {
case 'apache':
case 'apache2':
return new Apache($this->mapping);
case 'nginx':
return new Nginx($this->mapping);
default:
$this->logger->error('Invalid h264 pseudo streaming configuration.');
if ($throwException) {
throw new InvalidArgumentException(sprintf('Invalid h264 pseudo streaming configuration width type "%s"', $this->type));
}
return new NullMode();
}
}
/**
* Creates a new instance of H264 Factory given a configuration.
*
* @param Application $app
*
* @return H264Factory
*/
public static function create(Application $app)
{
$conf = $app['phraseanet.configuration']['h264-pseudo-streaming'];
$mapping = array();
if (isset($conf['mapping'])) {
$mapping = $conf['mapping'];
}
return new self($app['monolog'], $conf['enabled'], $conf['type'], $mapping);
}
/**
* @return Boolean
*/
public function isH264Enabled()
{
return $this->enabled;
}
}

View File

@@ -0,0 +1,25 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Http\H264PseudoStreaming;
use Alchemy\Phrasea\Http\ServerModeInterface;
use Guzzle\Http\Url;
interface H264Interface extends ServerModeInterface
{
/**
* @param $pathfile
*
* @return Url|null
*/
public function getUrl($pathfile);
}

View File

@@ -0,0 +1,114 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Http\H264PseudoStreaming;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Http\AbstractServerMode;
use Guzzle\Http\Url;
class Nginx extends AbstractServerMode implements H264Interface
{
/**
* @params array $mapping
*
* @throws InvalidArgumentException if mapping is invalid;
*/
public function setMapping(array $mapping)
{
$final = array();
foreach ($mapping as $key => $entry) {
if (!is_array($entry)) {
throw new InvalidArgumentException('H264 pseudo streaming mapping entry must be an array');
}
if (!isset($entry['directory'])) {
throw new InvalidArgumentException('H264 pseudo streaming mapping entry must contain at least a "directory" key');
}
if (!isset($entry['mount-point'])) {
throw new InvalidArgumentException('H264 pseudo streaming mapping entry must contain at least a "mount-point" key');
}
if (!isset($entry['passphrase'])) {
throw new InvalidArgumentException('H264 pseudo streaming mapping entry must contain at least a "passphrase" key');
}
if (false === is_dir(trim($entry['directory'])) || '' === trim($entry['mount-point']) || '' === trim($entry['passphrase'])) {
continue;
}
$final[$key] = array(
'directory' => $this->sanitizePath(realpath($entry['directory'])),
'mount-point' => $this->sanitizeMountPoint($entry['mount-point']),
'passphrase' => trim($entry['passphrase']),
);
}
$this->mapping = $final;
}
/**
* {@inheritdoc}
*/
public function getUrl($pathfile)
{
if (!is_file($pathfile)) {
return null;
}
$pathfile = realpath($pathfile);
foreach ($this->mapping as $entry) {
if (0 !== strpos($pathfile, $entry['directory'])) {
continue;
}
return $this->generateUrl($pathfile, $entry);
}
}
/**
* {@inheritdoc}
*/
public function getVirtualHostConfiguration()
{
$output = "\n";
foreach ($this->mapping as $entry) {
$output .= " location " . $entry['mount-point']. " {\n";
$output .= " mp4;\n";
$output .= " secure_link \$arg_hash,\$arg_expires;\n";
$output .= " secure_link_md5 \"\$secure_link_expires\$uri ".$entry['passphrase']."\";\n";
$output .= " \n";
$output .= " if (\$secure_link = \"\") {\n";
$output .= " return 403;\n";
$output .= " }\n";
$output .= " if (\$secure_link = \"0\") {\n";
$output .= " return 410;\n";
$output .= " }\n";
$output .= " \n";
$output .= " alias ".$entry['directory'].";\n";
$output .= " }\n";
}
return $output;
}
private function generateUrl($pathfile, array $entry)
{
$path = $entry['mount-point'].substr($pathfile, strlen($entry['directory']));
$expire = time() + 3600; // At which point in time the file should expire. time() + x; would be the usual usage.
$hash = str_replace(array('+', '/', '='), array('-', '_', ''), base64_encode(md5($expire.$path.' '.$entry['passphrase'], true)));
return Url::factory($path.'?hash='.$hash.'&expires='.$expire);
}
}

View File

@@ -0,0 +1,30 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Http\H264PseudoStreaming;
class NullMode implements H264Interface
{
/**
* {@inheritdoc}
*/
public function getUrl($pathfile)
{
}
/**
* {@inheritdoc}
*/
public function getVirtualHostConfiguration()
{
return "\n";
}
}

View File

@@ -11,7 +11,6 @@
namespace Alchemy\Phrasea\Http;
use Alchemy\Phrasea\Http\DeliverDataInterface;
use Alchemy\Phrasea\Application;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\BinaryFileResponse;

View File

@@ -0,0 +1,22 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Http;
interface ServerModeInterface
{
/**
* Prints virtualhost configuration for current XSendFile mode.
*
* @return string
*/
public function getVirtualHostConfiguration();
}

View File

@@ -12,9 +12,10 @@
namespace Alchemy\Phrasea\Http\XSendFile;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Http\AbstractServerMode;
use Symfony\Component\HttpFoundation\Request;
class ApacheMode extends AbstractXSendFileMode implements ModeInterface
class ApacheMode extends AbstractServerMode implements ModeInterface
{
/**
* {@inheritdoc}

View File

@@ -11,9 +11,10 @@
namespace Alchemy\Phrasea\Http\XSendFile;
use Alchemy\Phrasea\Http\ServerModeInterface;
use Symfony\Component\HttpFoundation\Request;
interface ModeInterface
interface ModeInterface extends ServerModeInterface
{
/**
* Sets XSendFile headers.
@@ -21,11 +22,4 @@ interface ModeInterface
* @params Request $request
*/
public function setHeaders(Request $request);
/**
* Prints virtualhost configuration for current XSendFile mode.
*
* @return string
*/
public function getVirtualHostConfiguration();
}

View File

@@ -12,9 +12,10 @@
namespace Alchemy\Phrasea\Http\XSendFile;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Http\AbstractServerMode;
use Symfony\Component\HttpFoundation\Request;
class NginxMode extends AbstractXSendFileMode implements ModeInterface
class NginxMode extends AbstractServerMode implements ModeInterface
{
/**
* {@inheritdoc}

View File

@@ -60,9 +60,9 @@ class XSendFileFactory
}
/**
* Returns a new instance of XSendFileModeInterface.
* Returns a new instance of ModeInterface.
*
* @return null|ModeInterface
* @return ModeInterface
*
* @throws InvalidArgumentException if mode type is unknown
*/

View File

@@ -354,10 +354,8 @@ class API_V1_adapter extends API_V1_Abstract
'modes' => array(
'XsendFile' => $app['phraseanet.configuration']['xsendfile']['enabled'],
'XsendFileMapping' => $app['phraseanet.configuration']['xsendfile']['mapping'],
'h264Streaming' => $app['phraseanet.registry']->get('GV_h264_streaming'),
'authTokenDirectory' => $app['phraseanet.registry']->get('GV_mod_auth_token_directory'),
'authTokenDirectoryPath' => $app['phraseanet.registry']->get('GV_mod_auth_token_directory_path'),
'authTokenPassphrase' => $app['phraseanet.registry']->get('GV_mod_auth_token_passphrase'),
'H264PseudoStreaming' => $app['phraseanet.configuration']['h264-pseudo-streaming']['enabled'],
'H264PseudoStreamingMapping' => $app['phraseanet.configuration']['h264-pseudo-streaming']['mapping'],
)
),
'maintenance' => array(

View File

@@ -742,9 +742,8 @@ class media_subdef extends media_abstract implements cache_cacheableInterface
}
if (in_array($this->mime, array('video/mp4'))) {
$token = p4file::apache_tokenize($this->app['phraseanet.registry'], $this->get_pathfile());
if ($token) {
$this->url = $token;
if (null !== $url = $this->app['phraseanet.h264']->getUrl($this->get_pathfile())) {
$this->url = $url;
return;
}

View File

@@ -1,60 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Guzzle\Http\Url;
class p4file
{
public static function apache_tokenize(\registry $registry, $file)
{
$ret = false;
if ($registry->get('GV_h264_streaming') && is_file($file)) {
if (($pos = mb_strpos($file, $registry->get('GV_mod_auth_token_directory_path'))) === false) {
return false;
}
$server = new system_server();
if ($server->is_nginx()) {
$fileToProtect = mb_substr($file, mb_strlen($registry->get('GV_mod_auth_token_directory_path')));
$secret = $registry->get('GV_mod_auth_token_passphrase');
$protectedPath = p4string::addFirstSlash(p4string::delEndSlash($registry->get('GV_mod_auth_token_directory')));
$hexTime = strtoupper(dechex(time() + 3600));
$token = md5($protectedPath . $fileToProtect . '/' . $secret . '/' . $hexTime);
$url = $protectedPath . $fileToProtect . '/' . $token . '/' . $hexTime;
$ret = $url;
} elseif ($server->is_apache()) {
$fileToProtect = mb_substr($file, mb_strlen($registry->get('GV_mod_auth_token_directory_path')));
$secret = $registry->get('GV_mod_auth_token_passphrase'); // Same as AuthTokenSecret
$protectedPath = p4string::addEndSlash(p4string::delFirstSlash($registry->get('GV_mod_auth_token_directory'))); // Same as AuthTokenPrefix
$hexTime = dechex(time()); // Time in Hexadecimal
$token = md5($secret . $fileToProtect . $hexTime);
// We build the url
$url = '/' . $protectedPath . $token . "/" . $hexTime . $fileToProtect;
$ret = $url;
}
}
return Url::factory($ret);
}
}

View File

@@ -0,0 +1,63 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Application;
class patch_384alpha1a implements patchInterface
{
/** @var string */
private $release = '3.8.4-alpha.1';
/** @var array */
private $concern = array(base::APPLICATION_BOX);
/**
* {@inheritdoc}
*/
public function get_release()
{
return $this->release;
}
/**
* {@inheritdoc}
*/
public function require_all_upgrades()
{
return false;
}
/**
* {@inheritdoc}
*/
public function concern()
{
return $this->concern;
}
/**
* {@inheritdoc}
*/
public function apply(base $appbox, Application $app)
{
$config = $app['phraseanet.configuration']->getConfig();
$config['h264-pseudo-streaming'] = array(
'enabled' => false,
'type' => null,
'mapping' => array(),
);
$app['phraseanet.configuration']->setConfig($config);
return true;
}
}

View File

@@ -229,34 +229,6 @@ return call_user_func_array(function(Application $app) {
), array(
'section' => _('Executables settings'),
'vars' => array(
array(
'type' => \registry::TYPE_BOOLEAN,
'name' => 'GV_h264_streaming',
'comment' => _('Enable H264 stream mode'),
'help' => _('Use with mod_token. Attention requires the apache modules and mod_h264_streaming mod_auth_token'),
'default' => false
),
array(
'type' => \registry::TYPE_STRING,
'name' => 'GV_mod_auth_token_directory',
'end_slash' => true,
'comment' => _('Auth_token mount point'),
'default' => false
),
array(
'type' => \registry::TYPE_STRING,
'name' => 'GV_mod_auth_token_directory_path',
'end_slash' => false,
'comment' => _('Auth_token directory path'),
'default' => false
),
array(
'type' => \registry::TYPE_STRING,
'name' => 'GV_mod_auth_token_passphrase',
'comment' => _('Auth_token passphrase'),
'help' => _('Defined in Apache configuration'),
'default' => false
),
array(
'type' => \registry::TYPE_STRING,
'name' => 'GV_PHP_INI',

View File

@@ -140,4 +140,8 @@ xsendfile:
enabled: false
type: nginx
mapping: []
h264-pseudo-streaming:
enabled: false
type: nginx
mapping: []
plugins: []

View File

@@ -66,7 +66,13 @@
{src:"/include/jslibs/flowplayer/flowplayer-3.2.18.swf", wmode: "transparent"},
{clip:{url:"{{url|url_encode}}",autoPlay: true,autoBuffering:true,provider: "h264streaming",scaling:"fit"},
onError:function(code,message){getNewVideoToken("{{thumbnail.get_sbas_id() ~'_'~thumbnail.get_record_id()}}", this);},
plugins: {h264streaming: {url: "/include/jslibs/flowplayer/pseudostreaming/flowplayer.pseudostreaming-3.2.13.swf"}}
plugins: {
{% if app['phraseanet.h264-factory'].isH264Enabled() %}
h264streaming: {
url: "/include/jslibs/flowplayer/pseudostreaming/flowplayer.pseudostreaming-3.2.13.swf"
}
{% endif %}
}
});
</script>
{% elseif record_type == 'FLEXPAPER' %}
@@ -172,7 +178,15 @@
flowplayer("preview{{random}}",
{src:"/include/jslibs/flowplayer/flowplayer-3.2.18.swf", wmode: "transparent"},
{clip:{url:"{{url}}",autoPlay: true,autoBuffering:true,provider: "h264streaming",scaling:"fit"},
onError:function(code,message){getNewVideoToken({{thumbnail.get_sbas_id() ~'_'~thumbnail.get_record_id()}}, this);}, plugins: {h264streaming: {url: "/include/jslibs/flowplayer/pseudostreaming/flowplayer.pseudostreaming-3.2.13.swf"}}});
onError:function(code,message){getNewVideoToken({{thumbnail.get_sbas_id() ~'_'~thumbnail.get_record_id()}}, this);},
plugins: {
{% if app['phraseanet.h264-factory'].isH264Enabled() %}
h264streaming: {
url: "/include/jslibs/flowplayer/pseudostreaming/flowplayer.pseudostreaming-3.2.13.swf"
}
{% endif %}
}
});
</script>
{% elseif record_type == 'FLEXPAPER' %}
{% set random = thumbnail.get_random() %}

View File

@@ -23,6 +23,16 @@ class FileServeServiceProviderTest extends ServiceProviderTestCase
'phraseanet.xsendfile-factory',
'Alchemy\Phrasea\Http\XSendFile\XSendFileFactory'
),
array(
'Alchemy\Phrasea\Core\Provider\FileServeServiceProvider',
'phraseanet.h264-factory',
'Alchemy\Phrasea\Http\H264PseudoStreaming\H264Factory'
),
array(
'Alchemy\Phrasea\Core\Provider\FileServeServiceProvider',
'phraseanet.h264',
'Alchemy\Phrasea\Http\H264PseudoStreaming\H264Interface'
),
);
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Alchemy\Tests\Phrasea\Http\H264PseudoStream;
use Alchemy\Phrasea\Http\H264PseudoStreaming\Apache;
class ApacheTest extends \PhraseanetPHPUnitAbstract
{
/**
* @dataProvider provideMappingsAndFiles
*/
public function testGetUrl(array $mapping, $expectedRegExp, $pathfile)
{
$mode = new Apache($mapping);
if (null === $expectedRegExp) {
$this->assertNull($mode->getUrl($pathfile));
} else {
$this->assertRegExp($expectedRegExp, (string) $mode->getUrl($pathfile));
}
}
public function provideMappingsAndFiles()
{
$dir = sys_get_temp_dir().'/to/subdef';
$file = $dir . '/to/file';
if (!is_dir(dirname($file))) {
mkdir(dirname($file), 0777, true);
}
if (!is_file($file)) {
touch($file);
}
$mapping = array(array(
'directory' => $dir,
'mount-point' => 'mp4-videos',
'passphrase' => '123456',
));
return array(
array(array(), null, '/path/to/file'),
array($mapping, null, '/path/to/file'),
array($mapping, '/^\/mp4-videos\/[a-zA-Z0-9]+\/[0-9a-f]+\/to\/file$/', $file),
);
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace Alchemy\Tests\Phrasea\Http\H264PseudoStreaming;
use Alchemy\Phrasea\Http\H264PseudoStreaming\H264Factory;
class H264FactoryTest extends \PhraseanetPHPUnitAbstract
{
public function testFactoryCreation()
{
$factory = H264Factory::create(self::$DI['app']);
$this->assertInstanceOf('Alchemy\Phrasea\Http\H264PseudoStreaming\H264Factory', $factory);
}
public function testFactoryWithH264Enable()
{
$logger = $this->getMock('Psr\Log\LoggerInterface');
$factory = new H264Factory($logger, true, 'nginx', $this->getNginxMapping());
$this->assertInstanceOf('Alchemy\Phrasea\Http\H264PseudoStreaming\H264Interface', $factory->createMode());
$this->assertTrue($factory->isH264Enabled());
}
public function testFactoryWithH264Disabled()
{
$logger = $this->getMock('Psr\Log\LoggerInterface');
$factory = new H264Factory($logger, false, 'nginx',$this->getNginxMapping());
$this->assertInstanceOf('Alchemy\Phrasea\Http\H264PseudoStreaming\NullMode', $factory->createMode());
$this->assertFalse($factory->isH264Enabled());
}
/**
* @expectedException \Alchemy\Phrasea\Exception\InvalidArgumentException
*/
public function testFactoryWithWrongTypeThrowsAnExceptionIfRequired()
{
$logger = $this->getMock('Psr\Log\LoggerInterface');
$factory = new H264Factory($logger, true, 'wrong-type', $this->getNginxMapping());
$factory->createMode(true);
}
public function testFactoryWithWrongTypeDoesNotThrowsAnException()
{
$logger = $this->getMock('Psr\Log\LoggerInterface');
$logger->expects($this->once())
->method('error')
->with($this->isType('string'));
$factory = new H264Factory($logger, true, 'wrong-type', $this->getNginxMapping());
$this->assertInstanceOf('Alchemy\Phrasea\Http\H264PseudoStreaming\NullMode', $factory->createMode(false));
}
/**
* @dataProvider provideTypes
*/
public function testFactoryType($type, $mapping, $classmode)
{
$logger = $this->getMock('Psr\Log\LoggerInterface');
$factory = new H264Factory($logger, true, $type, $mapping);
$this->assertInstanceOf($classmode, $factory->createMode());
}
public function provideTypes()
{
return array(
array('nginx', $this->getNginxMapping(), 'Alchemy\Phrasea\Http\H264PseudoStreaming\Nginx'),
array('apache', $this->getNginxMapping(), 'Alchemy\Phrasea\Http\H264PseudoStreaming\Apache'),
array('apache2', $this->getNginxMapping(), 'Alchemy\Phrasea\Http\H264PseudoStreaming\Apache'),
);
}
private function getNginxMapping()
{
return array(array(
'directory' => __DIR__ . '/../../../../files/',
'mount-point' => '/protected/',
'passphrase' => 'dfdskqhfsfilddsmfmqsdmlfomqs',
));
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Alchemy\Tests\Phrasea\Http\H264PseudoStream;
use Alchemy\Phrasea\Http\H264PseudoStreaming\Nginx;
class NginxTest extends \PhraseanetPHPUnitAbstract
{
/**
* @dataProvider provideMappingsAndFiles
*/
public function testGetUrl(array $mapping, $expectedRegExp, $pathfile)
{
$mode = new Nginx($mapping);
if (null === $expectedRegExp) {
$this->assertNull($mode->getUrl($pathfile));
} else {
$this->assertRegExp($expectedRegExp, (string) $mode->getUrl($pathfile));
}
}
public function provideMappingsAndFiles()
{
$dir = sys_get_temp_dir().'/to/subdef';
$file = $dir . '/to/file';
if (!is_dir(dirname($file))) {
mkdir(dirname($file), 0777, true);
}
if (!is_file($file)) {
touch($file);
}
$mapping = array(array(
'directory' => $dir,
'mount-point' => 'mp4-videos',
'passphrase' => '123456',
));
return array(
array(array(), null, '/path/to/file'),
array($mapping, null, '/path/to/file'),
array($mapping, '/^\/mp4-videos\/to\/file\?hash=[a-zA-Z0-9-_+]+&expires=[0-9]+/', $file),
);
}
}