[matroska] r1050 - trunk/foo_matroska

[email protected]
Newsgroups gmane.comp.multimedia.matroska.cvs
Message-ID <[email protected]>
Author: toff
Date: 2005-01-22 23:10:04 +0300 (Sat, 22 Jan 2005)
New Revision: 1050

Modified:
   trunk/foo_matroska/foo_input_matroska.cpp
   trunk/foo_matroska/matroska_parser.cpp
   trunk/foo_matroska/matroska_parser.h
Log:
Experimental multi track support

Modified: trunk/foo_matroska/foo_input_matroska.cpp
===================================================================
--- trunk/foo_matroska/foo_input_matroska.cpp	2005-01-20 12:01:18 UTC (rev 1049)
+++ trunk/foo_matroska/foo_input_matroska.cpp	2005-01-22 20:10:04 UTC (rev 1050)
@@ -138,18 +138,31 @@
 		if (m_parser->Parse(!(flags & OPEN_FLAG_DECODE))) {
 			console::error("Matroska: Invalid Matroska file.");
 			return false;			
-		}
-		
-		m_parser->SetSubSong(info->get_subsong_index());
+		}		
 
 		m_TrackNo = m_parser->GetFirstAudioTrack();
 		if (m_TrackNo == -1) {
 			console::error("Matroska: no decodable streams found.");
 			return false;
+		}	
+
+#ifdef MULTITRACK
+		if(m_parser->GetChapters().size() > 0)
+		{			
+			int idx = info->get_subsong_index() / m_parser->GetChapters().size();
+			m_TrackNo = m_parser->GetAudioTrackIndex(idx);
+			m_parser->SetCurrentTrack(m_TrackNo);
+			m_parser->SetSubSong(info->get_subsong_index() % m_parser->GetChapters().size());
+		} else {
+			m_TrackNo = m_parser->GetAudioTrackIndex(info->get_subsong_index());
+			m_parser->SetCurrentTrack(m_TrackNo);
+			m_parser->SetSubSong(0);
 		}
+#else
+		m_parser->SetSubSong(info->get_subsong_index());
 		m_parser->SetCurrentTrack(m_TrackNo);
-
-	
+#endif
+			
 		// Set the current track
 
 		MatroskaTrackInfo &currentTrack = m_parser->GetTrack(m_TrackNo);
@@ -512,15 +525,30 @@
 		scanner.Parse(true);
 
 		std::vector<MatroskaChapterInfo> &chapters = scanner.GetChapters();
-		
+
+#ifdef MULTITRACK
 		if (chapters.size() > 0) {
+			for (size_t c = 0; c < chapters.size() * scanner.GetAudioTrackCount(); c++) {
+				out->on_entry(make_playable_location(filename, (int)c));
+			}
+			r->reader_release();
+			return 1;
+		} else if(scanner.GetAudioTrackCount() > 0) {
+			for (size_t t = 0; t < scanner.GetAudioTrackCount(); t++) {
+				out->on_entry(make_playable_location(filename, (int)t));
+			}
+			r->reader_release();
+			return 1;
+		}
+#else
+		if (chapters.size() > 0) {
 			for (size_t c = 0; c < chapters.size(); c++) {
-				MatroskaChapterInfo &currentChapter = chapters.at(c);
 				out->on_entry(make_playable_location(filename, (int)c));
 			}
 			r->reader_release();
 			return 1;
 		}
+#endif
 
 		r->reader_release();
 		return 0;
@@ -529,7 +557,7 @@
 
 static service_factory_single_t<track_indexer,track_indexer_matroska> foo_matroska1;
 
-DECLARE_COMPONENT_VERSION("Matroska Plugin" ,"0.8.0","Copyright (C) 2003-2004 Jory Stone ([email protected])\nCopyright (C) 2003-2004 Peter Pawlowski");
+DECLARE_COMPONENT_VERSION("Matroska Plugin" ,"0.8.5","Copyright (C) 2003-2004 Jory Stone ([email protected])\nCopyright (C) 2003-2004 Peter Pawlowski");
 
 
 DECLARE_FILE_TYPE("Matroska Audio files","*.MKA");

