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

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: pximgfil.cpp,v 1.1.26.1 2004/07/09 01:54:51 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
  50. #include "hxtypes.h"
  51. #include "hxwintyp.h"
  52. #include "hxcom.h"
  53. #include "hxresult.h"
  54. #include "hxcomm.h"
  55. #include "ihxpckts.h"
  56. // hxcont
  57. #include "hxslist.h"
  58. #include "hxstring.h"
  59. #include "hxmap.h"
  60. // hxmisc
  61. #include "baseobj.h"
  62. #include "unkimp.h"
  63. // pxcomlib
  64. #include "pxrect.h"
  65. #include "pxcolor.h"
  66. #include "pxeffect.h"
  67. #include "wirefmgr.h"
  68. #include "pxffmcod.h"
  69. #include "pxcmpmgr.h"
  70. #include "pxffcmgr.h"
  71. #include "pximgfil.h"
  72. // hxdebug
  73. #include "hxheap.h"
  74. #ifdef _DEBUG
  75. #undef HX_THIS_FILE
  76. static char HX_THIS_FILE[] = __FILE__;
  77. #endif
  78. PXImageFile::PXImageFile(PXWireFormatManager*      pWireFormatManager,
  79.                          PXFileFormatCodecManager* pCodecManager,
  80.                          IHXCommonClassFactory*   pCommonClassFactory)
  81. {
  82.     HX_ASSERT(pWireFormatManager);
  83.     if (pWireFormatManager)
  84.     {
  85.         m_pWireFormatManager = pWireFormatManager;
  86.         m_pWireFormatManager->AddRef();
  87.     }
  88.     HX_ASSERT(pCodecManager);
  89.     if (pCodecManager)
  90.     {
  91.         m_pCodecManager = pCodecManager;
  92.         m_pCodecManager->AddRef();
  93.     }
  94.     HX_ASSERT(pCommonClassFactory);
  95.     if (pCommonClassFactory)
  96.     {
  97.         m_pCommonClassFactory = pCommonClassFactory;
  98.         m_pCommonClassFactory->AddRef();
  99.     }
  100.     m_lRefCount     = 0;
  101.     m_ulHandle      = 0;
  102.     m_ulNumPackets  = 0;
  103.     m_ulTotalBytes  = 0;
  104.     m_ulImageWidth  = 0;
  105.     m_ulImageHeight = 0;
  106.     m_pPacketList   = NULL;
  107.     m_pCookieList   = NULL;
  108.     m_pListItr      = NULL;
  109. }
  110. PXImageFile::~PXImageFile()
  111. {
  112.     Deallocate();
  113. };
  114. void PXImageFile::Deallocate()
  115. {
  116.     HX_RELEASE(m_pWireFormatManager);
  117.     HX_RELEASE(m_pCodecManager);
  118.     HX_RELEASE(m_pCommonClassFactory);
  119.     ReleaseAllPackets();
  120.     ClearCookieList();
  121.     HX_DELETE(m_pPacketList);
  122.     HX_DELETE(m_pCookieList);
  123. }
  124. void PXImageFile::ReleaseAllPackets()
  125. {
  126.     if (m_pPacketList)
  127.     {
  128.         LISTPOSITION pos = m_pPacketList->GetHeadPosition();
  129.         while (pos)
  130.         {
  131.             IHXPacket* pPacket = (IHXPacket*) m_pPacketList->GetNext(pos);
  132.             HX_RELEASE(pPacket);
  133.         }
  134.         m_pPacketList->RemoveAll();
  135.     }
  136. }
  137. void PXImageFile::ClearCookieList()
  138. {
  139.     if (m_pCookieList)
  140.     {
  141.         LISTPOSITION pos = m_pCookieList->GetHeadPosition();
  142.         while (pos)
  143.         {
  144.             CookiePair* pPair = (CookiePair*) m_pCookieList->GetNext(pos);
  145.             if (pPair)
  146.             {
  147.                 HX_RELEASE(pPair->m_pURLStr);
  148.                 HX_RELEASE(pPair->m_pCookie);
  149.             }
  150.             HX_DELETE(pPair);
  151.         }
  152.         m_pCookieList->RemoveAll();
  153.     }
  154. }
  155. STDMETHODIMP PXImageFile::QueryInterface(REFIID riid, void** ppvObj)
  156. {
  157.     HX_RESULT retVal = HXR_OK;
  158.     if (IsEqualIID(riid, IID_IUnknown))
  159.     {
  160.         AddRef();
  161.         *ppvObj = (IUnknown *) this;
  162.     }
  163.     else
  164.     {
  165.         *ppvObj = NULL;
  166.         retVal  = HXR_NOINTERFACE;
  167.     }
  168.     return retVal;
  169. }
  170. STDMETHODIMP_(UINT32) PXImageFile::AddRef()
  171. {
  172.     return InterlockedIncrement(&m_lRefCount);
  173. }
  174. STDMETHODIMP_(UINT32) PXImageFile::Release()
  175. {
  176.     
  177.     if (InterlockedDecrement(&m_lRefCount) > 0)
  178.         return m_lRefCount;
  179.     delete this;
  180.     return 0;
  181. }
  182. HX_RESULT PXImageFile::AddCookie(IHXBuffer* pURLStr, IHXBuffer* pCookie)
  183. {
  184.     HX_RESULT retVal = HXR_OK;
  185.     if (pURLStr && pCookie)
  186.     {
  187.         if (!m_pCookieList)
  188.         {
  189.             m_pCookieList = new CHXSimpleList();
  190.             if (!m_pCookieList)
  191.             {
  192.                 retVal = HXR_OUTOFMEMORY;
  193.             }
  194.         }
  195.         if (SUCCEEDED(retVal))
  196.         {
  197.             CookiePair* pPair = new CookiePair;
  198.             if (pPair)
  199.             {
  200.                 pPair->m_pURLStr = pURLStr;
  201.                 pPair->m_pURLStr->AddRef();
  202.                 pPair->m_pCookie = pCookie;
  203.                 pPair->m_pCookie->AddRef();
  204.                 m_pCookieList->AddTail((void*) pPair);
  205.             }
  206.             else
  207.             {
  208.                 retVal = HXR_OUTOFMEMORY;
  209.             }
  210.         }
  211.     }
  212.     else
  213.     {
  214.         retVal = HXR_FAIL;
  215.     }
  216.     return retVal;
  217. }
  218. HX_RESULT PXImageFile::EnqueueCookiePacket()
  219. {
  220.     HX_RESULT retVal = HXR_OK;
  221.     // Add the cookie packet
  222.     if (m_pCookieList)
  223.     {
  224.         if (m_pCookieList->GetCount() > 0)
  225.         {
  226.             IHXBuffer** ppURL = NULL;
  227.             ppURL              = new IHXBuffer* [m_pCookieList->GetCount()];
  228.             if (ppURL)
  229.             {
  230.                 IHXBuffer** ppCookie = NULL;
  231.                 ppCookie              = new IHXBuffer* [m_pCookieList->GetCount()];
  232.                 if (ppCookie)
  233.                 {
  234.                     UINT32       i   = 0;
  235.                     LISTPOSITION pos = m_pCookieList->GetHeadPosition();
  236.                     while (pos)
  237.                     {
  238.                         CookiePair* pPair = (CookiePair*) m_pCookieList->GetNext(pos);
  239.                         if (pPair)
  240.                         {
  241.                             ppURL[i]    = pPair->m_pURLStr;
  242.                             ppCookie[i] = pPair->m_pCookie;
  243.                             i++;
  244.                         }
  245.                     }
  246.                     IHXPacket* pPacket = NULL;
  247.                     retVal              = m_pWireFormatManager->SetCookieInfo(m_pCookieList->GetCount(),
  248.                                                                               ppURL,
  249.                                                                               ppCookie,
  250.                                                                               0,
  251.                                                                               pPacket);
  252.                     if (SUCCEEDED(retVal))
  253.                     {
  254.                         // Add this to the packet list
  255.                         // FALSE makes it add at the head instead of tail
  256.                         retVal = AddPacket(pPacket, FALSE);
  257.                     }
  258.                     HX_RELEASE(pPacket);
  259.                 }
  260.                 HX_VECTOR_DELETE(ppCookie);
  261.             }
  262.             HX_VECTOR_DELETE(ppURL);
  263.             // Clear the cookie list
  264.             ClearCookieList();
  265.         }
  266.     }
  267.     return retVal;
  268. }
  269. HX_RESULT PXImageFile::EnqueueImagePackets(UINT32      ulHandle,
  270.                                            IHXBuffer* pFileBuffer)
  271. {
  272.     HX_RESULT retVal = HXR_FAIL;
  273.     if (ulHandle && pFileBuffer)
  274.     {
  275.         // Save the members
  276.         m_ulHandle = ulHandle;
  277.         // Get a codec to parse this image
  278.         IHXRealPixFileFormatCodec* pCodec = NULL;
  279.         retVal                             = m_pCodecManager->GetCodec(NULL,        // file mime type
  280.                                                                        NULL,        // file name
  281.                                                                        pFileBuffer, // file buffer
  282.                                                                        pCodec);
  283.         if (SUCCEEDED(retVal))
  284.         {
  285.             // Get the mime type for this codec
  286.             const char** ppTmp1        = NULL;
  287.             const char** ppTmp2        = NULL;
  288.             const char*  pszStreamMime = NULL;
  289.             UINT32       ulVer         = 0;
  290.             UINT32       ulMaxPerImg   = 0;
  291.             UINT32       ulMaxPerPckt  = 0;
  292.             retVal                     = pCodec->GetFileFormatCodecInfo(ppTmp1, ppTmp2, pszStreamMime,
  293.                                                                         ulVer, ulMaxPerImg, ulMaxPerPckt);
  294.             if (SUCCEEDED(retVal))
  295.             {
  296.                 IHXPacket* pImageHeaderPacket = NULL;
  297.                 retVal                         = m_pWireFormatManager->SetImageHeaderInfo(ulHandle,
  298.                                                                                           pFileBuffer->GetSize(),
  299.                                                                                           0,
  300.                                                                                           pszStreamMime,
  301.                                                                                           0,
  302.                                                                                           pImageHeaderPacket);
  303.                 if (SUCCEEDED(retVal))
  304.                 {
  305.                     // Add image header packet to list tail
  306.                     retVal = AddPacket(pImageHeaderPacket);
  307.                     if (SUCCEEDED(retVal))
  308.                     {
  309.                         // Parse the image
  310.                         UINT32      ulNumDataPackets = 0;
  311.                         IHXValues* pParam           = NULL;
  312.                         UINT32      ulSessionHandle  = 0;
  313.                         retVal                       = pCodec->ParseImage(pFileBuffer,
  314.                                                                           ulNumDataPackets,
  315.                                                                           pParam,
  316.                                                                           ulSessionHandle);
  317.                         if (SUCCEEDED(retVal))
  318.                         {
  319.                             // Get width and height
  320.                             pParam->GetPropertyULONG32("ImageWidth",  m_ulImageWidth);
  321.                             pParam->GetPropertyULONG32("ImageHeight", m_ulImageHeight);
  322.                             // Get all the image data packets
  323.                             for (UINT32 i = 0; i < ulNumDataPackets && SUCCEEDED(retVal); i++)
  324.                             {
  325.                                 IHXBuffer* pData   = NULL;
  326.                                 IHXBuffer* pOpaque = NULL;
  327.                                 BOOL        bReq    = FALSE;
  328.                                 retVal              = pCodec->GetImagePacket(ulSessionHandle, i, pData, pOpaque, bReq);
  329.                                 if (SUCCEEDED(retVal))
  330.                                 {
  331.                                     IHXPacket* pImageDataPacket = NULL;
  332.                                     retVal                       = m_pWireFormatManager->SetImageDataInfo(ulHandle, pData, pOpaque,
  333.                                                                                                           i, 0, bReq, pImageDataPacket);
  334.                                     if (SUCCEEDED(retVal))
  335.                                     {
  336.                                         // Add image data packet to tail of the list
  337.                                         retVal = AddPacket(pImageDataPacket);
  338.                                     }
  339.                                     HX_RELEASE(pImageDataPacket);
  340.                                 }
  341.                                 HX_RELEASE(pData);
  342.                                 HX_RELEASE(pOpaque);
  343.                             }
  344.                             // Now we're done with this parse session
  345.                             pCodec->ReleaseImage(ulSessionHandle);
  346.                         }
  347.                         HX_RELEASE(pParam);
  348.                     }
  349.                 }
  350.                 HX_RELEASE(pImageHeaderPacket);
  351.             }
  352.         }
  353.         HX_RELEASE(pCodec);
  354.     }
  355.     return retVal;
  356. }
  357. HX_RESULT PXImageFile::EnqueueEffectPacket(UINT32      ulEffectType,
  358.                                            UINT32      ulStart,
  359.                                            UINT32      ulDuration,
  360.                                            UINT32      ulTarget,
  361.                                            const char* pszURL,
  362.                                            UINT32      ulFillColor,
  363.                                            BOOL        bBackChannel,
  364.                                            BOOL        bLastUse,
  365.                                            BOOL        bDisplayImmediately)
  366. {
  367.     HX_RESULT retVal = HXR_OK;
  368.     // Create an effect object
  369.     PXEffect* pEffect = NULL;
  370.     retVal            = PXEffect::CreateObject(&pEffect);
  371.     if (SUCCEEDED(retVal))
  372.     {
  373.         // AddRef the effect
  374.         pEffect->AddRef();
  375.         // Set a bunch of parameters
  376.         pEffect->SetEffectType((BYTE) ulEffectType);
  377.         pEffect->SetStart(ulStart);
  378.         pEffect->SetDuration(ulDuration);
  379.         pEffect->SetTarget(ulTarget);
  380.         if (pszURL)
  381.         {
  382.             pEffect->SetURL(pszURL);
  383.         }
  384.         pEffect->SetColor(ulFillColor);
  385.         pEffect->SetPostBackChannel(bBackChannel);
  386.         pEffect->SetLastUse(bLastUse);
  387.         pEffect->SetDisplayImmediately(bDisplayImmediately);
  388.         // Get the packet
  389.         IHXPacket* pEffectPacket = NULL;
  390.         retVal                     = m_pWireFormatManager->SetEffectInfo(pEffect, 0, pEffectPacket);
  391.         if (SUCCEEDED(retVal))
  392.         {
  393.             // Add the effect packet to the tail
  394.             retVal = AddPacket(pEffectPacket);
  395.         }
  396.         HX_RELEASE(pEffectPacket);
  397.     }
  398.     HX_RELEASE(pEffect);
  399.     return retVal;
  400. }
  401. void PXImageFile::ComputeStatistics()
  402. {
  403.     m_ulNumPackets = 0;
  404.     m_ulTotalBytes = 0;
  405.     if (m_pPacketList)
  406.     {
  407.         if (m_pPacketList->GetCount() > 0)
  408.         {
  409.             // Set the number of packets
  410.             m_ulNumPackets = m_pPacketList->GetCount();
  411.             // Compute the size with overhead
  412.             m_ulTotalBytes   = 0;
  413.             LISTPOSITION pos = m_pPacketList->GetHeadPosition();
  414.             while (pos)
  415.             {
  416.                 IHXPacket* pListPacket = (IHXPacket*) m_pPacketList->GetNext(pos);
  417.                 if (pListPacket)
  418.                 {
  419.                     IHXBuffer *pListBuffer = pListPacket->GetBuffer();
  420.                     if (pListBuffer)
  421.                     {
  422.                         m_ulTotalBytes += pListBuffer->GetSize();
  423.                     }
  424.                     HX_RELEASE(pListBuffer);
  425.                 }
  426.             }
  427.         }
  428.     }
  429. }
  430. HX_RESULT PXImageFile::DequeuePacket(REF(IHXPacket*) rpPacket,
  431.                                      UINT32           ulBitrate,
  432.                                      REF(INT32)       rlCurrentTimeStamp)
  433. {
  434.     HX_RESULT retVal = HXR_FAIL;
  435.     if (ulBitrate && m_pPacketList)
  436.     {
  437.         if (m_pPacketList->GetCount() > 0)
  438.         {
  439.             IHXPacket* pPacket = (IHXPacket*) m_pPacketList->RemoveHead();
  440.             if (pPacket)
  441.             {
  442.                 UINT32      ulTimeStamp = (UINT32) (rlCurrentTimeStamp >= 0 ? rlCurrentTimeStamp : 0);
  443.                 UINT32      ulSize      = 0;
  444.                 IHXPacket* pNewPacket  = NULL;
  445.                 retVal                  = SetPacketTimeStamp(pPacket, ulTimeStamp,
  446.                                                              ulSize, pNewPacket);
  447.                 if (SUCCEEDED(retVal))
  448.                 {
  449.                     // Update the time stamp
  450.                     rlCurrentTimeStamp += (INT32) (ulSize * 8000 / ulBitrate);
  451.                     // Assign the out parameter
  452.                     HX_RELEASE(rpPacket);
  453.                     rpPacket = pNewPacket;
  454.                     rpPacket->AddRef();
  455.                 }
  456.                 HX_RELEASE(pNewPacket);
  457.             }
  458.             HX_RELEASE(pPacket);
  459.         }
  460.     }
  461.     return retVal;
  462. }
  463. HX_RESULT PXImageFile::GetFirstPacket(REF(IHXPacket*) rpPacket)
  464. {
  465.     HX_RESULT retVal = HXR_FAIL;
  466.     if (m_pPacketList)
  467.     {
  468.         LISTPOSITION pos = m_pPacketList->GetHeadPosition();
  469.         if (pos)
  470.         {
  471.             IHXPacket* pPacket = (IHXPacket*) m_pPacketList->GetNext(pos);
  472.             if (pPacket)
  473.             {
  474.                 HX_RELEASE(rpPacket);
  475.                 rpPacket = pPacket;
  476.                 rpPacket->AddRef();
  477.                 m_pListItr = pos;
  478.                 retVal     = HXR_OK;
  479.             }
  480.         }
  481.     }
  482.     return retVal;
  483. }
  484. HX_RESULT PXImageFile::GetNextPacket(REF(IHXPacket*) rpPacket)
  485. {
  486.     HX_RESULT retVal = HXR_FAIL;
  487.     if (m_pPacketList && m_pListItr)
  488.     {
  489.         IHXPacket* pPacket = (IHXPacket*) m_pPacketList->GetNext(m_pListItr);
  490.         if (pPacket)
  491.         {
  492.             HX_RELEASE(rpPacket);
  493.             rpPacket = pPacket;
  494.             rpPacket->AddRef();
  495.             retVal   = HXR_OK;
  496.         }
  497.     }
  498.     return retVal;
  499. }
  500. HX_RESULT PXImageFile::SetPacketTimeStamp(IHXPacket*      pPacket,
  501.                                           UINT32           ulTimeStamp,
  502.                                           REF(UINT32)      rulPacketSize,
  503.                                           REF(IHXPacket*) rpPacket)
  504. {
  505.     return FactorySetTimeStamp(pPacket, m_pCommonClassFactory, ulTimeStamp,
  506.                                rulPacketSize, rpPacket);
  507. }
  508. HX_RESULT PXImageFile::FactorySetTimeStamp(IHXPacket*             pPacket,
  509.                                            IHXCommonClassFactory* pFactory,
  510.                                            UINT32                  ulTimeStamp,
  511.                                            REF(UINT32)             rulPacketSize,
  512.                                            REF(IHXPacket*)        rpPacket)
  513. {
  514.     HX_RESULT retVal = HXR_OK;
  515.     if (pPacket && pFactory)
  516.     {
  517.         // Get the packet parameters
  518.         IHXBuffer* pBuffer         = NULL;
  519.         UINT32      ulTime          = 0;
  520.         UINT16      usStreamNumber  = 0;
  521.         UINT8       ucASMFlags      = 0;
  522.         UINT16      usASMRuleNumber = 0;
  523.         retVal                      = pPacket->Get(pBuffer,
  524.                                                    ulTime,
  525.                                                    usStreamNumber,
  526.                                                    ucASMFlags,
  527.                                                    usASMRuleNumber);
  528.         if (SUCCEEDED(retVal))
  529.         {
  530.             // Create a new packet
  531.             IHXPacket* pNewPacket = NULL;
  532.             retVal                 = pFactory->CreateInstance(CLSID_IHXPacket,
  533.                                                               (void**) &pNewPacket);
  534.             if (SUCCEEDED(retVal))
  535.             {
  536.                 // Set these values with the new timestamp into the new packet
  537.                 retVal = pNewPacket->Set(pBuffer,
  538.                                          ulTimeStamp,
  539.                                          usStreamNumber,
  540.                                          ucASMFlags,
  541.                                          usASMRuleNumber);
  542.                 if (SUCCEEDED(retVal))
  543.                 {
  544.                     // Assign the out parameters
  545.                     rulPacketSize = pBuffer->GetSize();
  546.                     HX_RELEASE(rpPacket);
  547.                     rpPacket = pNewPacket;
  548.                     rpPacket->AddRef();
  549.                 }
  550.             }
  551.             HX_RELEASE(pNewPacket);
  552.         }
  553.         HX_RELEASE(pBuffer);
  554.     }
  555.     else
  556.     {
  557.         retVal = HXR_INVALID_PARAMETER;
  558.     }
  559.     return retVal;
  560. }
  561. HX_RESULT PXImageFile::AddPacket(IHXPacket* pPacket, BOOL bTail)
  562. {
  563.     HX_RESULT retVal = HXR_OK;
  564.     if (pPacket)
  565.     {
  566.         // Create list if it doesn't exist
  567.         if (!m_pPacketList)
  568.         {
  569.             m_pPacketList = new CHXSimpleList();
  570.             if (!m_pPacketList)
  571.             {
  572.                 retVal = HXR_OUTOFMEMORY;
  573.             }
  574.         }
  575.         // AddRef the packet
  576.         pPacket->AddRef();
  577.         if (bTail)
  578.         {
  579.             // Add the packet at the tail
  580.             m_pPacketList->AddTail((void*) pPacket);
  581.         }
  582.         else
  583.         {
  584.             // Add the packet at the head
  585.             m_pPacketList->AddHead((void*) pPacket);
  586.         }
  587.     }
  588.     else
  589.     {
  590.         retVal = HXR_FAIL;
  591.     }
  592.     return retVal;
  593. }
  594. UINT32 PXImageFile::GetNumPacketsLeft() const
  595. {
  596.     return (m_pPacketList ? m_pPacketList->GetCount() : 0);
  597. }
  598. UINT32 PXImageFile::GetTotalSendTime(UINT32 ulBitrate) const
  599. {
  600.     UINT32 ulTime = 0;
  601.     if (ulBitrate)
  602.     {
  603.         ulTime = (m_ulTotalBytes * 8000 + (ulBitrate >> 1)) / ulBitrate;
  604.     }
  605.     return ulTime;
  606. }
  607. UINT32 PXImageFile::GetPacketSendTime(IHXPacket* pPacket, UINT32 ulBitrate)
  608. {
  609.     UINT32 ulTime = 0;
  610.     if (pPacket && ulBitrate)
  611.     {
  612.         IHXBuffer* pBuffer = pPacket->GetBuffer();
  613.         if (pBuffer)
  614.         {
  615.             ulTime = (pBuffer->GetSize() * 8000 + (ulBitrate >> 1)) / ulBitrate;
  616.         }
  617.         HX_RELEASE(pBuffer);
  618.     }
  619.     return ulTime;
  620. }