[hxdatatype] mp3ff code size savings diff

[hxdatatype] mp3ff code size savings diff

Eric Hyche ehyche at real.com
Thu Jul 24 08:28:21 PDT 2003


dev at datatype:

The following diff should achieve some code size and
heap size savings in the mp3 ff. Here are the changes:

1) Removed m_ulPreRoll member variable. It was only
    used in one place, so I removed it and replaced
    it with a local stack variable.
2) Removed m_dTimePerFrame member variable. It was
    not being used anywhere.
3) Changed READ_BUFFER_SIZE from a member variable
    to a class-specific enum constant kReadSize.
    READ_BUFFER_SIZE was being set to one value and
    never changed, so there was no need for it to
    be a member variable.
4) Expanded some HELIX_FEATURE_SERVER defines to
    include a broader amount of server-specific code.
5) Replace several blocks of code in creating the
    file header with calls to SetCStringProperty().
6) Replaced code which had several calls to the
    same method (just with different arguments) to
    be one call to the method. For instance, I replaced
    code like:

       if ()
           foo->Read(A)
       else if ()
           foo->Read(B)
       else
           foo->Read(C)

    with

       size = C
       if () size=A
       else if() size=B

       foo->Read(size)

7) Included some RTP-specific code inside MPA_FMT_DRAFT00
    defines which were not previously included.
8) Removed m_ulRet member variable - it was not being
    used anywhere.
9) Put the declaration of SetMetaInfo() inside of
    HELIX_FEATURE_MP3FF_ONDEMANDMETAINFO defines - the
    implementation was already inside of these defines.

I have verified this still builds and runs when building
under -all-defines.

I plan to check this in around 2pm EDT (11am PDT) unless
there are any objections.

Eric

======================================
M. Eric Hyche (ehyche at real.com)
Core Technologies
RealNetworks, Inc.
-------------- next part --------------
Index: mp3ff.cpp
===================================================================
RCS file: /cvs/datatype/mp3/fileformat/mp3ff.cpp,v
retrieving revision 1.20
diff -u -w -u -w -r1.20 mp3ff.cpp
--- mp3ff.cpp	21 Jul 2003 21:07:15 -0000	1.20
+++ mp3ff.cpp	24 Jul 2003 15:16:44 -0000
@@ -179,7 +179,6 @@
       m_szPlayerReg   (NULL),
       m_State         (Ready),
       m_ulNextPacketDeliveryTime(0),
-      m_ulPreRoll(1000),
       m_ulFileSize(0),
       m_ulMetaReadSize(0),
       m_ulNextMetaPos((UINT32)-1),
@@ -189,7 +188,6 @@
       m_ulFileOffset(0),
       m_nChannels(0),
       m_dNextPts(0.0),
-      m_dTimePerFrame(0.0),
       m_bEOF(0),
       m_bRtp(0),
       m_bHasVbrHdr(0),
@@ -200,7 +198,6 @@
       m_bCheckBadData(0),
       m_bLive(0),
       m_bLicensed(0),
-      READ_BUFFER_SIZE(2048),
       m_pFmtBuf(NULL),
       m_pMp3Fmt(NULL),
       m_ulGarbageBytesRead(0),
@@ -591,6 +588,7 @@
 
                 return hr;
             }
+#if defined(HELIX_FEATURE_SERVER)
             // Server is full
             else
             {
@@ -600,6 +598,7 @@
 
                 return HXR_NOT_AUTHORIZED;
             }
+#endif /* #if defined(HELIX_FEATURE_SERVER) */
         }
         
         // Invalid stream
@@ -794,12 +793,13 @@
         pStreamHeaderObj->SetPropertyULONG32("SampleRate", m_ulMaxSampRate);
         pStreamHeaderObj->SetPropertyULONG32("NumChannels", m_nChannels);
         
+        UINT32 ulPreRoll = 1000;
         if (m_pFileObj->Advise(HX_FILEADVISE_RANDOMACCESS) == HXR_ADVISE_PREFER_LINEAR)
-            m_ulPreRoll += 2000;
+            ulPreRoll += 2000;
 
