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
00044 if (pMultiplex)
00045 {
00046 for (int i = 0; i < pMultiplex->GetArgCount(); i++)
00047 {
00048 MHParseNode *pItem = pMultiplex->GetArgN(i);
00049
00050 if (pItem->GetTagNo() == C_AUDIO)
00051 {
00052 MHAudio *pAudio = new MHAudio;
00053 m_Multiplex.Append(pAudio);
00054 pAudio->Initialise(pItem, engine);
00055 }
00056 else if (pItem->GetTagNo() == C_VIDEO)
00057 {
00058 MHVideo *pVideo = new MHVideo;
00059 m_Multiplex.Append(pVideo);
00060 pVideo->Initialise(pItem, engine);
00061 }
00062 else if (pItem->GetTagNo() == C_RTGRAPHICS)
00063 {
00064 MHRTGraphics *pRtGraph = new MHRTGraphics;
00065 m_Multiplex.Append(pRtGraph);
00066 pRtGraph->Initialise(pItem, engine);
00067 }
00068
00069
00070 }
00071 }
00072
00073 MHParseNode *pStorage = p->GetNamedArg(C_STORAGE);
00074
00075 if (pStorage)
00076 {
00077 m_nStorage = (enum Storage) pStorage->GetArgN(0)->GetEnumValue();
00078 }
00079
00080 MHParseNode *pLooping = p->GetNamedArg(C_LOOPING);
00081
00082 if (pLooping)
00083 {
00084 m_nLooping = pLooping->GetArgN(0)->GetIntValue();
00085 }
00086 }
00087
00088 void MHStream::PrintMe(FILE *fd, int nTabs) const
00089 {
00090 PrintTabs(fd, nTabs);
00091 fprintf(fd, "{:Stream ");
00092 MHPresentable::PrintMe(fd, nTabs + 1);
00093 PrintTabs(fd, nTabs + 1);
00094 fprintf(fd, ":Multiplex (\n");
00095
00096 for (int i = 0; i < m_Multiplex.Size(); i++)
00097 {
00098 m_Multiplex.GetAt(i)->PrintMe(fd, nTabs + 2);
00099 }
00100
00101 PrintTabs(fd, nTabs + 1);
00102 fprintf(fd, " )\n");
00103
00104 if (m_nStorage != ST_Stream)
00105 {
00106 PrintTabs(fd, nTabs + 1);
00107 fprintf(fd, ":Storage memory\n");
00108 }
00109
00110 if (m_nLooping != 0)
00111 {
00112 PrintTabs(fd, nTabs + 1);
00113 fprintf(fd, ":Looping %d\n", m_nLooping);
00114 }
00115
00116 PrintTabs(fd, nTabs);
00117 fprintf(fd, "}\n");
00118 }
00119
00120 void MHStream::Preparation(MHEngine *engine)
00121 {
00122 if (m_fAvailable)
00123 {
00124 return;
00125 }
00126
00127 for (int i = 0; i < m_Multiplex.Size(); i++)
00128 {
00129 MHPresentable *pItem = m_Multiplex.GetAt(i);
00130
00131 if (pItem->InitiallyActive())
00132 {
00133 pItem->Activation(engine);
00134 }
00135 }
00136
00137 MHPresentable::Preparation(engine);
00138 }
00139
00140 void MHStream::Destruction(MHEngine *engine)
00141 {
00142
00143 for (int j = m_Multiplex.Size(); j > 0; j--)
00144 {
00145 m_Multiplex.GetAt(j - 1)->Destruction(engine);
00146 }
00147
00148 MHPresentable::Destruction(engine);
00149 }
00150
00151 void MHStream::Activation(MHEngine *engine)
00152 {
00153 if (m_fRunning)
00154 {
00155 return;
00156 }
00157
00158 MHPresentable::Activation(engine);
00159
00160
00161 for (int i = 0; i < m_Multiplex.Size(); i++)
00162 {
00163 m_Multiplex.GetAt(i)->BeginPlaying(engine);
00164 }
00165
00166 m_fRunning = true;
00167 engine->EventTriggered(this, EventIsRunning);
00168 }
00169
00170 void MHStream::Deactivation(MHEngine *engine)
00171 {
00172 if (! m_fRunning)
00173 {
00174 return;
00175 }
00176
00177
00178 for (int i = 0; i < m_Multiplex.Size(); i++)
00179 {
00180 m_Multiplex.GetAt(i)->StopPlaying(engine);
00181 }
00182
00183 MHPresentable::Deactivation(engine);
00184 }
00185
00186
00187
00188 void MHStream::ContentPreparation(MHEngine *engine)
00189 {
00190 engine->EventTriggered(this, EventContentAvailable);
00191
00192 for (int i = 0; i < m_Multiplex.Size(); i++)
00193 {
00194 m_Multiplex.GetAt(i)->SetStreamRef(engine, m_ContentRef);
00195 }
00196 }
00197
00198
00199
00200
00201
00202 MHRoot *MHStream::FindByObjectNo(int n)
00203 {
00204 if (n == m_ObjectReference.m_nObjectNo)
00205 {
00206 return this;
00207 }
00208
00209 for (int i = m_Multiplex.Size(); i > 0; i--)
00210 {
00211 MHRoot *pResult = m_Multiplex.GetAt(i - 1)->FindByObjectNo(n);
00212
00213 if (pResult)
00214 {
00215 return pResult;
00216 }
00217 }
00218
00219 return NULL;
00220 }
00221
00222 MHAudio::MHAudio()
00223 {
00224 m_nComponentTag = 0;
00225 m_nOriginalVol = 0;
00226 m_fStreamPlaying = false;
00227 }
00228
00229 void MHAudio::Initialise(MHParseNode *p, MHEngine *engine)
00230 {
00231 MHPresentable::Initialise(p, engine);
00232 MHParseNode *pComponentTagNode = p->GetNamedArg(C_COMPONENT_TAG);
00233
00234 if (pComponentTagNode)
00235 {
00236 m_nComponentTag = pComponentTagNode->GetArgN(0)->GetIntValue();
00237 }
00238
00239 MHParseNode *pOrigVol = p->GetNamedArg(C_ORIGINAL_VOLUME);
00240
00241 if (pOrigVol)
00242 {
00243 m_nOriginalVol = pOrigVol->GetIntValue();
00244 }
00245 }
00246
00247 void MHAudio::PrintMe(FILE *fd, int nTabs) const
00248 {
00249 PrintTabs(fd, nTabs);
00250 fprintf(fd, "{:Audio ");
00251 MHPresentable::PrintMe(fd, nTabs + 1);
00252 PrintTabs(fd, nTabs + 1);
00253 fprintf(fd, ":ComponentTag %d\n", m_nComponentTag);
00254
00255 if (m_nOriginalVol != 0)
00256 {
00257 PrintTabs(fd, nTabs + 1);
00258 fprintf(fd, "OriginalVolume %d ", m_nOriginalVol);
00259 }
00260
00261 PrintTabs(fd, nTabs);
00262 fprintf(fd, "}\n");
00263 }
00264
00265
00266 void MHAudio::Activation(MHEngine *engine)
00267 {
00268 if (m_fRunning)
00269 {
00270 return;
00271 }
00272
00273 MHPresentable::Activation(engine);
00274
00275 m_fRunning = true;
00276 engine->EventTriggered(this, EventIsRunning);
00277
00278 if (m_fStreamPlaying && m_streamContentRef.IsSet())
00279 {
00280 QString stream;
00281 MHOctetString &str = m_streamContentRef.m_ContentRef;
00282
00283 if (str.Size() != 0)
00284 {
00285 stream = QString::fromUtf8((const char *)str.Bytes(), str.Size());
00286 }
00287
00288 engine->GetContext()->BeginAudio(stream, m_nComponentTag);
00289 }
00290 }
00291
00292
00293 void MHAudio::Deactivation(MHEngine *engine)
00294 {
00295 if (! m_fRunning)
00296 {
00297 return;
00298 }
00299
00300 m_fRunning = false;
00301
00302
00303 if (m_fStreamPlaying)
00304 {
00305 engine->GetContext()->StopAudio();
00306 }
00307
00308 MHPresentable::Deactivation(engine);
00309 }
00310
00311 void MHAudio::SetStreamRef(MHEngine *engine, const MHContentRef &cr)
00312 {
00313 m_streamContentRef.Copy(cr);
00314
00315 if (m_fStreamPlaying)
00316 {
00317 BeginPlaying(engine);
00318 }
00319 }
00320
00321 void MHAudio::BeginPlaying(MHEngine *engine)
00322 {
00323 m_fStreamPlaying = true;
00324
00325 if (m_fRunning && m_streamContentRef.IsSet())
00326 {
00327 QString stream;
00328 MHOctetString &str = m_streamContentRef.m_ContentRef;
00329
00330 if (str.Size() != 0)
00331 {
00332 stream = QString::fromUtf8((const char *)str.Bytes(), str.Size());
00333 }
00334
00335 engine->GetContext()->BeginAudio(stream, m_nComponentTag);
00336 }
00337 }
00338
00339 void MHAudio::StopPlaying(MHEngine *engine)
00340 {
00341 m_fStreamPlaying = false;
00342
00343 if (m_fRunning)
00344 {
00345 engine->GetContext()->StopAudio();
00346 }
00347 }
00348
00349
00350 MHVideo::MHVideo()
00351 {
00352 m_nComponentTag = 0;
00353 m_Termination = VI_Disappear;
00354 m_nXDecodeOffset = 0;
00355 m_nYDecodeOffset = 0;
00356 m_nDecodeWidth = 0;
00357 m_nDecodeHeight = 0;
00358
00359 m_fStreamPlaying = false;
00360 }
00361
00362 void MHVideo::Initialise(MHParseNode *p, MHEngine *engine)
00363 {
00364 MHVisible::Initialise(p, engine);
00365 MHParseNode *pComponentTagNode = p->GetNamedArg(C_COMPONENT_TAG);
00366
00367 if (pComponentTagNode)
00368 {
00369 m_nComponentTag = pComponentTagNode->GetArgN(0)->GetIntValue();
00370 }
00371
00372 MHParseNode *pTerm = p->GetNamedArg(C_TERMINATION);
00373
00374 if (pTerm)
00375 {
00376 m_Termination = (enum Termination)pTerm->GetEnumValue();
00377 }
00378 }
00379
00380 void MHVideo::PrintMe(FILE *fd, int nTabs) const
00381 {
00382 PrintTabs(fd, nTabs);
00383 fprintf(fd, "{:Video ");
00384 MHVisible::PrintMe(fd, nTabs + 1);
00385 PrintTabs(fd, nTabs + 1);
00386 fprintf(fd, ":ComponentTag %d\n", m_nComponentTag);
00387
00388 if (m_Termination != VI_Disappear)
00389 {
00390 PrintTabs(fd, nTabs + 1);
00391 fprintf(fd, "Termination freeze ");
00392 }
00393
00394 PrintTabs(fd, nTabs);
00395 fprintf(fd, "}\n");
00396 }
00397
00398 void MHVideo::Preparation(MHEngine *engine)
00399 {
00400 if (m_fAvailable)
00401 {
00402 return;
00403 }
00404
00405 MHVisible::Preparation(engine);
00406
00407 m_nDecodeWidth = m_nBoxWidth;
00408 m_nDecodeHeight = m_nBoxHeight;
00409 }
00410
00411 void MHVideo::ContentPreparation(MHEngine *engine)
00412 {
00413
00414 engine->EventTriggered(this, EventContentAvailable);
00415 }
00416
00417
00418 void MHVideo::Display(MHEngine *engine)
00419 {
00420 if (! m_fRunning)
00421 {
00422 return;
00423 }
00424
00425 if (m_nBoxWidth == 0 || m_nBoxHeight == 0)
00426 {
00427 return;
00428 }
00429
00430
00431
00432
00433 QRect videoRect = QRect(m_nPosX + m_nXDecodeOffset, m_nPosY + m_nYDecodeOffset,
00434 m_nDecodeWidth, m_nDecodeHeight);
00435 QRect displayRect = videoRect.intersect(QRect(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight));
00436 engine->GetContext()->DrawVideo(videoRect, displayRect);
00437 }
00438
00439 void MHVideo::ScaleVideo(int xScale, int yScale, MHEngine *engine)
00440 {
00441 if (xScale == m_nDecodeWidth && yScale == m_nDecodeHeight)
00442 {
00443 return;
00444 }
00445
00446 QRegion updateArea = GetVisibleArea();
00447 m_nDecodeWidth = xScale;
00448 m_nDecodeHeight = yScale;
00449 updateArea += GetVisibleArea();
00450 engine->Redraw(updateArea);
00451 }
00452
00453
00454 void MHVideo::SetVideoDecodeOffset(int newXOffset, int newYOffset, MHEngine *engine)
00455 {
00456 QRegion updateArea = GetVisibleArea();
00457 m_nXDecodeOffset = newXOffset;
00458 m_nYDecodeOffset = newYOffset;
00459 updateArea += GetVisibleArea();
00460 engine->Redraw(updateArea);
00461 }
00462
00463
00464 void MHVideo::GetVideoDecodeOffset(MHRoot *pXOffset, MHRoot *pYOffset, MHEngine *)
00465 {
00466 pXOffset->SetVariableValue(m_nXDecodeOffset);
00467 pYOffset->SetVariableValue(m_nYDecodeOffset);
00468 }
00469
00470
00471 QRegion MHVideo::GetVisibleArea()
00472 {
00473 if (! m_fRunning)
00474 {
00475 return QRegion();
00476 }
00477
00478
00479
00480 QRegion boxRegion = QRegion(m_nPosX, m_nPosY, m_nBoxWidth, m_nBoxHeight);
00481 QRegion videoRegion = QRegion(m_nPosX + m_nXDecodeOffset, m_nPosY + m_nYDecodeOffset,
00482 m_nDecodeWidth, m_nDecodeHeight);
00483 return boxRegion & videoRegion;
00484 }
00485
00486 void MHVideo::Activation(MHEngine *engine)
00487 {
00488 if (m_fRunning)
00489 {
00490 return;
00491 }
00492
00493 MHVisible::Activation(engine);
00494
00495 if (m_fStreamPlaying && m_streamContentRef.IsSet())
00496 {
00497 QString stream;
00498 MHOctetString &str = m_streamContentRef.m_ContentRef;
00499
00500 if (str.Size() != 0)
00501 {
00502 stream = QString::fromUtf8((const char *)str.Bytes(), str.Size());
00503 }
00504
00505 engine->GetContext()->BeginVideo(stream, m_nComponentTag);
00506 }
00507 }
00508
00509 void MHVideo::Deactivation(MHEngine *engine)
00510 {
00511 if (! m_fRunning)
00512 {
00513 return;
00514 }
00515
00516 MHVisible::Deactivation(engine);
00517
00518 if (m_fStreamPlaying)
00519 {
00520 engine->GetContext()->StopVideo();
00521 }
00522 }
00523
00524 void MHVideo::SetStreamRef(MHEngine *engine, const MHContentRef &cr)
00525 {
00526 m_streamContentRef.Copy(cr);
00527
00528 if (m_fStreamPlaying)
00529 {
00530 BeginPlaying(engine);
00531 }
00532 }
00533
00534 void MHVideo::BeginPlaying(MHEngine *engine)
00535 {
00536 m_fStreamPlaying = true;
00537
00538 if (m_fRunning && m_streamContentRef.IsSet())
00539 {
00540 QString stream;
00541 MHOctetString &str = m_streamContentRef.m_ContentRef;
00542
00543 if (str.Size() != 0)
00544 {
00545 stream = QString::fromUtf8((const char *)str.Bytes(), str.Size());
00546 }
00547
00548 engine->GetContext()->BeginVideo(stream, m_nComponentTag);
00549 }
00550 }
00551
00552 void MHVideo::StopPlaying(MHEngine *engine)
00553 {
00554 m_fStreamPlaying = false;
00555
00556 if (m_fRunning)
00557 {
00558 engine->GetContext()->StopVideo();
00559 }
00560 }
00561
00562
00563 MHRTGraphics::MHRTGraphics()
00564 {
00565
00566 }
00567
00568 MHRTGraphics::~MHRTGraphics()
00569 {
00570
00571 }
00572
00573 void MHRTGraphics::Initialise(MHParseNode *p, MHEngine *engine)
00574 {
00575 MHVisible::Initialise(p, engine);
00576
00577 }
00578
00579 void MHRTGraphics::PrintMe(FILE *fd, int nTabs) const
00580 {
00581 MHVisible::PrintMe(fd, nTabs);
00582
00583 }