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

List:       helix-datatype-cvs
Subject:    [Datatype-cvs] mkv/fileformat mkv_file_format.cpp, 1.11.2.3,
From:       joeli () helixcommunity ! org
Date:       2010-11-26 2:15:03
Message-ID: 201011260215.oAQ2FAtq011813 () mailer ! progressive-comp ! com
[Download RAW message or body]

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

Modified Files:
      Tag: hxclient_3_6_1_atlas
	mkv_file_format.cpp 
Log Message:

dified by: joeli@real.com
Date: 2010-11-24
Project: RealPlayer for Android Smartphones
Bug Number: 12083 12084 12085

Overview: Currently helix mkv doesn't support eac3 and not support for multi-streams, \
if contents have subtitles embedded, the audio can't be played. about this fix, most \
of source codes are merged from helix.420 branch.

Fix includes the follow points:
1.       support the content encoding element for eac3 audio format.
2.       handle multi-streams, if It has subtitles, remove the sync header from audio \
packets 3.       some crash issues

Files Added:
NA

Files Modified:
datatype/mkv/fileformat/pub/mkv_file_format.h
datatype/mkv/fileformat/mkv_file_format.cpp
datatype/mkv/libmatroska/libebml/ebml/EbmlBinary.h
datatype/mkv/libmatroska/libebml/src/EbmlBinary.cpp
datatype/mkv/libmatroska/libebml/src/IOCallback.cpp
datatype/mkv/libmatroska/libmatroska/matroska/KaxBlock.h
datatype/mkv/libmatroska/libmatroska/src/KaxBlock.cpp
datatype/mkv/libmatroska/Matroska.cpp
datatype/mkv/libmatroska/mkvtypes.h

Image Size and Heap Use impact (Client-Only):
None

Platforms and Profiles Affected:
Platform: hxclient_3_6_1_atlas 
Profile: helix-client-android and helix-client-all-defines

Distribution Libraries Affected:
NA 

Distribution library impact and planned action:
NA 

Platforms and Profiles Build Verified:
Platform: hxclient_3_6_1_atlas 
Profile:  helix-client-android and helix-client-all-defines

Platforms and Profiles Functionality verified:
Platform: hxclient_3_6_1_atlas
Profile: helix-client-android and helix-client-all-defines

Branch: hxclient_3_6_1_atlas
Copyright assignment: I am a RealNetworks employee



Index: mkv_file_format.cpp
===================================================================
RCS file: /cvsroot/datatype/mkv/fileformat/mkv_file_format.cpp,v
retrieving revision 1.11.2.3
retrieving revision 1.11.2.4
diff -u -d -r1.11.2.3 -r1.11.2.4
--- mkv_file_format.cpp	23 Jul 2010 15:02:20 -0000	1.11.2.3
+++ mkv_file_format.cpp	26 Nov 2010 02:15:00 -0000	1.11.2.4
@@ -72,11 +72,15 @@
 #define MKV_MP4_MIMETYPE "V_MPEG4"
 #define HELIX_MP4_MIMETYPE "video/X-RN-MP4"
 #define MKV_AAC_MIMETYPE "A_AAC"
+#define MKV_AAC3_MIMETYPE "A_AC3"
 #define HELIX_AAC_MIMETYPE "audio/X-HX-AAC-GENERIC"
 
 
 #define DEFAULT_RTP_SAMPLES 90000
 
+#define ONE_THOUSAND 1000
+#define ONE_MILLION 1000000
+
 #define CONVERT_TO_MILI_SECOND 1000000 // MKV file format duration are in \
nanoseconds.   #define MKV_ABSVAL(val) (((val) < 0) ? (-(val)) : (val))
 #define MKV_BFRAME_MAXIMUMDEPTH 16
@@ -125,6 +129,47 @@
 
 static const UINT16 SizeOfMimeTypeMap = \
