[matroska] r896 - trunk/DvdMenuXtractor

[email protected]
Newsgroups gmane.comp.multimedia.matroska.cvs
Message-ID <[email protected]>
Author: robux4
Date: 2004-10-19 17:46:13 +0400 (Tue, 19 Oct 2004)
New Revision: 896

Modified:
   trunk/DvdMenuXtractor/VobParser.cpp
   trunk/DvdMenuXtractor/VobParser.h
Log:
better solution using libdvdread to read VOB files (temporary code)

Modified: trunk/DvdMenuXtractor/VobParser.cpp
===================================================================
--- trunk/DvdMenuXtractor/VobParser.cpp	2004-10-19 13:15:38 UTC (rev 895)
+++ trunk/DvdMenuXtractor/VobParser.cpp	2004-10-19 13:46:13 UTC (rev 896)
@@ -34,7 +34,7 @@
 #define SUBSTREAM_PCM_LOW		0xA0
 #define SUBSTREAM_PCM_HIGH		(SUBSTREAM_PCM_LOW + 8)
 
-#define CURRENT_OFFSET		(m_pktindex * PACKET_SIZE + m_index)
+#define CURRENT_OFFSET		(m_pktindex * DVD_VIDEO_LB_LEN + m_index)
 
 #define USE_DEBUG_LOG 1
 
@@ -75,107 +75,39 @@
 
 // ----------------------------------------------------------------------------
 
-VobFile::VobFile(const char *filename)
-:m_file(NULL)
-{
-	m_file = fopen(filename,"rb");
-
-	if (m_file == NULL)
-		throw VobParserFileNotFoundException(filename);
-}
-
-VobFile::~VobFile()
-{
-	if (m_file)
-		fclose(m_file);
-}
-
-size_t VobFile::Read(void *buffer, size_t blocks)
-{
-	assert(m_file != NULL);
-	return fread(buffer, PACKET_SIZE, blocks, m_file);
-}
-
-int VobFile::Seek(long position, int origin)
-{
-	assert(m_file != NULL);
-	return fseek(m_file, position, origin);
-}
-
-long VobFile::Tell()
-{
-	assert(m_file != NULL);
-	return ftell(m_file);
-}
-
-boolean VobFile::Eof()
-{
-	assert(m_file != NULL);
-	return feof(m_file);
-}
-
-unsigned long VobFile::Size()
-{
-	unsigned long _result;
-
-	Seek(0,SEEK_END);
-	_result = Tell();
-	Seek(0,SEEK_SET);
-
-	return _result;
-}
-
-// ----------------------------------------------------------------------------
-
-WX_DEFINE_LIST(FileHandleList);
-
 VobParser::VobParser(const char* dirname, int16_t title)
-  :m_title(title)
-   ,m_demuxer(NULL)
-   ,m_vobfile(NULL)
+	:m_title(title)
+	,m_demuxer(NULL)
+	,m_dvdhandle(NULL)
+	,m_menustream(NULL)
+	,m_vobstream(NULL)
+	,m_readingmenu(true)
+	,m_blockoffset(0)
 {
-	VobFile *_file;
+	dvd_file_t *_file;
 	wxString FileName;
-	uint64_t fileSize = 0;
 
-	m_files.Clear();
+	m_pktcount = 0;
 
 	// handle all parts of this title (VIDEO_TS.vob or VTS_XX_Y.vob)
-	if (title == 0)
+	m_dvdhandle = DVDOpen(dirname);
+
+	if (m_dvdhandle)
 	{
-		FileName = wxString::Format("%sVIDEO_TS.VOB",dirname);
-		_file = new VobFile(FileName.c_str());
-		if (_file != NULL)
-		{
-			m_files.Append(_file);
-			fileSize += _file->Size();
-		}
+		m_menustream = DVDOpenFile(m_dvdhandle, title, DVD_READ_MENU_VOBS);
+		m_vobstream = DVDOpenFile(m_dvdhandle, title, DVD_READ_TITLE_VOBS);
 	}
-	else
-	{
-		int i=0;
-		do {
-			FileName = wxString::Format("%sVTS_%02d_%d.VOB",dirname,title,i++);
-			_file = new VobFile(FileName.c_str());
-			if (_file != NULL)
-			{
-				m_files.Append(_file);
-				fileSize += _file->Size();
-			}
-		} while (_file != NULL);
-	}
 
-	if(!m_files.GetCount())
+	if(m_menustream == NULL && m_vobstream == NULL)
 	{
 		throw VobParserFileNotFoundException(dirname);
 	}
 	else
 	{
-		m_vobfile = m_files.GetFirst();
+		m_pktcount =  DVDFileSize(m_menustream);
+		m_pktcount += DVDFileSize(m_vobstream);
 	}
 
-	m_pktcount = fileSize / PACKET_SIZE;
-
 	Reset();
 }
 
