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

List:       helix-datatype-cvs
Subject:    [Datatype-cvs] mpeg2ts/fileformat tsfformat.cpp, 1.20.2.11.2.9, 1.20.2.11.2.10
From:       ching_li () helixcommunity ! org
Date:       2012-03-29 10:00:22
[Download RAW message or body]

Update of /cvsroot/datatype/mpeg2ts/fileformat
In directory cvs01.internal.helixcommunity.org:/tmp/cvs-serv27848/fileformat

Modified Files:
      Tag: hxclient_3_6_1_atlas
	tsfformat.cpp 
Log Message:
Modified by: qingli@realnetworks.com<mailto:qingli@realnetworks.com>
Date: 03/06/2012
Project: RealPlayer for Android Smartphones
Bug ID: 14315&  14560
Bug URL: https://bugs.helixcommunity.org/show_bug.cgi?id=14315
         https://bugs.helixcommunity.org/show_bug.cgi?id=14560

Synopsis: Chang to fix several issues which are related with ts file format module

Overview:
> At first, there 2 memory leak issues in the module:
> 1) forgot to delete m_ppPrograms[nProgram]->ppESStreams[nStream] in \
> CTSDemuxer::Close function. The changes are following: @@ -129,6 +131,10 @@
> for (UINT16 nStream=0; nStream<MAX_STREAMS_PERPROGRAM; nStream++)
> {
> ReleaseStream(nProgram, nStream);
> +            if (m_ppPrograms[nProgram])
> +            {
> +                HX_DELETE( m_ppPrograms[nProgram]->ppESStreams[nStream] );
> +            }
> }
> HX_DELETE(m_ppPrograms[nProgram]);
> }
> 2) InitializePayloadHandlers will be invoked more than one time, so we should check \
> if pESStream->pPayloadHandler has been created. The changes are following: @@ \
> -1622,6 +1631,13 @@ {
> HXBOOL bIgnore = FALSE;
> TSStreamInfo* pESStream = m_pCurrentProgram->ppESStreams[i];
> +        if (pESStream->pPayloadHandler)
> +        {
> +            // the payload has been initialized.
> +            ++i;
> +            continue;
> +        }
> +
> switch (pESStream->ulStreamFormat)
> {
> case TS_STREAM_TYPE_VC1:
> 
> And at second, since PCR packet's PID could be different with any other streams', \
> please see the following logs: V/HelixPlayer( 1415): tsdemuxer.cpp:383 the PID of \
>                 PCR packet is 1001
> ...
> V/HelixPlayer( 1415): tsdemuxer.cpp:418 there are 2 streams!
> V/HelixPlayer( 1415): tsdemuxer.cpp:1694 stream format ID is 1b, PID is 1011
> V/HelixPlayer( 1415): tsdemuxer.cpp:1694 stream format ID is 81, PID is 1100
> ...
> so I added a function ParsePCRHigh to parse the PCR packet and changed the related \
> condition to process the case. The changes are following: @@ -836,43 +835,38 @@
> HX_RESULT ret = ParseTSHeader(pData,&ts_header);
> if (FAILED(ret)) return ret;
> 
> -        //does it belong to current program?
> -        if (m_pCurrentProgram->ulStreamCount  == 0 || \
> GetStreamNumber(ts_header.nPID)>  MAX_STREAMS_PERPROGRAM) +        if \
> (ts_header.nPID == m_pCurrentProgram->nPCR_PID) {
> -            // If the mapped nStreamNumber>  MAX_STREAMS_PERPROGRAM,
> -            // it means that this TS packet is not part of the
> -            // current program.  We will skip it.
> -            continue;
> +            retVal = ParsePCRHigh(&ts_header, pData, \
> m_pCurrentProgram->u64LastPCRHigh); +        }
> }
> 
> -        // if we have adaptation field
> -        if (ts_header.uAdaptionField&  0x02)
> +    if (HXR_OK != retVal)
> +    {
> +        retVal = ParsePES(pPESData, nPESSize);
> +    }
> +
> +    return retVal;
> +}
> +
> +HX_RESULT CTSDemuxer::ParsePCRHigh(TSPrefix_t* pTs_header, BYTE* pData, UINT64&  \
> u64PCRHigh) +{
> +    if (pTs_header->uAdaptionField&  0x02)
> {
> BYTE* pADA = pData + TS_PREFIX_SIXE;
> int nAdaptationFieldLength = pADA[0] + 1;
> HXBOOL bPCR = (pADA[1]>>  4)&  0x01;
> -
> -           // PCR (Program Clock Reference)
> if (bPCR&&  nAdaptationFieldLength>= 8)
> {
> -              // PCR high, 90kHz
> -              m_pCurrentProgram->u64LastPCRHigh =
> -                                         ( pADA[2]<<  25 ) |
> +            u64PCRHigh = ( pADA[2]<<  25 ) |
> ( pADA[3]<<  17 ) |
> ( pADA[4]<<  9 ) |
> ( pADA[5]<<  1 ) |
> ( pADA[6]>>  7 );
> -              retVal = HXR_OK;
> -            }
> -        }
> +            return HXR_OK;
> }
> -
> -    if (HXR_OK != retVal)
> -    {
> -        retVal = ParsePES( pPESData, nPESSize );
> }
> -
> -    return retVal;
> +    return HXR_NO_DATA;
> }
> 
> UINT32
> @@ -925,12 +920,16 @@
> // If the mapped nStreamNumber>  MAX_STREAMS_PERPROGRAM,
> // it means that this TS packet is not part of the
> // current program.  We will skip it.
> -            if (nStreamNumber<= MAX_STREAMS_PERPROGRAM)
> +            if (nStreamNumber<  MAX_STREAMS_PERPROGRAM)
> {
> retVal = CollectES(&ts_header, pData + TS_PREFIX_SIXE, nStreamNumber);
> -                if (FAILED(retVal))
> +            }
> +            else if (ts_header.nPID == m_pCurrentProgram->nPCR_PID)
> {
> -                    break;
> +                retVal = ParsePCRHigh(&ts_header, pData, \
> m_pCurrentProgram->u64PCRHigh); +                if \
> (m_pCurrentProgram->u64FirstPCRHigh == 0) +                {
> +                    m_pCurrentProgram->u64FirstPCRHigh = \
> m_pCurrentProgram->u64PCRHigh; }
> }
> }
> 
> And at third, for function CTSDemuxer::ScanEndTime, since ScanValidPacket function \
> has considered the cases of different packet size, its return value, that is \
> ulStart, has included the value of m_usOffset, we shouldn't adjust pData with \
> m_usOffset again. The changes are following: @@ -824,8 +823,8 @@
> return HXR_CORRUPT_FILE;
> }
> 
> -    pData += ulStart + m_usOffSet;
> -    nSize -= ulStart + m_usOffSet;
> +    pData += ulStart;
> +    nSize -= ulStart;
> BYTE * pPESData = pData;
> UINT32 nPESSize = nSize;
> 
> 
> And at fourth, since there could be more than 1 audio/subtitle stream in a clip, we \
> don't have to return HXR_UNSUPPORTED_AUDIO if some audio/subtitle stream is \
> unsupported, we can just ignore it. The changes are following: @@ -1642,67 +1658,72 \
> @@ break;
> 
> case TS_STREAM_TYPE_MPEG1_VIDEO:
> -        case TS_STREAM_TYPE_MPEG2_VIDEO:
> pESStream->bVideoStream = TRUE;
> m_pCurrentProgram->bHasVideoStream = TRUE;
> pESStream->pPayloadHandler = (CHXBasePayload*) (new \
> CHXMPEGVideoPayload(m_pContext)); break;
> 
> case TS_STREAM_TYPE_MPEG1_AUDIO:
> -        case TS_STREAM_TYPE_MPEG2_AUDIO:
> pESStream->bVideoStream = FALSE;
> pESStream->pPayloadHandler = (CHXBasePayload*) (new \
> CHXMPEGAudioPayload(m_pContext)); break;
> 
> -        case TS_STREAM_TYPE_PRIVATE_PES:
> -            // XXXJDG really should do some checking to figure out if
> -            // the private stream is actually AC3.
> case TS_STREAM_TYPE_AC3_ATSC:
> pESStream->bVideoStream = FALSE;
> pESStream->pPayloadHandler = (CHXBasePayload*) (new \
> CHXAC3AudioPayload(m_pContext)); break;
> 
> -        // Fail on unsupported video streams
> -        case 0x10:  // MPEG4 (video)
> -        case 0x80:  // MPEG-2 MOTO video
> -        case 0xa0:  // MSCODEC vlc (video)
> -            pESStream->pPayloadHandler = NULL;
> -            retVal = HXR_UNSUPPORTED_VIDEO;
> +        case TS_STREAM_TYPE_DTS:
> +        case TS_STREAM_TYPE_DTS_2:
> +            pESStream->bVideoStream = FALSE;
> +            pESStream->pPayloadHandler = (CHXBasePayload*) (new \
> CHXDTSAudioPayload(m_pContext)); break;
> 
> -        // Fail on unsupported audio streams
> -        case TS_STREAM_TYPE_AAC_LATM:
> -        case 0x83:  // LPCM (audio)
> -        case 0x84:  // SDDS (audio)
> -        case 0x85:  // DTS (audio)
> -        case 0x87:  // E-AC3
> -        case 0x91:  // A52 vls (audio)
> -        case 0x94:  // SDDS (audio)
> +        // Fail on unsupported video streams
> +        case TS_STREAM_TYPE_MPEG2_VIDEO:
> +        case TS_STREAM_TYPE_MPEG4_VIDEO:
> +        //case TS_STREAM_TYPE_DC2_VIDEO:
> +        case TS_STREAM_TYPE_WMV:
> pESStream->pPayloadHandler = NULL;
> -            retVal = HXR_UNSUPPORTED_AUDIO;
> +            bIgnore = TRUE;
> +            retVal = HXR_UNSUPPORTED_VIDEO;
> break;
> 
> -        case TS_STREAM_TYPE_PGSSUBTITLE:  // PGS subtitle
> #ifdef HELIX_FEATURE_EMBEDED_SUBTITLE
> +        case TS_STREAM_TYPE_PGS_SUBTITLE:
> pESStream->bVideoStream = FALSE;
> pESStream->pPayloadHandler = (CHXBasePayload*) (new CHXPGSPayload(m_pContext));
> -#else
> -            bIgnore = TRUE;
> -            pESStream->pPayloadHandler = NULL;
> -#endif
> break;
> +#endif
> +
> +        // Fail on unsupported audio streams
> +        case TS_STREAM_TYPE_PCM:
> +        case TS_STREAM_TYPE_MPEG2_AUDIO:
> +        case TS_STREAM_TYPE_AAC_LATM:
> +        case TS_STREAM_TYPE_LPCM:
> +        case TS_STREAM_TYPE_SDDS:
> +        case TS_STREAM_TYPE_DTS_HD:
> +        case TS_STREAM_TYPE_EAC3:
> +        case TS_STREAM_TYPE_AC3_DVB:
> +        case TS_STREAM_TYPE_EAC3_2:
> +        case TS_STREAM_TYPE_DTS_HD_2:
> +        case TS_STREAM_TYPE_SDDS_2:
> 
> // Ignore streams that are known to not be audio/video
> // or are an unrecognized type
> -        case 0x82:  // DVD_SPU (sub)
> -        case 0x92:  // DVD_SPU vls (sub)
> +        case TS_STREAM_TYPE_VLS_SUBTITLE:
> default:
> bIgnore = TRUE;
> pESStream->pPayloadHandler = NULL;
> break;
> }
> 
> -        if (!bIgnore)
> +        if (bIgnore)
> +        {
> +            ReleaseStream(i);
> +            // don't increment the iterator, we need to do this index again
> +        }
> +        else
> {
> ++i;
> 
> @@ -1711,28 +1732,29 @@
> pESStream->bNeedsAU = pESStream->pPayloadHandler->NeedAU();
> }
> }
> -        else
> +    }
> +
> +    return retVal;
> +}
> +
> +void
> +CTSDemuxer::ReleaseStream(UINT16 nStreamNumber)
> {
> // remove this stream from the list
> -            ReleaseStream(m_usCurrentProgramNum, i);
> +    ReleaseStream(m_usCurrentProgramNum, nStreamNumber);
> 
> // shift the rest back
> -            for (UINT16 j = i; j<  m_pCurrentProgram->ulStreamCount - 1; ++j)
> +    TSStreamInfo * pESStream = m_pCurrentProgram->ppESStreams[nStreamNumber];
> +    for (UINT16 i = nStreamNumber; i<  m_pCurrentProgram->ulStreamCount - 1; ++i)
> {
> -                m_pCurrentProgram->ppESStreams[j] =
> -                    m_pCurrentProgram->ppESStreams[j + 1];
> +        m_pCurrentProgram->ppESStreams[i] =
> +            m_pCurrentProgram->ppESStreams[i + 1];
> }
> +    m_pCurrentProgram->ppESStreams[m_pCurrentProgram->ulStreamCount - 1] = \
> pESStream; 
> // decrement stream count and move the now empty one to
> // the vacated end slot
> --m_pCurrentProgram->ulStreamCount;
> -            m_pCurrentProgram->ppESStreams[m_pCurrentProgram->ulStreamCount] = \
>                 pESStream;
> -
> -            // don't increment the iterator, we need to do this index again
> -        }
> -    }
> -
> -    return retVal;
> }
> 
> #ifdef HELIX_FEATURE_EMBEDED_SUBTITLE
> 
> And at last, I added a new function ReleaseStream and more stream type macros to \
> improve the readability and fixed 2 error code issues. 
> Files Added: None
> 
> Files Modified:
> datatype/mpeg2ts/demuxer/tsdemuxer.cpp
> datatype/mpeg2ts/demuxer/pub/tsdemuxer.h
> datatype/mpeg2ts/fileformat/tsfformat.cpp
> datatype/mpeg2ts/fileformat/pub/tsfformat.h
> 
> Image Size and Heap Use impact (Client -Only): None
> 
> Platforms and Profiles Affected:
> Platform: android-4.0-arm-qsd_8x60
> Profile: helix-client-android-full
> 
> Distribution Libraries Affected:None
> 
> Distribution library impact and planned action:None
> 
> Platforms and Profiles Build Verified:
> Platform: android-4.0-arm-qsd_8x60
> Profile: helix-client-android-full
> 
> Platforms and Profiles Functionality verified:
> Platform: android-4.0-arm-qsd_8x60
> Profile: helix-client-android-full
> 
> Branch: 361atlas
> 
> Copyright assignment: I am a RealNetworks employee or contractor
> 
> Best Regards!
> Li Qing
> --
> RealNetworks China, Beijing Office
> Tel: 008601059542848
> Fax: 008601085656477
> Address: 18th Floor,Tower B,Pacific Century Place,2A GongTiBeiLu,Chaoyang \
> District,Beijing, China Post Code: 100027