-        pStreamHeaderObj->SetPropertyULONG32("Preroll", m_ulPreRoll);
+        pStreamHeaderObj->SetPropertyULONG32("Preroll", ulPreRoll);
 
-        m_Info.nPacketSize = min(m_Info.nPacketSize, READ_BUFFER_SIZE);
+        m_Info.nPacketSize = min(m_Info.nPacketSize, kReadSize);
 
         double dDur;
         dDur = m_ulFileSize / (double)(m_Info.ulBitRate>>3) * 1000.0;
@@ -822,50 +822,44 @@
         
         // "MimeType": this stream's MIME type. This associates this
         // stream type with a particular renderer.
-        IHXBuffer* pStringObj = NULL;
-        m_pClassFactory->CreateInstance(CLSID_IHXBuffer,
-                                         (void**)&pStringObj);
-        if (pStringObj != NULL)
-        {
-            char* streamMimeType;
-
+        const char* pszTmp = MY_LOCAL_MIME_TYPE;
 #if defined (MPA_FMT_DRAFT00)
             if (m_bStreaming)
             {
                 if(m_bRtp)
-                    streamMimeType = MY_RTP_MIME_TYPE;
+                pszTmp = MY_RTP_MIME_TYPE;
                 else
-                    streamMimeType = MY_STREAM_MIME_TYPE;
+                pszTmp = MY_STREAM_MIME_TYPE;
             }
-            else
 #endif //MPA_FMT_DRAFT00
-                streamMimeType = MY_LOCAL_MIME_TYPE;
+        SetCStringProperty(pStreamHeaderObj, "MimeType", pszTmp, m_pContext);
 
-            pStringObj->Set((const UCHAR*)streamMimeType,
-                             strlen(streamMimeType) + 1);
-            pStreamHeaderObj->SetPropertyCString("MimeType", pStringObj);
-            pStringObj->Release();
-        }
-
-        IHXBuffer* pASMBuf = NULL;
-        m_pClassFactory->CreateInstance(CLSID_IHXBuffer, (void**)&pASMBuf);
-        if (pASMBuf != NULL)
-        {
-            ULONG32 dwPriority = 9;
+        // Set the ASM rule book
             char    *pRuleBook = new char[sizeof(char) * 100];
-            
+        if (pRuleBook)
+        {
+            // Create the string
             if (m_bRtp)
-                SafeSprintf(pRuleBook, 100, "marker=0, AverageBandwidth=%ld, Priority=%ld, timestampdelivery=true;", m_Info.ulBitRate, dwPriority); 
+            {
+                SafeSprintf(pRuleBook, 100,
+                            "marker=0, AverageBandwidth=%ld, Priority=9, "
+                            "timestampdelivery=true;",
+                            m_Info.ulBitRate); 
+            }
             else
-                SafeSprintf(pRuleBook, 100,"AverageBandwidth=%ld, AverageBandwidthStd=0, Priority=%ld;", m_Info.ulBitRate, dwPriority);
-
-            pASMBuf->Set((const UCHAR*)pRuleBook, strlen(pRuleBook)+1);
-            pStreamHeaderObj->SetPropertyCString("ASMRuleBook", pASMBuf);
-
-            pASMBuf->Release();
-            delete [] pRuleBook;
+            {
+                SafeSprintf(pRuleBook, 100,
+                            "AverageBandwidth=%ld, AverageBandwidthStd=0, "
+                            "Priority=9;",
+                            m_Info.ulBitRate);
+            }
+            // Set it into the stream header
+            SetCStringProperty(pStreamHeaderObj, "ASMRuleBook",
+                               (const char*) pRuleBook, m_pContext);
         }
+        HX_VECTOR_DELETE(pRuleBook);
 
+#if defined(HELIX_FEATURE_SERVER)
         if (!m_bLicensed)
         {
             if (m_pError)
@@ -879,6 +873,7 @@
 
             status = HXR_NOT_LICENSED;
         }
+#endif /* #if defined(HELIX_FEATURE_SERVER) */
         
         // Notify the RMA core that stream header object is ready
         m_pStatus->StreamHeaderReady(status, pStreamHeaderObj);
@@ -912,7 +907,7 @@
         m_bNeedPacket = 1;
 
         m_State = GetPacketReadPending;
-        m_pFileObj->Read(READ_BUFFER_SIZE);
+        m_pFileObj->Read(kReadSize);
 
         return HXR_OK;
     }
