[prev in list] [next in list] [prev in thread] [next in thread] 

List:       helix-server-cvs
Subject:    [Server-cvs] engine/session clientsession.cpp,1.70,1.71
From:       rasher () helixcommunity ! org
Date:       2007-10-30 10:19:13
Message-ID: 200710301019.l9UAJMHd004474 () mailer ! progressive-comp ! com
[Download RAW message or body]

Update of /cvsroot/server/engine/session
In directory cvs01.internal.helixcommunity.org:/tmp/cvs-serv21364

Modified Files:
	clientsession.cpp 
Log Message:
Synopsis
 ==========

This CR is a fix for FCS for handling stats for each clip separately.

Branches           :  HEAD
Suggested Reviewer :  Jamie

  Description
  ============

1)    StatDone for each clip returns the file size but it was obtained
only for the first clip.We want the file size for every clip

2)  If format style less than 7( FORMAT_STYLE7_SERVER) then the session
stats  methods get called for e.g.GetURL and GetDuration.m_pStats is only
1 per clientSession and was not updated for every clip.

  Fix
 ===========

    StatDone for each clip is now obtained as when Stat is called on the
file object the response object is the CSwitchElement which is 1 per
clip.So each clips StatDone is received in the per clip CSwitchElement.

    CSwitchElement is made to derive from IHXFileStatResponse and becomes
the response object.Now CSwitchElement is not deleted but AddRef'd and
Released. InitClipStats and ClipDone now have an argument which is the
ClipStats object.
    In CTBaseLog::LookupOutputArg if format style less than 7(
FORMAT_STYLE7_SERVER) then SessionStats methods are called.in this
method we check whether pClipStats is non NULL and call ClipStats
method for common methods for e.g.GetURL,GetDuration.Now we get the
correct URL,duration etc. for


  Files Affected
 ================

  server\engine\session\clientsession.cpp
  server\engine\session\pub\clientsession.h
  server\log\tmplgpln\legacy_access_log.h

  Testing Performed
 =================
Integration Tests:
Tested with switching clips for a session.File size is correctly logged
for each switching clip.Also if format < 7 urls for each
clip,filesize,duration are correctly logged for each clip.

Leak Tests:
No leaks related to these changes.All the SwitchElements for each clip are
freed.

Performance Tests: n/a

Build verified: win32-i386-vc7, linux-rhel4, Sunos-5.10

Platforms tested: win32-i386-vc7



 QA Hints
===========





Thanks
Raj  Asher



Index: clientsession.cpp
===================================================================
RCS file: /cvsroot/server/engine/session/clientsession.cpp,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- clientsession.cpp	29 Oct 2007 14:52:10 -0000	1.70
+++ clientsession.cpp	30 Oct 2007 10:19:11 -0000	1.71
@@ -355,6 +355,7 @@
 void
 ClientSession::Done(HX_RESULT status)
 {
+    IHXClipStats* pClipStats = NULL;
     if (m_bDone)
         return;
 
@@ -416,15 +417,20 @@
 
         m_pStats->SetEndStatus(ulEndStatus);
     }
-
-    if (m_pClipStats)
+#ifdef HELIX_FEATURE_SERVER_FCS
+    if(m_pCompletedSwitch)
+         pClipStats = m_pCompletedSwitch->m_pClipStats;
+    else
+#endif //HELIX_FEATURE_SERVER_FCS
+         pClipStats = m_pClipStats;
+    if (pClipStats)
     {
         // all but the last clip done event in a switching session are 
         // triggered at switch time. the last clip done event needs to 
         // be triggered differently since it doesn't happen as a result 
         // of a switch.
-        m_pClipStats->SetEndFlag(TRUE);
-        ClipDone();
+        pClipStats->SetEndFlag(TRUE);
+        ClipDone(pClipStats);
     }
 
 #ifdef HELIX_FEATURE_SERVER_FCS
@@ -438,14 +444,14 @@
     if(m_pCurrentSwitch)
     {
         m_pCurrentSwitch->m_pSwitchSource->Done();
-        HX_DELETE(m_pCurrentSwitch);
+        HX_RELEASE(m_pCurrentSwitch);
     }
     if(m_pWaitingSwitch)
     {
         m_pWaitingSwitch->m_pSwitchSource->Done();
-        HX_DELETE(m_pWaitingSwitch);
+        HX_RELEASE(m_pWaitingSwitch);
     }
-    HX_DELETE(m_pCompletedSwitch);
+    HX_RELEASE(m_pCompletedSwitch);
 #endif //HELIX_FEATURE_SERVER_FCS
 
     m_pProc->pc->client_stats_manager->SessionDone(m_pClient->GetClientStats(), 
@@ -1772,8 +1778,12 @@
     }
 
 #ifdef HELIX_FEATURE_SERVER_FCS