Index: tsfformat.cpp
===================================================================
RCS file: /cvsroot/datatype/mpeg2ts/fileformat/tsfformat.cpp,v
retrieving revision 1.20.2.11.2.9
retrieving revision 1.20.2.11.2.10
diff -u -d -r1.20.2.11.2.9 -r1.20.2.11.2.10
--- tsfformat.cpp	10 Jan 2012 15:35:29 -0000	1.20.2.11.2.9
+++ tsfformat.cpp	29 Mar 2012 10:00:19 -0000	1.20.2.11.2.10
@@ -313,7 +313,7 @@
             }
 
             if (SUCCEEDED(pRequestHeaders->GetPropertyULONG32("UseRawDTS", ulVal)))
-            {      
+            {
                 m_bUseRawDTS = ((ulVal == 0) ? FALSE : TRUE);      
             }
 
@@ -321,9 +321,9 @@
             pRequestHeaders->GetPropertyBuffer("FirstDTSBaseOffset", pBuffer);
             if (pBuffer)
             {
-               UnpackUINT64BE(pBuffer->GetBuffer(), sizeof(UINT64), \
                &u64DTSBaseOffset);
-               m_bFirstDTSBaseSet = TRUE;
-            }     
+                UnpackUINT64BE(pBuffer->GetBuffer(), sizeof(UINT64), \
&u64DTSBaseOffset); +                m_bFirstDTSBaseSet = TRUE;
+            }
             HX_RELEASE(pRequestHeaders);
         }
     }
