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

List:       helix-client-cvs
Subject:    [Client-cvs] encodesvc/plugins/transform/audioresampler
From:       gwright () helixcommunity ! org
Date:       2009-04-27 19:58:55
Message-ID: 200904272102.n3RL2TXZ014919 () mailer ! progressive-comp ! com
[Download RAW message or body]

Update of /cvsroot/client/encodesvc/plugins/transform/audioresampler
In directory cvs01.internal.helixcommunity.org:/tmp/cvs-serv14501

Modified Files:
	audioresampler.h resampleragent.cpp 
Log Message:
Adding support for auto-samplerates.CVS: \
----------------------------------------------------------------------


Index: audioresampler.h
===================================================================
RCS file: /cvsroot/client/encodesvc/plugins/transform/audioresampler/audioresampler.h,v
 retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- audioresampler.h	20 Aug 2008 21:08:34 -0000	1.3
+++ audioresampler.h	27 Apr 2009 19:58:53 -0000	1.4
@@ -70,16 +70,17 @@
 
 class CExactResamplerFilter : public CHXTConfigurationAgent , public \
IHXTConnectionAgent , public IHXTTransformFilter ,public CUnknownIMP  {
-public:
+  public:
     CExactResamplerFilter();
     ~CExactResamplerFilter();
     DECLARE_UNKNOWN (CExactResamplerFilter)
-	
-	//overriding method of CHXTConfigurationAgent.
-	STDMETHOD (Initialize) ( IHXTPropertyBag* pPropBag, IHXTPropertyBag** ppErrorBag );
+        
+    //overriding method of CHXTConfigurationAgent.
+    STDMETHOD (Initialize) ( IHXTPropertyBag* pPropBag, IHXTPropertyBag** ppErrorBag \
);  STDMETHOD (OnSetString)( const char* szName, const CHAR *cszValue ) ;
     STDMETHOD (OnSetDouble)( const char* szName, double dValue ) ;
     STDMETHOD (OnSetBool)( const char* szName, BOOL bValue ) ;
+    STDMETHOD (OnSetUintList)( const char* szName, IHXTUintList *pValue ) ;
     
     /*IHXTConnectionAgent*/
     STDMETHOD_ (UINT32 , GetInputStreamCount) ();
@@ -89,7 +90,7 @@
     STDMETHOD (SetNegotiatedInputFormat) ( UINT32 uStreamID , IHXTPropertyBag* \
                pInputFormat );
     STDMETHOD (SetNegotiatedOutputFormat) ( UINT32 uStreamID , IHXTPropertyBag* \
                pOutputFormat );
     STDMETHOD ( GetPreferredInputFormat ) ( THIS_ UINT32 uIndex, UINT32 uPrefRank, \
                IHXTPropertyBag** ppPreferredFormat ) {return HXR_FAIL;}
-    STDMETHOD ( GetPreferredOutputFormat ) ( THIS_ UINT32 uIndex, UINT32 uPrefRank, \
IHXTPropertyBag** ppPreferredFormat ) {return HXR_FAIL;}	 +    STDMETHOD ( \
GetPreferredOutputFormat ) ( THIS_ UINT32 uIndex, UINT32 uPrefRank, IHXTPropertyBag** \
                ppPreferredFormat ) {return HXR_FAIL;}    
     STDMETHOD ( GetNegotiatedInputFormat ) ( THIS_ UINT32 uIndex, IHXTPropertyBag** \
                pSupportedFormats ) {return HXR_FAIL;}
     STDMETHOD ( GetNegotiatedOutputFormat ) ( THIS_ UINT32 uIndex, IHXTPropertyBag** \
pSupportedFormats ) {return HXR_FAIL;}  
@@ -105,6 +106,8 @@
     STDMETHOD( DiscardCachedSamples )( THIS_ UINT32 uStream ) {return HXR_OK;}
     
 private:
+
+    STDMETHOD (SelectAutoSampleRate) (IHXTUintList* pList, UINT32& ulValue );
     STDMETHOD (ReceiveSample2) ( IHXTMediaSample * pSample ) ;
     HX_RESULT setUpDownmixer() ;
     
@@ -122,15 +125,15 @@
     enum { HEADROOM = 3 } ;
     
     typedef struct UPMIXSTATEMACHINE {
-	int inoffs, outoffs;
-	const struct UPMIXSTATEMACHINE* nextState;
+        int inoffs, outoffs;
+        const struct UPMIXSTATEMACHINE* nextState;
     } tUpmixMachine ;
     
     typedef UINT32 (CExactResamplerFilter::*tfDownmixer)(const void *in, INT32* out, \
int nSamplesIn) ;  struct REMIXERS {
-	UINT32 chmaskin, chmaskout, ulResampleChannels, nbps, ulHeadroom ;
-	tfDownmixer pfDownmixer ;
-	const tUpmixMachine* pUpmixMachine ;
+        UINT32 chmaskin, chmaskout, ulResampleChannels, nbps, ulHeadroom ;
+        tfDownmixer pfDownmixer ;
+        const tUpmixMachine* pUpmixMachine ;
     } ;
     static const struct REMIXERS remixers[] ;
     static const tUpmixMachine upmix_1_2[2] ;
@@ -151,7 +154,7 @@
     INT64 m_nSamplesProcessed;
 #ifdef _DEBUG
     UINT32 m_nTimeEaten;
-#endif	//  _DEBUG
+#endif  //  _DEBUG
     UINT32 m_ulFilterDelay ;
     UINT32 m_eatDelayedSamples ;
     HXT_TIME m_tDelayInMs ;
@@ -167,10 +170,10 @@
     UINT32 m_ulChannels_0, m_ulChannels_1_2, m_ulChannels_3 ;
     UINT32 m_ulTileSampleFrames ;
     
-    int m_resamplingQuality ;
-    
-    INT32 *m_pTempBuffer2 ;
-    INT32 *m_pTempBuffer3 ;
+    int             m_resamplingQuality;
+    IHXTUintListPtr m_spAutoSampleRates;
+    INT32*          m_pTempBuffer2;
+    INT32*          m_pTempBuffer3;
     
     // tools
     RAExactResampler* m_pResampler ;
@@ -192,7 +195,7 @@
     UINT32 downmix16_5_4(const void* in, INT32 *out, int nSamples) ;
     UINT32 downmix16_6_4(const void* in, INT32 *out, int nSamples) ;
     
-	SPIHXCommonClassFactory m_spFactory;
+        SPIHXCommonClassFactory m_spFactory;
     
 #ifdef PROFILING_CODECS
     CProfiler m_Profiler ;

Index: resampleragent.cpp
===================================================================
RCS file: /cvsroot/client/encodesvc/plugins/transform/audioresampler/resampleragent.cpp,v
 retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- resampleragent.cpp	13 Sep 2007 16:40:40 -0000	1.3
+++ resampleragent.cpp	27 Apr 2009 19:58:53 -0000	1.4
@@ -65,7 +65,7 @@
 #include "RAResampler.h"
 #include "ihxtaudioresampler.h"
 #include "hxstrutl.h" // stricmp
-
+#include "hxtproputils.h"
 #include "hxheap.h"
 #ifdef _DEBUG
 #undef HX_THIS_FILE     
@@ -90,6 +90,7 @@
     END_INTERFACE_LIST
 
 
+
 CExactResamplerFilter::CExactResamplerFilter() :
     m_pAllocator(NULL)
     ,m_pOutputSink(NULL)
@@ -231,6 +232,69 @@
 }
 
 