sizeof(MkvToHelixMimeTypeMap)/sizeof(MkvToHelixMimeTypeMap[0]);  static const UINT16 \
SizeOfMSMimeTypeMap = \
sizeof(MkvMSToHelixMimeTypeMap)/sizeof(MkvMSToHelixMimeTypeMap[0]); +const UINT32 \
uDDFrameSizetTbl [38][3] = +{
+    128,	138,	192,
+    128,	140,	192,
+    160,	174,	240,
+    160,	176,	240,
+    192,	208,	288,
+    192,	210,	288,
+    224,	242,	336,
+    224,	244,	336,
+    256,	278,	384,
+    256,	280,	384,
+    320,	348,	480,
+    320,	350,	480,
+    384,	416,	576,
+    384,	418,	576,
+    448,	486,	672,
+    448,	488,	672,
+    512,	556,	768,
+    512,	558,	768,
+    640,	696,	960,
+    640,	698,	960,
+    768,	834,	1152,
+    768,	836,	1152,
+    896,	974,	1344,
+    896,	976,	1344,
+    1024,	1114,	1536,
+    1024,	1116,	1536,
+    1280,	1392,	1920,
+    1280,	1394,	1920,
+    1536,	1670,	2304,
+    1536,	1672,	2304,
+    1792,	1950,	2688,
+    1792,	1952,	2688,
+    2048,	2228,	3072,
+    2048,	2230,	3072,
+    2304,	2506,	3456,
+    2304,	2508,	3456,
+    2560,	2786,	3840,
+    2560,	2788,	3840,
+};
 
 CMKVFileFormat::CMKVFileFormat():m_lRefCount(0), m_pContext(NULL), \
                m_pCommonClassFactory(NULL),
                                  m_pRequest(NULL), m_pFormatResponse(NULL), \
m_pScheduler(NULL), @@ -344,6 +389,7 @@
 		{
 			HXLOGL1(HXLOG_MKVF, "CMKVFileFormat::GetFileHeader(): Invalid File!");
 			retVal = HXR_INVALID_FILE;
+			m_pFormatResponse->FileHeaderReady(retVal, NULL);
 		}
 	}
 
@@ -496,7 +542,7 @@
             retval = pRTPPacket ->QueryInterface(IID_IHXPacket,(void**) &pPacket);
             HX_RELEASE(pRTPPacket );
         }
