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

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: mediamrk.cpp,v 1.3.20.1 2004/07/09 02:05:58 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. #if defined(HELIX_FEATURE_MEDIAMARKER)
  50. // include
  51. #include "hxtypes.h"
  52. #include "hxcom.h"
  53. #include "hxresult.h"
  54. #include "hxengin.h"
  55. #include "hxcore.h"
  56. #include "hxgroup.h"
  57. #include "hxmmrkr.h"
  58. // pncont
  59. #include "hxslist.h"
  60. #include "hxmap.h"
  61. // rmacore
  62. #include "hxplay.h"
  63. #include "hxcleng.h"
  64. #include "mediamrk.h"
  65. // pndebug
  66. #include "hxheap.h"
  67. #ifdef _DEBUG
  68. #undef HX_THIS_FILE             
  69. static const char HX_THIS_FILE[] = __FILE__;
  70. #endif
  71. CMarkerInfo::CMarkerInfo(IHXBuffer* pURLStr,
  72.                          IHXBuffer* pNameStr,
  73.                          UINT32      ulTime,
  74.                          IHXValues* pOtherParams)
  75. {
  76.     m_pURLStr      = pURLStr;
  77.     m_pNameStr     = pNameStr;
  78.     m_ulTime       = ulTime;
  79.     m_pOtherParams = pOtherParams;
  80.     if (m_pURLStr)      m_pURLStr->AddRef();
  81.     if (m_pNameStr)     m_pNameStr->AddRef();
  82.     if (m_pOtherParams) m_pOtherParams->AddRef();
  83. }
  84. CMarkerInfo::~CMarkerInfo()
  85. {
  86.     HX_RELEASE(m_pURLStr);
  87.     HX_RELEASE(m_pNameStr);
  88.     HX_RELEASE(m_pOtherParams);
  89. }
  90. CHXMediaMarkerManager::CHXMediaMarkerManager(HXPlayer* pPlayer)
  91. {
  92.     m_lRefCount   = 0;
  93.     m_pPlayer     = pPlayer;
  94.     m_pMarkerList = NULL;
  95.     m_pSinkList   = NULL;
  96.     if (m_pPlayer)
  97.     {
  98.         m_pPlayer->AddRef();
  99.     }
  100. }
  101. CHXMediaMarkerManager::~CHXMediaMarkerManager()
  102. {
  103.     Close();
  104. }
  105. STDMETHODIMP CHXMediaMarkerManager::QueryInterface(REFIID riid, void** ppvObj)
  106. {
  107.     HX_RESULT retVal = HXR_OK;
  108.     if (ppvObj)
  109.     {
  110.         QInterfaceList qiList[] =
  111.             {
  112.                 { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXMediaMarkerManager*)this },
  113.                 { GET_IIDHANDLE(IID_IHXMediaMarkerManager), (IHXMediaMarkerManager*)this },
  114.             };
  115.         
  116.         retVal = ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
  117.     }
  118.     else
  119.     {
  120.         retVal = HXR_FAIL;
  121.     }
  122.     return retVal;
  123. }
  124. STDMETHODIMP_(ULONG32) CHXMediaMarkerManager::AddRef()
  125. {
  126.     return InterlockedIncrement(&m_lRefCount);
  127. }
  128. STDMETHODIMP_(ULONG32) CHXMediaMarkerManager::Release()
  129. {
  130.     if (InterlockedDecrement(&m_lRefCount) > 0)
  131.     {
  132.         return m_lRefCount;
  133.     }
  134.     delete this;
  135.     return 0;
  136. }
  137. STDMETHODIMP CHXMediaMarkerManager::Close()
  138. {
  139.     HX_RESULT retVal = HXR_OK;
  140.     HX_RELEASE(m_pPlayer);
  141.     ClearMarkerList();
  142.     ClearSinkList();
  143.     return retVal;
  144. }
  145. STDMETHODIMP CHXMediaMarkerManager::AddMediaMarkerSink(IHXMediaMarkerSink* pSink)
  146. {
  147.     HX_RESULT retVal = HXR_FAIL;
  148.     if (pSink)
  149.     {
  150.         // Do we have a list?
  151.         if (!m_pSinkList)
  152.         {
  153.             m_pSinkList = new CHXSimpleList();
  154.         }
  155.         if (m_pSinkList)
  156.         {
  157.             // Make sure this sink is not already on the list
  158.             if (!WasSinkAdded(pSink))
  159.             {
  160.                 // AddRef before we put it on the list
  161.                 pSink->AddRef();
  162.                 // Now put this sink on the tail of the list
  163.                 m_pSinkList->AddTail((void*) pSink);
  164.                 // Clear the return value
  165.                 retVal = HXR_OK;
  166.             }
  167.         }
  168.     }
  169.     return retVal;
  170. }
  171. STDMETHODIMP CHXMediaMarkerManager::RemoveMediaMarkerSink(IHXMediaMarkerSink* pSink)
  172. {
  173.     HX_RESULT retVal = HXR_OK;
  174.     if (pSink)
  175.     {
  176.         if (m_pSinkList)
  177.         {
  178.             LISTPOSITION pos = m_pSinkList->GetHeadPosition();
  179.             while (pos)
  180.             {
  181.                 IHXMediaMarkerSink* pListSink =
  182.                     (IHXMediaMarkerSink*) m_pSinkList->GetAt(pos);
  183.                 if (pListSink == pSink)
  184.                 {
  185.                     m_pSinkList->RemoveAt(pos);
  186.                     HX_RELEASE(pListSink);
  187.                     break;
  188.                 }
  189.                 m_pSinkList->GetNext(pos);
  190.             }
  191.         }
  192.     }
  193.     else
  194.     {
  195.         retVal = HXR_FAIL;
  196.     }
  197.     return retVal;
  198. }
  199. STDMETHODIMP CHXMediaMarkerManager::AddMediaMarkerSinkFilter(IHXMediaMarkerSink* pSink,
  200.                                                               IHXValues*          pFilter)
  201. {
  202.     HX_RESULT retVal = HXR_NOTIMPL;
  203.     return retVal;
  204. }
  205. STDMETHODIMP CHXMediaMarkerManager::ResolveMarker(IHXBuffer* pURLStr,
  206.                                                    IHXBuffer* pMarkerNameStr,
  207.                                                    UINT32      ulTime,
  208.                                                    IHXValues* pOtherMarkerParams)
  209. {
  210.     HX_RESULT retVal = HXR_FAIL;
  211.     if (pURLStr && pMarkerNameStr)
  212.     {
  213.         // Create a CMarkerInfo struct
  214.         CMarkerInfo* pInfo = new CMarkerInfo(pURLStr, pMarkerNameStr,
  215.                                              ulTime, pOtherMarkerParams);
  216.         if (pInfo)
  217.         {
  218.             // Add the marker to all our data structures. This method
  219.             // will fail if an identical marker is already present
  220.             retVal = AddMarkerInfo(pInfo);
  221.             if (SUCCEEDED(retVal))
  222.             {
  223.                 // Now we need to broadcast this marker to
  224.                 // all the sinks who haven't filtered this
  225.                 // marker out. 
  226.                 BroadcastMarkerToSinks(pInfo);
  227.             }
  228.             else
  229.             {
  230.                 HX_DELETE(pInfo);
  231.             }
  232.         }
  233.     }
  234.     return retVal;
  235. }
  236. STDMETHODIMP_(BOOL) CHXMediaMarkerManager::IsMarkerResolved(IHXBuffer* pURLStr,
  237.                                                              IHXBuffer* pMarkerNameStr)
  238. {
  239.     HX_RESULT retVal = HXR_NOTIMPL;
  240.     return retVal;
  241. }
  242. STDMETHODIMP CHXMediaMarkerManager::GetFirstMarker(IHXMediaMarkerSink* pSink,
  243.                                                     REF(IHXBuffer*)     rpURLStr,
  244.                                                     REF(IHXBuffer*)     rpMarkerNameStr,
  245.                                                     REF(UINT32)          rulTime,
  246.                                                     REF(IHXValues*)     rpOtherMarkerParams)
  247. {
  248.     HX_RESULT retVal = HXR_NOTIMPL;
  249.     return retVal;
  250. }
  251. STDMETHODIMP CHXMediaMarkerManager::GetNextMarker(IHXMediaMarkerSink* pSink,
  252.                                                    REF(IHXBuffer*)     rpURLStr,
  253.                                                    REF(IHXBuffer*)     rpMarkerNameStr,
  254.                                                    REF(UINT32)          rulTime,
  255.                                                    REF(IHXValues*)     rpOtherMarkerParams)
  256. {
  257.     HX_RESULT retVal = HXR_NOTIMPL;
  258.     return retVal;
  259. }
  260. void CHXMediaMarkerManager::ClearMarkerList()
  261. {
  262.     if (m_pMarkerList)
  263.     {
  264.         // Run through the list, freeing the marker objects
  265.         LISTPOSITION pos = m_pMarkerList->GetHeadPosition();
  266.         while (pos)
  267.         {
  268.             CMarkerInfo* pInfo = (CMarkerInfo*) m_pMarkerList->GetNext(pos);
  269.             HX_DELETE(pInfo);
  270.         }
  271.         m_pMarkerList->RemoveAll();
  272.         HX_DELETE(m_pMarkerList);
  273.     }
  274. }
  275. void CHXMediaMarkerManager::ClearSinkList()
  276. {
  277.     if (m_pSinkList)
  278.     {
  279.         // Run through the list, releasing the sinks
  280.         LISTPOSITION pos = m_pSinkList->GetHeadPosition();
  281.         while (pos)
  282.         {
  283.             IHXMediaMarkerSink* pSink = (IHXMediaMarkerSink*) m_pSinkList->GetNext(pos);
  284.             HX_RELEASE(pSink);
  285.         }
  286.         m_pSinkList->RemoveAll();
  287.         HX_DELETE(m_pSinkList);
  288.     }
  289. }
  290. BOOL CHXMediaMarkerManager::WasSinkAdded(IHXMediaMarkerSink* pSink)
  291. {
  292.     BOOL bRet = FALSE;
  293.     if (m_pSinkList)
  294.     {
  295.         LISTPOSITION pos = m_pSinkList->GetHeadPosition();
  296.         while (pos)
  297.         {
  298.             IHXMediaMarkerSink* pListSink =
  299.                 (IHXMediaMarkerSink*) m_pSinkList->GetNext(pos);
  300.             if (pListSink == pSink)
  301.             {
  302.                 bRet = TRUE;
  303.                 break;
  304.             }
  305.         }
  306.     }
  307.     return bRet;
  308. }
  309. HX_RESULT CHXMediaMarkerManager::AddMarkerInfo(CMarkerInfo* pInfo)
  310. {
  311.     HX_RESULT retVal = HXR_FAIL;
  312.     if (pInfo)
  313.     {
  314.         // First we add the marker to the master list
  315.         //
  316.         // Do we have a master list yet?
  317.         if (!m_pMarkerList)
  318.         {
  319.             // We don't - create one
  320.             m_pMarkerList = new CHXSimpleList();
  321.         }
  322.         if (m_pMarkerList)
  323.         {
  324.             // This master list will be sorted in increasing time. Therefore,
  325.             // since we expect most datatypes to add markers in increasing
  326.             // time, then we search the list from the TAIL for the right
  327.             // place to insert.
  328.             LISTPOSITION pos = m_pMarkerList->GetTailPosition();
  329.             while (pos)
  330.             {
  331.                 CMarkerInfo* pLInfo = (CMarkerInfo*) m_pMarkerList->GetAt(pos);
  332.                 if (pLInfo && pLInfo->m_ulTime <= pInfo->m_ulTime)
  333.                 {
  334.                     if (!AreMarkersIdentical(pLInfo, pInfo))
  335.                     {
  336.                         // Time of the list marker is either less
  337.                         // than or equal to ours, but we know they
  338.                         // are not the same marker, so we can safely
  339.                         // add our marker after the list marker.
  340.                         m_pMarkerList->InsertAfter(pos, (void*) pInfo);
  341.                         // We DID add the marker, so clear the return value
  342.                         retVal = HXR_OK;
  343.                     }
  344.                     // Whether we added or not, we are bustin' outta here.
  345.                     break;
  346.                 }
  347.                 m_pMarkerList->GetPrev(pos);
  348.             }
  349.             // If we haven't already inserted this marker, then
  350.             // add it at the head and clear the return value
  351.             if (FAILED(retVal))
  352.             {
  353.                 m_pMarkerList->AddHead((void*) pInfo);
  354.                 retVal = HXR_OK;
  355.             }
  356.             // XXXMEH - TODO - Add this marker to any additional
  357.             // data structures we will keep
  358.         }
  359.     }
  360.     return retVal;
  361. }
  362. BOOL CHXMediaMarkerManager::AreMarkersIdentical(CMarkerInfo* pInfo1, CMarkerInfo* pInfo2)
  363. {
  364.     BOOL bRet = FALSE;
  365.     if (pInfo1 && pInfo2)
  366.     {
  367.         // Check url
  368.         if (pInfo1->m_pURLStr && pInfo2->m_pURLStr &&
  369.             !strcmp((const char*) pInfo1->m_pURLStr->GetBuffer(),
  370.                     (const char*) pInfo2->m_pURLStr->GetBuffer()))
  371.         {
  372.             // Check marker name
  373.             if (pInfo1->m_pNameStr && pInfo2->m_pNameStr &&
  374.                 !strcmp((const char*) pInfo1->m_pNameStr->GetBuffer(),
  375.                         (const char*) pInfo2->m_pNameStr->GetBuffer()))
  376.             {
  377.                 // Check time
  378.                 if (pInfo1->m_ulTime == pInfo2->m_ulTime)
  379.                 {
  380.                     bRet = TRUE;
  381.                 }
  382.             }
  383.         }
  384.     }
  385.     return bRet;
  386. }
  387. void CHXMediaMarkerManager::BroadcastMarkerToSinks(CMarkerInfo* pInfo)
  388. {
  389.     if (pInfo && m_pSinkList)
  390.     {
  391.         // Loop through the list of marker sinks
  392.         LISTPOSITION pos = m_pSinkList->GetHeadPosition();
  393.         while (pos)
  394.         {
  395.             // Get the marker sink and check whether this
  396.             // marker should be passed to this sink
  397.             IHXMediaMarkerSink* pSink =
  398.                 (IHXMediaMarkerSink*) m_pSinkList->GetNext(pos);
  399.             if (SinkWantsThisMarker(pSink, pInfo))
  400.             {
  401.                 // This sink DOES want to be notified of this marker,
  402.                 // so call IHXMediaMarkerSink::MarkerResolved()
  403.                 pSink->MarkerResolved(pInfo->m_pURLStr,
  404.                                       pInfo->m_pNameStr,
  405.                                       pInfo->m_ulTime,
  406.                                       pInfo->m_pOtherParams);
  407.             }
  408.         }
  409.     }
  410. }
  411. BOOL CHXMediaMarkerManager::SinkWantsThisMarker(IHXMediaMarkerSink* pSink,
  412.                                                  CMarkerInfo*         pInfo)
  413. {
  414.     BOOL bRet = TRUE;
  415.     return bRet;
  416. }
  417. #endif /* #if defined(HELIX_FEATURE_MEDIAMARKER) */