[matroska] r1083 - trunk/mkxuncat

[email protected]
Newsgroups gmane.comp.multimedia.matroska.cvs
Message-ID <[email protected]>
Author: robux4
Date: 2005-03-04 23:19:53 +0300 (Fri, 04 Mar 2005)
New Revision: 1083

Modified:
   trunk/mkxuncat/mkxuncat.cpp
Log:
mkxuncat: create output files for each original file found (no data copy yet)

Modified: trunk/mkxuncat/mkxuncat.cpp
===================================================================
--- trunk/mkxuncat/mkxuncat.cpp	2005-03-04 20:11:17 UTC (rev 1082)
+++ trunk/mkxuncat/mkxuncat.cpp	2005-03-04 20:19:53 UTC (rev 1083)
@@ -38,8 +38,11 @@
 
 #include <ebml/EbmlStream.h>
 #include <ebml/EbmlHead.h>
+#include <ebml/EbmlContexts.h>
+#include <matroska/KaxSegment.h>
 
 using namespace LIBEBML_NAMESPACE;
+using namespace LIBMATROSKA_NAMESPACE;
 
 #if defined(_WIN32)
 #include <WinIOCallback.h>
@@ -49,6 +52,14 @@
 typedef StdIOCallback IOclass;
 #endif
 
+EbmlSemantic KaxAll_ContextList[2] =
+{
+	EbmlSemantic(false, false, EbmlHead::ClassInfos),
+	EbmlSemantic(false, false, KaxSegment::ClassInfos),
+};
+const EbmlSemanticContext KaxAll_Context = EbmlSemanticContext(countof(KaxAll_ContextList), KaxAll_ContextList, NULL, *GetEbmlGlobal_Context, NULL);
+
+
 int main(int argc, const char *argv[])
 {
 	if ( argc != 2 )
@@ -66,17 +77,50 @@
 		basename = basename.substr( 0, basename.rfind( '.' ) );
 	}
 
-	IOclass p_DataFile( argv[1], MODE_READ );
+	IOclass p_InputFile( argv[1], MODE_READ );
+	if ( p_InputFile.getFilePointer() != 0 )
+	{
+		fprintf( stderr, "Could not open file '%s' for reading\n", argv[1] );
+		return -2;
+	}
 
-	EbmlStream aStream( p_DataFile );
+	EbmlStream aStream( p_InputFile );
 
+	unsigned int u_OuputFileIndex = 0;
+	char t_IndexBuffer[8];
+	int64 i_SizeToCopy;
+	string OutputFilename;
+	int i_Level = 0;
+	IOclass *p_OutputFile = NULL;
+
 	EbmlElement * ElementLevel0;
 
 	// find the EBML head in the file
-	ElementLevel0 = aStream.FindNextID( EbmlHead::ClassInfos, 0xFFFFFFFFL );
+	ElementLevel0 = aStream.FindNextElement( KaxAll_Context, i_Level, 0xFFFFFFFFL, false, 1 );
 	
 	while ( ElementLevel0 != NULL )
 	{
+		if ( EbmlId(*ElementLevel0) == EbmlHead::ClassInfos.GlobalId )
+		{
+			delete p_OutputFile;
+
+			OutputFilename = basename + '.' + itoa( u_OuputFileIndex++, t_IndexBuffer, 10 ) + '.' + extension;
+			p_OutputFile = new IOclass( OutputFilename.c_str(), MODE_CREATE );
+			if ( p_OutputFile->getFilePointer() != 0 )
+			{
+				fprintf( stderr, "Could not open file '%s' for writing\n", OutputFilename.c_str() );
+				return -3;
+			}
+		}
+
+		p_InputFile.setFilePointer( ElementLevel0->GetElementPosition() );
+		i_SizeToCopy = ElementLevel0->ElementSize();
+		
+		// TODO copy data
+
+		p_InputFile.setFilePointer( ElementLevel0->GetElementPosition() + i_SizeToCopy );
+
+		ElementLevel0 = aStream.FindNextElement( KaxAll_Context, i_Level, 0xFFFFFFFFL, false, 1 );
 	}
 
 	return 0;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.