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

List:       helix-datatype-cvs
Subject:    [Datatype-cvs]
From:       ckarusala () helixcommunity ! org
Date:       2011-12-29 9:49:48
[Download RAW message or body]

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

Modified Files:
      Tag: SERVER_14_2_GLOBECOMM_LR
	audinfo.cpp mp3format.cpp 
Log Message:

Porting MP3 payload changes needed for compiling MPEG2-TS demuxer and stream \
fileformat on SERVER_14_2_GLOBECOMM_LR branch for server's MPEG2-TS ingress feature.


Index: mp3format.cpp
===================================================================
RCS file: /cvsroot/datatype/mp3/common/mp3format.cpp,v
retrieving revision 1.14
retrieving revision 1.14.24.1
diff -u -d -r1.14 -r1.14.24.1
--- mp3format.cpp	14 Jul 2009 20:30:40 -0000	1.14
+++ mp3format.cpp	29 Dec 2011 09:49:45 -0000	1.14.24.1
@@ -151,21 +151,20 @@
     memset(&h, 0, sizeof(h));
 
     int nBitRate = 0;
-	UINT32 ulTempSampleRate = 0;
-	UINT32 ulTempChannels = 0;
-	UINT32 ulTempSamplesPerFrame = 0;
+    UINT32 ulTempSampleRate = 0;
+    UINT32 ulTempChannels = 0;
+    UINT32 ulTempSamplesPerFrame = 0;
 	
-	if (!head_info2(pHeader, dwSize, &h, &nBitRate, m_bTrustPackets))
-		return 0;
+    if (!head_info2(pHeader, dwSize, &h, &nBitRate, m_bTrustPackets))
+	    return 0;
     
     if (3 == h.mode)
         ulTempChannels = 1;
     else
         ulTempChannels = 2;
 
-    ulTempSampleRate = aSampRate[h.id][h.sr_index] >> m_bMpeg25;
-	if(ulTempSampleRate <= 0)
-		return 0;
+    
+    ulTempSampleRate = aSampRate[h.id][h.sr_index];
 
     // Get the layer so we can work out the bit rate
     switch (h.option)
@@ -184,20 +183,24 @@
 
     if((h.option == 1) & (h.id == 0))  // MPEGII Layer III
     {
+        // If it's MPEG-2.5 L3, sample rate is halved
+        int nMPEG25 = 1 - (h.sync & 1);
+        ulTempSampleRate >>= nMPEG25;
+
         ulTempSamplesPerFrame = 576;
         m_pFnGetData = GetDataOffsetMPEG2;
     }
     else if(h.option == 3)
         ulTempSamplesPerFrame = 384;     // Layer I
     else
-        ulTempSamplesPerFrame = 1152;
+        ulTempSamplesPerFrame = 1152;    // Layer II
 
     nPadding = h.pad;
 
-	ulBitRate = nBitRate;
-	ulSampleRate = ulTempSampleRate;
-	nChannels = ulTempChannels;
-	nSamplesPerFrame = ulTempSamplesPerFrame;
+    ulBitRate = nBitRate;
+    ulSampleRate = ulTempSampleRate;
+    nChannels = ulTempChannels;
+    nSamplesPerFrame = ulTempSamplesPerFrame;
 
     return 1;
 }
@@ -375,22 +378,39 @@
         return 0;
 }
 
