Nested playlists are allowed now with cyclic-recursion checking.

This commit is contained in:
tomas 2005-03-24 03:48:40 +00:00
parent 8f3c89c22e
commit b80950568d
2 changed files with 53 additions and 17 deletions

View file

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.55 $ Version : $Revision: 1.56 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/GreenBox.php,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/GreenBox.php,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -35,7 +35,7 @@ require_once "BasicStor.php";
* LiveSupport file storage module * LiveSupport file storage module
* *
* @author $Author: tomas $ * @author $Author: tomas $
* @version $Revision: 1.55 $ * @version $Revision: 1.56 $
* @see BasicStor * @see BasicStor
*/ */
class GreenBox extends BasicStor{ class GreenBox extends BasicStor{
@ -498,12 +498,21 @@ class GreenBox extends BasicStor{
require_once"Playlist.php"; require_once"Playlist.php";
$pl =& Playlist::recallByToken($this, $token); $pl =& Playlist::recallByToken($this, $token);
if(PEAR::isError($pl)) return $pl; if(PEAR::isError($pl)) return $pl;
$acGunid = $this->_gunidFromId($acId);
if($pl->_cyclicRecursion($acGunid)){
return PEAR::raiseError(
"GreenBox::addAudioClipToPlaylist: cyclic-recursion detected".
" ($type)"
);
}
/*
if('playlist' == ($type = $this->getFileType($acId))){ if('playlist' == ($type = $this->getFileType($acId))){
return PEAR::raiseError( return PEAR::raiseError(
"GreenBox::addAudioClipToPlaylist: object type not supported". "GreenBox::addAudioClipToPlaylist: object type not supported".
" ($type)" " ($type)"
); );
} }
*/
$res = $pl->addAudioClip($acId, $fadeIn, $fadeOut); $res = $pl->addAudioClip($acId, $fadeIn, $fadeOut);
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;
// recalculate offsets and total length: // recalculate offsets and total length:

View file

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.11 $ Version : $Revision: 1.12 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/Playlist.php,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/Playlist.php,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -72,6 +72,7 @@ class Playlist extends StoredFile{
* <li>acGunid, string - audioClip gunid</li> * <li>acGunid, string - audioClip gunid</li>
* <li>acLen string - length of clip in dcterms:extent format</li> * <li>acLen string - length of clip in dcterms:extent format</li>
* <li>acTit string - clip title</li> * <li>acTit string - clip title</li>
* <li>elType string - audioclip | playlist</li>
* </ul> * </ul>
*/ */
function getAcInfo($acId) function getAcInfo($acId)
@ -87,7 +88,9 @@ class Playlist extends StoredFile{
if(PEAR::isError($r)){ return $r; } if(PEAR::isError($r)){ return $r; }
if(isset($r[0]['value'])) $acTit = $r[0]['value']; if(isset($r[0]['value'])) $acTit = $r[0]['value'];
else $acTit = $acGunid; else $acTit = $acGunid;
return compact('acGunid', 'acLen', 'acTit'); $elType = $this->gb->getObjType($acId);
if($elType == 'webstream') $elType = 'audioclip';
return compact('acGunid', 'acLen', 'acTit', 'elType');
} }
/** /**
@ -163,6 +166,7 @@ class Playlist extends StoredFile{
* @param fadeIn string - fadein value in ss.ssssss or extent format * @param fadeIn string - fadein value in ss.ssssss or extent format
* @param fadeOut string - fadeout value in ss.ssssss or extent format * @param fadeOut string - fadeout value in ss.ssssss or extent format
* @param plElGunid string - optional playlist element gunid * @param plElGunid string - optional playlist element gunid
* @param elType string - optional 'audioClip' | 'playlist'
* @return array with fields: * @return array with fields:
* <ul> * <ul>
* <li>plElId int - record id of playlistElement</li> * <li>plElId int - record id of playlistElement</li>
@ -172,7 +176,7 @@ class Playlist extends StoredFile{
* </ul> * </ul>
*/ */
function insertPlaylistElement($parid, $offset, $acGunid, $acLen, $acTit, function insertPlaylistElement($parid, $offset, $acGunid, $acLen, $acTit,
$fadeIn=NULL, $fadeOut=NULL, $plElGunid=NULL) $fadeIn=NULL, $fadeOut=NULL, $plElGunid=NULL, $elType='audioClip')
{ {
// insert playlistElement // insert playlistElement
$r = $this->md->insertMetadataEl($parid, 'playlistElement'); $r = $this->md->insertMetadataEl($parid, 'playlistElement');
@ -186,8 +190,8 @@ class Playlist extends StoredFile{
$r = $this->md->insertMetadataEl( $r = $this->md->insertMetadataEl(
$plElId, 'relativeOffset', $offset, 'A'); $plElId, 'relativeOffset', $offset, 'A');
if(PEAR::isError($r)){ return $r; } if(PEAR::isError($r)){ return $r; }
// insert audioClip element into playlistElement // insert audioClip (or playlist) element into playlistElement
$r = $this->md->insertMetadataEl($plElId, 'audioClip'); $r = $this->md->insertMetadataEl($plElId, $elType);
if(PEAR::isError($r)){ return $r; } if(PEAR::isError($r)){ return $r; }
$acId = $r; $acId = $r;
$r = $this->md->insertMetadataEl($acId, 'id', $acGunid, 'A'); $r = $this->md->insertMetadataEl($acId, 'id', $acGunid, 'A');
@ -297,7 +301,7 @@ class Playlist extends StoredFile{
// get information about audioClip // get information about audioClip
$acInfo = $this->getAcInfo($acId); $acInfo = $this->getAcInfo($acId);
if(PEAR::isError($acInfo)){ return $acInfo; } if(PEAR::isError($acInfo)){ return $acInfo; }
extract($acInfo); // 'acGunid', 'acLen', 'acTit' extract($acInfo); // 'acGunid', 'acLen', 'acTit', 'elType'
// get information about playlist and containers // get information about playlist and containers
$plInfo = $this->getPlInfo(); $plInfo = $this->getPlInfo();
if(PEAR::isError($plInfo)){ return $plInfo; } if(PEAR::isError($plInfo)){ return $plInfo; }
@ -306,7 +310,8 @@ class Playlist extends StoredFile{
// insert new playlist element // insert new playlist element
$offset = $plLen; $offset = $plLen;
$plElInfo = $this->insertPlaylistElement($parid, $offset, $plElInfo = $this->insertPlaylistElement($parid, $offset,
$acGunid, $acLen, $acTit, $fadeIn, $fadeOut, $plElGunid); $acGunid, $acLen, $acTit, $fadeIn, $fadeOut, $plElGunid,
$elType);
if(PEAR::isError($plElInfo)){ return $plElInfo; } if(PEAR::isError($plElInfo)){ return $plElInfo; }
extract($plElInfo); // 'plElId', 'plElGunid', 'fadeInId', 'fadeOutId' extract($plElInfo); // 'plElId', 'plElGunid', 'fadeInId', 'fadeOutId'
@ -510,6 +515,8 @@ class Playlist extends StoredFile{
$offset = $offArr[0]['value']; $offset = $offArr[0]['value'];
// get audioClip: // get audioClip:
$acArr = $this->md->getMetadataEl('audioClip', $elId); $acArr = $this->md->getMetadataEl('audioClip', $elId);
if(is_array($acArr) && is_null($acArr[0]))
$acArr = $this->md->getMetadataEl('playlist', $elId);
if(PEAR::isError($acArr)){ return $acArr; } if(PEAR::isError($acArr)){ return $acArr; }
$storedAcMid = $acArr[0]['mid']; $storedAcMid = $acArr[0]['mid'];
// get playlength: // get playlength:
@ -585,10 +592,8 @@ class Playlist extends StoredFile{
function displayPlaylistClipAtOffset($offset, $distance=0) function displayPlaylistClipAtOffset($offset, $distance=0)
{ {
$offsetS = $this->_plTimeToSecs($offset); $offsetS = $this->_plTimeToSecs($offset);
# echo "\nOFFSET: $offset, SECS=$offsetS, DISTANCE=$distance\n";
$plGunid = $this->gunid; $plGunid = $this->gunid;
$arr = $this->md->genPhpArray(); $arr = $this->md->genPhpArray();
# var_dump($arr); exit;
if(PEAR::isError($arr)){ return $arr; } if(PEAR::isError($arr)){ return $arr; }
$plArr = array('els'=>array()); $plArr = array('els'=>array());
foreach($arr[children] as $i=>$plEl){ foreach($arr[children] as $i=>$plEl){
@ -601,7 +606,7 @@ class Playlist extends StoredFile{
); );
$plInfo['elOffset'] = $pom = $plEl['attrs']['relativeoffset']; $plInfo['elOffset'] = $pom = $plEl['attrs']['relativeoffset'];
$plInfo['elOffsetS'] = $this->_plTimeToSecs($pom); $plInfo['elOffsetS'] = $this->_plTimeToSecs($pom);
foreach($plEl[children] as $j=>$acFi){ foreach($plEl['children'] as $j=>$acFi){
switch($acFi['elementname']){ switch($acFi['elementname']){
case"audioclip": case"audioclip":
$plInfo['acLen'] = $pom = $acFi['attrs']['playlength']; $plInfo['acLen'] = $pom = $acFi['attrs']['playlength'];
@ -634,15 +639,12 @@ class Playlist extends StoredFile{
$plArr['length'] = $pom = $arr['attrs']['playlength']; $plArr['length'] = $pom = $arr['attrs']['playlength'];
$plArr['lengthS'] = $this->_plTimeToSecs($pom); $plArr['lengthS'] = $this->_plTimeToSecs($pom);
} }
# var_dump($plArr); exit;
$res = array('gunid'=>NULL, 'elapsed'=>NULL, $res = array('gunid'=>NULL, 'elapsed'=>NULL,
'remaining'=>NULL, 'duration'=>NULL); 'remaining'=>NULL, 'duration'=>NULL);
$dd = -1; $dd = -1;
foreach($plArr['els'] as $el){ foreach($plArr['els'] as $el){
# var_dump($el);
extract($el); extract($el);
# echo " ### $offsetS, $elOffsetS, ".($elOffsetS+$acLenS)."\n";
if($offsetS > $elOffsetS && if($offsetS > $elOffsetS &&
$offsetS < ($elOffsetS + $acLenS) && $offsetS < ($elOffsetS + $acLenS) &&
$dd<0 $dd<0
@ -651,7 +653,6 @@ class Playlist extends StoredFile{
$playedS = $offsetS - $elOffsetS; $playedS = $offsetS - $elOffsetS;
if($playedS < 0) $playedS = 0; if($playedS < 0) $playedS = 0;
$remainS = $acLenS - $playedS; $remainS = $acLenS - $playedS;
# echo " X $acGunid, $playedS, $remainS, $acLenS\n";
$res = array('gunid'=>$acGunid, $res = array('gunid'=>$acGunid,
'elapsed' => $this->_secsToPlTime($playedS), 'elapsed' => $this->_secsToPlTime($playedS),
'remaining' => $this->_secsToPlTime($remainS), 'remaining' => $this->_secsToPlTime($remainS),
@ -659,7 +660,6 @@ class Playlist extends StoredFile{
); );
return $res; return $res;
} }
# echo " * elOffset: $elOffset, secs=$elOffsetS, playLength:$acLen\n";
if($dd >= 0) $dd++; if($dd >= 0) $dd++;
} }
return $res; return $res;
@ -701,6 +701,33 @@ class Playlist extends StoredFile{
return $res; return $res;
} }
/**
* Cyclic-recursion checking
*
* @param insGunid string, gunid of playlist beeing inserted
* @return
*/
function _cyclicRecursion($insGunid)
{
if($this->gunid == $insGunid) return TRUE;
$pl =& Playlist::recallByGunid($this->gb, $insGunid);
if(PEAR::isError($pl)){ return $pl; }
$arr = $pl->md->genPhpArray();
if(PEAR::isError($arr)){ return $arr; }
$els =& $arr['children'];
if(!is_array($els)) return FALSE;
foreach($els as $i=>$plEl){
if($plEl['elementname'] != "playlistelement") continue;
foreach($plEl['children'] as $j=>$elCh){
if($elCh['elementname'] != "playlist") continue;
$nextGunid = $elCh['attrs']['id'];
$res = $this->_cyclicRecursion($nextGunid);
if($res) return TRUE;
}
}
return FALSE;
}
/** /**
* *
* / * /