[matroska] r1219 - in trunk/libmatroska: matroska src

[email protected] Tue, 11 Oct 2005 00:47:28 +0400 (MSD)
Newsgroups gmane.comp.multimedia.matroska.cvs
Message-ID <[email protected]>
Author: robux4
Date: 2005-10-11 00:47:21 +0400 (Tue, 11 Oct 2005)
New Revision: 1219

Modified:
   trunk/libmatroska/matroska/KaxBlock.h
   trunk/libmatroska/matroska/KaxBlockData.h
   trunk/libmatroska/matroska/KaxCuesData.h
   trunk/libmatroska/matroska/KaxTypes.h
   trunk/libmatroska/src/KaxBlock.cpp
   trunk/libmatroska/src/KaxBlockData.cpp
   trunk/libmatroska/src/KaxCues.cpp
   trunk/libmatroska/src/KaxCuesData.cpp
Log:
libmatroska: more code to use SimpleBlock automatically (when enabled)
reworked the KaxCues code to use KaxBlockBlob where possible, the previous API may not be 100% compatible (mkvmerge not affected)
the code is still not 100% operational

Modified: trunk/libmatroska/matroska/KaxBlock.h
===================================================================
--- trunk/libmatroska/matroska/KaxBlock.h	2005-10-10 16:00:28 UTC (rev 1218)
+++ trunk/libmatroska/matroska/KaxBlock.h	2005-10-10 20:47:21 UTC (rev 1219)
@@ -49,6 +49,7 @@
 class KaxCluster;
 class KaxReferenceBlock;
 class KaxInternalBlock;