+	CSwitchElement* pSwitchElement = NULL;
     if(m_pStack->GetSize())
     {
+        pSwitchElement = (CSwitchElement*)m_pStack->GetAt(m_uTestIndex);
+        pSwitchElement->GetStat(pFileObject);
+        HX_RELEASE(pSwitchElement);
         return HandleSourceSwitch(status, pSourceContainer, pFileObject);
     }
 #endif //HELIX_FEATURE_SERVER_FCS
@@ -2627,7 +2637,9 @@
         m_pStats->QueryInterface(IID_IHXSessionStats3, (void **)&m_pStats3);
         if (m_pStats3)
         {
-            InitClipStats();
+            m_pClipStats = new ClipStats();
+            m_pClipStats->AddRef();
+            InitClipStats(m_pClipStats);
         }
 
     }
@@ -3466,13 +3478,16 @@
             sprintf(str, "%s.FileSize", m_pRegistryKey);
             m_pProc->pc->registry->AddInt(str, ulSize, m_pProc);
         }
-        m_pStats->SetFileSize(ulSize);
-
+   
     }
 
     HX_ASSERT(m_pStats);
 
     m_pStats->SetFileSize(ulSize);
+    if(m_pClipStats)
+    {
+        m_pClipStats->SetFileSize(ulSize);
+    }  
     return HXR_OK;
 }
 
@@ -5180,20 +5195,20 @@
 ClientSession::ReportSwitchFailure(UINT32 uStatus)
 {
     CSwitchElement* pSwitchElement = NULL;
-    IHXClipStats* pClipStats = new ClipStats();
-    pClipStats->AddRef();
-
-    pClipStats->SetSession(m_pStats);
+    
+    IHXClipStats* pClipStats = NULL;
     pSwitchElement = (CSwitchElement*)m_pStack->GetAt(m_uTestIndex);
+    pClipStats = pSwitchElement->m_pClipStats;
     pClipStats->SetURL(pSwitchElement->m_pURL);
     pClipStats->SetStatus(uStatus);
+    pClipStats->SetSession(m_pStats);
+    HX_RELEASE(pSwitchElement);
 
     m_pProc->pc->client_stats_manager->ClipDone(m_pClient->GetClientStats(), 
                                                 m_pStats,
                                                 pClipStats, 
                                                 m_pProc);
 
-    HX_RELEASE(pClipStats);
 }
 
 
@@ -5201,6 +5216,7 @@
 ClientSession::SwitchDone(HX_RESULT status)
 {
     CSwitchElement* pSwitchElement = NULL;
+    IHXClipStats* pClipStats = NULL;
     if (m_pCurrentSwitch == NULL || m_pCurrentSwitch->m_bReady == FALSE)
     {
         // cancelled while waiting for streamDone
@@ -5208,8 +5224,12 @@
     }
     if (SUCCEEDED(status))
     {
-        ClipDone();
-        InitClipStats();
+        if(m_pCompletedSwitch)
+            pClipStats = m_pCompletedSwitch->m_pClipStats;
+        else
+            pClipStats = m_pClipStats;
+        ClipDone(pClipStats);
+        InitClipStats(m_pCurrentSwitch->m_pClipStats);
     }
 
     if (SUCCEEDED(status))
@@ -5240,7 +5260,7 @@
         OnBegin();
     }
 
-    HX_DELETE(m_pCompletedSwitch);
+    HX_RELEASE(m_pCompletedSwitch);
     m_pCompletedSwitch = m_pCurrentSwitch;
     m_pCurrentSwitch = NULL;
     // m_pWaitingSwitch is non NULL when current switch was Switch now
@@ -5285,7 +5305,7 @@
         pSwitchElement = (CSwitchElement*)m_pStack->GetAt(m_uTestIndex);
         m_pStack->RemoveAt(m_uTestIndex);
         pSwitchElement->SwitchDone(status);
-        HX_DELETE(pSwitchElement);
+        HX_RELEASE(pSwitchElement);
         m_pSrcFinder->Close();
         HX_RELEASE(m_pSrcFinder);
         pSwitchElement = (CSwitchElement*)m_pStack->TopOfStack();
@@ -5319,7 +5339,7 @@
         pSwitchElement = (CSwitchElement*)m_pStack->GetAt(m_uTestIndex);
         m_pStack->RemoveAt(m_uTestIndex);
         pSwitchElement->SwitchDone(hRes);
