home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / mac / SiteBldr / AMOVIE / SDK / _SETUP / COMMON.Z / iplaydoc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-15  |  20.0 KB  |  824 lines

  1. // This code and information is provided "as is" without warranty of
  2. // any kind, either expressed or implied, including but not limited to
  3. // the implied warranties of merchantability and/or fitness for a
  4. // particular purpose.
  5.  
  6. // Copyright (C) 1996 Intel corporation.  All rights reserved.
  7.  
  8. // IPlaydoc.cpp : implementation of the CIPlayDoc class
  9. //
  10.  
  11. #include "stdafx.h"
  12. #include "IPlay.h"
  13. #include "IPlaydoc.h"
  14.  
  15. #include <initguid.h>       // OLE (Quartz) initialization
  16.  
  17. #include "datatype.h"
  18. #include "ax_spec.h"
  19.  
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char BASED_CODE THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CIPlayDoc
  27.  
  28. IMPLEMENT_DYNCREATE(CIPlayDoc, CDocument)
  29.  
  30. BEGIN_MESSAGE_MAP(CIPlayDoc, CDocument)
  31.     //{{AFX_MSG_MAP(CIPlayDoc)
  32.     ON_COMMAND(ID_MEDIA_LOOP, OnMediaLoop)
  33.     ON_COMMAND(ID_MEDIA_PAUSE, OnMediaPause)
  34.     ON_COMMAND(ID_MEDIA_ZOOMX2, OnMediaZoomx2)
  35.     ON_UPDATE_COMMAND_UI(ID_MEDIA_PAUSE, OnUpdateMediaPause)
  36.     ON_UPDATE_COMMAND_UI(ID_MEDIA_PLAY, OnUpdateMediaPlay)
  37.     ON_UPDATE_COMMAND_UI(ID_MEDIA_STOP, OnUpdateMediaStop)
  38.     ON_UPDATE_COMMAND_UI(ID_MEDIA_ZOOMX2, OnUpdateMediaZoomx2)
  39.     ON_UPDATE_COMMAND_UI(ID_MEDIA_LOOP, OnUpdateMediaLoop)
  40.     ON_COMMAND(ID_MEDIA_PLAY, OnMediaPlay)
  41.     ON_COMMAND(ID_MEDIA_STOP, OnMediaStop)
  42.     //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44.  
  45. R4_DEC_SEQ_DATA   m_r4SeqData;  // Indeo data structures
  46. R4_DEC_FRAME_DATA m_r4FrameData;
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CIPlayDoc construction/destruction
  50.  
  51. CIPlayDoc::CIPlayDoc()
  52. {
  53.     m_pGraph      = NULL;
  54.     m_hGraphEvent = NULL;
  55.     m_pIndeo      = NULL;
  56.     m_lpstrPath[0] = '\0';
  57.     m_bLoop       = FALSE;
  58.     m_bZoom          = FALSE;
  59.     m_lWidth      = 0;
  60.     m_lHeight      = 0;
  61.     m_State       = Uninitialized;
  62.  
  63.     // Initialize the headers for the Indeo data structures
  64.     // This stuff never changes (except for dwFlags)
  65.     m_r4FrameData.dwSize = sizeof(R4_DEC_FRAME_DATA);
  66.     m_r4FrameData.dwFourCC = FOURCC_IV41;
  67.     m_r4FrameData.dwVersion = SPECIFIC_INTERFACE_VERSION;
  68.     m_r4FrameData.oeEnvironment = OE_32;
  69.     m_r4FrameData.dwFlags = 0;
  70.  
  71.     m_r4SeqData.dwSize = sizeof(R4_DEC_SEQ_DATA);
  72.     m_r4SeqData.dwFourCC = FOURCC_IV41;
  73.     m_r4SeqData.dwVersion = SPECIFIC_INTERFACE_VERSION;
  74.     m_r4SeqData.oeEnvironment = OE_32;
  75.     m_r4SeqData.dwFlags = 0;
  76.  
  77.     ((CIPlayApp *) AfxGetApp())->OnDocumentCreated( this );
  78. }
  79.  
  80. CIPlayDoc::~CIPlayDoc()
  81. {
  82.     DeleteContents();
  83.  
  84.     ((CIPlayApp *) AfxGetApp())->OnDocumentDestroyed( this );
  85.  
  86. }
  87.  
  88.  
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CIPlayDoc diagnostics
  91.  
  92. #ifdef _DEBUG
  93. void CIPlayDoc::AssertValid() const
  94. {
  95.     CDocument::AssertValid();
  96. }
  97.  
  98. void CIPlayDoc::Dump(CDumpContext& dc) const
  99. {
  100.     CDocument::Dump(dc);
  101. }
  102. #endif //_DEBUG
  103.  
  104. /////////////////////////////////////////////////////////////////////////////
  105. // CIPlayDoc Message Handlers
  106.  
  107. BOOL CIPlayDoc::OnOpenDocument(LPCTSTR lpszPathName) 
  108. {
  109.     WCHAR         wPath[MAX_PATH];
  110.  
  111.     IFilter      *pFilter;  // EnumFilters vars
  112.     IEnumFilters *pEnum;
  113.     ULONG        pcFetched;
  114.     HRESULT      hr;
  115. //    HWND            hVidWin;
  116.  
  117.     void *pIF;      // generic interface to graph object
  118.  
  119.     // Get rid of any previously opened graph.
  120.     DeleteContents();
  121.  
  122.     // Create a new filter graph object.
  123.     if ( !CreateFilterGraph() ) {
  124.         AfxMessageBox(IDS_CANT_INIT_QUARTZ);
  125.         return FALSE;
  126.     }
  127.  
  128.     // Render the file using the new filter graph.
  129.     // This will add the necessary filters to the
  130.     // graph (which up til now was empty).
  131.     strcpy(m_lpstrPath, lpszPathName);
  132.     MultiByteToWideChar( CP_ACP, 0, lpszPathName,
  133.                          -1, wPath, MAX_PATH );
  134.  
  135.     hr = m_pGraph->QueryInterface(IID_IGraphBuilder, &pIF);
  136.  
  137.     if (FAILED( ((IGraphBuilder *)pIF)->RenderFile(wPath, NULL) )) {
  138.         AfxMessageBox(IDS_CANT_RENDER_FILE);
  139.         return FALSE;
  140.     }
  141.     ((IGraphBuilder *)pIF)->Release();
  142.  
  143.     // Position and set the title of the video window.
  144.     SetWindow((BSTR)wPath);
  145.     
  146.     // Get and save the native video size -- used for 
  147.     // zoom by 2.
  148.     hr = m_pGraph->QueryInterface(IID_IBasicVideo, &pIF);
  149.  
  150.     if( SUCCEEDED(hr) ){
  151.         ((IBasicVideo *)pIF)->GetVideoSize(&m_lWidth, &m_lHeight);
  152.         ((IBasicVideo *)pIF)->Release();
  153.     }
  154.  
  155.     // Call the stop function to queue up the first
  156.     // frame of the clip.  Have to set the state first
  157.     // to Paused so we can transistion to Stopped.
  158.     m_State = Paused;
  159.     OnMediaStop();
  160.  
  161.     // See if the Indeo codec filter is in the graph.
  162.     hr = m_pGraph->EnumFilters(&pEnum);
  163.  
  164.     if (FAILED(hr))
  165.         return TRUE;
  166.  
  167.     while ((hr = pEnum->Next(1, &pFilter, &pcFetched)) == S_OK)
  168.     {
  169.         hr = pFilter->QueryInterface(IID_IIndeoDecode, &m_pIndeo);
  170.         pFilter->Release();
  171.         if (hr == S_OK)
  172.             break;
  173.  
  174.     }
  175.     // This interface needs to be released, even though
  176.     // it was not obtained in the usual way with QueryInterface.
  177.     pEnum->Release(); 
  178.     
  179.     // Someday, the following line can replace the above section of code
  180.     // that enumerates the filters in the graph to find the 
  181.     // IIndeoDecode interface, but apparently that someday is not today.
  182.  
  183.     //hr = m_pGraph->QueryInterface(IID_IIndeoDecode, &m_pIndeo);
  184.  
  185.     return TRUE;
  186. }
  187.  
  188. void CIPlayDoc::OnGraphNotify(void) {
  189.     IMediaEvent *pME;
  190.     long lEventCode, lParam1, lParam2;
  191.  
  192.     ASSERT( m_hGraphEvent != NULL );
  193.  
  194.     if( SUCCEEDED(m_pGraph->QueryInterface(IID_IMediaEvent, (void **) &pME))){
  195.         if( SUCCEEDED(pME->GetEvent(&lEventCode, &lParam1, &lParam2, 0)) )  {
  196.  
  197.             switch (lEventCode) {
  198.  
  199.                 case EC_COMPLETE:
  200.                         OnMediaStop();
  201.                     if (m_bLoop) OnMediaPlay();
  202.                     break;
  203.                 case EC_USERABORT:
  204.                 case EC_ERRORABORT:
  205.                     OnMediaStop();
  206.             }
  207.         }
  208.  
  209.         pME->Release();
  210.     }
  211.  
  212.     // Send a message so toolbar gets updated
  213.     PostMessage( AfxGetMainWnd()->m_hWnd, WM_USER, 0, 0 );
  214.  
  215. }
  216.  
  217. void CIPlayDoc::OnMediaLoop() 
  218. {
  219.     m_bLoop = !m_bLoop;
  220.     
  221. }
  222.  
  223. void CIPlayDoc::OnMediaPause() 
  224. {
  225.     if( CanPause() ){
  226.         HRESULT    hr;
  227.         IMediaControl *pMC;
  228.  
  229.         // Obtain the interface to our filter graph
  230.         hr = m_pGraph->QueryInterface(IID_IMediaControl, (void **) &pMC);
  231.  
  232.         if( SUCCEEDED(hr) ){
  233.             // Ask the filter graph to pause and release the interface
  234.             hr = pMC->Pause();
  235.             pMC->Release();
  236.  
  237.             if( SUCCEEDED(hr) ){
  238.                 m_State = Paused;
  239.                 return;
  240.             }
  241.         }
  242.     }
  243.     
  244. }
  245.  
  246. void CIPlayDoc::OnMediaPlay() 
  247. {
  248.     if( CanPlay() ){
  249.         HRESULT    hr;
  250.         IMediaControl *pMC;
  251.  
  252.         // Obtain the interface to our filter graph
  253.         hr = m_pGraph->QueryInterface(IID_IMediaControl, (void **) &pMC);
  254.  
  255.         if( SUCCEEDED(hr) ){
  256.             // Ask the filter graph to play and release the interface
  257.             hr = pMC->Run();
  258.             pMC->Release();
  259.  
  260.             if( SUCCEEDED(hr) ){
  261.                 m_State=Playing;
  262.                 // Let Indeo view object know the state changed
  263.                 UpdateAllViews(NULL);
  264.                 return;
  265.             }
  266.         }
  267.     }
  268.     
  269. }
  270.  
  271. void CIPlayDoc::OnMediaStop() 
  272. {
  273.     if( CanStop() ){
  274.         HRESULT    hr;
  275.         IMediaControl *pMC;
  276.         IMediaPosition *pMP;
  277.         OAFilterState fstate;
  278.  
  279.         // Obtain the interface to our filter graph
  280.         hr = m_pGraph->QueryInterface(IID_IMediaControl, (void **) &pMC);
  281.  
  282.         if( SUCCEEDED(hr) ){
  283.             // Ask the filter graph to stop and release the interface
  284.  
  285.             // put graph in stopped state
  286.             hr = pMC->Stop();  
  287.  
  288.             // Rewind the stream
  289.             hr = m_pGraph->QueryInterface(IID_IMediaPosition, (void **) &pMP);
  290.             hr = pMP->put_CurrentPosition(0);
  291.             hr = pMP->Release();
  292.  
  293.             // Flush the graph
  294.             hr = pMC->Pause();
  295.  
  296.             // Wait for state transition to complete
  297.             hr = pMC->GetState(5000, &fstate);
  298.  
  299.             // Now back to stopped state
  300.             hr = pMC->Stop();
  301.  
  302.             pMC->Release();
  303.  
  304.             if( SUCCEEDED(hr) ){
  305.                 m_State = Stopped;
  306.                 // Let Indeo view object know the state changed
  307.                 UpdateAllViews(NULL);
  308.                 return;
  309.             }
  310.         }
  311.     }
  312.     
  313. }
  314.  
  315. void CIPlayDoc::OnMediaZoomx2() 
  316. {
  317.     // This function doubles the width & height of the original video
  318.     // size -- depending on the hardware, this may result in a
  319.     // better quality video than a random stretch of the video window.
  320.     // Subsequent calls toggle the video size between the original size 
  321.     // and the "x2" size, ignoring the fact that the user may have 
  322.     // resized the window using the window frame.  The function attempts to 
  323.     // keep the video window's center in place (zooms/unzooms from top,
  324.     // bottom, right and left).
  325.  
  326.     HRESULT hr;
  327.     void *pIF;
  328.     long x,y,width,height,width2,height2;
  329.  
  330.     m_bZoom = !m_bZoom;
  331.     
  332.     hr = m_pGraph->QueryInterface(IID_IVideoWindow, &pIF);
  333.  
  334.     if( SUCCEEDED(hr) ){
  335.         if (m_bZoom) {
  336.             // Set the width & height to twice the native video size
  337.             // Allow for the window frame -- we really want to just
  338.             // double the size of the client area.
  339.             width2 = (m_lWidth * 2) + (m_lWinWidth - m_lWidth);
  340.             height2 = (m_lHeight * 2) + (m_lWinHeight - m_lHeight);
  341.             ((IVideoWindow *)pIF)->GetWindowPosition(&x, &y, &width, &height);
  342.             ((IVideoWindow *)pIF)->SetWindowPosition(x + (width - width2)/2,
  343.                 y + (height - height2)/2, width2, height2);
  344.         }
  345.         else {
  346.             // Restore original size
  347.             ((IVideoWindow *)pIF)->GetWindowPosition(&x, &y, &width, &height);
  348.             ((IVideoWindow *)pIF)->SetWindowPosition(x +
  349.                 (width - m_lWinWidth)/2, y + (height - m_lWinHeight)/2,
  350.                 m_lWinWidth, m_lWinHeight);
  351.         } 
  352.  
  353.         ((IVideoWindow *)pIF)->Release();
  354.  
  355.     }
  356. }
  357.  
  358. void CIPlayDoc::OnUpdateMediaPause(CCmdUI* pCmdUI) 
  359. {
  360.     pCmdUI->Enable( CanPause() );
  361.     
  362. }
  363.  
  364. void CIPlayDoc::OnUpdateMediaPlay(CCmdUI* pCmdUI) 
  365. {
  366.     pCmdUI->Enable( CanPlay() );
  367.     
  368. }
  369.  
  370. void CIPlayDoc::OnUpdateMediaStop(CCmdUI* pCmdUI) 
  371. {
  372.     pCmdUI->Enable( CanStop() );
  373.     
  374. }
  375.  
  376. void CIPlayDoc::OnUpdateMediaLoop(CCmdUI* pCmdUI) 
  377. {
  378.     pCmdUI->Enable( IsInitialized() );
  379.     pCmdUI->SetCheck( m_bLoop );
  380.     
  381. }
  382.  
  383. void CIPlayDoc::OnUpdateMediaZoomx2(CCmdUI* pCmdUI) 
  384. {
  385.     pCmdUI->Enable( IsInitialized() );
  386.     pCmdUI->SetCheck( m_bZoom );
  387.     
  388. }
  389.  
  390. /////////////////////////////////////////////////////////////////////////////
  391. // CIPlayDoc Commands
  392.  
  393. BOOL CIPlayDoc::IsIndeo()
  394. {
  395.     return (m_pIndeo != NULL);
  396. }
  397.  
  398. void CIPlayDoc::GetBCS(int& b, int& c, int& s)
  399. {
  400.     HRESULT hr;
  401.  
  402.     m_r4FrameData.mtType = MT_DECODE_FRAME_VALUE;
  403.     m_r4FrameData.dwFlags = DECFRAME_BRIGHTNESS |
  404.                             DECFRAME_CONTRAST |
  405.                             DECFRAME_SATURATION |
  406.                             DECFRAME_VALID;
  407.  
  408.     hr = ((IIndeoDecode *)m_pIndeo)->get_DecodeFrame(&m_r4FrameData);
  409.  
  410.     if (FAILED( hr )) {
  411.         AfxMessageBox(IDS_CANT_GET_FRAME_DATA);
  412.         return;
  413.     }
  414.  
  415.     b = LOWORD(m_r4FrameData.lBrightness);
  416.     c = LOWORD(m_r4FrameData.lContrast);
  417.     s = LOWORD(m_r4FrameData.lSaturation);
  418.  
  419.     return;
  420. }
  421.  
  422. void CIPlayDoc::GetDecodeTime(DWORD& time)
  423. {
  424.     HRESULT hr;
  425.  
  426.     m_r4FrameData.mtType = MT_DECODE_FRAME_VALUE;
  427.     m_r4FrameData.dwFlags = DECFRAME_TIME_LIMIT | DECFRAME_VALID;
  428.  
  429.     hr = ((IIndeoDecode *)m_pIndeo)->get_DecodeFrame(&m_r4FrameData);
  430.  
  431.     if (FAILED( hr )) {
  432.         AfxMessageBox(IDS_CANT_SET_FRAME_DATA);
  433.         return;
  434.     }
  435.  
  436.     time = m_r4FrameData.dwTimeLimit;
  437.  
  438.     return;
  439. }
  440.  
  441.  
  442. void CIPlayDoc::GetDecodeRect(DWORD& x, DWORD& y, DWORD& width, DWORD& height)
  443. {
  444.     HRESULT hr;
  445.  
  446.     m_r4FrameData.mtType = MT_DECODE_FRAME_VALUE;
  447.     m_r4FrameData.dwFlags = DECFRAME_DECODE_RECT | DECFRAME_VALID;
  448.  
  449.     hr = ((IIndeoDecode *)m_pIndeo)->get_DecodeFrame(&m_r4FrameData);
  450.  
  451.     if (FAILED( hr )) {
  452.         AfxMessageBox(IDS_CANT_GET_FRAME_DATA);
  453.         return;
  454.     }
  455.  
  456.     x = m_r4FrameData.rDecodeRect.dwX;
  457.     y = m_r4FrameData.rDecodeRect.dwY;
  458.     width = m_r4FrameData.rDecodeRect.dwWidth;
  459.     height = m_r4FrameData.rDecodeRect.dwHeight;
  460.  
  461.     return;
  462. }
  463.  
  464. void CIPlayDoc::GetViewRect(DWORD& x, DWORD& y, DWORD& width, DWORD& height)
  465. {
  466.     HRESULT hr;
  467.  
  468.     m_r4FrameData.mtType = MT_DECODE_FRAME_VALUE;
  469.     m_r4FrameData.dwFlags = DECFRAME_VIEW_RECT | DECFRAME_VALID;
  470.  
  471.     hr = ((IIndeoDecode *)m_pIndeo)->get_DecodeFrame(&m_r4FrameData);
  472.  
  473.     if (FAILED( hr )) {
  474.         AfxMessageBox(IDS_CANT_GET_FRAME_DATA);
  475.         return;
  476.     }
  477.  
  478.     x = m_r4FrameData.rViewRect.dwX;
  479.     y = m_r4FrameData.rViewRect.dwY;
  480.     width = m_r4FrameData.rViewRect.dwWidth;
  481.     height = m_r4FrameData.rViewRect.dwHeight;
  482.  
  483.     return;
  484. }
  485.  
  486. void CIPlayDoc::GetSequenceOptions(BOOL& altline, BOOL& scal, BOOL& trans, BOOL& usekey,
  487.     DWORD& key)
  488. {
  489.     HRESULT hr;
  490.  
  491.     m_r4SeqData.mtType = MT_DECODE_SEQ_VALUE;
  492.     m_r4SeqData.dwFlags =    DECSEQ_KEY |
  493.                             DECSEQ_SCALABILITY |
  494.                             DECSEQ_FILL_TRANSPARENT |
  495.                             DECSEQ_ALT_LINE |
  496.                             DECSEQ_VALID;
  497.  
  498.     hr = ((IIndeoDecode *)m_pIndeo)->get_DecodeSequence(&m_r4SeqData);
  499.  
  500.     if (FAILED( hr )) {
  501.         AfxMessageBox(IDS_CANT_GET_SEQ_DATA);
  502.         return;
  503.     }
  504.  
  505.     altline = m_r4SeqData.fAltLine;
  506.     scal = m_r4SeqData.fScalability;
  507.     trans = m_r4SeqData.fFillTransparentPixels;
  508.     usekey = m_r4SeqData.fEnabledKey;
  509.     key = m_r4SeqData.dwKey;
  510.  
  511.     return;
  512. }
  513.  
  514. void CIPlayDoc::SetBCS(int b, int c, int s)
  515. {
  516.     HRESULT hr;
  517.  
  518.     m_r4FrameData.mtType = MT_DECODE_FRAME_VALUE;
  519.     m_r4FrameData.dwFlags = DECFRAME_BRIGHTNESS |
  520.                             DECFRAME_CONTRAST |
  521.                             DECFRAME_SATURATION |
  522.                             DECFRAME_VALID;
  523.  
  524.     m_r4FrameData.lBrightness = b;
  525.     m_r4FrameData.lContrast = c;
  526.     m_r4FrameData.lSaturation = s;
  527.  
  528.     hr = ((IIndeoDecode *)m_pIndeo)->set_DecodeFrame(&m_r4FrameData);
  529.  
  530.     if (FAILED( hr )) 
  531.         AfxMessageBox(IDS_CANT_SET_FRAME_DATA);
  532.  
  533.     return;
  534. }
  535.  
  536.  
  537. void CIPlayDoc::SetDecodeTime(DWORD time)
  538. {
  539.     HRESULT hr;
  540.  
  541.     m_r4FrameData.mtType = MT_DECODE_FRAME_VALUE;
  542.     m_r4FrameData.dwFlags = DECFRAME_TIME_LIMIT | DECFRAME_VALID;
  543.  
  544.     m_r4FrameData.dwTimeLimit = time;
  545.  
  546.     hr = ((IIndeoDecode *)m_pIndeo)->set_DecodeFrame(&m_r4FrameData);
  547.  
  548.     if (FAILED( hr )) 
  549.         AfxMessageBox(IDS_CANT_SET_FRAME_DATA);
  550.  
  551.     return;
  552. }
  553.  
  554. void CIPlayDoc::SetDecodeRect(DWORD x, DWORD y, DWORD width, DWORD height)
  555. {
  556.     HRESULT hr;
  557.  
  558.     m_r4FrameData.mtType = MT_DECODE_FRAME_VALUE;
  559.     m_r4FrameData.dwFlags = DECFRAME_DECODE_RECT | DECFRAME_VALID;
  560.  
  561.     m_r4FrameData.rDecodeRect.dwX = x;
  562.     m_r4FrameData.rDecodeRect.dwY = y;
  563.     m_r4FrameData.rDecodeRect.dwWidth = width;
  564.     m_r4FrameData.rDecodeRect.dwHeight = height;
  565.  
  566.     hr = ((IIndeoDecode *)m_pIndeo)->set_DecodeFrame(&m_r4FrameData);
  567.  
  568.     if (FAILED( hr )) 
  569.         AfxMessageBox(IDS_CANT_SET_FRAME_DATA);
  570.  
  571.     return;
  572. }
  573.  
  574. void CIPlayDoc::SetViewRect(DWORD x, DWORD y, DWORD width, DWORD height)
  575. {
  576.     HRESULT hr;
  577.  
  578.     m_r4FrameData.mtType = MT_DECODE_FRAME_VALUE;
  579.     m_r4FrameData.dwFlags = DECFRAME_VIEW_RECT | DECFRAME_VALID;
  580.  
  581.     m_r4FrameData.rViewRect.dwX = x;
  582.     m_r4FrameData.rViewRect.dwY = y;
  583.     m_r4FrameData.rViewRect.dwWidth = width;
  584.     m_r4FrameData.rViewRect.dwHeight = height;
  585.  
  586.     hr = ((IIndeoDecode *)m_pIndeo)->set_DecodeFrame(&m_r4FrameData);
  587.  
  588.     if (FAILED( hr )) 
  589.         AfxMessageBox(IDS_CANT_SET_FRAME_DATA);
  590.  
  591.     return;
  592. }
  593.  
  594. void CIPlayDoc::SetSequenceOptions(BOOL altline, BOOL scal, BOOL fill, BOOL usekey, DWORD key)
  595. {
  596.     HRESULT hr;
  597.  
  598.     m_r4SeqData.mtType = MT_DECODE_SEQ_VALUE;
  599.     m_r4SeqData.dwFlags =    DECSEQ_KEY |
  600.                             DECSEQ_SCALABILITY |
  601.                             DECSEQ_FILL_TRANSPARENT |
  602.                             DECSEQ_ALT_LINE |
  603.                             DECSEQ_VALID;
  604.  
  605.     m_r4SeqData.fAltLine = altline;
  606.     m_r4SeqData.fScalability = scal;
  607.     m_r4SeqData.fFillTransparentPixels = fill;
  608.     m_r4SeqData.fEnabledKey = usekey;
  609.     m_r4SeqData.dwKey = key;
  610.  
  611.     hr = ((IIndeoDecode *)m_pIndeo)->set_DecodeSequence(&m_r4SeqData);
  612.  
  613.     if (FAILED( hr )) 
  614.         AfxMessageBox(IDS_CANT_SET_SEQ_DATA);
  615.  
  616.     return;
  617. }
  618.  
  619. void CIPlayDoc::GetFrameDefaults(int& b, int& c, int& s,    DWORD& time,
  620.                       DWORD& dx, DWORD& dy, DWORD& dWidth, DWORD& dHeight,
  621.                       DWORD& vx, DWORD& vy, DWORD& vWidth, DWORD& vHeight)
  622. {
  623.     HRESULT hr;
  624.  
  625.     m_r4FrameData.mtType = MT_DECODE_FRAME_DEFAULT;
  626.     m_r4FrameData.dwFlags = DECFRAME_BRIGHTNESS |
  627.                             DECFRAME_CONTRAST |
  628.                             DECFRAME_SATURATION | 
  629.                               DECFRAME_TIME_LIMIT |
  630.                             DECFRAME_DECODE_RECT |
  631.                             DECFRAME_VIEW_RECT |
  632.                             DECFRAME_VALID;
  633.  
  634.     hr = ((IIndeoDecode *)m_pIndeo)->get_DecodeFrame(&m_r4FrameData);
  635.  
  636.     if (FAILED( hr )) {
  637.         AfxMessageBox(IDS_CANT_GET_FRAME_DATA);
  638.         return;
  639.     }
  640.  
  641.     b = LOWORD(m_r4FrameData.lBrightness);
  642.     c = LOWORD(m_r4FrameData.lContrast);
  643.     s = LOWORD(m_r4FrameData.lSaturation);
  644.     time = m_r4FrameData.dwTimeLimit;
  645.     dx = m_r4FrameData.rDecodeRect.dwX;
  646.     dy = m_r4FrameData.rDecodeRect.dwY;
  647.     dWidth = m_r4FrameData.rDecodeRect.dwWidth;
  648.     dHeight = m_r4FrameData.rDecodeRect.dwHeight;
  649.     vx = m_r4FrameData.rViewRect.dwX;
  650.     vy = m_r4FrameData.rViewRect.dwY;
  651.     vWidth = m_r4FrameData.rViewRect.dwWidth;
  652.     vHeight = m_r4FrameData.rViewRect.dwHeight;
  653.  
  654.     return;
  655. }
  656.  
  657. void CIPlayDoc::GetSeqDefaults(BOOL& altline, BOOL& scal, BOOL& trans, BOOL& usekey,
  658.     DWORD& key)
  659. {
  660.     HRESULT hr;
  661.  
  662.     m_r4SeqData.mtType = MT_DECODE_SEQ_DEFAULT;
  663.     m_r4SeqData.dwFlags =    DECSEQ_KEY |
  664.                             DECSEQ_SCALABILITY |
  665.                             DECSEQ_FILL_TRANSPARENT |
  666.                             DECSEQ_ALT_LINE |
  667.                             DECSEQ_VALID;
  668.  
  669.     hr = ((IIndeoDecode *)m_pIndeo)->get_DecodeSequence(&m_r4SeqData);
  670.  
  671.     if (FAILED( hr )) {
  672.         AfxMessageBox(IDS_CANT_GET_SEQ_DATA);
  673.         return;
  674.     }
  675.  
  676.     altline = m_r4SeqData.fAltLine;
  677.     scal = m_r4SeqData.fScalability;
  678.     trans = m_r4SeqData.fFillTransparentPixels;
  679.     usekey = m_r4SeqData.fEnabledKey;
  680.     key = m_r4SeqData.dwKey;
  681. }
  682.  
  683. ULONG CIPlayDoc::VideoWidth()
  684. {
  685.     HRESULT hr;
  686.     IBasicVideo *pIF;
  687.     long width;
  688.  
  689.     hr = m_pGraph->QueryInterface(IID_IBasicVideo, (void **)&pIF);
  690.  
  691.     if( FAILED(hr) )     {
  692.         AfxMessageBox(IDS_CANT_GET_VIDEO_INTERFACE);
  693.         return 0;
  694.     }
  695.  
  696.     pIF->get_DestinationWidth(&width);
  697.     pIF->Release();
  698.  
  699.     return width;
  700.  
  701. }
  702.  
  703. ULONG CIPlayDoc::VideoHeight()
  704. {
  705.     HRESULT hr;
  706.     IBasicVideo *pIF;
  707.     long height;
  708.  
  709.     hr = m_pGraph->QueryInterface(IID_IBasicVideo, (void **)&pIF);
  710.  
  711.     if( FAILED(hr) )     {
  712.         AfxMessageBox(IDS_CANT_GET_VIDEO_INTERFACE);
  713.         return 0;
  714.     }
  715.  
  716.     pIF->get_DestinationHeight(&height);
  717.     pIF->Release();
  718.  
  719.     return height;
  720.  
  721. }
  722.  
  723. /////////////////////////////////////////////////////////////////////////////
  724. // CIPlayDoc protected funtions
  725.  
  726. BOOL CIPlayDoc::CreateFilterGraph(void) {
  727.     HRESULT hr;    // return code
  728.  
  729.  
  730.     ASSERT(m_pGraph == NULL);
  731.  
  732.     // Create this document's filter graph object
  733.     hr = CoCreateInstance(CLSID_FilterGraph,     
  734.                           NULL,
  735.                           CLSCTX_INPROC_SERVER,
  736.                           IID_IFilterGraph,
  737.                           (void **) &m_pGraph);
  738.  
  739.  
  740.     if (FAILED(hr)){
  741.         m_pGraph = NULL;
  742.         return FALSE;
  743.     }
  744.  
  745.     // get media event handle 
  746.     IMediaEvent *pME;
  747.     hr = m_pGraph->QueryInterface(IID_IMediaEvent, (void **) &pME);
  748.     if (FAILED(hr)) {
  749.         DeleteContents();
  750.         return FALSE;
  751.     }
  752.  
  753.     hr = pME->GetEventHandle((OAEVENT*) &m_hGraphEvent);
  754.  
  755.     pME->Release();
  756.  
  757.     if (FAILED(hr)) {
  758.         DeleteContents();
  759.         return FALSE;
  760.     }
  761.     return TRUE;
  762. }
  763.  
  764. void CIPlayDoc::DeleteContents() 
  765. {
  766.     // Release all interfaces to graph
  767.     // and filters.
  768.  
  769.     if (m_pIndeo != NULL) {
  770.          ((IIndeoDecode *)m_pIndeo)->Release();
  771.         m_pIndeo = NULL;
  772.     }
  773.  
  774.     if (m_pGraph != NULL) {
  775.         m_pGraph->Release();
  776.         m_pGraph = NULL;
  777.     }
  778.  
  779.     m_hGraphEvent = NULL;
  780.  
  781.     m_State = Uninitialized;
  782. }
  783.  
  784. void CIPlayDoc::SetWindow(BSTR wPath)
  785. {
  786.     HRESULT hr;
  787.     IVideoWindow *pVidWin;
  788.     RECT rDeskTop;
  789.     int x, y;
  790.  
  791.     hr = m_pGraph->QueryInterface(IID_IVideoWindow, (void **)&pVidWin);
  792.  
  793.     if( FAILED(hr) )     {
  794.         AfxMessageBox(IDS_CANT_GET_WINDOW_INTERFACE);
  795.         return;
  796.     }
  797.  
  798.     // Set the caption of the video window
  799.     pVidWin->put_Caption(wPath);
  800.  
  801.     // Save the original size for zoom x 2
  802.     pVidWin->get_Width(&m_lWinWidth);
  803.     pVidWin->get_Height(&m_lWinHeight);
  804.  
  805.     // Center the window on the screen
  806.        GetWindowRect(GetDesktopWindow(), &rDeskTop);
  807.  
  808.     if (  m_lWinWidth < (rDeskTop.right - rDeskTop.left) ) 
  809.            x = ((rDeskTop.right - rDeskTop.left) - m_lWinWidth) / 2;
  810.     else
  811.         x = rDeskTop.left;
  812.  
  813.     if ( m_lWinHeight < (rDeskTop.bottom - rDeskTop.top) ) 
  814.         y = ((rDeskTop.bottom - rDeskTop.top) - m_lWinHeight) / 2;
  815.     else
  816.         y = rDeskTop.top;
  817.  
  818.     pVidWin->SetWindowPosition(x, y, m_lWinWidth, m_lWinHeight);
  819.  
  820.     pVidWin->Release();
  821. }
  822.  
  823.  
  824.