@@ -1281,16 +1276,20 @@
             break;
 
         case GetFileHeaderSeekPending:
+            {
             m_State = GetFileHeaderReadPending;
 
             // Read the file header data from the file.
             // Read more when we are streaming - we need more   
             // accurate avg bitrate for vbrs when streaming.   
+                UINT32 ulReadSize = MY_FILE_HEADER_LENGTH << 3;
             if (m_bLive ||
                 m_pFileObj->Advise(HX_FILEADVISE_RANDOMACCESS) == HXR_ADVISE_PREFER_LINEAR)
-                m_pFileObj->Read(MY_FILE_HEADER_LENGTH); 
-            else   
-                m_pFileObj->Read(MY_FILE_HEADER_LENGTH<<3);   
+                {
+                    ulReadSize = MY_FILE_HEADER_LENGTH;
+                }
+                m_pFileObj->Read(ulReadSize);
+            }
             break;
 
         case GetStreamHeaderSeekPending:
@@ -1300,7 +1299,7 @@
         case GetPacketSeekPending:
         {
             m_State = GetPacketReadPending;
-            UINT32  ulReadSize = READ_BUFFER_SIZE;
+            UINT32  ulReadSize = kReadSize;
             
 #if defined(MPA_FMT_SHOUTCAST)
             if (m_ulMetaReadSize)
@@ -1394,7 +1393,7 @@
                 m_ReadBuf.dwBytesRemaining = pBufferRead->GetSize();
                 m_ReadBuf.dwBufferSize = pBufferRead->GetSize();
 
-                if (m_ReadBuf.dwBufferSize < (UINT32)READ_BUFFER_SIZE)
+                if (m_ReadBuf.dwBufferSize < kReadSize)
                     m_bEOF = TRUE;
                 else
                     m_bEOF = FALSE;
@@ -1518,6 +1517,7 @@
                                 }
                             }
 
+#if defined(HELIX_FEATURE_REGISTRY)
                             if(m_ulMetaLength)
                             {
                                 // Put the song title in an IHXBuffer
@@ -1525,10 +1525,8 @@
                                     nLen+1);
                                 pTitle->GetBuffer()[nLen] = '\0';
 
-#if defined(HELIX_FEATURE_REGISTRY)
                                 m_pRegistry->SetStrByName(
                                     (char*)m_szPlayerReg->GetBuffer(), pTitle);
-#endif /* #if defined(HELIX_FEATURE_REGISTRY) */
                                 HX_RELEASE(pTitle);
 
                                 m_pClassFactory->CreateInstance(
@@ -1549,11 +1547,10 @@
                                          (char*)m_szPlayerReg->GetBuffer(), 128); 
                                     strcpy(&szTitle[strlen(szTitle)-6], /* Flawfinder: ignore */
                                         "Title");
-#if defined(HELIX_FEATURE_REGISTRY)
                                     m_pRegistry->SetStrByName(szTitle, pTitle);
-#endif /* #if defined(HELIX_FEATURE_REGISTRY) */
                                 }
                             }
+#endif /* #if defined(HELIX_FEATURE_REGISTRY) */
 
                             HX_RELEASE(pTitle);
                         }
@@ -1653,12 +1650,12 @@
     // skip the vbr header at the start of the file.
     if (!ulPacketStart && m_bStreaming && !m_bRtp)
         m_bSkipVbrHdr = m_bHasVbrHdr;
-#endif //MPA_FMT_DRAFT00
 
     memset(&m_RtpPackets, 0, sizeof(m_RtpPackets));
     m_RtpPackets.ulBytesFree = RTP_PACKET_SIZE;
     m_RtpPackets.dScr = m_dNextPts;
     m_RtpPackets.dPts = m_dNextPts;
