playhpnv.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:16k
源码类别:

Symbian

开发平台:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0/RPSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
  5.  *      
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of the RealNetworks Public Source License 
  8.  * Version 1.0 (the "RPSL") available at 
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed 
  10.  * the file under the RealNetworks Community Source License Version 1.0 
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
  12.  * in which case the RCSL will apply. You may also obtain the license terms 
  13.  * directly from RealNetworks.  You may not use this file except in 
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or 
  16.  * RCSL for the rights, obligations and limitations governing use of the 
  17.  * contents of the file.  
  18.  *  
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  20.  * developer of the Original Code and owns the copyrights in the portions 
  21.  * it created. 
  22.  *  
  23.  * This file, and the files included with this file, is distributed and made 
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  28.  * 
  29.  * Technology Compatibility Kit Test Suite(s) Location: 
  30.  *    http://www.helixcommunity.org/content/tck 
  31.  * 
  32.  * Contributor(s): 
  33.  *  
  34.  * ***** END LICENSE BLOCK ***** */ 
  35. #include "hlxclib/stdio.h"
  36. #if defined(_AIX)
  37. #include <string.h>
  38. #define strnicmp strncasecmp
  39. #endif // _AIX
  40. #include "hxtypes.h"
  41. #include "hxresult.h"
  42. #include "hxcom.h"
  43. #include "hxprefs.h"
  44. #include "hxhyper.h"
  45. #include "hxplugn.h"
  46. #include "hxfiles.h"
  47. #include "hxtick.h"
  48. #include "plghand2.h"
  49. #include "hxcore.h"
  50. #include "playhpnv.h"
  51. #include "dbcs.h"
  52. #include "hxstring.h"
  53. #include "hxrquest.h"
  54. #include "nptime.h"
  55. #include "chxpckts.h"
  56. #include "hxstrutl.h"
  57. #include "hxgroup.h"
  58. #include "hxmon.h"
  59. #include "dbcs.h"
  60. #include "corshare.h"
  61. #include "hxheap.h"
  62. #ifdef _DEBUG
  63. #undef HX_THIS_FILE
  64. static const char HX_THIS_FILE[] = __FILE__;
  65. #endif
  66. /****************************************************************************
  67.  *
  68.  *  Interface:
  69.  *
  70.  * HXHyperNavigate
  71.  *
  72.  *  Purpose:
  73.  *
  74.  * TBD
  75.  *
  76.  *  IID_IHXHyperNavigate:
  77.  *
  78.  * {00000900-61DF-11d0-9CEE-080017035B43}
  79.  *
  80.  */
  81. PlayerHyperNavigate::PlayerHyperNavigate() :
  82.       m_bInitialized(FALSE)
  83.     , m_lRefCount(0)
  84.     , m_pContext(NULL)
  85.     , m_pPlayer(0)
  86.     , m_pGroupManager(0)
  87.     , m_pHyperNavigate(0)
  88.     , m_pHyperNavigateWithContext(NULL)
  89.     , m_pPendingRequest(NULL)
  90.     , m_pScheduler(NULL)
  91.     , m_CallbackHandle(0)
  92.     , m_pFileObject(0)
  93. {
  94. }
  95. PlayerHyperNavigate::~PlayerHyperNavigate()
  96. {
  97.     Close();
  98. }
  99. /////////////////////////////////////////////////////////////////////////
  100. // Method:
  101. // IUnknown::QueryInterface
  102. // Purpose:
  103. // Implement this to export the interfaces supported by your
  104. // object.
  105. //
  106. STDMETHODIMP PlayerHyperNavigate::QueryInterface(REFIID riid, void** ppvObj)
  107. {
  108.     QInterfaceList qiList[] =
  109.         {
  110.             { GET_IIDHANDLE(IID_IHXHyperNavigate), (IHXHyperNavigate*)this },
  111.             { GET_IIDHANDLE(IID_IHXHyperNavigate2), (IHXHyperNavigate2*)this },
  112.             { GET_IIDHANDLE(IID_IHXHyperNavigateHint), (IHXHyperNavigateHint*)this },
  113.             { GET_IIDHANDLE(IID_IHXHTTPRedirectResponse), (IHXHTTPRedirectResponse*)this },
  114.             { GET_IIDHANDLE(IID_IHXFileSystemManagerResponse), (IHXFileSystemManagerResponse*)this },
  115.             { GET_IIDHANDLE(IID_IHXCallback), (IHXCallback*)this },
  116.             { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXHyperNavigate*)this },
  117.         };
  118.     
  119.     return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
  120. }
  121. /////////////////////////////////////////////////////////////////////////
  122. // Method:
  123. // IUnknown::AddRef
  124. // Purpose:
  125. // Everyone usually implements this the same... feel free to use
  126. // this implementation.
  127. //
  128. STDMETHODIMP_(ULONG32) PlayerHyperNavigate::AddRef()
  129. {
  130.     return InterlockedIncrement(&m_lRefCount);
  131. }
  132. /////////////////////////////////////////////////////////////////////////
  133. // Method:
  134. // IUnknown::Release
  135. // Purpose:
  136. // Everyone usually implements this the same... feel free to use
  137. // this implementation.
  138. //
  139. STDMETHODIMP_(ULONG32) PlayerHyperNavigate::Release()
  140. {
  141.     if (InterlockedDecrement(&m_lRefCount) > 0)
  142.     {
  143. return m_lRefCount;
  144.     }
  145.     delete this;
  146.     return 0;
  147. }
  148. void     
  149. PlayerHyperNavigate::Close(void)
  150. {
  151.     HX_RELEASE(m_pFileObject);
  152.     HX_RELEASE(m_pContext);
  153.     HX_RELEASE(m_pPlayer);
  154.     HX_RELEASE(m_pGroupManager);
  155.     HX_RELEASE(m_pHyperNavigate);
  156.     HX_RELEASE(m_pHyperNavigateWithContext);
  157.     HX_RELEASE(m_pPendingRequest);
  158.     if (m_CallbackHandle && m_pScheduler)
  159.     {
  160. m_pScheduler->Remove(m_CallbackHandle);
  161. m_CallbackHandle = 0;
  162.     }
  163.     HX_RELEASE(m_pScheduler);
  164. }
  165. STDMETHODIMP PlayerHyperNavigate::Init(IUnknown* pContext, IHXHyperNavigate* pHyperNavigate, 
  166.        IHXHyperNavigateWithContext* pHyperNavigateWithContext)
  167. {
  168.     if (!pContext)
  169.     {
  170. return HXR_UNEXPECTED;
  171.     }
  172.     m_pContext = pContext;
  173.     m_pContext->AddRef();
  174.     IHXPlayer* pPlayer = 0;
  175.     if (pContext && pContext->QueryInterface(IID_IHXPlayer, (void**)&pPlayer) == HXR_OK)
  176.     {
  177.         m_pPlayer = pPlayer;
  178.     }
  179.     IHXGroupManager* pGroupManager = 0;
  180.     if (m_pPlayer && m_pPlayer->QueryInterface(IID_IHXGroupManager, (void**)&pGroupManager) == HXR_OK)
  181.     {
  182. m_pGroupManager = pGroupManager;
  183.     }
  184.     if (m_pPlayer)
  185.     {
  186. m_pPlayer->QueryInterface(IID_IHXScheduler, (void**)&m_pScheduler);
  187.     }
  188.     m_pHyperNavigate = pHyperNavigate;
  189.     m_pHyperNavigateWithContext = pHyperNavigateWithContext;
  190.     if (m_pHyperNavigate)
  191. m_pHyperNavigate->AddRef();
  192.     if (m_pHyperNavigateWithContext)
  193. m_pHyperNavigateWithContext->AddRef();
  194.     m_bInitialized = TRUE;
  195.     return HXR_OK;
  196. }
  197. /*
  198.  * IHXHyperNavigate methods
  199.  */
  200. #define URL_COMMAND_SEEK "seek("
  201. #define URL_COMMAND_PLAY "play("
  202. #define URL_COMMAND_PAUSE "pause("
  203. #define URL_COMMAND_STOP "stop("
  204. #define URL_COMMAND_PREVIOUSCLIP "previousclip("
  205. #define URL_COMMAND_NEXTCLIP "nextclip("
  206. #define URL_COMMAND_ADSCOOKIES "adscookies("
  207. /************************************************************************
  208.  * Method:
  209.  *     IHXHyperNavigate::GoToURL
  210.  * Purpose:
  211.  *     Parses and delegates player commands or performs a simple Go To
  212.  *          URL operation in the user's browser.
  213.  */
  214. STDMETHODIMP PlayerHyperNavigate::GoToURL(const char* pURL, const char* pTarget)
  215. {
  216.     return ExecuteWithContext(pURL, pTarget, NULL, NULL, NULL, NULL);
  217. }
  218. /************************************************************************
  219.  * Method:
  220.  *     IHXHyperNavigate2::Execute
  221.  * Purpose:
  222.  *     
  223.  * Parameters:
  224.  *      pURL:     URL (absolute or relative)
  225.  *     pTargetInstance:
  226.  *     pTargetApplication: 
  227.  *     pTargetRegion:
  228.  *     pParams:
  229.  */
  230. STDMETHODIMP 
  231. PlayerHyperNavigate::Execute(const char* pURL,
  232.      const char* pTargetInstance,
  233.      const char* pTargetApplication,
  234.      const char* pTargetRegion,
  235.      IHXValues* pParams)
  236. {
  237.     return ExecuteWithContext(pURL, pTargetInstance, pTargetApplication,
  238.       pTargetRegion, pParams, NULL);
  239. }
  240. HX_RESULT
  241. PlayerHyperNavigate::ExecuteWithContext(const char* pURL,
  242. const char* pTargetInstance,
  243. const char* pTargetApplication,
  244. const char* pTargetRegion,
  245. IHXValues* pParams,
  246. IUnknown* pContext)
  247. {
  248.     if (!m_bInitialized)
  249.     {
  250. return HXR_NOT_INITIALIZED;
  251.     }
  252.     if (pURL == NULL)
  253.     {
  254. return HXR_FAIL;
  255.     }
  256.     HX_RESULT hxrResult = HXR_NOTIMPL;
  257.     // first, deleegate to the alternate hypernavigation interface
  258.     if (m_pHyperNavigateWithContext)
  259.     {
  260. hxrResult = m_pHyperNavigateWithContext->ExecuteWithContext(pURL, pTargetInstance, 
  261.     pTargetApplication, pTargetRegion, pParams, pContext);
  262.     }
  263.     else if (m_pHyperNavigate)
  264.     {
  265. hxrResult = m_pHyperNavigate->GoToURL(pURL, pTargetInstance);
  266.     }
  267.     // if alternate hypernavigation says it doesn't implement
  268.     if (hxrResult != HXR_NOTIMPL)
  269. return(hxrResult);
  270.     return HandleCommands(pURL, pTargetInstance, pParams);
  271. }
  272. STDMETHODIMP 
  273. PlayerHyperNavigate::Hint(const char* pURL,
  274.                           const char* pTarget,
  275.                           IHXValues*  pParams)
  276. {
  277.     HX_RESULT     hxrResult = HXR_NOTIMPL;
  278.     IHXHyperNavigateHint*   pHyperNavigateHint = NULL;
  279.     if (m_pHyperNavigateWithContext)
  280.     {
  281. m_pHyperNavigateWithContext->QueryInterface(IID_IHXHyperNavigateHint, (void**) &pHyperNavigateHint);
  282.     }
  283.     if (!pHyperNavigateHint && m_pHyperNavigate)
  284.     {
  285. m_pHyperNavigate->QueryInterface(IID_IHXHyperNavigateHint, (void**) &pHyperNavigateHint);
  286.     }
  287.     if (pHyperNavigateHint)
  288.     {
  289. hxrResult = pHyperNavigateHint->Hint(pURL, pTarget, pParams);
  290. HX_RELEASE(pHyperNavigateHint);
  291.     }
  292.     return hxrResult;
  293. }
  294. HX_RESULT
  295. PlayerHyperNavigate::HandleCommands(const char* pURL, const char* pTarget, IHXValues* pParams)
  296. {
  297.     HX_RESULT hxrResult = HXR_NOTIMPL;
  298.     char* pArgument = NULL;
  299.     //
  300.     // Check for player commands.
  301.     //
  302.     if (strnicmp(pURL, URL_COMMAND, sizeof(URL_COMMAND) - 1) == 0)
  303.     {
  304. const char *pOpen = HXFindChar(pURL, '(');
  305. const char *pClose = HXReverseFindChar(pURL, ')');
  306. if (! pOpen || ! pClose || (pOpen > pClose))
  307. {
  308.     return HXR_FAILED;
  309. }
  310. // beginning of actual player command
  311. const char* pCommand = pURL + sizeof(URL_COMMAND) - 1;
  312. int   iLength = pClose - (pOpen + 1);
  313. if (strnicmp(pCommand, URL_COMMAND_SEEK, sizeof(URL_COMMAND_SEEK) - 1) == 0)
  314. {
  315.     if (m_pPlayer)
  316.     {
  317. pArgument = new_string(pOpen + 1, iLength);
  318. if (!pArgument)
  319. {
  320.     return HXR_OUTOFMEMORY;
  321. }
  322. NPTime  time(pArgument);
  323. hxrResult = m_pPlayer->Seek(time);
  324.     }
  325. }
  326. else if (strnicmp(pCommand, URL_COMMAND_PLAY, sizeof(URL_COMMAND_PLAY) - 1) == 0)
  327. {
  328.     if ((iLength == 0) && m_pPlayer)
  329.     {
  330. hxrResult = m_pPlayer->Begin();
  331.     }
  332. }
  333. else if (strnicmp(pCommand, URL_COMMAND_PAUSE, sizeof(URL_COMMAND_PAUSE) - 1) == 0)
  334. {
  335.     if ((iLength == 0) && m_pPlayer)
  336.     {
  337. hxrResult = m_pPlayer->Pause();
  338.     }
  339. }
  340. else if (strnicmp(pCommand, URL_COMMAND_STOP, sizeof(URL_COMMAND_STOP) - 1) == 0)
  341. {
  342.     if ((iLength == 0) && m_pPlayer)
  343.     {
  344. hxrResult = m_pPlayer->Stop();
  345.     }
  346. }
  347. else if (strnicmp(pCommand, URL_COMMAND_PREVIOUSCLIP, sizeof(URL_COMMAND_PREVIOUSCLIP) - 1) == 0)
  348. {
  349.     if ((iLength == 0) && m_pGroupManager)
  350.     {
  351. UINT16  iCurrent = 0;
  352. m_pGroupManager->GetCurrentGroup(iCurrent);
  353. // play previous clip if one exists
  354. if ((iCurrent > 0) && ((iCurrent - 1) < m_pGroupManager->GetGroupCount()))
  355. {
  356.     hxrResult = m_pGroupManager->SetCurrentGroup(iCurrent - 1);
  357. }
  358.     }
  359. }
  360. else if (strnicmp(pCommand, URL_COMMAND_NEXTCLIP, sizeof(URL_COMMAND_NEXTCLIP) - 1) == 0)
  361. {
  362.     if ((iLength == 0) && m_pGroupManager)
  363.     {
  364. UINT16  iCurrent = 0;
  365. m_pGroupManager->GetCurrentGroup(iCurrent);
  366. // play next clip if one exists
  367. if (iCurrent < m_pGroupManager->GetGroupCount())
  368. {
  369.     hxrResult = m_pGroupManager->SetCurrentGroup(iCurrent + 1);
  370. }
  371.     }
  372. }
  373. else if (strnicmp(pCommand, URL_COMMAND_ADSCOOKIES, sizeof(URL_COMMAND_ADSCOOKIES) - 1) == 0)
  374. {
  375.     pArgument = new_string(pOpen + 1, iLength);
  376.     if (!pArgument)
  377.     {
  378. return HXR_OUTOFMEMORY;
  379.     }
  380.     hxrResult = SendAdsCookies(pArgument);
  381. }
  382. HX_VECTOR_DELETE(pArgument);
  383. return hxrResult;
  384.     }
  385.     else if (pTarget && stricmp(pTarget, "_player") == 0)
  386.     {
  387. /* we want to unwind the stack...since it may come from
  388.  * an OnTimeSync() into syncMM renderer...and if we call 
  389.  * OpenURL() syncronously, bad things happen in the
  390.  * core (srcinfo gets deleted).
  391.  * use our friendly scheduler...
  392.  */
  393. HX_RELEASE(m_pPendingRequest);
  394. IHXCommonClassFactory* pCommonClassFactory = NULL;
  395. m_pPlayer->QueryInterface(IID_IHXCommonClassFactory,
  396. (void**)&pCommonClassFactory);
  397. if (pCommonClassFactory)
  398. {
  399.     pCommonClassFactory->CreateInstance(IID_IHXRequest, (void**) &m_pPendingRequest);
  400.     HX_ASSERT(m_pPendingRequest);
  401.     if (m_pPendingRequest)
  402.     {
  403. m_pPendingRequest->SetURL(pURL);
  404. if (pParams)
  405. {
  406.     m_pPendingRequest->SetRequestHeaders(pParams);
  407. }
  408.     }
  409.     HX_RELEASE(pCommonClassFactory);
  410. }
  411. if (m_pScheduler && m_pPendingRequest)
  412. {
  413.     if (!m_CallbackHandle)
  414.     {
  415. m_CallbackHandle = m_pScheduler->RelativeEnter((IHXCallback*) this, 0);
  416.     }
  417. }
  418. else
  419. {
  420.     Func();
  421. }
  422. return HXR_OK;
  423.     }
  424.     return HXR_FAILED;
  425. }
  426. /////////////////////////////////////////////////////////////////////////
  427. //  Method:
  428. //   IHXHyperNavigateRedirectResponse::RedirectDone
  429. //
  430. STDMETHODIMP
  431. PlayerHyperNavigate::RedirectDone(IHXBuffer*   pBuffer)
  432. {
  433.     if (pBuffer && m_pHyperNavigate)
  434.     {
  435. // deligate to alternate hypernavigation interface
  436. return m_pHyperNavigate->GoToURL((const char*)pBuffer->GetBuffer(), NULL);
  437.     }
  438.     return HXR_OK;
  439. }
  440. /************************************************************************
  441.  * Method:
  442.  * IHXFileSystemManagerResponse::InitDone
  443.  * Purpose:
  444.  */
  445. STDMETHODIMP
  446. PlayerHyperNavigate::InitDone(HX_RESULT status)
  447. {
  448.     return HXR_OK;
  449. }
  450. STDMETHODIMP
  451. PlayerHyperNavigate::FileObjectReady(HX_RESULT status,
  452.      IUnknown* pObject)
  453. {   
  454.     HX_RESULT theErr = HXR_OK;
  455.     IHXHTTPRedirect* pRedirect = NULL;
  456.     if (!pObject)
  457.     {
  458. theErr = HXR_FAILED;
  459.     }
  460.     else if (HXR_OK != pObject->QueryInterface(IID_IHXFileObject, (void**)&m_pFileObject))
  461.     {
  462. theErr = HXR_FAILED;
  463.     }
  464.     else if (HXR_OK != pObject->QueryInterface(IID_IHXHTTPRedirect, (void**)&pRedirect))
  465.     {
  466. theErr = HXR_FAILED;
  467.     }
  468.     else
  469.     {
  470. theErr = pRedirect->Init((IHXHTTPRedirectResponse*)this);
  471.     }
  472.     HX_RELEASE(pRedirect);
  473.     return theErr;
  474. }
  475. /*
  476.  * The following method is deprecated and should return HXR_NOTIMPL
  477.  */
  478. STDMETHODIMP
  479. PlayerHyperNavigate::DirObjectReady(HX_RESULT status,
  480.     IUnknown* pDirObject)
  481. {
  482.     return HXR_NOTIMPL;
  483. }
  484. /*
  485.  * IHXCallback methods
  486.  */
  487. STDMETHODIMP
  488. PlayerHyperNavigate::Func()
  489. {
  490.     m_CallbackHandle = 0;
  491.     if (m_pPlayer && m_pPendingRequest)
  492.     {
  493. IHXPlayer2* pPlayer2 = NULL;
  494. m_pPlayer->QueryInterface(IID_IHXPlayer2, (void**) &pPlayer2);
  495. pPlayer2->OpenRequest(m_pPendingRequest);
  496. m_pPlayer->Begin();
  497. pPlayer2->Release();
  498. HX_RELEASE(m_pPendingRequest);
  499.     }
  500.     return HXR_OK;
  501. }
  502. HX_RESULT
  503. PlayerHyperNavigate::SendAdsCookies(char* pURL)
  504. {
  505.     HX_RESULT     hr = HXR_OK;
  506.     IHXRequest*     pRequest = NULL;
  507.     IHXFileSystemManager*  pFileSystemManager = NULL;
  508.     IHXCommonClassFactory* pCommonClassFactory = NULL;
  509.     if (HXR_OK != m_pPlayer->QueryInterface(IID_IHXCommonClassFactory,
  510.     (void**)&pCommonClassFactory))
  511.     {
  512. hr = HXR_FAILED;
  513.     }
  514.     else if (HXR_OK != pCommonClassFactory->CreateInstance(CLSID_IHXFileSystemManager,
  515.      (void**)&pFileSystemManager))
  516.     {
  517. hr = HXR_FAILED;
  518.     }
  519.     else if (HXR_OK != pFileSystemManager->Init((IHXFileSystemManagerResponse*)this))
  520.     {
  521. hr = HXR_FAILED;
  522.     }
  523.     else
  524.     {
  525. IHXPreferences* pPreferences = NULL;
  526. if (m_pPlayer->QueryInterface(IID_IHXPreferences, (void **) &pPreferences) == HXR_OK)
  527. {
  528.     IHXRegistry* pRegistry = NULL;   
  529.     m_pPlayer->QueryInterface(IID_IHXRegistry, (void**)&pRegistry);
  530.     ::SetRequest(pURL,
  531.  FALSE,
  532.  pPreferences,
  533.  pRegistry,
  534.  NULL,
  535.  pRequest);
  536.     HX_RELEASE(pRegistry);
  537. }
  538. HX_RELEASE(pPreferences);
  539. hr = pFileSystemManager->GetNewFileObject(pRequest, 0);
  540.     }
  541.     HX_RELEASE(pRequest);
  542.     HX_RELEASE(pFileSystemManager);
  543.     HX_RELEASE(pCommonClassFactory);
  544.     return hr;
  545. }