Modified: trunk/foo_matroska/matroska_parser.cpp
===================================================================
--- trunk/foo_matroska/matroska_parser.cpp	2005-01-20 12:01:18 UTC (rev 1049)
+++ trunk/foo_matroska/matroska_parser.cpp	2005-01-22 20:10:04 UTC (rev 1050)
@@ -990,6 +990,34 @@
 	return -1;
 }
 
+uint32 MatroskaAudioParser::GetAudioTrackCount()
+{
+	uint32 count = 0;
+	for (uint16 t = 0; t < m_Tracks.size(); t++)
+	{
+		MatroskaTrackInfo &currentTrack = m_Tracks.at(t);
+		if (!strncmp(currentTrack.codecID.c_str(),"A_",2))
+			count++;
+	}
+	return count;
+}
+
+uint32 MatroskaAudioParser::GetAudioTrackIndex(uint32 index)
+{
+	uint32 idx = 0;
+	for (uint16 t = 0; t < m_Tracks.size(); t++)
+	{
+		MatroskaTrackInfo &currentTrack = m_Tracks.at(t);
+		if (!strncmp(currentTrack.codecID.c_str(),"A_",2))
+		{
+			if(t == index)
+				break;
+			idx++;
+		}
+	}
+	return idx;
+}
+
 static bool is_rg_field(const char * name)
 {
 	int m;
@@ -1330,12 +1358,22 @@
 	if(m_CurrentChapter != NULL)
 	{
 		// If TITLE tag is empty we get it from the chapter name
-		if ((info->meta_get("TITLE") == NULL) || (strlen(info->meta_get("TITLE")) == 0))
+		if ( (m_CurrentChapter->display.size() > 0) &&
+			 ((info->meta_get("TITLE") == NULL) ||
+			  (strlen(info->meta_get("TITLE")) == 0) ) )
+		{
 			info->meta_set("TITLE", m_CurrentChapter->display.at(0).string.GetUTF8().c_str());
+		}
 		if ((info->meta_get("TRACKNUMBER") == NULL) || (strlen(info->meta_get("TRACKNUMBER")) == 0))
 		{
 			char trackNumberString[32];
+#ifdef MULTITRACK			
+			wsprintf(trackNumberString, "%d",
+				(info->get_subsong_index() % m_Chapters.size()) +1);
+#else
+			
 			wsprintf(trackNumberString, "%d",info->get_subsong_index()+1);
+#endif
 			info->meta_set("TRACKNUMBER", trackNumberString);
 		}
 		if ((info->meta_get("ALBUM") == NULL) || (strlen(info->meta_get("ALBUM")) == 0))

Modified: trunk/foo_matroska/matroska_parser.h
===================================================================
--- trunk/foo_matroska/matroska_parser.h	2005-01-20 12:01:18 UTC (rev 1049)
+++ trunk/foo_matroska/matroska_parser.h	2005-01-22 20:10:04 UTC (rev 1050)
@@ -23,6 +23,8 @@
 #ifndef _MATROSKA_PARSER_H_
 #define _MATROSKA_PARSER_H_
 
+#define MULTITRACK 1
+
 #include "../SDK/foobar2000.h"
 #include "Foobar2000ReaderIOCallback.h"
 #include "DbgOut.h"
@@ -239,6 +241,9 @@
 
 	std::vector<MatroskaEditionInfo> &GetEditions() { return m_Editions; };
 	std::vector<MatroskaChapterInfo> &GetChapters() { return m_Chapters; };
+	std::vector<MatroskaTrackInfo> &GetTracks() { return m_Tracks; };
+	uint32 GetAudioTrackCount();
+	uint32 GetAudioTrackIndex(uint32 index);
 
 	int32 GetAvgBitrate();
 	/// Seek to a position
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.