playhpnv.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:17k
源码类别:

Symbian

开发平台:

Visual C++

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