|
| 1 | +/*++ |
| 2 | +
|
| 3 | +Copyright (C) 2020 Autodesk Inc. |
| 4 | +
|
| 5 | +All rights reserved. |
| 6 | +
|
| 7 | +Redistribution and use in source and binary forms, with or without |
| 8 | +modification, are permitted provided that the following conditions are met: |
| 9 | + * Redistributions of source code must retain the above copyright |
| 10 | + notice, this list of conditions and the following disclaimer. |
| 11 | + * Redistributions in binary form must reproduce the above copyright |
| 12 | + notice, this list of conditions and the following disclaimer in the |
| 13 | + documentation and/or other materials provided with the distribution. |
| 14 | + * Neither the name of the Autodesk Inc. nor the |
| 15 | + names of its contributors may be used to endorse or promote products |
| 16 | + derived from this software without specific prior written permission. |
| 17 | +
|
| 18 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 19 | +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 | +DISCLAIMED. IN NO EVENT SHALL AUTODESK INC. BE LIABLE FOR ANY |
| 22 | +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 23 | +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 24 | +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 25 | +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 27 | +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | +
|
| 29 | +*/ |
| 30 | + |
| 31 | +#define __AMCIMPL_UI_MODULE |
| 32 | +#define __AMCIMPL_API_CONSTANTS |
| 33 | + |
| 34 | +#include "amc_ui_module_contentitem_videostream.hpp" |
| 35 | +#include "libmc_interfaceexception.hpp" |
| 36 | +#include "amc_api_constants.hpp" |
| 37 | +#include "Common/common_utils.hpp" |
| 38 | +#include "amc_parameterhandler.hpp" |
| 39 | +#include "libmc_exceptiontypes.hpp" |
| 40 | +#include "amc_ui_module.hpp" |
| 41 | + |
| 42 | +using namespace AMC; |
| 43 | + |
| 44 | +PUIModule_ContentVideoStream CUIModule_ContentVideoStream::makeFromXML(const pugi::xml_node& xmlNode, const std::string& sItemName, const std::string& sModulePath, PUIModuleEnvironment pUIModuleEnvironment) |
| 45 | +{ |
| 46 | + LibMCAssertNotNull(pUIModuleEnvironment); |
| 47 | + |
| 48 | + CUIExpression streamResourceExpression(xmlNode, "streamresource", true); |
| 49 | + CUIExpression aspectRatioExpression(xmlNode, "aspectratio", false); |
| 50 | + CUIExpression maxWidthExpression(xmlNode, "maxwidth", false); |
| 51 | + CUIExpression maxHeightExpression(xmlNode, "maxheight", false); |
| 52 | + |
| 53 | + std::string sUUID = AMCCommon::CUtils::createUUID(); |
| 54 | + |
| 55 | + auto pStateMachineData = pUIModuleEnvironment->stateMachineData(); |
| 56 | + |
| 57 | + auto pItem = std::make_shared <CUIModule_ContentVideoStream>(sUUID, sItemName, sModulePath, streamResourceExpression, aspectRatioExpression, maxWidthExpression, maxHeightExpression, pStateMachineData); |
| 58 | + return pItem; |
| 59 | +} |
| 60 | + |
| 61 | + |
| 62 | +CUIModule_ContentVideoStream::CUIModule_ContentVideoStream(const std::string& sUUID, const std::string& sItemName, const std::string& sModulePath, CUIExpression streamResource, CUIExpression dAspectRatio, CUIExpression maxWidth, CUIExpression maxHeight, PStateMachineData pStateMachineData) |
| 63 | + : CUIModule_ContentItem(sUUID, sItemName, sModulePath), |
| 64 | + m_StreamResource(streamResource), |
| 65 | + m_AspectRatio(dAspectRatio), |
| 66 | + m_MaxWidth(maxWidth), |
| 67 | + m_MaxHeight(maxHeight), |
| 68 | + m_pStateMachineData(pStateMachineData) |
| 69 | +{ |
| 70 | + LibMCAssertNotNull(pStateMachineData) |
| 71 | +} |
| 72 | + |
| 73 | +CUIModule_ContentVideoStream::~CUIModule_ContentVideoStream() |
| 74 | +{ |
| 75 | + |
| 76 | +} |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | +void CUIModule_ContentVideoStream::addLegacyContentToJSON(CJSONWriter& writer, CJSONWriterObject& object, CParameterHandler* pClientVariableHandler, uint32_t nStateID) |
| 81 | +{ |
| 82 | + object.addString(AMC_API_KEY_UI_ITEMTYPE, "videostream"); |
| 83 | + object.addString(AMC_API_KEY_UI_ITEMUUID, m_sUUID); |
| 84 | + |
| 85 | + auto pClientVariableGroup = pClientVariableHandler->findGroup(getItemPath(), true); |
| 86 | + |
| 87 | + // The stream resource is typically a UUID that the state machine sets dynamically |
| 88 | + // via SetUIProperty, pointing to an active video stream UUID. |
| 89 | + if (m_StreamResource.needsSync()) |
| 90 | + pClientVariableGroup->setParameterValueByName(AMC_API_KEY_UI_ITEMSTREAMRESOURCE, m_StreamResource.evaluateStringValue(m_pStateMachineData)); |
| 91 | + if (m_AspectRatio.needsSync()) |
| 92 | + pClientVariableGroup->setParameterValueByName(AMC_API_KEY_UI_ITEMASPECTRATIO, m_AspectRatio.evaluateStringValue(m_pStateMachineData)); |
| 93 | + if (m_MaxWidth.needsSync()) |
| 94 | + pClientVariableGroup->setParameterValueByName(AMC_API_KEY_UI_ITEMMAXWIDTH, m_MaxWidth.evaluateStringValue(m_pStateMachineData)); |
| 95 | + if (m_MaxHeight.needsSync()) |
| 96 | + pClientVariableGroup->setParameterValueByName(AMC_API_KEY_UI_ITEMMAXHEIGHT, m_MaxHeight.evaluateStringValue(m_pStateMachineData)); |
| 97 | + |
| 98 | + std::string sStreamUUID = pClientVariableGroup->getParameterValueByName(AMC_API_KEY_UI_ITEMSTREAMRESOURCE); |
| 99 | + |
| 100 | + // Normalize UUID if it looks like one, otherwise pass it through |
| 101 | + if (!sStreamUUID.empty() && AMCCommon::CUtils::stringIsUUIDString(sStreamUUID)) { |
| 102 | + sStreamUUID = AMCCommon::CUtils::normalizeUUIDString(sStreamUUID); |
| 103 | + } |
| 104 | + |
| 105 | + object.addString(AMC_API_KEY_UI_ITEMSTREAMRESOURCE, sStreamUUID); |
| 106 | + object.addString(AMC_API_KEY_UI_ITEMASPECTRATIO, pClientVariableGroup->getParameterValueByName(AMC_API_KEY_UI_ITEMASPECTRATIO)); |
| 107 | + if (!m_MaxWidth.isEmpty(m_pStateMachineData)) |
| 108 | + object.addString(AMC_API_KEY_UI_ITEMMAXWIDTH, pClientVariableGroup->getParameterValueByName(AMC_API_KEY_UI_ITEMMAXWIDTH)); |
| 109 | + if (!m_MaxHeight.isEmpty(m_pStateMachineData)) |
| 110 | + object.addString(AMC_API_KEY_UI_ITEMMAXHEIGHT, pClientVariableGroup->getParameterValueByName(AMC_API_KEY_UI_ITEMMAXHEIGHT)); |
| 111 | + |
| 112 | +} |
| 113 | + |
| 114 | + |
| 115 | +void CUIModule_ContentVideoStream::configurePostLoading() |
| 116 | +{ |
| 117 | + |
| 118 | +} |
| 119 | + |
| 120 | + |
| 121 | +void CUIModule_ContentVideoStream::populateClientVariables(CParameterHandler* pClientVariableHandler) |
| 122 | +{ |
| 123 | + LibMCAssertNotNull(pClientVariableHandler); |
| 124 | + auto pGroup = pClientVariableHandler->addGroup(getItemPath(), "videostream UI element"); |
| 125 | + pGroup->addNewStringParameter(AMC_API_KEY_UI_ITEMSTREAMRESOURCE, "Stream Resource UUID", m_StreamResource.evaluateStringValue(m_pStateMachineData)); |
| 126 | + pGroup->addNewStringParameter(AMC_API_KEY_UI_ITEMASPECTRATIO, "Aspect Ratio", m_AspectRatio.evaluateStringValue(m_pStateMachineData)); |
| 127 | + pGroup->addNewStringParameter(AMC_API_KEY_UI_ITEMMAXWIDTH, "Maximum Width", m_MaxWidth.evaluateStringValue(m_pStateMachineData)); |
| 128 | + pGroup->addNewStringParameter(AMC_API_KEY_UI_ITEMMAXHEIGHT, "Maximum Height", m_MaxHeight.evaluateStringValue(m_pStateMachineData)); |
| 129 | +} |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | +std::string CUIModule_ContentVideoStream::findElementPathByUUID(const std::string& sUUID) |
| 134 | +{ |
| 135 | + if (sUUID == m_sUUID) |
| 136 | + return getItemPath(); |
| 137 | + |
| 138 | + return ""; |
| 139 | +} |
0 commit comments