Просмотр исходного кода

Merge branch 'master' of https://github.com/unaio/una

AntonLV 4 лет назад
Родитель
Сommit
a67385681e

+ 2 - 1
modules/boonex/stream/classes/BxStrmCronPublishing.php

@@ -19,11 +19,12 @@ class BxStrmCronPublishing extends BxDolCron
         parent::__construct();
 
     	$this->_sModule = 'bx_stream';
-    	$this->_oModule = BxDolModule::getInstance($this->_sModule);
     }
 
     function processing()
     {
+    	$this->_oModule = BxDolModule::getInstance($this->_sModule);
+
         $mixedIds = $this->_oModule->_oDb->publishEntries();
         if($mixedIds === false)
             return;

+ 36 - 0
modules/boonex/stream/classes/BxStrmCronRecordings.php

@@ -0,0 +1,36 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    Stream Stream
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxStrmCronRecordings extends BxDolCron
+{
+    protected $_sModule;
+
+    public function __construct()
+    {
+        parent::__construct();
+
+    	$this->_sModule = 'bx_stream';
+    }
+
+    function processing()
+    {
+    	$oModule = BxDolModule::getInstance($this->_sModule);
+
+        $a = $oModule->_oDb->getPendingRecordings();
+        foreach($a as $r) {
+            $aContentInfo = $oModule->_oDb->getContentInfoById($r['content_id']);
+            $oModule->getStreamEngine()->processRecordings($r['id'], $aContentInfo, $oModule, $r['tries']);
+        }
+    }
+}
+
+/** @} */
+

+ 11 - 0
modules/boonex/stream/classes/BxStrmDb.php

@@ -31,6 +31,17 @@ class BxStrmDb extends BxBaseModTextDb
         return $this->getOne("SELECT `id` FROM `bx_stream_recordings_seq` WHERE `content_id` = :content_id ORDER BY `id` DESC", ['content_id' => $iContentId]);
     }
 
+    public function getPendingRecordings ($iLimit = 2)
+    {
+        return $this->getAll("SELECT * FROM `bx_stream_recordings_seq` ORDER BY `id` ASC LIMIT " . (int)$iLimit);
+    }
+
+    public function updateRecording($iRecordingId, $aValues = [])
+    {
+        $sValues = $this->arrayToSQL($aValues);
+        return $this->getOne("UPDATE `bx_stream_recordings_seq` SET $sValues WHERE `id` = :id", ['id' => $iRecordingId]);
+    }
+
     public function deleteRecording($iRecordingId)
     {
         return $this->query("DELETE FROM `bx_stream_recordings_seq` WHERE `id` = :id", ['id' => $iRecordingId]);

+ 5 - 0
modules/boonex/stream/classes/BxStrmEngineNGINX.php

@@ -11,6 +11,11 @@
 
 class BxStrmEngineNGINX extends BxDol
 {
+    public function getName()
+    {
+        return 'NGINX';
+    }
+
     public function isSreamFromBrowser()
     {
         return false;

+ 46 - 0
modules/boonex/stream/classes/BxStrmEngineOvenMediaEngine.php

@@ -11,6 +11,11 @@
 
 class BxStrmEngineOvenMediaEngine extends BxDol
 {
+    public function getName()
+    {
+        return 'OvenMediaEngine';
+    }
+
     public function isSreamFromBrowser()
     {
         return true;
@@ -65,6 +70,47 @@ class BxStrmEngineOvenMediaEngine extends BxDol
         ]);
     }
 
+    public function getRecordings($iRecordingId)
+    {
+        $sApp = getParam('bx_stream_app');
+        if (!$sApp)
+            return false;
+
+        return $this->_apiRequest("/vhosts/default/apps/{$sApp}:records", 'post-json', [
+            "id" => "{$iRecordingId}",
+        ]);
+    }
+
+    public function processRecordings ($iRecordingId, $aContentInfo, $oModule, $iTries = 0)
+    {
+        $CNF = &$oModule->_oConfig->CNF;
+        $bDeleteRecording = false;
+        $oStorage = BxDolStorage::getObjectInstance('bx_stream_recordings');
+
+        if ($oStorage) {
+            $sFileUrl = getParam('bx_stream_recordings_url') . $aContentInfo['key'] . '_' . $iRecordingId . '.ts';
+
+            $iFileId = $oStorage->storeFileFromUrl($sFileUrl, true, $aContentInfo[$CNF['FIELD_AUTHOR']], $aContentInfo['id']);
+            if ($iFileId) {
+                $bDeleteRecording = true;
+            }
+            else {
+                bx_log('bx_stream', "Store recording from URL(" . getParam('bx_stream_recordings_url') . $a['filePath'] . ") failed for content id($iContentId): " . $oStorage->getErrorString());
+            }
+        }
+        else {
+            bx_log('bx_stream', "Store recording failed because 'bx_stream_recordings' storage doesn't exist");
+            $bDeleteRecording = true;
+        }
+
+        if ($bDeleteRecording || ($iTries + 1) > 10) {
+            $oModule->_oDb->deleteRecording($iRecordingId);
+        }
+        else {
+            $oModule->_oDb->updateRecording($iRecordingId, ['tries' => $iTries + 1]);
+        }
+    }
+
     public function getRtmpSettings($sStreamKey)
     {
         $sHost = getParam('bx_stream_server_host');

+ 1 - 12
modules/boonex/stream/classes/BxStrmModule.php

@@ -297,18 +297,7 @@ class BxStrmModule extends BxBaseModTextModule
             if ($iRecordingId) {
 
                 $aRecordings = $this->getStreamEngine()->stopRecording($iRecordingId);
-                foreach ($aRecordings as $a) {
-                    if ($a && !empty($a['filePath']) && $oStorage = BxDolStorage::getObjectInstance('bx_stream_recordings')) {
-                        $iFileId = $oStorage->storeFileFromUrl(getParam('bx_stream_recordings_url') . $a['filePath'], true, $aContentInfo[$CNF['FIELD_AUTHOR']], $iContentId);
-                        if ($iFileId) {
-                            $this->_oDb->deleteRecording($iRecordingId);
-                        }
-                        else {
-                            bx_log('bx_stream', "Store recording from URL(" . getParam('bx_stream_recordings_url') . $a['filePath'] . ") failed for content id($iContentId)");
-                        }
-                    }
-                }
-
+                $this->getStreamEngine()->processRecordings($iRecordingId, $aContentInfo, $this);
                 BxDolSession::getInstance()->unsetValue('bx-stream-rec-' . $iContentId);
 
             }

+ 2 - 1
modules/boonex/stream/install/sql/enable.sql

@@ -399,4 +399,5 @@ INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 -- CRON
 
 INSERT INTO `sys_cron_jobs` (`name`, `time`, `class`, `file`, `service_call`) VALUES
-('bx_stream_publishing', '* * * * *', 'BxStrmCronPublishing', 'modules/boonex/stream/classes/BxStrmCronPublishing.php', '');
+('bx_stream_publishing', '* * * * *', 'BxStrmCronPublishing', 'modules/boonex/stream/classes/BxStrmCronPublishing.php', ''),
+('bx_stream_recordings', '* * * * *', 'BxStrmCronRecordings', 'modules/boonex/stream/classes/BxStrmCronRecordings.php', '');

+ 1 - 0
modules/boonex/stream/install/sql/install.sql

@@ -85,6 +85,7 @@ CREATE TABLE IF NOT EXISTS `bx_stream_recordings` (
 CREATE TABLE IF NOT EXISTS `bx_stream_recordings_seq` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `content_id` int(10) unsigned NOT NULL,
+  `tries` tinyint(4) NOT NULL DEFAULT 0,
   `added` int(10) unsigned NOT NULL,
   PRIMARY KEY (`id`),
   KEY `content_id` (`content_id`)