chxavclipinfolist.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:9k
- /*============================================================================*
- *
- * (c) 1995-2002 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- *============================================================================*/
- #include <limits.h>
- #include "hxassert.h"
- #include "hxstring.h"
- #include "chxavutil.h"
- #include "chxavcleanupstack.h"
- #include "chxavcleanstring.h"
- #include "comptr.h"
- #include "chxavplayer.h"
- #include "chxavmisc.h"
- #include "hxapihelp.h"
- #include "hxapihelp_player.h"
- #include "chxavclipinfolist.h"
- ///////////////////////////////////
- // ctor
- CHXAvClipInfoList::CHXAvClipInfoList()
- {
- }
- ///////////////////////////////////
- // dtor
- CHXAvClipInfoList::~CHXAvClipInfoList()
- {
- }
- ///////////////////////////////////
- // helper
- void CHXAvClipInfoList::AddURLItemL(TInt idResTitle, const TDesC& url)
- {
- if( CHXAvUtil::IsLocal(url) )
- {
- // for local urls, display as local path (without file://)
- HBufC* pPath = CHXAvUtil::AllocStdPathFromPlayerUrlL(url);
- AUTO_PUSH_POP_DEL(pPath);
- AddLineL(idResTitle, *pPath);
- }
- else if(CHXAvUtil::HasValidNetworkURLSchemePrefix(url)) // filters 'helix-sdp:{huge sdp text}', 'streamid', etc.
- {
- // display un-adulterated URL if has valid url sheme
- AddLineL(idResTitle, url);
- }
- }
- ///////////////////////////////////
- // helper
- void CHXAvClipInfoList::AddFileSizeItemL(const char* pszURL)
- {
- if( CHXAvUtil::IsLocal(pszURL) )
- {
- // get path
- HBufC* pPath = CHXAvUtil::AllocStdPathFromPlayerUrlL(pszURL);
- AUTO_PUSH_POP_DEL(pPath);
- // get size
- TInt cbFile = CHXAvFile::GetFileSize(*pPath);
- if( cbFile > 0 )
- {
- HBufC* pText = AllocFileSizeDescL(cbFile);
- AUTO_PUSH_POP_DEL(pText);
- AddLineL(R_CLIPINF_FILESIZE, *pText);
- }
- }
- }
- ///////////////////////////////////
- // helper
- void CHXAvClipInfoList::AddStringItemL(const TDesC& caption, comptr<IHXValues>& header, const char* pszKey, val::ValType valType)
- {
- CHXString str;
- val::GetString(header, pszKey, str, valType);
- AddLineL(caption, CHXAvCleanString(str)());
- }
- ///////////////////////////////////
- // helper
- inline
- void CHXAvClipInfoList::AddIntItemL(TInt captionResId, comptr<IHXValues>& header,
- const char* pszKey, const TDesC& format)
- {
- AddIntItemL(CHXAvCleanString(captionResId)(), header, pszKey, format);
- }
- ///////////////////////////////////
- // helper
- void CHXAvClipInfoList::AddIntItemL(const TDesC& caption, comptr<IHXValues>& header,
- const char* pszKey, const TDesC& format)
- {
- UINT32 val = 0;
- if( val::GetUINT32(header, pszKey, val))
- {
- HX_ASSERT(val <= INT_MAX);
- CHXAvCleanString desc(format, TInt(val));
- AddLineL(caption, desc());
- }
- }
- ///////////////////////////////////
- // helper
- inline
- void CHXAvClipInfoList::AddStringItemL(TInt resId, comptr<IHXValues>& header, const char* pszKey, val::ValType valType)
- {
- AddStringItemL(CHXAvCleanString(resId)(), header, pszKey, valType);
- }
- // BuildClipInfo helper
- void CHXAvClipInfoList::BuildClipInfoForSource(CHXAvPlayer* pPlayer, UINT32 idxSource)
- {
- const CHXSymClipInfo& info = pPlayer->GetClipInfo();
- _LIT(KNakedIntFormat, "%d");
- if (idxSource > 0)
- {
- AddLineL(KNullDesC, CHXAvCleanString(_L("Source %d ==>"), TInt(idxSource))()); //XXXLCM res
- }
- comptr<IHXValues> header = info.GetFileHeader(idxSource);
- //fileheader
- AddStringItemL(R_CLIPINF_TITLE, header, "Title", val::buffer);
- AddStringItemL(R_CLIPINF_AUTHOR, header, "Author", val::buffer);
- AddStringItemL(R_CLIPINF_COPY, header, "Copyright", val::buffer);
- AddStringItemL(R_CLIPINF_ABSTRACT, header, "Abstract", val::buffer);
- if( 0 == idxSource )
- {
- if(pPlayer->IsPlaylistLoaded())
- {
- // container url
- AddURLItemL(R_CLIPINF_RAM_URL, CHXAvCleanString(pPlayer->GetMainURL())());
- // filesize
- AddFileSizeItemL(pPlayer->GetMainURL());
- // current playlist url
- AddURLItemL(R_CLIPINF_CLIP_URL, CHXAvCleanString(pPlayer->GetPlayURL())());
- // filesize
- AddFileSizeItemL(pPlayer->GetPlayURL());
- }
- else
- {
- // container or only url
- AddURLItemL(R_CLIPINF_RAM_URL, CHXAvCleanString(pPlayer->GetMainURL())());
- // filesize
- AddFileSizeItemL(pPlayer->GetMainURL());
- // sdp case will have 'control' in file header set to the URL
- CHXString str;
- if(val::GetString(header, "Control", str, val::string))
- {
- // control url
- AddURLItemL(R_CLIPINF_CLIP_URL, CHXAvCleanString(str)());
- // filesize (impossible?)
- // AddFileSizeItemL(str);
- }
- }
- }
- else
- {
- // source url
- const char* pszUrl = info.GetURL(idxSource);
- CHXAvCleanString url(pszUrl);
- AddURLItemL(R_CLIPINF_CLIP_URL, url());
-
- // filesize
- AddFileSizeItemL(pszUrl);
- }
- // width and height - qtffplin adds these but they are always 320 x 240
- //AddIntItemL(R_CLIPINF_WIDTH, header, "Width", KNakedIntFormat);
- //AddIntItemL(R_CLIPINF_HEIGHT, header, "Height", KNakedIntFormat);
- // iterate streams to get total bitrate and duration
-
- UINT32 totalBitrate = 0;
- UINT32 msDuration = 0;
- const UINT32 streamCount = info.GetStreamCount(idxSource);
- // only show duration for first source (most likely smil)
- bool bIncludeDuration = (0 == idxSource);
-
- UINT32 idx = 0;
- for(idx = 0; idx < streamCount; ++idx)
- {
- comptr<IHXValues> streamHeader = info.GetStreamHeader(idx, idxSource);
-
- if( bIncludeDuration)
- {
- UINT32 val = 0;
- val::GetUINT32(streamHeader, "Duration", val);
- msDuration = max(msDuration, val);
- }
- totalBitrate += info.GetStreamBitrate(idx, idxSource);
- }
-
-
- // duration
- if( !info.IsLive() && msDuration > 0 )
- {
- HBufC* pTimeText = CHXAvMisc::AllocTimerTextL(msDuration);
- AUTO_PUSH_POP_DEL(pTimeText);
- AddLineL(R_CLIPINF_DUR, *pTimeText);
- }
- // bitrate
- if( totalBitrate > 0 && streamCount > 1 )
- {
- CHXAvCleanString bitrateText(R_CLIP_KBPS_FORMAT, totalBitrate / double(CHXAvUtil::k_bitrateBytesPer1k));
- AddLineL(R_CLIPINF_BITRATE_TOTAL, bitrateText());
- }
- // server info //XXXLCM what if smil with live source?
- const char* pServerText = info.GetServerDescription();
- if( pServerText)
- {
- AddLineL(R_CLIPINF_SERVERINFO, CHXAvCleanString(pServerText)());
- }
-
- bool bIncludeStreamBreak = (streamCount > 1);
- // stream info
- for(idx = 0; idx < streamCount; ++idx)
- {
- if( bIncludeStreamBreak )
- {
- AddLineL(KNullDesC, _L("-------"));
- }
-
- comptr<IHXValues> streamHeader = info.GetStreamHeader(idx, idxSource);
- AddStringItemL(R_CLIPINF_STREAM_NAME, streamHeader, "StreamName", val::string);
- AddStringItemL(R_CLIPINF_MIME, streamHeader, "MimeType", val::string);
- AddStringItemL(R_CLIPINF_CODEC, streamHeader, "Codec", val::string);
- // sample rate
- AddIntItemL(R_CLIPINF_SAMPLERATE, streamHeader, "SampleRate", CHXAvCleanString(R_CLIPINF_SAMPLERATE_FORMAT)());
- // channels
- AddIntItemL(R_CLIPINF_CHANNELS, streamHeader, "Channels", KNakedIntFormat);
-
- // bitrate
- UINT32 bitrateStream = info.GetStreamBitrate(idx, idxSource);
- if(bitrateStream > 0)
- {
- CHXAvCleanString bitrateText(R_CLIP_KBPS_FORMAT, bitrateStream / double(CHXAvUtil::k_bitrateBytesPer1k));
- AddLineL(R_CLIPINF_BITRATE, bitrateText());
- }
- // image width and height
- AddIntItemL(R_CLIPINF_WIDTH, streamHeader, "ImageWidth", KNakedIntFormat);
- AddIntItemL(R_CLIPINF_HEIGHT, streamHeader, "ImageHeight", KNakedIntFormat);
- // width and height - qtffplin adds these but they are always 320 x 240
- //AddIntItemL(R_CLIPINF_WIDTH, header, "Width", KNakedIntFormat);
- //AddIntItemL(R_CLIPINF_HEIGHT, header, "Height", KNakedIntFormat);
- }
- }
- ////////////////////////////////////////////////////////
- // call ConstructL() on base, then this
- void CHXAvClipInfoList::BuildClipInfoL(CHXAvPlayer* pPlayer)
- {
- const UINT32 sourceCount = pPlayer->GetClipInfo().GetSourceCount();
- for(UINT32 idxSource = 0; idxSource < sourceCount; ++idxSource)
- {
- BuildClipInfoForSource(pPlayer, idxSource);
- }
-
- }