-        HX_DELETE(pSwitchElement);
+        HX_RELEASE(pSwitchElement);
         if(m_pSwitchabilityTest)
         {
             m_pSwitchabilityTest->Done();
@@ -5356,7 +5376,7 @@
         if(m_pWaitingSwitch)
         {
             m_pWaitingSwitch->m_pSwitchSource->Done();
-            HX_DELETE(m_pWaitingSwitch);
+            HX_RELEASE(m_pWaitingSwitch);
             m_pWaitingSwitch = NULL;
         }
         if(m_pCurrentSwitch && m_pCurrentSwitch->m_switchType == HX_SWITCH_NOW && \
pSwitchElement->m_switchType == HX_SWITCH_AT_END) @@ -5371,7 +5391,7 @@
             if(m_pCurrentSwitch)
             {
                 m_pCurrentSwitch->m_pSwitchSource->Done();
-                HX_DELETE(m_pCurrentSwitch);
+                HX_RELEASE(m_pCurrentSwitch);
             }
             m_pCurrentSwitch = pSwitchElement;
 
@@ -5425,9 +5445,9 @@
 }
 #endif //HELIX_FEATURE_SERVER_FCS
 
-void ClientSession::ClipDone()
+void ClientSession::ClipDone(IHXClipStats* pClipStats)
 {
-    HX_ASSERT(m_pClipStats);
+    HX_ASSERT(pClipStats);
     HX_ASSERT(m_pStats3);
 
 #ifdef HELIX_FEATURE_SERVER_FCS
@@ -5443,31 +5463,27 @@
 
     m_ulPlayTimeOffset = ulSessionPlayTime;
 
-    m_pClipStats->SetPlayTime(ulClipPlayTime);
-    m_pClipStats->SetNPTEndTime(m_ulEndTime);
+    pClipStats->SetPlayTime(ulClipPlayTime);
+    pClipStats->SetNPTEndTime(m_ulEndTime);
 
     // notify client stats manager of clip done event
     m_pProc->pc->client_stats_manager->ClipDone(m_pClient->GetClientStats(),
                                                 m_pStats,
-                                                m_pClipStats,
+                                                pClipStats,
                                                 m_pProc);
-    HX_RELEASE(m_pClipStats);
+    
 }
 
-void ClientSession::InitClipStats()
+void ClientSession::InitClipStats(IHXClipStats* pClipStats)
 {
     UINT32 ulFileDur = 0;
     IHXBuffer* pStartTime = GetStartTime();
 
-    // create and initialize the new clip stats object
-    m_pClipStats = new ClipStats();
-    m_pClipStats->AddRef();
-
-    m_pClipStats->SetSwitchCount(m_ulSwitchCount);
-    m_pClipStats->SetSession(m_pStats);
-    m_pClipStats->SetStatus(200);
-    m_pClipStats->SetNPTStartTime(m_ulEndTime);
-    m_pClipStats->SetStartTime(pStartTime);
+    pClipStats->SetSwitchCount(m_ulSwitchCount);
+    pClipStats->SetSession(m_pStats);
+    pClipStats->SetStatus(200);
+    pClipStats->SetNPTStartTime(m_ulEndTime);
+    pClipStats->SetStartTime(pStartTime);
 
     HX_RELEASE(pStartTime);
     m_ulSwitchCount++;
@@ -5477,16 +5493,16 @@
 #ifdef HELIX_FEATURE_SERVER_FCS
     if (m_pCurrentSwitch)
     {
-        m_pClipStats->SetURL(m_pCurrentSwitch->m_pURL);
+        pClipStats->SetURL(m_pCurrentSwitch->m_pURL);
 
         if(SUCCEEDED( \
m_pCurrentSwitch->m_pSwitchSource->GetFileDuration(ulFileDur)))  {
-            m_pClipStats->SetDuration(ulFileDur);
+            pClipStats->SetDuration(ulFileDur);
         }
     }
 #endif /* HELIX_FEATURE_SERVER_FCS */
 
-    m_pStats3->SetClip(m_pClipStats);
+    m_pStats3->SetClip(pClipStats);
 }
 
 #ifdef HELIX_FEATURE_SERVER_FCS
@@ -5515,7 +5531,12 @@
 CSwitchElement::CSwitchElement( const char* pNewURL,
                                 IHXSwitchResponse* pResp, 
                                 HX_SWITCH_TYPE switchType, 
-                                ServerRequest* pSwitchingRequest)
+                                ServerRequest* pSwitchingRequest) :
+    m_ulRefCount(0)
+  , m_bCleanedUp(FALSE)
+  , m_bReady(FALSE)
+  , m_pSwitchSource(NULL)
+  , m_ulLastModifiedTime(0)
 {
     m_pSwitchResponse = pResp;
     pResp->AddRef();
@@ -5527,8 +5548,8 @@
     m_pURL->Set((unsigned char *)pNewURL, strlen(pNewURL) + 1);
     m_pURL->AddRef();
 
-    m_pSwitchSource = NULL, 
-    m_bReady = FALSE;
+    m_pClipStats = new ClipStats();
+    m_pClipStats->AddRef();
 }
 
 CSwitchElement::~CSwitchElement()
