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

List:       helix-datatype-cvs
Subject:    [Datatype-cvs] common/audrend audrend.cpp,1.44.8.5,1.44.8.6
From:       qluo () helixcommunity ! org
Date:       2012-06-22 23:25:16
[Download RAW message or body]

Update of /cvsroot/datatype/common/audrend
In directory cvs01.internal.helixcommunity.org:/tmp/cvs-serv29766

Modified Files:
      Tag: hxclient_3_1_0_atlas
	audrend.cpp 
Log Message:
merge Jamie's audio format switch support in render to the 310 branch.

Index: audrend.cpp
===================================================================
RCS file: /cvsroot/datatype/common/audrend/audrend.cpp,v
retrieving revision 1.44.8.5
retrieving revision 1.44.8.6
diff -u -d -r1.44.8.5 -r1.44.8.6
--- audrend.cpp	8 Dec 2011 09:36:29 -0000	1.44.8.5
+++ audrend.cpp	22 Jun 2012 23:25:13 -0000	1.44.8.6
@@ -147,6 +147,7 @@
 	, m_bFirstPacket(TRUE)
 	, m_bDelayOffsetSet(FALSE)
 	, m_bCanChangeAudioStream(FALSE)
+        , m_bChangedAudioFormat(FALSE)
 	, m_bNeedStartTime(TRUE)
 	, m_pMutex(NULL)
         , m_pSrcProps(NULL)
@@ -160,6 +161,7 @@
 	, m_pRegistry(NULL)
 	, m_ulRegistryID(0)
 	, m_pAudioFormat(NULL)
+        , m_pNewAudioFormat(NULL)
         , m_pAudioStats(NULL)
 	, m_lRefCount(0)
 	, m_lPlaybackVelocity(HX_PLAYBACK_VELOCITY_NORMAL)
@@ -476,11 +478,8 @@
 
     HX_UNLOCK(m_pMutex);
 
-    if (m_pAudioFormat)
-    {
-        m_pAudioFormat->Release();
-        m_pAudioFormat = NULL;
-    }
+    HX_RELEASE(m_pAudioFormat);
+    HX_RELEASE(m_pNewAudioFormat);
     HX_RELEASE(m_pStream);
     HX_RELEASE(m_pBackChannel);
     HX_RELEASE(m_pAudioPlayer);
@@ -710,7 +709,52 @@
         m_bNeedStartTime = FALSE;
     }
 
-    m_pAudioFormat->Enqueue(pPacket);
+    if (pPacket->GetASMFlags() & HX_ASM_SWITCH_STREAM)
+    {
+        retVal = HXR_UNEXPECTED;
+        
+        IHXValues* pHeader = NULL;
+        IHXBuffer* pBuffer = pPacket->GetBuffer();
+        if (pBuffer)
+        {
+            retVal = UnpackValuesCCF(pHeader, pBuffer, m_pContext);
+            if (SUCCEEDED(retVal))
+            {
+                // XXXJDG is it possible to get another format switch before 
+                // completing the last switch?
+                // If that happens, we will for now just skip anything from the 
+                // intermediate stream
+                HX_RELEASE(m_pNewAudioFormat);
+                m_pNewAudioFormat = CreateFormatObject(pHeader);
+                if (m_pNewAudioFormat)
+                {
+                    m_pNewAudioFormat->AddRef();
+                    retVal = m_pNewAudioFormat->Init(pHeader);
+                    if (SUCCEEDED(retVal))
+                    {
+                        // Save the stream header
+                        HX_RELEASE(m_pHeader);
+                        m_pHeader = pHeader;
+                        pHeader = NULL;
+                    }
+                }
+                else
+                {
+                    retVal = HXR_OUTOFMEMORY;
+                }
+            }
+            pBuffer->Release();
+            HX_RELEASE(pHeader);
+        }
+    }
+    else if (m_pNewAudioFormat)
+    {
+        m_pNewAudioFormat->Enqueue(pPacket);
+    }
+    else
+    {
+        m_pAudioFormat->Enqueue(pPacket);
+    }
 
     if (m_PlayState != playing)
     {
@@ -1313,9 +1357,10 @@
     HXBOOL bTryWrite = TRUE;
 
     // Can the audio stream change on the fly?
+    // Or have we changed the audio format?
     // If so, then check for any change. If not,
     // then skip the check.
-    if (m_bCanChangeAudioStream)
+    if (m_bCanChangeAudioStream || m_bChangedAudioFormat)
     {
         HXBOOL bAudioStreamChanged = FALSE;
         pnr = CheckForAudioStreamChange(bAudioStreamChanged);
@@ -1327,6 +1372,7 @@
         {
             pAudioData->uAudioStreamType = TIMED_AUDIO;
         }
+        m_bChangedAudioFormat = FALSE;
     }
 
     while (bTryWrite)
@@ -1439,7 +1485,7 @@
     {
 	retVal = m_pAudioFormat->CreateAudioFrame(
 	    audioData,
-	    (m_bEndOfPackets) ? AUDIO_END_OF_PACKETS : audioState);
+	    (m_bEndOfPackets || m_pNewAudioFormat) ? AUDIO_END_OF_PACKETS : audioState);
 
 	if (retVal == HXR_OK)
 	{
@@ -1474,6 +1520,15 @@
 
 	    retVal = WriteToAudioServices(&audioData);        
 	}
+	else if (m_pNewAudioFormat && retVal == HXR_NO_DATA)
+        {
+            // We drained the pre-switch data, now we switch over.
+            HX_RELEASE(m_pAudioFormat);
+            
+            m_pAudioFormat = m_pNewAudioFormat;
+            m_pNewAudioFormat = NULL;
+            m_bChangedAudioFormat = TRUE;
+        }
 	else
 	{
 	    break;
@@ -1680,8 +1735,18 @@
                         HX_RELEASE(pPlayer);
                     }
 #endif
-                    // Init the new stream
-                    retVal = InitAudioStream(m_pHeader, &m_ppAudioStream[ulNewStreamIndex]);
+                    m_pHeader->SetPropertyULONG32("Resumed", 1);
+                    
+                    if (!m_ppAudioStream[ulNewStreamIndex])
+                    {
+                        // new audio stream
+                        retVal = InitAudioStream(m_pHeader, &m_ppAudioStream[ulNewStreamIndex]);
+                    }
+                    else
+                    {
+                        // we found an old one to use, just update the DryNotification
+                        retVal = m_ppAudioStream[ulNewStreamIndex]->AddDryNotification(pDryNot);
+                    }
                 }
             }
             HX_RELEASE(pDryNot);


_______________________________________________
Datatype-cvs mailing list
Datatype-cvs@helixcommunity.org
http://lists.helixcommunity.org/mailman/listinfo/datatype-cvs
[prev in list] [next in list] [prev in thread] [next in thread] 

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