TDME2  1.9.200
GUIVideoNode.cpp
Go to the documentation of this file.
2 
3 #include <memory>
4 #include <string>
5 
6 #include <tdme/tdme.h>
9 #include <tdme/engine/Engine.h>
19 #include <tdme/math/Math.h>
22 #include <tdme/utilities/Console.h>
25 #include <tdme/utilities/Time.h>
26 
28 
29 using std::make_unique;
30 using std::string;
31 using std::to_string;
32 using std::unique_ptr;
33 
54 
55 GUIVideoNode::GUIVideoNode(
56  GUIScreenNode* screenNode,
57  GUIParentNode* parentNode,
58  const string& id,
59  GUINode_Flow* flow,
60  const GUINode_Alignments& alignments,
61  const GUINode_RequestedConstraints& requestedConstraints,
62  const GUIColor& backgroundColor,
63  const string& backgroundImage,
64  const GUINode_Scale9Grid& backgroundImageScale9Grid,
65  const GUIColor& backgroundImageEffectColorMul,
66  const GUIColor& backgroundImageEffectColorAdd,
67  const GUINode_Border& border,
68  const GUINode_Padding& padding,
69  const GUINodeConditions& showOn,
70  const GUINodeConditions& hideOn,
71  const string& tooltip,
72  const string& source,
73  const RequestedDimensionConstraints& requestedDimensionConstraints,
74  bool mirrorX,
75  bool mirrorY,
76  const GUIColor& effectColorMul,
77  const GUIColor& effectColorAdd,
78  const GUINode_Scale9Grid& scale9Grid,
79  const GUINode_Clipping& clipping,
80  const string& mask,
81  float maskMaxValue):
83  screenNode,
84  parentNode,
85  id,
86  flow,
87  alignments,
88  requestedConstraints,
89  backgroundColor,
90  backgroundImage,
91  backgroundImageScale9Grid,
92  backgroundImageEffectColorMul,
93  backgroundImageEffectColorAdd,
94  border,
95  padding,
96  showOn,
97  hideOn,
98  tooltip,
99  requestedDimensionConstraints,
100  mirrorX,
101  mirrorY,
102  effectColorMul,
103  effectColorAdd,
104  scale9Grid,
105  clipping,
106  mask,
107  maskMaxValue
108  )
109 {
110  this->setSource(source);
111 }
112 
114 {
115  return "video";
116 }
117 
119 {
120  disposeVideo();
122 }
123 
124 const string& GUIVideoNode::getSource() {
125  return source;
126 }
127 
129  if (videoTexture != nullptr) {
130  videoTexture->dispose();
131  videoTexture = nullptr;
132  }
133  if (videoAudioBuffer != nullptr) {
134  videoAudioBuffer = nullptr;
135  }
136 }
137 
138 void GUIVideoNode::setSource(const string& source) {
139  disposeVideo();
140 
141  //
142  this->source = source;
143 
144  // video
146  FileSystem::getInstance()->getPathName(source),
147  FileSystem::getInstance()->getFileName(source)
148  );
149  videoTexture = make_unique<DynamicColorTexture>(videoDecoder.getVideoWidth(), videoDecoder.getVideoHeight());
150  videoTexture->initialize();
151 
152  // audio
153  videoAudioBuffer = unique_ptr<ByteBuffer>(ByteBuffer::allocate(32768));
154  /*
155  videoAudioStream = new PacketAudioStream("video");
156  videoAudioStream->setParameters(videoDecoder.getAudioSampleRate(), videoDecoder.getAudioChannels(), 32768);
157  // videoAudioStream->play();
158  */
159 
160  //
161  timeLast = -1LL;
162 
163  //
164  this->textureId = videoTexture->getColorTextureId();
167 }
168 
170  // time
171  auto timeNow = Time::getCurrentMillis();
172  auto timeDelta = timeLast == -1LL?0:timeNow - timeLast;
173 
174  // video
175  videoDecoder.update(static_cast<float>(timeDelta) / 1000.0f);
176  auto videoTextureData = videoTexture->getByteBuffer();
177  videoTextureData->clear();
178  if (videoDecoder.readVideoFromStream(videoTextureData) > 0) {
179  videoTexture->update();
180  }
181  videoAudioBuffer->clear();
183  // videoAudioStream->addPacket(videoAudioBuffer);
184  }
185 
186  //
187  timeLast = timeNow;
188 }
Engine main class.
Definition: Engine.h:131
GUI element node conditions.
GUI parent node base class thats supporting child nodes.
Definition: GUIParentNode.h:42
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:72
void dispose() override
Dispose node.
void onRenderTexture() override
On render texture event.
const string getNodeType() override
void dispose() override
Dispose node.
void setSource(const string &source)
Set image source.
unique_ptr< ByteBuffer > videoAudioBuffer
Definition: GUIVideoNode.h:52
void disposeVideo()
Dispose video related members.
unique_ptr< DynamicColorTexture > videoTexture
Definition: GUIVideoNode.h:51
File system singleton class.
Definition: FileSystem.h:17
Byte buffer class.
Definition: ByteBuffer.h:27
Console class.
Definition: Console.h:29
String tools class.
Definition: StringTools.h:22
Time utility class.
Definition: Time.h:20
PL_MPEG/MPEG1 video decoder.
Definition: MPEG1Decoder.h:28
int64_t readVideoFromStream(ByteBuffer *data) override
Read raw RGB video data from stream.
int64_t readAudioFromStream(ByteBuffer *data) override
Read raw PCM data from stream.
void update(float deltaTime) override
Update.
void openFile(const string &pathName, const string &fileName) override
Open a local file.
std::exception Exception
Exception base class.
Definition: Exception.h:18
GUI node border entity.
GUI node clipping entity.
GUI node padding entity.
GUI node scale 9 grid entity.