+#endif //MPA_FMT_DRAFT00
     
     // Move to the requested location in the file
     m_ulBytesRead = ulPacketStart;
@@ -1699,12 +1696,11 @@
     HX_RELEASE(m_szPlayerReg);
     HX_RELEASE(m_pClassFactory);
     HX_RELEASE(m_pContext);
+    HX_RELEASE(m_pMetaProps);
     
-    if (m_pFmtBuf)
-    {
-        delete m_pFmtBuf;
-        m_pFmtBuf = NULL;
-    }
+#if defined(MPA_FMT_DRAFT00)
+    HX_DELETE(m_pFmtBuf);
+#endif /* #if defined(MPA_FMT_DRAFT00) */
 
     return HXR_OK;
 }
@@ -1846,8 +1842,10 @@
 {
     HX_RELEASE(m_ReadBuf.pReadBuffer);
 
+#if defined(MPA_FMT_DRAFT00)
     if (m_pFmtBuf)
         m_pFmtBuf->Reset();
+#endif /* #if defined(MPA_FMT_DRAFT00) */
 }
 
 UCHAR* CRnMp3Fmt::GetMP3Frame_p(tReadBuffer* pPacketData, int &nSyncSize)
Index: pub/mp3ff.h
===================================================================
RCS file: /cvs/datatype/mp3/fileformat/pub/mp3ff.h,v
retrieving revision 1.7
diff -u -w -u -w -r1.7 mp3ff.h
--- pub/mp3ff.h	21 Jul 2003 21:07:15 -0000	1.7
+++ pub/mp3ff.h	24 Jul 2003 15:16:44 -0000
@@ -248,6 +248,11 @@
         HX_RESULT   status;
     } tReadBuffer;
 
+    enum
+    {
+        kReadSize = 2048
+    };
+
     ///////////////////////////////////////////////////////////////////////////
     // Private Class Variables
     INT32                  m_RefCount;         // Object's reference count
@@ -259,7 +264,6 @@
     IHXBuffer*             m_szPlayerReg;
     MyState                m_State;            // State used for asynch. calls
     UINT32                 m_ulNextPacketDeliveryTime; // Delivery time of next packet
-    UINT32                 m_ulPreRoll;        // ms
     UINT32                 m_ulFileSize;
     UINT32                 m_ulMaxSampRate;    // Max pcm sample rate in this stream
     UINT32                 m_ulMetaReadSize;   // A custom read size for meta data
@@ -269,12 +273,9 @@
     UINT32                 m_ulFileOffset;     // Offset for start of file to data
     int                    m_nChannels;        // Number of channels in the stream
     double                 m_dNextPts;         // decimal ms of the next packet
-    double                 m_dTimePerFrame;    // decimal ms per audio frame
     CIHXRingBuffer*        m_pFmtBuf;          // RingBuffer
-    HX_RESULT              m_ulRet;
     IHXValues*             m_pMetaProps;
     IUnknown*              m_pContext;
-    INT32                  READ_BUFFER_SIZE;
     tReadBuffer            m_ReadBuf;
     tRtpPacket             m_RtpPackets;
     tStreamInfo            m_Info;
@@ -328,7 +329,9 @@
 
     INT32       GetStartCode(UINT8 **ppBuffer, UINT32 &ulBytes);
 
+#if defined(HELIX_FEATURE_MP3FF_ONDEMANDMETAINFO)
     void        SetMetaInfo(IHXValues* pFileHeader, const char* pszProp);
+#endif /* #if defined(HELIX_FEATURE_MP3FF_ONDEMANDMETAINFO) */
 
     PRIVATE_DESTRUCTORS_ARE_NOT_A_CRIME      // Avoids GCC compiler warning
 };

-------------- next part --------------
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe at datatype.helixcommunity.org
For additional commands, e-mail: dev-help at datatype.helixcommunity.org


More information about the Datatype-dev mailing list
 

Site Map   |   Terms of Use   |   Privacy Policy   |   Contact Us

Copyright © 1995-2007 RealNetworks, Inc. All rights reserved. RealNetworks and Helix are trademarks of RealNetworks.
All other trademarks or registered trademarks are the property of their respective holders.