-        else
+        else if(trk->type == TrackAudio)
         {
             if(FAILED(CreatePacketCCF(pPacket, m_pContext)))
             {
@@ -511,6 +557,118 @@
 
 }
 
+HX_RESULT CMKVFileFormat::FormAAC3AudioPacket(REF(IHXPacket*) packet,UINT32 \
strNum,UINT64 uTimeCode,HXBOOL bKey,MKVTrack *track,IHXBuffer* pBuffer) +{
+    HX_RESULT retVal = HXR_OK;
+    IHXBuffer *pAudioBuffer = NULL;
+    UINT8 uFrameInfoByte=0;
+    if(pBuffer->GetSize()>=2)
+    {
+        uFrameInfoByte = *(pBuffer->GetBuffer()+2);
+    }
+    else
+    {
+        retVal=HXR_FAILED;
+        HXLOGL1(HXLOG_MKVF, "CMKVFileFormat::FormAAC3AudioPacket Failed \
pBuffer->Getsize() < =2 \n"); +        return retVal;
+    }
+    UINT8 uFameSizeCode = uFrameInfoByte & 0x3f;
+    UINT8 uSampleRateCode = uFrameInfoByte >> 6; 
+    UINT32 uFrameLen=1;
+    UINT32 index=0;
+    UINT32 offset=0,payloadoffset=0;
+    UINT32 uNumberofsyncword=0;
+    HXLOGL1(HXLOG_MKVF, "CMKVFileFormat::FormAudioPacket uFameSizeCode %d, \
uSampleRateCode %d \n",uFameSizeCode, uSampleRateCode); +    if ( uFameSizeCode < 38 \
&& uSampleRateCode < 3 ) +    {
+	    uFrameLen = uDDFrameSizetTbl[uFameSizeCode][uSampleRateCode];
+    }
+    if( uFrameLen > track->uContentCompressSetting)
+    {
+        uNumberofsyncword= (pBuffer->GetSize())/(uFrameLen - \
track->uContentCompressSetting); +        offset=( (pBuffer->GetSize()) % (uFrameLen \
- track->uContentCompressSetting)); +    }
+    else
+    {
+        retVal=HXR_FAILED;
+        HXLOGL1(HXLOG_MKVF, "CMKVFileFormat::FormAAC3AudioPacket Failed uFrameLen <  \
track->uContentCompressSetting :%d < %d \
\n",uFrameLen,track->uContentCompressSetting); +        return retVal;
+    }
+    if(track->uPaddingOffset == 0)
+    {
+        payloadoffset = 0;
+    }
+    else
+    {
+        payloadoffset=track->uPaddingOffset;
+    }
+    if(FAILED(CreateSizedBufferCCF(pAudioBuffer, m_pContext,((uNumberofsyncword + 1) \
*track->uContentCompressSetting )+pBuffer->GetSize()))) +    {
+        return HXR_OUTOFMEMORY;
+    }
+    UCHAR* pData=pAudioBuffer->GetBuffer();
+    while(index < uNumberofsyncword &&	payloadoffset <= ( pBuffer->GetSize()- \
offset)) +    {
+        memcpy(pData+track->uPaddingOffset,track->pContentCompressSetting,track->uContentCompressSetting);
 +        pData +=(track->uContentCompressSetting + track->uPaddingOffset);
+        memcpy((pData),(pBuffer->GetBuffer()+(index*(uFrameLen - \
track->uContentCompressSetting))),(uFrameLen - track->uContentCompressSetting)); +    \
pData +=(uFrameLen - track->uContentCompressSetting); +        index++;
+        payloadoffset += (uFrameLen - track->uContentCompressSetting);
+    }
+    if(offset)
+    {
+        track->uPaddingOffset=uFrameLen-offset;
+        memcpy(pData,track->pContentCompressSetting,track->uContentCompressSetting);
+        pData +=track->uContentCompressSetting;
+        memcpy(pData,(pBuffer->GetBuffer()+payloadoffset),offset);
+    }
+    retVal = CreatePacket(packet,strNum,pAudioBuffer,uTimeCode,uTimeCode,bKey);
+    HX_RELEASE(pAudioBuffer);
+    return retVal;
+}
+
+HX_RESULT CMKVFileFormat::FormAudioPacket(REF(IHXPacket*) packet,UINT32 \
strNum,UINT64 uTimeCode,HXBOOL bKey,MKVTrack *track,IHXBuffer* pBuffer) +{
+    HX_RESULT retVal = HXR_OK;
+    if((track == NULL) || (pBuffer == NULL))
+    {
+        retVal=HXR_FAILED;
+        HXLOGL1(HXLOG_MKVF, "CMKVFileFormat::FormAudioPacket Failed track == NULL \
\n"); +        return retVal;
+    }
+	switch(track->eCompressionType)
+	{
+		case eHEADERSTRIPING:
+		{
+			if((!strncmp(track->pszCodec, MKV_AAC3_MIMETYPE, strlen(MKV_AAC3_MIMETYPE))))// \
Header Stripping only for eac3 +			{
+				retVal=FormAAC3AudioPacket(packet,strNum,uTimeCode,bKey,track,pBuffer);
+			}
+			else
+			{
+                //Not Implemented for other audio format.
+			    HXLOGL1(HXLOG_MKVF, "CMKVFileFormat::FormAudioPacket Not Implemented for \
other format \n"); +			    retVal=HXR_NOTIMPL;
+			}
+				
+		}
+		break;
+		case eIZO1XCOMPRESSION: 
+		case eBZLIBCOMPRESSION: 
+		case eZLIBCOMPRESSION: // Not Implemented.
+		    retVal=HXR_NOTIMPL;
+		    HXLOGL1(HXLOG_MKVF, "CMKVFileFormat::FormAudioPacket Not Supported Compression \
track->eCompressionType: %d \n",track->eCompressionType); +		break;
+		case eNOCOMPRESSION:
+		    retVal = CreatePacket(packet,strNum,pBuffer,uTimeCode,uTimeCode,bKey);
+		break;
+		default: // Not expected. 
+		break;
+	}
+	return retVal;
+}
+
 //SendPacket
 STDMETHODIMP CMKVFileFormat::Func()
 {
@@ -548,6 +706,11 @@
 						m_pFormatResponse->StreamDone((UINT16)req->m_uStreamNum);
 						HX_RELEASE(pBuffer);
 						delete req;
+						if (m_pMKVFileObject->GetLastError() == HXR_READ_ERROR)
+						{
+						      HXLOGL2(HXLOG_MKVF, "CMKVFileFormat::Func() Read error on stream %d", \
(UINT16)req->m_uStreamNum);                                        +						      \
m_pFormatResponse->PacketReady(HXR_READ_ERROR, NULL); +						} 
 						return HXR_OK;
 					}
 					else if(SUCCEEDED(retVal))
@@ -596,15 +759,15 @@
                                 
 								retVal = CreatePacket(pPacket,strNum,pBuffer,uTimeCode,ulAdjustedPresentationTime,bKey);
  }