@@ -5554,6 +5575,82 @@
     HX_DELETE(m_pSwitchURL);
     HX_RELEASE(m_pURL);
     HX_RELEASE(m_pSwitchSource);
+    HX_RELEASE(m_pClipStats);
+    m_bCleanedUp = TRUE;
+}
+
+void CSwitchElement::GetStat(IUnknown* pFileObject)
+{
+    IHXFileStat* pFileStat = NULL;
+    if (pFileObject && SUCCEEDED(pFileObject->QueryInterface(IID_IHXFileStat,
+                                                (void**)&pFileStat)))
+    {
+        pFileStat->Stat(this);
+        pFileStat->Release();
+    }
+}
+
+STDMETHODIMP
+CSwitchElement::StatDone(HX_RESULT status,
+    UINT32 ulSize, UINT32 ulCreationTime, UINT32 ulAccessTime,
+    UINT32 ulModificationTime, UINT32 ulMode)
+{
+    if (m_bCleanedUp)
+    {
+        return HXR_OK;
+    }
+
+    if(status == HXR_OK)
+    {
+        m_ulLastModifiedTime = ulModificationTime;
+        if ((long)m_ulLastModifiedTime < 0)
+        {
+            m_ulLastModifiedTime = 0;
+        }
+    }
+
+    HX_ASSERT(m_pClipStats);
+
+    m_pClipStats->SetFileSize(ulSize);
+    return HXR_OK;
+}
+
+STDMETHODIMP
+CSwitchElement::QueryInterface(REFIID riid, void** ppvObj)
+{
+    if (IsEqualIID(riid, IID_IUnknown))
+    {
+        AddRef();
+        *ppvObj = (IUnknown*)(IHXPSinkControl*)this;
+        return HXR_OK;
+    }
+    else if (IsEqualIID(riid, IID_IHXFileStatResponse))
+    {
+        AddRef();
+        *ppvObj = (IHXFileStatResponse*)this;
+        return HXR_OK;
+    }
+
+    *ppvObj = NULL;
+    return HXR_NOINTERFACE;
+}
+
+STDMETHODIMP_(ULONG32)
+CSwitchElement::AddRef()
+{
+    return InterlockedIncrement(&m_ulRefCount);
+}
+
+STDMETHODIMP_(ULONG32)
+CSwitchElement::Release()
+{
+    if (InterlockedDecrement(&m_ulRefCount) > 0)
+    {
+        return m_ulRefCount;
+    }
+
+    delete this;
+    return 0;
 }
 
 #endif //HELIX_FEATURE_SERVER_FCS
@@ -6444,8 +6541,14 @@
 // deletes the value at index and adjusts the value of top
  void CHXFCStack::RemoveAt(int index ,int repeat)
  {
-    int cnt = 0,cnt1 = 0;
+    int cnt = 0,cnt1 = 0,ind;
     cnt = GetSize();
+    for(ind = 0;ind < repeat;ind++)
+    {
+        void* ptr = CHXPtrArray::GetAt(index + ind);
+        CSwitchElement* pSwitchElement = (CSwitchElement*)ptr;
+        HX_RELEASE(pSwitchElement);
+    }
     CHXPtrArray::RemoveAt(index, repeat);
     cnt1 = GetSize();
     top -= (cnt - cnt1);
@@ -6459,13 +6562,25 @@
     CSwitchElement* pSwitchElement = NULL;
     for(int i = 0;i < index ;i++)
     {
-        pSwitchElement = (CSwitchElement*)GetAt(0);
+        pSwitchElement = (CSwitchElement*)CHXPtrArray::GetAt(0);
         pSwitchElement->SwitchDone(HXR_CANCELLED);
-        CHXPtrArray::RemoveAt(0,1);
-        HX_DELETE(pSwitchElement);
+        RemoveAt(0,1);
     }
 }
 
+void CHXFCStack::Push(void* Pushee)
+{
+     ((CSwitchElement*)Pushee)->AddRef();
+     CHXStack::Push(Pushee);
+}
+
+void*
+CHXFCStack::GetAt(int index) const
+{
+    CSwitchElement* pSwitchElement = (CSwitchElement*)CHXPtrArray::GetAt(index);
+    pSwitchElement->AddRef();
+    return pSwitchElement;
+}
 // when session terminated the stack could contain certain switch request
 // need to delete them.
 CHXFCStack::~CHXFCStack()


_______________________________________________
Server-cvs mailing list
Server-cvs@helixcommunity.org
http://lists.helixcommunity.org/mailman/listinfo/server-cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic