[matroska] r813 - trunk/DvdMenuXtractor

[email protected]
Newsgroups gmane.comp.multimedia.matroska.cvs
Message-ID <[email protected]>
Author: robux4
Date: 2004-09-16 15:18:52 +0400 (Thu, 16 Sep 2004)
New Revision: 813

Modified:
   trunk/DvdMenuXtractor/DvdMenuXtractor.cpp
Log:
correct handling of PTT/Chapters in PGCs

Modified: trunk/DvdMenuXtractor/DvdMenuXtractor.cpp
===================================================================
--- trunk/DvdMenuXtractor/DvdMenuXtractor.cpp	2004-09-15 18:52:19 UTC (rev 812)
+++ trunk/DvdMenuXtractor/DvdMenuXtractor.cpp	2004-09-16 11:18:52 UTC (rev 813)
@@ -720,7 +720,7 @@
 		delete subdecoder;
     }
 
-	wxString IndentString(int lvl)
+	static wxString IndentString(int lvl)
 	{
 		wxString result = "";
 
@@ -852,8 +852,8 @@
 		for (int cell_num = entry_cell_num; cell_num<next_program_entry_cell_num; cell_num++)
 		{
 			// Output cells
-			
-			XmlFile.AddLine(IndentString(lvl)+wxString::Format("<!-- Program %sCell #%d -->",(cell_num==entry_cell_num)?"Entry ":"", cell_num));
+
+			XmlFile.AddLine(IndentString(lvl)+wxString::Format("<!-- Program %sCell CN#%d -->",(cell_num==entry_cell_num)?"Entry ":"", cell_num));
 			XmlFile.AddLine(IndentString(lvl)+"<ChapterAtom>");
 				lvl++;
 				const cell_position_t & position = pgc->cell_position[cell_num-1];
@@ -882,13 +882,13 @@
 		return end_time;
 	}
 	
-	uint64_t OutputPGC(int lvl, wxTextFile & XmlFile, const pgc_t * pgc, uint64_t start_time, uint16_t pgc_num, unsigned char pgc_type)
+	uint64_t OutputPGC(int lvl, wxTextFile & XmlFile, const pgc_t * pgc, uint64_t start_time, uint16_t pgc_num, unsigned char pgc_type, const ttu_t * ptts)
 	{
 		static unsigned char _PrivatePGC[] = {0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
 		static unsigned char _PrivatePTT[] = {0x18, 0x00};
 		uint64_t st_time = start_time, end_time;
 
-		XmlFile.AddLine(IndentString(lvl)+wxString::Format("<!-- PGC #%d type %s -->",pgc_num+1,GetPGCType(pgc_type)));
+		XmlFile.AddLine(IndentString(lvl)+wxString::Format("<!-- PGC PGCN#%d type %s -->",pgc_num+1,GetPGCType(pgc_type)));
 		XmlFile.AddLine(IndentString(lvl)+"<ChapterAtom>");
 		lvl++;
 		wxString _myUID = CreateUID();
@@ -911,33 +911,45 @@
 		// PGC commands
 		AddCommands(lvl, XmlFile, pgc->command_tbl);
 
-		// _TODO_: for the moment we assume we have 1 PTT per PGC
-		XmlFile.AddLine(IndentString(lvl)+wxString::Format("<!-- Chapter #%d -->", pgc_num+1));
-		XmlFile.AddLine(IndentString(lvl)+"<ChapterAtom>");
-		lvl++;
-			wxString _myUIDa = CreateUID();
-			XmlFile.AddLine(IndentString(lvl)+"<ChapterUID>"+_myUIDa+"</ChapterUID>");
-			_PrivatePTT[1] = (pgc_num+1) & 0xFF;
-			XmlFile.AddLine(IndentString(lvl)+"<ChapterProcessPrivate>"+encodebase64(_PrivatePTT,2)+"</ChapterProcessPrivate>");
-			// display the UID for the lazy rippers
-			XmlFile.AddLine(IndentString(lvl)+"<ChapterDisplay>");
-				lvl++;
-				XmlFile.AddLine(IndentString(lvl)+wxString::Format("<ChapterString>Your Name Here For Chapter #%d</ChapterString>", pgc_num+1));
-				lvl--;
-			XmlFile.AddLine(IndentString(lvl)+"</ChapterDisplay>");
-
-			// Handle the Programs/Cells in the PGC
-			for (int i=0; i< pgc->nr_of_programs; i++)
-			{
-				XmlFile.AddLine(IndentString(lvl)+"<!-- Program #"+wxString::Format("%d",i+1)+" in this PGC -->");
-				st_time = OutputProgram(lvl, XmlFile, pgc, i, st_time);
-			}
+		// Handle the Programs/Cells in the PGC
+		for (int i=0; i< pgc->nr_of_programs; i++)
+		{
+			XmlFile.AddLine(IndentString(lvl)+"<!-- Program PGN#"+wxString::Format("%d",i+1)+" in this PGC -->");
+			st_time = OutputProgram(lvl, XmlFile, pgc, i, st_time);
+			
+			// handle the PTT/Chapter
+			if (ptts != NULL)
+			{
+				// find if the PGCN/PGN is in the list
+				for (int ptt_num=0; ptt_num<ptts->nr_of_ptts; ptt_num++)
+				{
+					if (ptts->ptt[ptt_num].pgcn == pgc_num+1 && ptts->ptt[ptt_num].pgn == i+1)
+					{
+						XmlFile.AddLine(IndentString(lvl)+wxString::Format("<!-- Chapter PTT#%d -->", ptt_num+1));
+						XmlFile.AddLine(IndentString(lvl)+"<ChapterAtom>");
+						lvl++;
+							wxString _myUIDa = CreateUID();
+							XmlFile.AddLine(IndentString(lvl)+"<ChapterUID>"+_myUIDa+"</ChapterUID>");
+							_PrivatePTT[1] = (ptt_num+1) >> 8;
+							_PrivatePTT[2] = (ptt_num+1) & 0xFF;
+							XmlFile.AddLine(IndentString(lvl)+"<ChapterProcessPrivate>"+encodebase64(_PrivatePTT,3)+"</ChapterProcessPrivate>");
+							// display the UID for the lazy rippers
+							XmlFile.AddLine(IndentString(lvl)+"<ChapterDisplay>");
+								lvl++;
+								XmlFile.AddLine(IndentString(lvl)+wxString::Format("<ChapterString>Your Name Here For Chapter #%d</ChapterString>", ptt_num+1));
+								lvl--;
+							XmlFile.AddLine(IndentString(lvl)+"</ChapterDisplay>");
+				
+						// PTT start times (no end time, it's only a reference used to seek)
+						XmlFile.AddLine(IndentString(lvl)+"<ChapterTimeStart>"+TimeFormat(start_time)+"</ChapterTimeStart>");
+						lvl--;
+						XmlFile.AddLine(IndentString(lvl)+"</ChapterAtom>");
+						break;
+					}
+				}
+			}
+		}
 	
-		// PTT start/end times
-		DisplayTime(lvl, XmlFile, start_time, st_time);
-		lvl--;
-		XmlFile.AddLine(IndentString(lvl)+"</ChapterAtom>");
-
 		// PGC start/end times
 		DisplayTime(lvl, XmlFile, start_time, st_time);
 		lvl--;
@@ -974,28 +986,27 @@
 		
 		return nano_duration;
 	}
+	
+	static wxString TimeFormat(uint64_t a_time)
+	{
+		int hour, min, sec;
+		uint32_t nano;
+		
+		nano = a_time % 1000000000;
+		a_time /= 1000000000;
+		sec = a_time % 60;
+		a_time /= 60;
+		min = a_time % 60;
+		hour = a_time / 60;
+
+		return wxString::Format("%02d:%02d:%02d.%09d", hour, min, sec, nano);
+	}
 	
 	/// times in nanoseconds
-	void DisplayTime(int lvl, wxTextFile & XmlFile, uint64_t start_time, uint64_t end_time)
+	static void DisplayTime(int lvl, wxTextFile & XmlFile, uint64_t start_time, uint64_t end_time)
 	{
-		int hour, min, sec;
-		uint32_t nano;
-		
-		nano = start_time % 1000000000;
-		start_time /= 1000000000;
-		sec = start_time % 60;
-		start_time /= 60;
-		min = start_time % 60;
-		hour = start_time / 60;
-		XmlFile.AddLine(IndentString(lvl)+"<ChapterTimeStart>"+wxString::Format("%02d:%02d:%02d.%09d", hour, min, sec, nano)+"</ChapterTimeStart>");
-		
-		nano = end_time % 1000000000;
-		end_time /= 1000000000;
-		sec = end_time % 60;
-		end_time /= 60;
-		min = end_time % 60;
-		hour = end_time / 60;
-		XmlFile.AddLine(IndentString(lvl)+"<ChapterTimeEnd>"+wxString::Format("%02d:%02d:%02d.%09d", hour, min, sec, nano)+"</ChapterTimeEnd>");
+		XmlFile.AddLine(IndentString(lvl)+"<ChapterTimeStart>"+TimeFormat(start_time)+"</ChapterTimeStart>");
+		XmlFile.AddLine(IndentString(lvl)+"<ChapterTimeEnd>"+TimeFormat(end_time)+"</ChapterTimeEnd>");
 	}
 	
 	uint64_t HandleLanguageUnit(int lvl, wxTextFile & XmlFile, uint64_t start_time, const IFOFile & _ifo, int title)
@@ -1030,7 +1041,7 @@
 					for (int j=0; j<_LU.pgcit->nr_of_pgci_srp; j++)
 					{
 						const pgci_srp_t &_PGC_SRP = _LU.pgcit->pgci_srp[j];
-						timecode_endB = OutputPGC(lvl, XmlFile, _PGC_SRP.pgc, timecode_endB, j, _PGC_SRP.entry_id);
+						timecode_endB = OutputPGC(lvl, XmlFile, _PGC_SRP.pgc, timecode_endB, j, _PGC_SRP.entry_id, NULL);
 					}
 				}
 				DisplayTime(lvl, XmlFile, timecode_startB, timecode_endB);
@@ -1142,7 +1153,7 @@
 						uint64_t timecode_startB = timecode_endA, timecode_endB = timecode_endA;
 						for (int i=0; i<IfoFile->VtsTitles()->nr_of_srpts; i++)
 						{
-							XmlFile.AddLine(IndentString(lvl)+wxString::Format("<!-- Title #%d -->",i+1));
+							XmlFile.AddLine(IndentString(lvl)+wxString::Format("<!-- Title TTU_%d -->",i+1));
 							XmlFile.AddLine(IndentString(lvl)+"<ChapterAtom>");
 								lvl++;
 								wxString _myUIDa = CreateUID();
@@ -1152,14 +1163,14 @@
 								_PrivateTT[2] = (i+1) & 0xFF;
 								XmlFile.AddLine(IndentString(lvl)+"<ChapterProcessPrivate>"+encodebase64(_PrivateTT,3)+"</ChapterProcessPrivate>");
 							
-								// add the PGC that match this PTT
+								// add the PGC that match this PTT
 								uint64_t timecode_startC = timecode_startB, timecode_endC = timecode_startB;
 								for (int k=0; k<IfoFile->VtsPGCs()->nr_of_pgci_srp; k++)
 								{
 									if ((IfoFile->VtsPGCs()->pgci_srp[k].entry_id & 0x7F) == i+1)
 									{
 											timecode_startC = OutputPGC(lvl, XmlFile, 
-												IfoFile->VtsPGCs()->pgci_srp[k].pgc, timecode_startC, k, 0);
+												IfoFile->VtsPGCs()->pgci_srp[k].pgc, timecode_startC, k, 0, &IfoFile->VtsTitles()->title[i]);
 									}
 								}
 								timecode_endB = timecode_startC;
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.