Jelajahi Sumber

#3637 Stream: recording for Nginx

Alex Trofimov 4 tahun lalu
induk
melakukan
41e4ffc353

+ 1 - 1
modules/boonex/stream/classes/BxStrmEngineOvenMediaEngine.php

@@ -37,7 +37,7 @@ class BxStrmEngineOvenMediaEngine extends BxDol
     public function startRecording($iRecordingId, $sStreamKey)
     {
         $sApp = getParam('bx_stream_app');
-        $sSourceName = getParam('bx_stream_recordings_source');
+        $sSourceName = getParam('bx_stream_server_ome_recordings_source');
         if (!$sApp)
             return false;
 

+ 30 - 3
modules/boonex/stream/classes/BxStrmModule.php

@@ -40,6 +40,33 @@ class BxStrmModule extends BxBaseModTextModule
         return $this->_oEngine;
     }
 
+    public function actionNginxOnRecordDone()
+    {
+        $sKey = bx_get('name');
+        $sSecret = bx_get('s');
+        $sPath = bx_get('path');
+        $sBasePath = getParam('bx_stream_server_nginx_recording_base_path');
+        if (empty($sBasePath) || empty($sPath) || empty($sKey) || empty($sSecret) || 'NGINX' != getParam('bx_stream_engine') || !($aContentInfo = $this->_oDb->getEntriesBy(['type' => 'conditions', 'conditions' => ['key' => $sKey]]))) {
+            header('HTTP/1.0 404 Not Found');
+        }
+        elseif ($sSecret != base_convert(substr(md5(BX_DOL_SECRET . $sKey), -4), 16, 36)) {
+            header('HTTP/1.0 403 Forbidden');
+        }
+        elseif (CHECK_ACTION_RESULT_ALLOWED !== $this->checkAllowedRecord(true)) {
+            header('HTTP/1.0 403 Forbidden');
+        }
+        else {
+            $sBaseUrl = rtrim(getParam('bx_stream_recordings_url'), '/');
+            $sUrl = str_replace($sBasePath, $sBaseUrl, $sPath);
+            if ($oStorage = BxDolStorage::getObjectInstance('bx_stream_recordings')) {
+                $iFileId = $oStorage->storeFileFromUrl($sUrl, true, 0, $aContentInfo['id']);
+                if (!$iFileId) {
+                    bx_log('bx_stream', "Store recording from URL(" . $sUrl . ") failed for content id({$aContentInfo['id']})");
+                }
+            }
+        }
+    }
+
     public function actionNginxOnPublish()
     {
         $sKey = bx_get('name');
@@ -222,7 +249,7 @@ class BxStrmModule extends BxBaseModTextModule
         if(!$this->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => 'active'), array($CNF['FIELD_ID'] => $iContentId))) 
             return;
 
-        if (CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedRecord()) {
+        if (CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedRecord() && 'OvenMediaEngine' == getParam('bx_stream_engine')) {
             $iRecordingId = $this->_oDb->getNewRecordingId($iContentId);
             $this->getStreamEngine()->startRecording($iRecordingId, $aContentInfo[$CNF['FIELD_KEY']]);
             BxDolSession::getInstance()->setValue('bx-stream-rec-' . $iContentId, $iRecordingId);
@@ -249,7 +276,7 @@ class BxStrmModule extends BxBaseModTextModule
         if (!$this->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => 'awaiting'), array($CNF['FIELD_ID'] => $iContentId)))
             return;
 
-        if (CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedRecord(true)) {
+        if (CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedRecord(true) && 'OvenMediaEngine' == getParam('bx_stream_engine')) {
             $iRecordingId = BxDolSession::getInstance()->getValue('bx-stream-rec-' . $iContentId);
             if (!$iRecordingId)
                 $iRecordingId = $this->_oDb->getRecordingId($iContentId);
@@ -263,7 +290,7 @@ class BxStrmModule extends BxBaseModTextModule
                             $this->_oDb->deleteRecording($iRecordingId);
                         }
                         else {
-                            bx_log('bx_stream', "Store recording from URL(" . getParam('bx_stream_recordings_url') . $a['filePath'] . ") failed");
+                            bx_log('bx_stream', "Store recording from URL(" . getParam('bx_stream_recordings_url') . $a['filePath'] . ") failed for content id($iContentId)");
                         }
                     }
                 }

+ 2 - 1
modules/boonex/stream/install/langs/en.xml

@@ -16,15 +16,16 @@
     <string name="_bx_stream_option_ome_policy_secret"><![CDATA[OvenMediaEngine Signed Policy Secret Key]]></string>
 
     <string name="_bx_stream_option_ome_api_port"><![CDATA[OvenMediaEngine API Port]]></string>