-INT32 CMp3Format::ScanForSyncWord(UINT8 *pBuf,
-                                  INT32 lSize,
-                                  int &nFrameSize)
+HXBOOL 
+CMp3Format::ScanForSyncWord(UINT8* pBuf,
+                             UINT32 ulSize,
+                             UINT32& ulFrameSize,
+                             INT32& lOffset)
 {
     UINT8       *pStart = pBuf,
-                *pEnd = pBuf + lSize - 4,
+                *pEnd = pBuf + ulSize,
                 *pTemp = NULL,
                 ySyncCheck = 0;
     MPEG_HEAD   head;
-    int         iFrameSize = 0;
+    UINT32      iFrameSize = 0;
 
-    if (lSize < 4)
-        return -1;
+    ulFrameSize = 0;
+    lOffset = -1;
 
-    nFrameSize = 0;
+    if (ulSize < 4)
+    {
+        while (pBuf != pEnd)
+        {
+            if ((*pBuf++ == 0xFF) && 
+                (pBuf == pEnd || (*pBuf & 0xE0) == 0xE0))
+            {
+                // could be a sync word, but we don't have the full header
+                lOffset = pBuf - pStart;
+                return FALSE;
+            }
+        }
+       
+        return FALSE;
+    }
 
+    HXBOOL bVerified = TRUE;
     for (; pBuf < pEnd; pBuf++)
     {
         if (pBuf[0] != 0xFF)
@@ -415,17 +435,18 @@
             iFrameSize += head.pad;
 
             // Check for another frame
-            if (pBuf+iFrameSize < pEnd+3)
+            if (pBuf+iFrameSize < pEnd-1)
             {
                 pTemp = pBuf + iFrameSize;
 
-                if((pTemp[0] == 0xFF) && (pTemp[1] & 0xE0 == 0xE0))
+                if((pTemp[0] == 0xFF) && (pTemp[1] == ySyncCheck))
                 {
-                    nFrameSize = iFrameSize;
+                    // next sync word is right where it should be,
+                    // this is a valid sync word
+                    ulFrameSize = iFrameSize;
                 }
                 // We do not have consequitve frames..what to do, what to do?
-                else if ((pTemp[0] != 0xFF) |
-                    (pTemp[1] != ySyncCheck))
+                else
                 {
                     INT32 lHeaderSize = 0;
 
@@ -435,47 +456,64 @@
 
                     if (m_pMisc)
                         bFoundHdr = m_pMisc->CheckForHeaders(pTemp,
-                                                             pEnd-pTemp+4,
+                                                             pEnd-pTemp,
                                                              lHeaderSize);
                     if (bFoundHdr)
-                        nFrameSize = iFrameSize;
+                        ulFrameSize = iFrameSize;
 
                     // Next, check if the padding bit was incorrectly set
                     else if ((pTemp[-1] == 0xFF) &
                              (pTemp[0] == ySyncCheck))
-                        nFrameSize = iFrameSize;
+                        ulFrameSize = iFrameSize;
 
                     // Finally, check if the padding bit was not set and
                     // should have been.
                     else if ((pTemp[1] == 0xFF) &
                              (pTemp[2] == ySyncCheck))
-                        nFrameSize = iFrameSize;
+                        ulFrameSize = iFrameSize;
 
                     // Did not find consequtive frames.  Keep looking
                     else
                         continue;
                 }
+            }
+            else if (pBuf+iFrameSize == pEnd - 1)
+            {
+                // We have one extra byte. Check if it looks like the start
+                // of a consecutive sync word
+                if (pBuf[iFrameSize] == 0xFF)
+                {
+                    ulFrameSize = iFrameSize;
+                    bVerified = FALSE;
+                }
                 else
                 {
-                    // We found a frame
-                    nFrameSize = iFrameSize;
+                    continue;
                 }
             }
-            // There is one full frame in this buffer
-            else if (pBuf+iFrameSize == pEnd+4)
+            else if (pBuf == pStart && iFrameSize == ulSize)
             {
-                // We found a frame
-                nFrameSize = iFrameSize;
+                // Input was exactly one frame. 
+                // We take that to mean it is correct
+                ulFrameSize = iFrameSize;
+            }
+            else
+            {
+                // Looks like a sync word, but we don't have the whole frame
+                ulFrameSize = iFrameSize;
+                bVerified = FALSE;
             }
-
             break;
         }
     }
 
-    if (nFrameSize)
-        return pBuf - pStart;
-    else
-        return -1;
+    if (ulFrameSize)
+    {
+        lOffset = pBuf - pStart;
+        return bVerified;
+    }
+    
+    return FALSE;
 }
 
 HXBOOL CMp3Format::CheckForHeaders(UINT8 *pBuf,
@@ -496,6 +534,31 @@
         return eNone;
 }
 
+UINT32 CMp3Format::GetMaxFrameSize()
+{
+    // If we've initialized on ID and layer, get the relevant max
+    switch (m_ySyncWord & 0xFE)
+    {
+    case 0xFE:  // MPEG-1 L1
+        return 1344;
+    case 0xFC:  // MPEG-1 L2
+        return 3456;
+    case 0xFA:  // MPEG-1 L3
+        return 2880;
+    case 0xF6:  // MPEG-2 L1
+        return 1536;
+    case 0xF4:  // MPEG-2 L2
+        return 2880;
+    case 0xF2:  // MPEG-2 L3
+        return 1440;
+    case 0xE2:  // MPEG-2.5 L3
+        return 2880;
+    }
+
+    // Unset (or invalid)
+    return MAX_MPA_FRAME_SIZE; 
+}
+
 // Functions to access the Id3 header values
 UINT8* CMp3Format::GetId3Title(int &nLen)
 {

Index: audinfo.cpp
===================================================================
RCS file: /cvsroot/datatype/mp3/common/audinfo.cpp,v
retrieving revision 1.4
retrieving revision 1.4.154.1
diff -u -d -r1.4 -r1.4.154.1
--- audinfo.cpp	14 Mar 2005 19:17:03 -0000	1.4
+++ audinfo.cpp	29 Dec 2011 09:49:45 -0000	1.4.154.1
@@ -57,6 +57,22 @@
     return m_ySyncWord;
 }
 
+INT32 CAudioInfoBase::ScanForSyncWord(UINT8 *pBuf,
+                                  INT32 lSize,
+                                  int &nFrameSize)
+{
+    UINT32 ulFrameSize = 0;
+    INT32  lOffset = -1;
+
+    if (ScanForSyncWord(pBuf, (UINT32)lSize, ulFrameSize, lOffset))
+    {
+        nFrameSize = (int)ulFrameSize;
+        return lOffset;
+    }
+
+    return -1;
+}
+
 UINT32 CAudioInfoBase::GetAudioRtpPacket(UINT8 *pRead,
                                          UINT32 ulRead,
                                          tRtpPacket *pRtp)


_______________________________________________
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