+class KaxBlockBlob;
 
 class MATROSKA_DLL_API DataBuffer {
 	protected:
@@ -146,6 +147,7 @@
 			\brief Addition of a frame with a backward+forward reference (B frame)
 		*/
 		bool AddFrame(const KaxTrackEntry & track, uint64 timecode, DataBuffer & buffer, const KaxBlockGroup & PastBlock, const KaxBlockGroup & ForwBlock, LacingType lacing = LACING_AUTO);
+		bool AddFrame(const KaxTrackEntry & track, uint64 timecode, DataBuffer & buffer, const KaxBlockBlob * PastBlock, const KaxBlockBlob * ForwBlock, LacingType lacing = LACING_AUTO);
 
 		void SetParent(KaxCluster & aParentCluster);
 
@@ -300,10 +302,20 @@
 
 class MATROSKA_DLL_API KaxBlockBlob {
 public:
-	KaxBlockBlob(bool use_sblock) :bUseSimpleBlock(use_sblock), ParentCluster(NULL) {
+	KaxBlockBlob(BlockBlobType sblock_mode) :ParentCluster(NULL), SimpleBlockMode(sblock_mode) {
+		bUseSimpleBlock = (sblock_mode != BLOCK_BLOB_NO_SIMPLE);
 		Block.group = NULL;
 	}
 
+	~KaxBlockBlob() {
+#if MATROSKA_VERSION >= 2
+		if (bUseSimpleBlock)
+			delete Block.simpleblock;
+		else
+#endif // MATROSKA_VERSION
+			delete Block.group;
+	}
+
 	operator KaxBlockGroup &();
 	operator KaxSimpleBlock &();
 	operator KaxInternalBlock &();
@@ -315,7 +327,7 @@
 	void SetParent(KaxCluster & aParentCluster);
 	bool AddFrameAuto(const KaxTrackEntry & track, uint64 timecode, DataBuffer & buffer, LacingType lacing = LACING_AUTO, const KaxBlockBlob * PastBlock = NULL, const KaxBlockBlob * ForwBlock = NULL);
 
-	void ReplaceSimpleByGroup();
+	bool ReplaceSimpleByGroup();
 protected:
 	KaxCluster * ParentCluster;
 	union {
@@ -325,6 +337,7 @@
 #endif // MATROSKA_VERSION
 	} Block;
 	bool bUseSimpleBlock;
+	BlockBlobType SimpleBlockMode;
 };
 
 class MATROSKA_DLL_API KaxBlockDuration : public EbmlUInteger {

Modified: trunk/libmatroska/matroska/KaxBlockData.h
===================================================================
--- trunk/libmatroska/matroska/KaxBlockData.h	2005-10-10 16:00:28 UTC (rev 1218)
+++ trunk/libmatroska/matroska/KaxBlockData.h	2005-10-10 20:47:21 UTC (rev 1219)
@@ -44,6 +44,7 @@
 
 class KaxReferenceBlock;
 class KaxBlockGroup;
+class KaxBlockBlob;
 
 class MATROSKA_DLL_API KaxReferencePriority : public EbmlUInteger {
 	public:
@@ -74,12 +75,13 @@
 		*/
 		virtual uint64 UpdateSize(bool bSaveDefault = false, bool bForceRender = false);
 
-		const KaxBlockGroup & RefBlock() const;
-		void SetReferencedBlock(const KaxBlockGroup & aRefdBlock) {RefdBlock = &aRefdBlock; bValueIsSet = true;}
+		const KaxBlockBlob & RefBlock() const;
+		void SetReferencedBlock(const KaxBlockBlob * aRefdBlock);
+		void SetReferencedBlock(const KaxBlockGroup & aRefdBlock);
 		void SetParentBlock(const KaxBlockGroup & aParentBlock) {ParentBlock = &aParentBlock;}
 		
 	protected:
-		const KaxBlockGroup * RefdBlock;
+		const KaxBlockBlob * RefdBlock;
 		const KaxBlockGroup * ParentBlock;
 		void SetReferencedTimecode(int64 refTimecode) {Value = refTimecode; bTimecodeSet = true; bValueIsSet = true;};
 		bool bTimecodeSet;

Modified: trunk/libmatroska/matroska/KaxCuesData.h
===================================================================
--- trunk/libmatroska/matroska/KaxCuesData.h	2005-10-10 16:00:28 UTC (rev 1218)
+++ trunk/libmatroska/matroska/KaxCuesData.h	2005-10-10 20:47:21 UTC (rev 1219)
@@ -42,6 +42,7 @@
 START_LIBMATROSKA_NAMESPACE
 
 class KaxBlockGroup;
+class KaxBlockBlob;
 class KaxCueTrackPositions;
 class KaxInternalBlock;
 
@@ -144,6 +145,7 @@
 		EbmlElement * Clone() const {return new KaxCueReference(*this);}
 		
 		void AddReference(const KaxBlockGroup & BlockReferenced, uint64 GlobalTimecodeScale);
+		void AddReference(const KaxBlockBlob & BlockReferenced, uint64 GlobalTimecodeScale);
 };
 
 class MATROSKA_DLL_API KaxCueRefTime : public EbmlUInteger {

Modified: trunk/libmatroska/matroska/KaxTypes.h
===================================================================
--- trunk/libmatroska/matroska/KaxTypes.h	2005-10-10 16:00:28 UTC (rev 1218)
+++ trunk/libmatroska/matroska/KaxTypes.h	2005-10-10 20:47:21 UTC (rev 1219)
@@ -48,6 +48,12 @@
 	LACING_AUTO
 };
 
+enum BlockBlobType {
+	BLOCK_BLOB_NO_SIMPLE = 0,
+	BLOCK_BLOB_SIMPLE_AUTO,
+	BLOCK_BLOB_ALWAYS_SIMPLE,
+};
+
 END_LIBMATROSKA_NAMESPACE
 
 #endif // LIBMATROSKA_TYPES_H

Modified: trunk/libmatroska/src/KaxBlock.cpp
===================================================================
--- trunk/libmatroska/src/KaxBlock.cpp	2005-10-10 16:00:28 UTC (rev 1218)
+++ trunk/libmatroska/src/KaxBlock.cpp	2005-10-10 20:47:21 UTC (rev 1219)
@@ -778,6 +778,25 @@
 	return bRes;
 }
 
+bool KaxBlockGroup::AddFrame(const KaxTrackEntry & track, uint64 timecode, DataBuffer & buffer, const KaxBlockBlob * PastBlock, const KaxBlockBlob * ForwBlock, LacingType lacing)
+{
+	KaxBlock & theBlock = GetChild<KaxBlock>(*this);
+	assert(ParentCluster != NULL);
+	theBlock.SetParent(*ParentCluster);
+	ParentTrack = &track;
+	bool bRes = theBlock.AddFrame(track, timecode, buffer, lacing);
+
+	KaxReferenceBlock & thePastRef = GetChild<KaxReferenceBlock>(*this);
+	thePastRef.SetReferencedBlock(PastBlock);
+	thePastRef.SetParentBlock(*this);
+
+	KaxReferenceBlock & theFutureRef = AddNewChild<KaxReferenceBlock>(*this);
+	theFutureRef.SetReferencedBlock(ForwBlock);
+	theFutureRef.SetParentBlock(*this);
+
+	return bRes;
+}
+
 /*!
 	\todo we may cache the reference to the timecode block
 */
@@ -950,37 +969,61 @@
 
 bool KaxBlockBlob::AddFrameAuto(const KaxTrackEntry & track, uint64 timecode, DataBuffer & buffer, LacingType lacing, const KaxBlockBlob * PastBlock, const KaxBlockBlob * ForwBlock)
 {
-#if 0
-	if (bUseSimpleBlock)
-		if (Block.simpleblock->AddFrame(track, timecode, buffer, lacing)) {
-			Block.simpleblock->SetKeyframe(false);
-			Block.simpleblock->SetDiscardable(true);
-			return true;
-		} else
-			return false;
-	else
-		return Block.group->AddFrame(track, timecode, buffer, (KaxBlockGroup)*PastBlock, (KaxBlockGroup)*ForwBlock, lacing);
-#else
-	return false;
-#endif
+	bool bResult = false;
+	if ((SimpleBlockMode == BLOCK_BLOB_ALWAYS_SIMPLE) || (SimpleBlockMode == BLOCK_BLOB_SIMPLE_AUTO && PastBlock == NULL && ForwBlock == NULL)) {
+		assert(bUseSimpleBlock == true);
+		if (Block.simpleblock == NULL) {
+			Block.simpleblock = new KaxSimpleBlock();
+			Block.simpleblock->SetParent(*ParentCluster);
+		}
+
+		bResult = Block.simpleblock->AddFrame(track, timecode, buffer, lacing);
+		Block.simpleblock->SetKeyframe(PastBlock == NULL);
+		Block.simpleblock->SetDiscardable(ForwBlock != NULL);
+	} else {
+		if (ReplaceSimpleByGroup()) {
+			Block.group->SetParent(*ParentCluster);
+			bResult = Block.group->AddFrame(track, timecode, buffer, PastBlock, ForwBlock, lacing);
+		}
+	}
+
+	return bResult;
 }
 
 void KaxBlockBlob::SetParent(KaxCluster & parent_clust)
 {
 	ParentCluster = &parent_clust;
-	// TODO: set the parent of the right type before using it 
 }
 
 void KaxBlockBlob::SetBlockDuration(uint64 TimeLength)
 {
-	ReplaceSimpleByGroup();
-	Block.group->SetBlockDuration(TimeLength);
+	if (ReplaceSimpleByGroup())
+		Block.group->SetBlockDuration(TimeLength);
 }
 
-void KaxBlockBlob::ReplaceSimpleByGroup()
+bool KaxBlockBlob::ReplaceSimpleByGroup()
 {
-	if (!bUseSimpleBlock)
-		return;
+	if (SimpleBlockMode== BLOCK_BLOB_ALWAYS_SIMPLE)
+		return false;
+
+	if (!bUseSimpleBlock) {
+		if (Block.group == NULL) {
+			Block.group = new KaxBlockGroup();
+		}
+	} else {
+
+		if (Block.simpleblock != NULL) {
+			KaxSimpleBlock *old_simpleblock = Block.simpleblock;
+			Block.group = new KaxBlockGroup();
+			Block.group->SetParent(*ParentCluster);
+			// _TODO_ : move all the data to the blockgroup
+			// -> while(frame) AddFrame(myBuffer)
+			delete old_simpleblock;
+		}
+	}
+
+	bUseSimpleBlock = false;
+	return true;
 }
 
 void KaxBlockBlob::SetBlockGroup( KaxBlockGroup &BlockRef )

Modified: trunk/libmatroska/src/KaxBlockData.cpp
===================================================================
--- trunk/libmatroska/src/KaxBlockData.cpp	2005-10-10 16:00:28 UTC (rev 1218)
+++ trunk/libmatroska/src/KaxBlockData.cpp	2005-10-10 20:47:21 UTC (rev 1219)
@@ -101,7 +101,7 @@
  :EbmlMaster(KaxTimeSlice_Context)
 {}
 
-const KaxBlockGroup & KaxReferenceBlock::RefBlock() const
+const KaxBlockBlob & KaxReferenceBlock::RefBlock() const
 {
 	assert(RefdBlock != NULL);
 	return *RefdBlock;
@@ -113,9 +113,24 @@
 		assert(RefdBlock != NULL);
 		assert(ParentBlock != NULL);
 
-		Value = (int64(RefdBlock->GlobalTimecode()) - int64(ParentBlock->GlobalTimecode())) / int64(ParentBlock->GlobalTimecodeScale());
+		Value = (int64(((KaxInternalBlock*)RefdBlock)->GlobalTimecode()) - int64(ParentBlock->GlobalTimecode())) / int64(ParentBlock->GlobalTimecodeScale());
 	}
 	return EbmlSInteger::UpdateSize(bSaveDefault, bForceRender);
 }
 
+void KaxReferenceBlock::SetReferencedBlock(const KaxBlockBlob * aRefdBlock)
+{
+	assert(aRefdBlock == NULL);
+	RefdBlock = aRefdBlock; 
+	bValueIsSet = true;
+}
+
+void KaxReferenceBlock::SetReferencedBlock(const KaxBlockGroup & aRefdBlock)
+{
+	KaxBlockBlob *block_blob = new KaxBlockBlob(BLOCK_BLOB_SIMPLE_AUTO);
+	block_blob->SetBlockGroup(*const_cast<KaxBlockGroup*>(&aRefdBlock));
+	RefdBlock = block_blob; 
+	bValueIsSet = true;
+}
+
 END_LIBMATROSKA_NAMESPACE

Modified: trunk/libmatroska/src/KaxCues.cpp
===================================================================
--- trunk/libmatroska/src/KaxCues.cpp	2005-10-10 16:00:28 UTC (rev 1218)
+++ trunk/libmatroska/src/KaxCues.cpp	2005-10-10 20:47:21 UTC (rev 1219)
@@ -63,7 +63,7 @@
 {
 	// Do not add the element if it's already present.
 	std::vector<const KaxBlockBlob *>::iterator ListIdx;
-	KaxBlockBlob &BlockReference = *(new KaxBlockBlob(false));
+	KaxBlockBlob &BlockReference = *(new KaxBlockBlob(BLOCK_BLOB_SIMPLE_AUTO));
 	BlockReference.SetBlockGroup(*const_cast<KaxBlockGroup*>(&BlockRef));
 
 	for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ListIdx++)
@@ -107,7 +107,7 @@
 {
 	// look for the element in the temporary references
 	std::vector<const KaxBlockBlob *>::iterator ListIdx;
-	KaxBlockBlob &BlockReference = *(new KaxBlockBlob(false));
+	KaxBlockBlob &BlockReference = *(new KaxBlockBlob(BLOCK_BLOB_SIMPLE_AUTO));
 	BlockReference.SetBlockGroup(*const_cast<KaxBlockGroup*>(&BlockRef));
 
 	for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ListIdx++) {

Modified: trunk/libmatroska/src/KaxCuesData.cpp
===================================================================
--- trunk/libmatroska/src/KaxCuesData.cpp	2005-10-10 16:00:28 UTC (rev 1218)
+++ trunk/libmatroska/src/KaxCuesData.cpp	2005-10-10 20:47:21 UTC (rev 1219)
@@ -192,13 +192,14 @@
 /*!
 	\todo handle codec state checking
 */
-void KaxCueReference::AddReference(const KaxBlockGroup & BlockReference, uint64 GlobalTimecodeScale)
+void KaxCueReference::AddReference(const KaxBlockBlob & BlockReference, uint64 GlobalTimecodeScale)
 {
+	const KaxInternalBlock * theBlock = &(KaxInternalBlock &)BlockReference;
 	KaxCueRefTime & NewTime = GetChild<KaxCueRefTime>(*this);
-	*static_cast<EbmlUInteger*>(&NewTime) = BlockReference.GlobalTimecode() / GlobalTimecodeScale;
+	*static_cast<EbmlUInteger*>(&NewTime) = theBlock->GlobalTimecode() / GlobalTimecodeScale;
 
 	KaxCueRefCluster & TheClustPos = GetChild<KaxCueRefCluster>(*this);
-	*static_cast<EbmlUInteger*>(&TheClustPos) = BlockReference.ClusterPosition();
+	*static_cast<EbmlUInteger*>(&TheClustPos) = theBlock->ClusterPosition();
 
 #ifdef OLD
 	// handle recursive reference use