+    <string name="_bx_stream_option_ome_recordings_source"><![CDATA[Recording source (experimental)]]></string>
     <string name="_bx_stream_option_nginx_stats_url"><![CDATA[NGINX Stats URL]]></string>
     <string name="_bx_stream_option_nginx_auth"><![CDATA[NGINX Authentication (on_publish need to be set to http://site/m/stream/nginx_on_publish/)]]></string>
+    <string name="_bx_stream_option_nginx_recording_base_path"><![CDATA[NGINX recording folder path]]></string>
     <string name="_bx_stream_option_server_host"><![CDATA[Server Hostname]]></string>
     <string name="_bx_stream_option_app"><![CDATA[Application Name]]></string>
     <string name="_bx_stream_option_sources_pattern"><![CDATA[Sources Pattern]]></string>
     <string name="_bx_stream_option_dash_enabled"><![CDATA[Enable MPEG-DASH streaming]]></string>
     <string name="_bx_stream_option_hls_enabled"><![CDATA[Enable HLS streaming]]></string>
     <string name="_bx_stream_option_recordings_url"><![CDATA[Base URL for recordings (experimental)]]></string>
-    <string name="_bx_stream_option_recordings_source"><![CDATA[Recording source (experimental)]]></string>
     <string name="_bx_stream_option_enable_auto_approve"><![CDATA[Auto approve a stream after creation]]></string>
     <string name="_bx_stream_option_summary_chars"><![CDATA[Number of characters in auto-cropped stream summary]]></string>
     <string name="_bx_stream_option_plain_summary_chars"><![CDATA[Number of characters in plain stream description when stream hasn't thumb]]></string>

+ 5 - 4
modules/boonex/stream/install/sql/enable.sql

@@ -19,8 +19,7 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `c
 ('bx_stream_sources_pattern', '', @iCategId, '_bx_stream_option_sources_pattern', 'text', '', '', '', 24),
 ('bx_stream_dash_enabled', '', @iCategId, '_bx_stream_option_dash_enabled', 'checkbox', '', '', '', 26),
 ('bx_stream_hls_enabled', '', @iCategId, '_bx_stream_option_hls_enabled', 'checkbox', '', '', '', 28),
-('bx_stream_recordings_url', '', @iCategId, '_bx_stream_option_recordings_url', 'digit', '', '', '', 30),
-('bx_stream_recordings_source', '', @iCategId, '_bx_stream_option_recordings_source', 'digit', '', '', '', 32);
+('bx_stream_recordings_url', '', @iCategId, '_bx_stream_option_recordings_url', 'digit', '', '', '', 30);
 
 INSERT INTO `sys_options_categories` (`type_id`, `name`, `caption`, `order`)
 VALUES (@iTypeId, 'bx_stream_engine_ome', '_bx_stream_options_cat_engine_ome', 2);
@@ -31,7 +30,8 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `c
 ('bx_stream_server_ome_api_key', '', @iCategId, '_bx_stream_option_ome_api_key', 'digit', '', '', '', 10),
 ('bx_stream_server_ome_api_protocol', 'http', @iCategId, '_bx_stream_option_ome_api_protocol', 'select', '', '', 'http,https', 12),
 ('bx_stream_server_ome_api_port', '8081', @iCategId, '_bx_stream_option_ome_api_port', 'digit', '', '', '', 14),
-('bx_stream_server_ome_policy_secret', '', @iCategId, '_bx_stream_option_ome_policy_secret', 'digit', '', '', '', 20);
+('bx_stream_server_ome_policy_secret', '', @iCategId, '_bx_stream_option_ome_policy_secret', 'digit', '', '', '', 20),
+('bx_stream_server_ome_recordings_source', '', @iCategId, '_bx_stream_option_ome_recordings_source', 'digit', '', '', '', 30);
 
 INSERT INTO `sys_options_categories` (`type_id`, `name`, `caption`, `order`)
 VALUES (@iTypeId, 'bx_stream_engine_nginx', '_bx_stream_options_cat_engine_nginx', 3);
@@ -39,7 +39,8 @@ SET @iCategId = LAST_INSERT_ID();
 
 INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `check`, `check_error`, `extra`, `order`) VALUES
 ('bx_stream_server_nginx_stats_url', 'https://{host}/stat', @iCategId, '_bx_stream_option_nginx_stats_url', 'digit', '', '', '', 10),
-('bx_stream_server_nginx_auth', 'on', @iCategId, '_bx_stream_option_nginx_auth', 'checkbox', '', '', '', 12);
+('bx_stream_server_nginx_auth', 'on', @iCategId, '_bx_stream_option_nginx_auth', 'checkbox', '', '', '', 12),
+('bx_stream_server_nginx_recording_base_path', '', @iCategId, '_bx_stream_option_nginx_recording_base_path', 'checkbox', '', '', '', 20);
 
 INSERT INTO `sys_options_categories` (`type_id`, `name`, `caption`, `order`)
 VALUES (@iTypeId, 'bx_stream_general', '_bx_stream_options_cat_general', 4);