Skip to content

Commit 199f7e7

Browse files
Added new Videostream UI widget
1 parent b675ef7 commit 199f7e7

4 files changed

Lines changed: 349 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*++
2+
3+
Copyright (C) 2021 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+
32+
import * as Assert from "../common/AMCAsserts.js";
33+
import * as Common from "../common/AMCCommon.js"
34+
35+
36+
export default class AMCApplicationItem_Content_VideoStream extends Common.AMCApplicationItem {
37+
38+
constructor (moduleInstance, itemJSON)
39+
{
40+
Assert.ObjectValue (itemJSON);
41+
42+
super (moduleInstance, itemJSON.uuid, itemJSON.type);
43+
this.registerClass ("amcItem_VideoStream");
44+
45+
this.updateFromJSON (itemJSON);
46+
47+
this.setRefreshFlag ();
48+
}
49+
50+
updateFromJSON (updateJSON)
51+
{
52+
this.streamresource = Assert.UUIDValue (updateJSON.streamresource);
53+
if (updateJSON.aspectratio)
54+
this.aspectratio = Assert.NumberValue (updateJSON.aspectratio);
55+
if (updateJSON.maxwidth)
56+
this.maxwidth = Assert.NumberValue (updateJSON.maxwidth);
57+
if (updateJSON.maxheight)
58+
this.maxheight = Assert.NumberValue (updateJSON.maxheight);
59+
60+
}
61+
62+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
<template>
32+
33+
<div v-if="(moduleitem.type==='videostream')">
34+
<img
35+
v-bind:src="Application.getStreamURL(moduleitem.streamresource)"
36+
v-bind:style="imgStyle"
37+
alt="Video Stream"
38+
/>
39+
</div>
40+
41+
</template>
42+
43+
<script>
44+
45+
export default {
46+
props: ["Application", "moduleitem"],
47+
48+
computed: {
49+
imgStyle() {
50+
let style = { display: 'block' };
51+
if (this.moduleitem.maxwidth) {
52+
style['max-width'] = this.moduleitem.maxwidth + 'px';
53+
}
54+
if (this.moduleitem.maxheight) {
55+
style['max-height'] = this.moduleitem.maxheight + 'px';
56+
}
57+
if (!this.moduleitem.maxwidth && !this.moduleitem.maxheight) {
58+
style['max-width'] = '100%';
59+
}
60+
return style;
61+
}
62+
}
63+
64+
};
65+
66+
</script>
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
32+
#ifndef __AMC_UI_MODULE_CONTENTITEM_VIDEOSTREAM
33+
#define __AMC_UI_MODULE_CONTENTITEM_VIDEOSTREAM
34+
35+
#include "header_protection.hpp"
36+
37+
#ifndef __AMCIMPL_UI_MODULE
38+
#error this header is protected and should only be included in the corresponding implementation CPP files.
39+
#endif
40+
41+
#include "amc_ui_module_contentitem.hpp"
42+
#include "pugixml.hpp"
43+
#include "amc_ui_expression.hpp"
44+
#include "amc_statemachinedata.hpp"
45+
46+
47+
namespace AMC {
48+
49+
amcDeclareDependingClass(CUIModule_ContentVideoStream, PUIModule_ContentVideoStream);
50+
amcDeclareDependingClass(CUIModuleEnvironment, PUIModuleEnvironment);
51+
52+
class CUIModule_ContentVideoStream : public CUIModule_ContentItem {
53+
protected:
54+
CUIExpression m_StreamResource;
55+
CUIExpression m_AspectRatio;
56+
CUIExpression m_MaxWidth;
57+
CUIExpression m_MaxHeight;
58+
59+
PStateMachineData m_pStateMachineData;
60+
61+
public:
62+
63+
static PUIModule_ContentVideoStream makeFromXML(const pugi::xml_node& xmlNode, const std::string& sItemName, const std::string& sModulePath, PUIModuleEnvironment pUIModuleEnvironment);
64+
65+
CUIModule_ContentVideoStream(const std::string & sUUID, const std::string& sItemName, const std::string& sModulePath, CUIExpression streamResource, CUIExpression dAspectRatio, CUIExpression maxWidth, CUIExpression maxHeight, PStateMachineData pStateMachineData);
66+
67+
virtual ~CUIModule_ContentVideoStream();
68+
69+
void addLegacyContentToJSON(CJSONWriter& writer, CJSONWriterObject& object, CParameterHandler* pClientVariableHandler, uint32_t nStateID) override;
70+
71+
virtual void configurePostLoading() override;
72+
73+
virtual void populateClientVariables(CParameterHandler* pClientVariableHandler) override;
74+
75+
virtual std::string findElementPathByUUID(const std::string& sUUID) override;
76+
};
77+
78+
79+
}
80+
81+
82+
#endif //__AMC_UI_MODULE_CONTENTITEM_VIDEOSTREAM

0 commit comments

Comments
 (0)