@@ -183,8 +115,14 @@
 
 VobParser::~VobParser()
 {
-	for (unsigned int i=0; i<m_files.GetCount(); i++)
-		delete m_files.Item(i)->GetData();
+	if (m_menustream)
+		DVDCloseFile(m_menustream);
+
+	if (m_vobstream)
+		DVDCloseFile(m_vobstream);
+
+	if (m_dvdhandle)
+		DVDClose(m_dvdhandle);
 }
 
 // ----------------------------------------------------------------------------
@@ -272,7 +210,7 @@
 		
 		if(m_demuxer)
 		{
-			m_demuxer->ProcessVOBStream(m_buff,PACKET_SIZE);
+			m_demuxer->ProcessVOBStream(m_buff,DVD_VIDEO_LB_LEN);
 		}
 
 		m_pktindex++;
@@ -298,7 +236,7 @@
 
 bool VobParser::AvailablePacketData() const
 {
-	return (m_index < PACKET_SIZE);
+	return (m_index < DVD_VIDEO_LB_LEN);
 }
 
 // ----------------------------------------------------------------------------
@@ -306,12 +244,14 @@
 bool VobParser::GetNextPacket()
 {
 	m_index = 0;
+	dvd_file_t *_stream;
 
-	if (m_vobfile && m_vobfile->GetData()->Eof())
-		m_vobfile = m_vobfile->GetNext();
-	if (!m_vobfile)
-		return false;
-	return (m_vobfile->GetData()->Read(m_buff, 1) == 1);
+	if (m_readingmenu)
+		_stream = m_menustream;
+	else
+		_stream = m_vobstream;
+
+	return (DVDReadBlocks(_stream, m_blockoffset++, 1, m_buff) == 1);
 }
 
 // ----------------------------------------------------------------------------
@@ -746,8 +686,10 @@
 	previous_cellid = -1;
 	m_index = 0;
 	m_pktindex = 0;
-	for (unsigned int i=0; i<m_files.GetCount(); i++)
-		m_files.Item(i)->GetData()->Seek(0,SEEK_SET);
+	DVDFileSeek(m_menustream,0);
+	DVDFileSeek(m_vobstream,0);
+	m_readingmenu = true;
+	m_blockoffset = 0;
 	if (m_demuxer)
 		delete m_demuxer;
 	m_demuxer = NULL;

Modified: trunk/DvdMenuXtractor/VobParser.h
===================================================================
--- trunk/DvdMenuXtractor/VobParser.h	2004-10-19 13:15:38 UTC (rev 895)
+++ trunk/DvdMenuXtractor/VobParser.h	2004-10-19 13:46:13 UTC (rev 896)
@@ -10,6 +10,7 @@
 #include <string.h>
 #include <stdarg.h>
 #include <inttypes.h>
+#include "dvdread/ifo_read.h"
 
 #include "wx/wx.h"
 #include "wx/hashmap.h"
@@ -82,8 +83,6 @@
 	uint32_t c_eltm			: 32;	// Cell elapsed time (BCD)
 } nav_dsi_gi;
 
-#define PACKET_SIZE 2048
-
 typedef struct {
 	uint8_t PES_scrambling_control : 2;
 	uint8_t PES_priority : 1;
@@ -517,29 +516,25 @@
 private:
 	cell_info_node* m_cid;
 };
-
+/*
 class VobFile
 {
 	public:
-		VobFile(const char *filename);
-		~VobFile();
+		VobFile(const char *dirname, int16_t title);
+		virtual ~VobFile();
 
-		virtual size_t Read(void *buffer, size_t blocks);
-		virtual int Seek(long position, int origin);
-		virtual long Tell();
+		size_t Read(void *buffer, size_t blocks);
+		int Seek(unsigned int blocks);
 		unsigned long Size();
-		boolean Eof();
 
 	protected:
-		FILE *m_file;
+		dvd_reader_t *m_file;
 };
-
+*/
 // ============================================================================
 // Main class
 // ============================================================================
 
-WX_DECLARE_LIST(VobFile, FileHandleList);
-
 class VobParser  
 {
 public:
@@ -585,9 +580,12 @@
 	void SkipNBytes(int n);
 
 private:
-	FileHandleList m_files;
-	FileHandleList::Node *m_vobfile;
-	uint8_t m_buff[PACKET_SIZE];
+	dvd_reader_t *m_dvdhandle;
+	dvd_file_t *m_menustream;
+	dvd_file_t *m_vobstream;
+	boolean m_readingmenu;
+	ssize_t m_blockoffset;
+	uint8_t m_buff[DVD_VIDEO_LB_LEN];
 	uint32_t m_index;
 	uint32_t m_pktindex;
 	uint32_t m_pktcount;
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.