00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "Presentable.h"
00023 #include "Ingredients.h"
00024 #include "Root.h"
00025 #include "BaseClasses.h"
00026 #include "ParseNode.h"
00027 #include "ASN1Codes.h"
00028 #include "Engine.h"
00029 #include "Stream.h"
00030 #include "freemheg.h"
00031
00032
00033 MHStream::MHStream()
00034 {
00035 m_nStorage = ST_Stream;
00036 m_nLooping = 0;
00037 }
00038
00039 void MHStream::Initialise(MHParseNode *p, MHEngine *engine)
00040 {
00041 MHPresentable::Initialise(p, engine);
00042 MHParseNode *pMultiplex = p->GetNamedArg(C_MULTIPLEX);
00043 for (int i = 0; i < pMultiplex->GetArgCount(); i++) {
00044 MHParseNode *pItem = pMultiplex->GetArgN(i);
00045 if (pItem->GetTagNo() == C_AUDIO) {
00046 MHAudio *pAudio = new MHAudio;
00047 m_Multiplex.Append(pAudio);
00048 pAudio->Initialise(pItem, engine);
00049 }
00050 else if (pItem->GetTagNo() == C_VIDEO) {
00051 MHVideo *pVideo = new MHVideo;
00052 m_Multiplex.Append(pVideo);
00053 pVideo->Initialise(pItem, engine);
00054 }
00055 else if (pItem->GetTagNo() == C_RTGRAPHICS) {
00056 MHRTGraphics *pRtGraph = new MHRTGraphics;
00057 m_Multiplex.Append(pRtGraph);
00058 pRtGraph->Initialise(pItem, engine);
00059 }
00060
00061 }
00062 MHParseNode *pStorage = p->GetNamedArg(C_STORAGE);
00063 if (pStorage) m_nStorage = (enum Storage) pStorage->GetArgN(0)->GetEnumValue();
00064 MHParseNode *pLooping = p->GetNamedArg(C_LOOPING);
00065 if (pLooping) m_nLooping = pLooping->GetArgN(0)->GetIntValue();
00066 }
00067
00068 void MHStream::PrintMe(FILE *fd, int nTabs) const
00069 {
00070 PrintTabs(fd, nTabs); fprintf(fd, "{:Stream ");
00071 MHPresentable::PrintMe(fd, nTabs+1);
00072 PrintTabs(fd, nTabs+1); fprintf(fd, ":Multiplex (\n");
00073 for (int i = 0; i < m_Multiplex.Size(); i++) m_Multiplex.GetAt(i)->PrintMe(fd, nTabs+2);
00074 PrintTabs(fd, nTabs+1); fprintf(fd, " )\n");
00075 if (m_nStorage != ST_Stream) { PrintTabs(fd, nTabs+1); fprintf(fd, ":Storage memory\n"); }
00076 if (m_nLooping != 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":Looping %d\n", m_nLooping); }
00077 PrintTabs(fd, nTabs); fprintf(fd, "}\n");
00078 }
00079
00080 void MHStream::Preparation(MHEngine *engine)
00081 {
00082 if (m_fAvailable) return;
00083 for (int i = 0; i < m_Multiplex.Size(); i++) {
00084 MHPresentable *pItem = m_Multiplex.GetAt(i);
00085 if (pItem->InitiallyActive()) {
00086 pItem->Activation(engine);
00087 }
00088 }
00089 MHPresentable::Preparation(engine);
00090 }
00091
00092 void MHStream::Destruction(MHEngine *engine)
00093 {
00094
00095 for (int j = m_Multiplex.Size(); j > 0; j--)
00096 m_Multiplex.GetAt(j-1)->Destruction(engine);
00097 MHPresentable::Destruction(engine);
00098 }
00099
00100 void MHStream::Activation(MHEngine *engine)
00101 {
00102 if (m_fRunning) return;
00103 MHPresentable::Activation(engine);
00104
00105 for (int i = 0; i < m_Multiplex.Size(); i++)
00106 m_Multiplex.GetAt(i)->BeginPlaying(engine);
00107 m_fRunning = true;
00108 engine->EventTriggered(this, EventIsRunning);
00109 }
00110
00111 void MHStream::Deactivation(MHEngine *engine)
00112 {
00113 if (! m_fRunning) return;
00114
00115 for (int i = 0; i < m_Multiplex.Size(); i++)
00116 m_Multiplex.GetAt(i)->StopPlaying(engine);
00117 MHPresentable::Deactivation(engine);
00118 }
00119
00120
00121
00122
00123 void MHStream::ContentPreparation(MHEngine *engine)
00124 {
00125 engine->EventTriggered(this, EventContentAvailable);
00126 for (int i = 0; i < m_Multiplex.Size(); i++)
00127 m_Multiplex.GetAt(i)->SetStreamRef(m_ContentRef);
00128 }
00129
00130
00131
00132
00133
00134 MHRoot *MHStream::FindByObjectNo(int n)
00135 {
00136 if (n == m_ObjectReference.m_nObjectNo) return this;
00137 for (int i = m_Multiplex.Size(); i > 0; i--) {
00138 MHRoot *pResult = m_Multiplex.GetAt(i-1)->FindByObjectNo(n);
00139 if (pResult) return pResult;
00140 }
00141 return NULL;
00142 }
00143
00144 MHAudio::MHAudio()
00145 {
00146 m_nOriginalVol = 0;
00147 m_fStreamPlaying = false;
00148 }
00149
00150 void MHAudio::Initialise(MHParseNode *p, MHEngine *engine)
00151 {
00152 MHPresentable::Initialise(p, engine);
00153 m_nComponentTag = p->GetNamedArg(C_COMPONENT_TAG)->GetArgN(0)->GetIntValue();
00154 MHParseNode *pOrigVol = p->GetNamedArg(C_ORIGINAL_VOLUME);
00155 if (pOrigVol) m_nOriginalVol = pOrigVol->GetIntValue();
00156 }
00157
00158 void MHAudio::PrintMe(FILE *fd, int nTabs) const
00159 {
00160 PrintTabs(fd, nTabs); fprintf(fd, "{:Audio ");
00161 MHPresentable::PrintMe(fd, nTabs+1);
00162 PrintTabs(fd, nTabs+1); fprintf(fd, ":ComponentTag %d\n", m_nComponentTag);
00163 if (m_nOriginalVol != 0) { PrintTabs(fd, nTabs+1); fprintf(fd, "OriginalVolume %d ", m_nOriginalVol); }
00164 PrintTabs(fd, nTabs); fprintf(fd, "}\n");
00165 }
00166
00167
00168 void MHAudio::Activation(MHEngine *engine)
00169 {
00170 if (m_fRunning) return;
00171 MHPresentable::Activation(engine);
00172
00173 m_fRunning = true;
00174 engine->EventTriggered(this, EventIsRunning);
00175
00176 if (m_fStreamPlaying && m_streamContentRef.IsSet())
00177 {
00178 QString stream;
00179 MHOctetString &str = m_streamContentRef.m_ContentRef;
00180 if (str.Size() != 0) stream = QString::fromUtf8((const char *)str.Bytes(), str.Size());
00181 engine->GetContext()->BeginAudio(stream, m_nComponentTag);
00182 }
00183 }
00184
00185
00186 void MHAudio::Deactivation(MHEngine *engine)
00187 {
00188 if (! m_fRunning) return;
00189 m_fRunning = false;
00190
00191
00192 if (m_fStreamPlaying) engine->GetContext()->StopAudio();
00193
00194 MHPresentable::Deactivation(engine);
00195 }
00196
00197 void MHAudio::SetStreamRef(const MHContentRef &cr)
00198 {
00199 m_streamContentRef.Copy(cr);
00200 }
00201
00202 void MHAudio::BeginPlaying(MHEngine *engine)
00203 {
00204 m_fStreamPlaying = true;
00205 if (m_fRunning && m_streamContentRef.IsSet())
00206 {
00207 QString stream;
00208 MHOctetString &str = m_streamContentRef.m_ContentRef;
00209 if (str.Size() != 0) stream = QString::fromUtf8((const char *)str.Bytes(), str.Size());
00210 engine->GetContext()->BeginAudio(stream, m_nComponentTag);
00211 }
00212 }
00213
00214 void MHAudio::StopPlaying(MHEngine *engine)
00215 {
00216 m_fStreamPlaying = false;
00217 if (m_fRunning) engine->GetContext()->StopAudio();
00218 }
00219
00220
00221 MHVideo::MHVideo()
00222 {
00223 m_Termination = VI_Disappear;
00224 m_nXDecodeOffset = 0;
00225 m_nYDecodeOffset = 0;
00226 m_nDecodeWidth = 0;
00227 m_nDecodeHeight = 0;
00228
00229 m_fStreamPlaying = false;
00230 }
00231
00232 void MHVideo::Initialise(MHParseNode *p, MHEngine *engine)
00233 {
00234 MHVisible::Initialise(p, engine);
00235 m_nComponentTag = p->GetNamedArg(C_COMPONENT_TAG)->GetArgN(0)->GetIntValue();
00236 MHParseNode *pTerm = p->GetNamedArg(C_TERMINATION);
00237 if (pTerm) m_Termination = (enum Termination)pTerm->GetEnumValue();
00238 }
00239
00240 void MHVideo::PrintMe(FILE *fd, int nTabs) const
00241 {
00242 PrintTabs(fd, nTabs); fprintf(fd, "{:Video ");
00243 MHVisible::PrintMe(fd, nTabs+1);
00244 PrintTabs(fd, nTabs+1); fprintf(fd, ":ComponentTag %d\n", m_nComponentTag);
00245 if (m_Termination != VI_Disappear) { PrintTabs(fd, nTabs+1); fprintf(fd, "Termination freeze "); }
00246 PrintTabs(fd, nTabs); fprintf(fd, "}\n");
00247 }
00248
00249 void MHVideo::Preparation(MHEngine *engine)
00250 {
00251 if (m_fAvailable) return;
00252 MHVisible::Preparation(engine);
00253
00254 m_nDecodeWidth = m_nBoxWidth;
00255 m_nDecodeHeight = m_nBoxHeight;
00256 }
00257
00258 void MHVideo::ContentPreparation(MHEngine *engine)
00259 {
00260
00261 engine->EventTriggered(this, EventContentAvailable);
00262 }
00263
00264
00265 void MHVideo::Display(MHEngine *engine)
00266 {
00267 if (! m_fRunning) return;
00268 if (m_nBoxWidth == 0 || m_nBoxHeight == 0) return;
00269
00270
00271
00272 QRect videoRect = QRect(m_nPosX+m_nXDecodeOffset, m_nPosY+m_nYDecodeOffset,
00273 m_nDecodeWidth, m_nDecodeHeight);
00274 QRect displayRect = videoRect.intersect(QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight));
00275 engine->GetContext()->DrawVideo(videoRect, displayRect);
00276 }
00277
00278 void MHVideo::ScaleVideo(int xScale, int yScale, MHEngine *engine)
00279 {
00280 if (xScale == m_nDecodeWidth && yScale == m_nDecodeHeight) return;
00281 QRegion updateArea = GetVisibleArea();
00282 m_nDecodeWidth = xScale;
00283 m_nDecodeHeight = yScale;
00284 updateArea += GetVisibleArea();
00285 engine->Redraw(updateArea);
00286 }
00287
00288
00289 void MHVideo::SetVideoDecodeOffset(int newXOffset, int newYOffset, MHEngine *engine)
00290 {
00291 QRegion updateArea = GetVisibleArea();
00292 m_nXDecodeOffset = newXOffset;
00293 m_nYDecodeOffset = newYOffset;
00294 updateArea += GetVisibleArea();
00295 engine->Redraw(updateArea);
00296 }
00297
00298
00299 void MHVideo::GetVideoDecodeOffset(MHRoot *pXOffset, MHRoot *pYOffset, MHEngine *)
00300 {
00301 pXOffset->SetVariableValue(m_nXDecodeOffset);
00302 pYOffset->SetVariableValue(m_nYDecodeOffset);
00303 }
00304
00305
00306 QRegion MHVideo::GetVisibleArea()
00307 {
00308 if (! m_fRunning) return QRegion();
00309
00310
00311 QRegion boxRegion = QRegion(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight);
00312 QRegion videoRegion = QRegion(m_nPosX+m_nXDecodeOffset, m_nPosY+m_nYDecodeOffset,
00313 m_nDecodeWidth, m_nDecodeHeight);
00314 return boxRegion & videoRegion;
00315 }
00316
00317 void MHVideo::Activation(MHEngine *engine)
00318 {
00319 if (m_fRunning) return;
00320 MHVisible::Activation(engine);
00321 if (m_fStreamPlaying && m_streamContentRef.IsSet())
00322 {
00323 QString stream;
00324 MHOctetString &str = m_streamContentRef.m_ContentRef;
00325 if (str.Size() != 0) stream = QString::fromUtf8((const char *)str.Bytes(), str.Size());
00326 engine->GetContext()->BeginVideo(stream, m_nComponentTag);
00327 }
00328 }
00329
00330 void MHVideo::Deactivation(MHEngine *engine)
00331 {
00332 if (! m_fRunning) return;
00333 MHVisible::Deactivation(engine);
00334 if (m_fStreamPlaying) engine->GetContext()->StopVideo();
00335 }
00336
00337 void MHVideo::SetStreamRef(const MHContentRef &cr)
00338 {
00339 m_streamContentRef.Copy(cr);
00340 }
00341
00342 void MHVideo::BeginPlaying(MHEngine *engine)
00343 {
00344 m_fStreamPlaying = true;
00345 if (m_fRunning && m_streamContentRef.IsSet())
00346 {
00347 QString stream;
00348 MHOctetString &str = m_streamContentRef.m_ContentRef;
00349 if (str.Size() != 0) stream = QString::fromUtf8((const char *)str.Bytes(), str.Size());
00350 engine->GetContext()->BeginVideo(stream, m_nComponentTag);
00351 }
00352 }
00353
00354 void MHVideo::StopPlaying(MHEngine *engine)
00355 {
00356 m_fStreamPlaying = false;
00357 if (m_fRunning) engine->GetContext()->StopVideo();
00358 }
00359
00360
00361 MHRTGraphics::MHRTGraphics()
00362 {
00363
00364 }
00365
00366 MHRTGraphics::~MHRTGraphics()
00367 {
00368
00369 }
00370
00371 void MHRTGraphics::Initialise(MHParseNode *p, MHEngine *engine)
00372 {
00373 MHVisible::Initialise(p, engine);
00374
00375 }
00376
00377 void MHRTGraphics::PrintMe(FILE *fd, int nTabs) const
00378 {
00379 MHVisible::PrintMe(fd, nTabs);
00380
00381 }