+
+STDMETHODIMP CExactResamplerFilter::SelectAutoSampleRate( IHXTUintList* pList,
+                                                          UINT32&       it )
+{
+    HX_RESULT res = HXR_FAIL;
+
+    //
+    // We know our input sample rate already. The way we choose from the
+    // list of sample rates passsed in it to
+    //
+    //  o Choose the same as input(m_ulInpSamplingRate)
+    //  o Choose the next highest from the input sample rate
+    //  o Choose the next lowest from the input sample rate.
+    //
+    if( NULL!=pList && pList->GetSize()>0 )
+    {
+        IHXTUintEnumeratorPtr spListEnum;
+        res = pList->GetEnumerator(spListEnum.Adopt());
+        if( SUCCEEDED(res) )
+        {
+            UINT32    ulValue   = 0;
+            UINT32    ulLowOne  = 0;
+            UINT32    ulHighOne = MAX_UINT32;
+            HX_RESULT resEnum   = spListEnum->First(&ulValue);
+            
+            while( SUCCEEDED(resEnum) && resEnum!=HXR_ELEMENT_NOT_FOUND )
+            {
+                //Quick exit if exact.
+                if( ulValue==m_ulInpSamplingRate )
+                {
+                    ulHighOne = ulValue;
+                    ulLowOne  = ulValue;
+                    break;
+                }
+                
+                //Other wise, keep track of out closest higher and lower
+                //neighbors.
+                if( ulValue<m_ulInpSamplingRate)
+                {
+                    if( m_ulInpSamplingRate-ulValue < m_ulInpSamplingRate-ulLowOne )
+                    {
+                        ulLowOne = ulValue;
+                    }
+                }
+                else
+                {
+                    if( ulValue-m_ulInpSamplingRate < ulHighOne-m_ulInpSamplingRate \
) +                    {
+                        ulHighOne = ulValue;
+                    }                    
+                }
+                resEnum = spListEnum->Next(&ulValue);
+            }
+            //Choose the higher sample rate if we found one.
+            HX_ASSERT(ulHighOne!=MAX_UINT32 || ulLowOne!= 0 );
+            it = ( ulHighOne != MAX_UINT32 ) ? ulHighOne : ulLowOne;
+            HX_ASSERT(it!=0);
+        }
+    }
+    return res;
+}
+
+
 /////////////////////////////////////////////////////////////
 //GetSupportedInputFormat
 //uStreamID: Stream ID (Currently igmored)
