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

[email protected] Thu, 13 Oct 2005 02:12:05 +0400 (MSD)
Newsgroups gmane.comp.multimedia.matroska.cvs
Message-ID <[email protected]>
Author: robux4
Date: 2005-10-13 02:12:02 +0400 (Thu, 13 Oct 2005)
New Revision: 1222

Modified:
   trunk/libmatroska/matroska/KaxBlock.h
   trunk/libmatroska/src/KaxBlock.cpp
   trunk/libmatroska/src/KaxCluster.cpp
   trunk/libmatroska/src/KaxCues.cpp
Log:
libmatroska: writing from KaxBlockBlob now works !

Modified: trunk/libmatroska/matroska/KaxBlock.h
===================================================================
--- trunk/libmatroska/matroska/KaxBlock.h	2005-10-12 21:21:00 UTC (rev 1221)
+++ trunk/libmatroska/matroska/KaxBlock.h	2005-10-12 22:12:02 UTC (rev 1222)
@@ -319,6 +319,7 @@
 	operator KaxBlockGroup &();
 	operator KaxSimpleBlock &();
 	operator KaxInternalBlock &();
+	operator const KaxInternalBlock &() const;
 
 	void SetBlockGroup( KaxBlockGroup &BlockRef );
 
@@ -327,6 +328,8 @@
 	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);
 
+	bool IsSimpleBlock() const {return bUseSimpleBlock;}
+
 	bool ReplaceSimpleByGroup();
 protected:
 	KaxCluster * ParentCluster;

Modified: trunk/libmatroska/src/KaxBlock.cpp
===================================================================
--- trunk/libmatroska/src/KaxBlock.cpp	2005-10-12 21:21:00 UTC (rev 1221)
+++ trunk/libmatroska/src/KaxBlock.cpp	2005-10-12 22:12:02 UTC (rev 1222)
@@ -958,6 +958,15 @@
 		return *Block.group;
 }
 
+KaxBlockBlob::operator const KaxInternalBlock &() const
+{
+	assert(Block.group);
+	if (bUseSimpleBlock)
+		return *Block.simpleblock;
+	else
+		return *Block.group;
+}
+
 #if defined(MATROSKA_VERSION) && (MATROSKA_VERSION == 2)
 KaxBlockBlob::operator KaxSimpleBlock &()
 {

Modified: trunk/libmatroska/src/KaxCluster.cpp
===================================================================
--- trunk/libmatroska/src/KaxCluster.cpp	2005-10-12 21:21:00 UTC (rev 1221)
+++ trunk/libmatroska/src/KaxCluster.cpp	2005-10-12 22:12:02 UTC (rev 1222)
@@ -174,6 +174,7 @@
 uint32 KaxCluster::Render(IOCallback & output, KaxCues & CueToUpdate, bool bSaveDefault)
 {
 	uint32 Result = 0;
+	size_t TrkIndex, Index;
 
 	// update the Timecode of the Cluster before writing
 	KaxClusterTimecode * Timecode = static_cast<KaxClusterTimecode *>(this->FindElt(KaxClusterTimecode::ClassInfos));
@@ -181,7 +182,6 @@
 
 	if (Blobs.size() == 0) {
 		// old-school direct KaxBlockGroup
-		size_t TrkIndex, Index;
 
 		// SilentTracks handling
 		// check the parent cluster for existing tracks and see if they are contained in this cluster or not
@@ -222,6 +222,47 @@
 		}
 	} else {
 		// new school, using KaxBlockBlob
+		for (Index = 0; Index<Blobs.size(); Index++)
+		{
+			if (Blobs[Index]->IsSimpleBlock())
+				ElementList.push_back( &(KaxSimpleBlock&) *Blobs[Index] );
+			else
+				ElementList.push_back( &(KaxBlockGroup&) *Blobs[Index] );
+		}
+
+		// SilentTracks handling
+		// check the parent cluster for existing tracks and see if they are contained in this cluster or not
+		if (bSilentTracksUsed)
+		{
+			KaxTracks & MyTracks = *static_cast<KaxTracks *>(ParentSegment->FindElt(KaxTracks::ClassInfos));
+			for (TrkIndex = 0; TrkIndex < MyTracks.ListSize(); TrkIndex++) {
+				if (EbmlId(*MyTracks[TrkIndex]) == KaxTrackEntry::ClassInfos.GlobalId)
+				{
+					KaxTrackEntry & entry = *static_cast<KaxTrackEntry *>(MyTracks[TrkIndex]);
+					uint32 tracknum = entry.TrackNumber();
+					for (Index = 0; Index<Blobs.size(); Index++) {
+						if (((KaxInternalBlock&)*Blobs[Index]).TrackNum() == tracknum)
+								break; // this track is used
+					}
+					// the track wasn't found in this cluster
+					if (Index == ElementList.size())
+					{
+						KaxClusterSilentTracks * SilentTracks = static_cast<KaxClusterSilentTracks *>(this->FindFirstElt(KaxClusterSilentTracks::ClassInfos));
+						assert(SilentTracks != NULL); // the flag bSilentTracksUsed should be set when creating the Cluster
+						KaxClusterSilentTrackNumber * trackelt = static_cast<KaxClusterSilentTrackNumber *>(SilentTracks->AddNewElt(KaxClusterSilentTrackNumber::ClassInfos));
+						*static_cast<EbmlUInteger *>(trackelt) = tracknum;
+					}
+				}
+			}
+		}
+
+		Result = EbmlMaster::Render(output, bSaveDefault);
+
+		// For all Blocks add their position on the CueEntry
+		for (Index = 0; Index<Blobs.size(); Index++) {
+			CueToUpdate.PositionSet(*Blobs[Index]);
+		}
+
 		Blobs.clear();
 	}
 

Modified: trunk/libmatroska/src/KaxCues.cpp
===================================================================
--- trunk/libmatroska/src/KaxCues.cpp	2005-10-12 21:21:00 UTC (rev 1221)
+++ trunk/libmatroska/src/KaxCues.cpp	2005-10-12 22:12:02 UTC (rev 1222)
@@ -96,7 +96,8 @@
 		if (*ListIdx == &BlockReference) {
 			// found, now add the element to the entry list
 			KaxCuePoint & NewPoint = AddNewChild<KaxCuePoint>(*this);
-			NewPoint.PositionSet((KaxInternalBlock&)BlockReference, GlobalTimecodeScale());
+			const KaxInternalBlock &intblock = BlockReference;
+			NewPoint.PositionSet(intblock, GlobalTimecodeScale());
 			myTempReferences.erase(ListIdx);
 			break;
 		}
@@ -114,7 +115,8 @@
 		if (*ListIdx == &BlockReference) {
 			// found, now add the element to the entry list
 			KaxCuePoint & NewPoint = AddNewChild<KaxCuePoint>(*this);
-			NewPoint.PositionSet((KaxInternalBlock&)BlockReference, GlobalTimecodeScale());
+			const KaxInternalBlock &intblock = BlockReference;
+			NewPoint.PositionSet(intblock, GlobalTimecodeScale());
 			myTempReferences.erase(ListIdx);
 			break;
 		}