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

Symbian

开发平台:

C/C++

  1. /*============================================================================*
  2.  *
  3.  * (c) 1995-2002 RealNetworks, Inc. Patents pending. All rights reserved.
  4.  *
  5.  *============================================================================*/
  6. #include <limits.h>
  7. #include "hxassert.h"
  8. #include "hxstring.h"
  9. #include "chxavutil.h"
  10. #include "chxavcleanupstack.h"
  11. #include "chxavcleanstring.h"
  12. #include "comptr.h"
  13. #include "chxavplayer.h"
  14. #include "chxavmisc.h"
  15. #include "hxapihelp.h"
  16. #include "hxapihelp_player.h"
  17. #include "chxavclipinfolist.h"
  18. ///////////////////////////////////
  19. // ctor
  20. CHXAvClipInfoList::CHXAvClipInfoList()
  21. {
  22. }
  23. ///////////////////////////////////
  24. // dtor
  25. CHXAvClipInfoList::~CHXAvClipInfoList()
  26. {
  27. }
  28. ///////////////////////////////////
  29. // helper
  30. void CHXAvClipInfoList::AddURLItemL(TInt idResTitle, const TDesC& url)
  31. {
  32.     if( CHXAvUtil::IsLocal(url) )
  33.     {
  34.         // for local urls, display as local path (without file://)
  35.         HBufC* pPath = CHXAvUtil::AllocStdPathFromPlayerUrlL(url);
  36.         AUTO_PUSH_POP_DEL(pPath);
  37.         AddLineL(idResTitle, *pPath);
  38.     }
  39.     else if(CHXAvUtil::HasValidNetworkURLSchemePrefix(url)) // filters 'helix-sdp:{huge sdp text}', 'streamid', etc.
  40.     {
  41.         // display un-adulterated URL if has valid url sheme
  42.         AddLineL(idResTitle, url);
  43.     }
  44. }
  45. ///////////////////////////////////
  46. // helper
  47. void CHXAvClipInfoList::AddFileSizeItemL(const char* pszURL)
  48. {
  49.     if( CHXAvUtil::IsLocal(pszURL) )
  50.     {
  51.         // get path
  52.         HBufC* pPath = CHXAvUtil::AllocStdPathFromPlayerUrlL(pszURL);
  53.         AUTO_PUSH_POP_DEL(pPath);
  54.         // get size
  55.         TInt cbFile = CHXAvFile::GetFileSize(*pPath);
  56.         if( cbFile > 0 )
  57.         {
  58.             HBufC* pText = AllocFileSizeDescL(cbFile);
  59.             AUTO_PUSH_POP_DEL(pText);
  60.             AddLineL(R_CLIPINF_FILESIZE, *pText);
  61.         }
  62.     }
  63. }
  64. ///////////////////////////////////
  65. // helper
  66. void CHXAvClipInfoList::AddStringItemL(const TDesC& caption, comptr<IHXValues>& header, const char* pszKey, val::ValType valType)
  67. {
  68.     CHXString str;
  69.     val::GetString(header, pszKey, str, valType);
  70.     AddLineL(caption, CHXAvCleanString(str)());
  71. }
  72. ///////////////////////////////////
  73. // helper
  74. inline
  75. void CHXAvClipInfoList::AddIntItemL(TInt captionResId, comptr<IHXValues>& header, 
  76.                                      const char* pszKey, const TDesC& format)
  77. {
  78.     AddIntItemL(CHXAvCleanString(captionResId)(), header, pszKey, format);
  79. }
  80. ///////////////////////////////////
  81. // helper
  82. void CHXAvClipInfoList::AddIntItemL(const TDesC& caption, comptr<IHXValues>& header, 
  83.                                      const char* pszKey, const TDesC& format)
  84. {
  85.     UINT32 val = 0;
  86.     if( val::GetUINT32(header, pszKey, val))
  87.     {
  88.         HX_ASSERT(val <= INT_MAX);
  89.         CHXAvCleanString desc(format, TInt(val));
  90.         AddLineL(caption, desc());
  91.     }
  92. }
  93. ///////////////////////////////////
  94. // helper
  95. inline
  96. void CHXAvClipInfoList::AddStringItemL(TInt resId, comptr<IHXValues>& header, const char* pszKey, val::ValType valType)
  97. {
  98.     AddStringItemL(CHXAvCleanString(resId)(), header, pszKey, valType);
  99. }
  100. // BuildClipInfo helper
  101. void CHXAvClipInfoList::BuildClipInfoForSource(CHXAvPlayer* pPlayer, UINT32 idxSource)
  102. {
  103.     const CHXSymClipInfo& info = pPlayer->GetClipInfo();
  104.     _LIT(KNakedIntFormat, "%d");
  105.     if (idxSource > 0)
  106.     {
  107.         AddLineL(KNullDesC, CHXAvCleanString(_L("Source %d ==>"), TInt(idxSource))()); //XXXLCM res
  108.     }
  109.     comptr<IHXValues> header = info.GetFileHeader(idxSource);
  110.     //fileheader
  111.     AddStringItemL(R_CLIPINF_TITLE, header, "Title", val::buffer);
  112.     AddStringItemL(R_CLIPINF_AUTHOR, header, "Author", val::buffer);
  113.     AddStringItemL(R_CLIPINF_COPY, header, "Copyright", val::buffer);
  114.     AddStringItemL(R_CLIPINF_ABSTRACT, header, "Abstract", val::buffer);
  115.     if( 0 == idxSource )
  116.     {
  117.         if(pPlayer->IsPlaylistLoaded())
  118.         {
  119.             // container url
  120.             AddURLItemL(R_CLIPINF_RAM_URL, CHXAvCleanString(pPlayer->GetMainURL())());
  121.             // filesize
  122.             AddFileSizeItemL(pPlayer->GetMainURL());
  123.             // current playlist url
  124.             AddURLItemL(R_CLIPINF_CLIP_URL, CHXAvCleanString(pPlayer->GetPlayURL())());
  125.             // filesize
  126.             AddFileSizeItemL(pPlayer->GetPlayURL());
  127.         }
  128.         else
  129.         {
  130.             // container or only url
  131.             AddURLItemL(R_CLIPINF_RAM_URL, CHXAvCleanString(pPlayer->GetMainURL())());
  132.             // filesize
  133.             AddFileSizeItemL(pPlayer->GetMainURL());
  134.             // sdp case will have 'control' in file header set to the URL
  135.             CHXString str;
  136.             if(val::GetString(header, "Control", str, val::string))
  137.             {
  138.                 // control url
  139.                 AddURLItemL(R_CLIPINF_CLIP_URL, CHXAvCleanString(str)());
  140.                 // filesize (impossible?)
  141.                 // AddFileSizeItemL(str);
  142.             }
  143.         }
  144.     }
  145.     else
  146.     {
  147.         // source url
  148.         const char* pszUrl = info.GetURL(idxSource);
  149.         CHXAvCleanString url(pszUrl);
  150.         AddURLItemL(R_CLIPINF_CLIP_URL, url());
  151.         
  152.         // filesize
  153.         AddFileSizeItemL(pszUrl);
  154.     }
  155.     // width and height - qtffplin adds these but they are always 320 x 240
  156.     //AddIntItemL(R_CLIPINF_WIDTH, header, "Width", KNakedIntFormat);
  157.     //AddIntItemL(R_CLIPINF_HEIGHT, header, "Height", KNakedIntFormat);
  158.     // iterate streams to get total bitrate and duration
  159.     
  160.     UINT32 totalBitrate = 0;
  161.     UINT32 msDuration = 0;
  162.     const UINT32 streamCount = info.GetStreamCount(idxSource);
  163.     // only show duration for first source (most likely smil)
  164.     bool bIncludeDuration = (0 == idxSource);
  165.     
  166.     UINT32 idx = 0;
  167.     for(idx = 0; idx < streamCount; ++idx)
  168.     {
  169.         comptr<IHXValues> streamHeader = info.GetStreamHeader(idx, idxSource);
  170.     
  171.         if( bIncludeDuration)
  172.         {
  173.             UINT32 val = 0;
  174.             val::GetUINT32(streamHeader, "Duration", val);
  175.             msDuration = max(msDuration, val);
  176.         }
  177.         totalBitrate += info.GetStreamBitrate(idx, idxSource);
  178.     }
  179.     
  180.     
  181.     // duration
  182.     if( !info.IsLive() && msDuration > 0 )
  183.     {
  184.         HBufC* pTimeText = CHXAvMisc::AllocTimerTextL(msDuration);
  185.         AUTO_PUSH_POP_DEL(pTimeText);
  186. AddLineL(R_CLIPINF_DUR, *pTimeText); 
  187.     }
  188.     // bitrate
  189.     if( totalBitrate > 0 && streamCount > 1 )
  190.     {
  191.         CHXAvCleanString bitrateText(R_CLIP_KBPS_FORMAT, totalBitrate / double(CHXAvUtil::k_bitrateBytesPer1k));
  192.         AddLineL(R_CLIPINF_BITRATE_TOTAL, bitrateText());
  193.     }
  194.     // server info //XXXLCM what if smil with live source?
  195.     const char* pServerText = info.GetServerDescription();
  196.     if( pServerText)
  197.     {
  198.         AddLineL(R_CLIPINF_SERVERINFO, CHXAvCleanString(pServerText)());
  199.     }
  200.     
  201.     bool bIncludeStreamBreak = (streamCount > 1);
  202.     // stream info
  203.     for(idx = 0; idx < streamCount; ++idx)
  204.     {
  205.         if( bIncludeStreamBreak )
  206.         {
  207.             AddLineL(KNullDesC, _L("-------"));
  208.         }
  209.         
  210.         comptr<IHXValues> streamHeader = info.GetStreamHeader(idx, idxSource);
  211.         AddStringItemL(R_CLIPINF_STREAM_NAME, streamHeader, "StreamName", val::string);
  212.         AddStringItemL(R_CLIPINF_MIME, streamHeader, "MimeType", val::string);
  213.         AddStringItemL(R_CLIPINF_CODEC, streamHeader, "Codec", val::string);
  214.         // sample rate
  215.         AddIntItemL(R_CLIPINF_SAMPLERATE, streamHeader, "SampleRate", CHXAvCleanString(R_CLIPINF_SAMPLERATE_FORMAT)());
  216.         // channels
  217.         AddIntItemL(R_CLIPINF_CHANNELS, streamHeader, "Channels", KNakedIntFormat);
  218.         
  219.         // bitrate
  220.         UINT32 bitrateStream = info.GetStreamBitrate(idx, idxSource);
  221.         if(bitrateStream > 0)
  222.         {
  223.             CHXAvCleanString bitrateText(R_CLIP_KBPS_FORMAT, bitrateStream / double(CHXAvUtil::k_bitrateBytesPer1k));
  224.             AddLineL(R_CLIPINF_BITRATE, bitrateText());
  225.         }
  226.         // image width and height
  227.         AddIntItemL(R_CLIPINF_WIDTH, streamHeader, "ImageWidth", KNakedIntFormat);
  228.         AddIntItemL(R_CLIPINF_HEIGHT, streamHeader, "ImageHeight", KNakedIntFormat);
  229.         // width and height - qtffplin adds these but they are always 320 x 240
  230.         //AddIntItemL(R_CLIPINF_WIDTH, header, "Width", KNakedIntFormat);
  231.         //AddIntItemL(R_CLIPINF_HEIGHT, header, "Height", KNakedIntFormat);
  232.     }
  233. }
  234. ////////////////////////////////////////////////////////
  235. // call ConstructL() on base, then this
  236. void CHXAvClipInfoList::BuildClipInfoL(CHXAvPlayer* pPlayer)
  237. {
  238.     const UINT32 sourceCount = pPlayer->GetClipInfo().GetSourceCount();
  239.     for(UINT32 idxSource = 0; idxSource < sourceCount; ++idxSource)
  240.     {
  241.         BuildClipInfoForSource(pPlayer, idxSource);
  242.     }
  243.     
  244. }