@@ -419,14 +483,34 @@
     // Set sample rate range    
     if (SUCCEEDED(res))
     {
-        IHXTUintRangePtr spSampleRates;
-        res = m_spFactory->CreateInstance(IID_IHXTUintRange, \
                spSampleRates.AdoptVoid());
-
-        if (SUCCEEDED(res))
-            res = spSampleRates->Set(1, 96000);
-
-        if (SUCCEEDED(res))
-            res = spOutputFormat->SetUintRange ( kPropAudioSampleRate , \
spSampleRates ); +        //If we have been passed, via OnSetUintList() a list of \
'auto' sample +        //rates from the code filter, then we need to pick the best \
match from +        //that list to use as our output.
+        if( m_spAutoSampleRates.IsValid() )
+        {
+            //Pick the best one from the list of samplerates that the codec
+            //filter is looking for. Just choose the largest right now.
+            UINT32 ulValue = 0;
+            SelectAutoSampleRate(m_spAutoSampleRates, ulValue);
+            if( SUCCEEDED(res) )
+            {
+                res = spOutputFormat->SetUint( kPropAudioSampleRate, ulValue );
+            }
+        }
+        else
+        {
+            IHXTUintRangePtr spSampleRates;
+            res = m_spFactory->CreateInstance(IID_IHXTUintRange, \
spSampleRates.AdoptVoid()); +            if (SUCCEEDED(res))
+            {
+                res = spSampleRates->Set(1, 96000);
+            }
+            
+            if (SUCCEEDED(res))
+            {
+                res = spOutputFormat->SetUintRange ( kPropAudioSampleRate , \
spSampleRates ); +            }
+        }
     }
     
 
@@ -706,3 +790,22 @@
     
     return HXR_OK ;
 }
+
+STDMETHODIMP CExactResamplerFilter::OnSetUintList( const char* szName, IHXTUintList* \
pValue ) +{
+    HX_RESULT res = HXR_OK;
+    if( !stricmp(szName, kPropAudioAutoSampleRates) )
+    {
+        if( pValue )
+        {
+            m_spAutoSampleRates = pValue;
+            res = HXR_OK;
+        }
+    }
+    else
+    {
+        HX_ASSERT("Invalid string property"==NULL);
+    }
+    
+    return res;
+}


_______________________________________________
Client-cvs mailing list
Client-cvs@helixcommunity.org
http://lists.helixcommunity.org/mailman/listinfo/client-cvs


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

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