-							else
+							else if(trk->type == TrackAudio)
 							{
-								retVal = CreatePacket(pPacket,strNum,pBuffer,uTimeCode,uTimeCode,bKey);
+								retVal=FormAudioPacket(pPacket,strNum,uTimeCode,bKey,trk,pBuffer);
 							}
 							if(FAILED(retVal))
 							{
 								HX_RELEASE(pBuffer);
 								HX_RELEASE(pPacket);
-								return HXR_OUTOFMEMORY;
+								return retVal;
 							}
 						}
 						// Set the packet data
@@ -814,9 +977,20 @@
 		pHdr->SetPropertyULONG32("SamplesPerSecond", m_ulRTPTimeScale);
 		pHdr->SetPropertyULONG32("Width",  trk->video.uWidth);
 		pHdr->SetPropertyULONG32("Height", trk->video.uHeight);
-		if(trk->video.uFPS > 0.0)
+		if(trk->video.fFPS > 0.0)
 		{
-			pHdr->SetPropertyULONG32("FramesPerMSecond", trk->video.uFPS / 1000);
+			pHdr->SetPropertyULONG32("FramesPerMSecond", trk->video.fFPS*ONE_MILLION);
+			HXLOGL2(HXLOG_MKVF, "CMKVFileFormat::SetTypeSpecificProperties(): video.fFPS %d",
+			        trk->video.fFPS*ONE_MILLION);
+		}
+		else if(trk->uDefaultDuration)
+		{
+		    // uDefaultDuration is in nanoseconds 
+		    INT64 lFramesPerMSec  = \
(INT64)ONE_MILLION*ONE_THOUSAND*CONVERT_TO_MILI_SECOND/ +		                          \
(trk->uDefaultDuration); +		    pHdr->SetPropertyULONG32("FramesPerMSecond", \
INT64_TO_ULONG32(lFramesPerMSec )); +		    HXLOGL2(HXLOG_MKVF, \
"CMKVFileFormat::SetTypeSpecificProperties(): framesPerMSec %d", +		            \
INT64_TO_ULONG32(lFramesPerMSec ));  }
 	}
 
@@ -1012,7 +1186,7 @@
 	return HXR_OK;
 }
 
-MKVFileObject::MKVFileObject(IHXFileObject *pFileObject, IHXCommonClassFactory* \
pCommonClassFactory) +MKVFileObject::MKVFileObject(IHXFileObject *pFileObject, \
IHXCommonClassFactory* pCommonClassFactory):m_ulLastError(HXR_OK)  {
 	HXLOGL2(HXLOG_MKVF, "MKVFileObject::MKVFileObject()");
   
@@ -1072,13 +1246,14 @@
 #ifdef HELIX_FEATURE_64_BIT_FILE_SUPPORT
 	if(m_pFileObject2 && hxr == HXR_OK)
 	{
-		HX_RESULT ret = m_pFileObject2->Read(pBuffer, (UINT64) Size);
-		if(SUCCEEDED(ret))
+		m_ulLastError = m_pFileObject2->Read(pBuffer, (UINT64) Size);
+		if(SUCCEEDED(m_ulLastError))
 		{
 		  // TODO optimize to avoid the extra memory copy
 		  // could use the CHXBuffer constructor ?
 			memcpy(Buffer, pBuffer->GetBuffer(), pBuffer->GetSize());
 			retSize = pBuffer->GetSize();
+			HX_RELEASE(pBuffer);
 		}
 		else
 		{


_______________________________________________
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