@@ -753,7 +753,7 @@
         bFileHeaderNeedMoreData = FALSE;
         for (UINT16 i=0; i<m_ulStreamCount; i++)
         {
-            if (m_pTSDemuxer->IsStreamHeaderInfoReady(i) == FALSE)
+            if ( !m_pTSDemuxer->IsStreamHeaderInfoReady(i) )
             {
                 bFileHeaderNeedMoreData = TRUE;
                 break;
@@ -776,7 +776,7 @@
             m_pTSDemuxer->CalculateDTSOffset();
 
             // setup stream info
-            retVal = HXR_OUTOFMEMORY;
+            retVal = HXR_UNEXPECTED;
             HX_VECTOR_DELETE(m_pStreamInfo);
 
             m_eStatus = Ready;
@@ -784,10 +784,14 @@
             if (m_ulStreamCount)
             {
                 m_pStreamInfo = new CHXTSFFStreamInfo [m_ulStreamCount];
-            }
-            if (m_pStreamInfo)
-            {
-                retVal = HXR_OK;
+                if (m_pStreamInfo)
+                {
+                    retVal = HXR_OK;
+                }
+                else
+                {
+                    retVal = HXR_OUTOFMEMORY;
+                }
             }
 
             if (SUCCEEDED(retVal))
@@ -948,7 +952,7 @@
     {
         return HXR_OK;
     }
-        
+
     switch (m_eStatus)
     {
     case SeekSeekPending:


_______________________________________________
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