[xiph-commits] r8608 - in trunk/oggdsf/src: lib/helper/libOOOggChef tools/mod_oggchef

ozone at motherfish-iii.xiph.org ozone at motherfish-iii.xiph.org
Tue Jan 4 01:27:33 PST 2005


Author: ozone
Date: 2005-01-04 01:27:33 -0800 (Tue, 04 Jan 2005)
New Revision: 8608

Modified:
   trunk/oggdsf/src/lib/helper/libOOOggChef/AnnodexRecomposer.cpp
   trunk/oggdsf/src/lib/helper/libOOOggChef/AnnodexRecomposer.h
   trunk/oggdsf/src/lib/helper/libOOOggChef/IRecomposer.h
   trunk/oggdsf/src/tools/mod_oggchef/mod_oggchef.cpp
Log:
oggdsf:
 * Output CMML with preamble and surrounding <cmml></cmml> tags
 * Work around bug in AutoAnxSeekTable, which sometimes returns a byte position of 0 for time offset 0 (it should return the byte position corresponding to the first non-header packet)


Modified: trunk/oggdsf/src/lib/helper/libOOOggChef/AnnodexRecomposer.cpp
===================================================================
--- trunk/oggdsf/src/lib/helper/libOOOggChef/AnnodexRecomposer.cpp	2005-01-04 07:53:54 UTC (rev 8607)
+++ trunk/oggdsf/src/lib/helper/libOOOggChef/AnnodexRecomposer.cpp	2005-01-04 09:27:33 UTC (rev 8608)
@@ -66,6 +66,12 @@
 }
 
 
+bool wantOnlyCMML(const vector<string>* inWantedMIMETypes)
+{
+	return (	inWantedMIMETypes->size() == 1
+			&&	inWantedMIMETypes->at(0) == "text/x-cmml");
+}
+
 /** The starting time offset's units is in seconds, while the wanted MIME types
     is a vector of strings, which will be matched against the MIME type in the
 	AnxData header of the logical bitstream. */
@@ -109,6 +115,12 @@
 	mDebugFile << "locStartOfBodyOffset: " << locStartOfBodyOffset << endl;
 #endif
 
+	// Output CMML preamble if the user wants it
+	if (wantOnlyCMML(mWantedMIMETypes)) {
+		const string CMML_PREAMBLE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<cmml>";
+		mBufferWriter((unsigned char *) CMML_PREAMBLE.c_str(), (unsigned long) CMML_PREAMBLE.length(), mBufferWriterUserData);
+	}
+
 	// Grab the headers from the stream
 	mDemuxParserState = LOOK_FOR_HEADERS;
 	{
@@ -138,7 +150,7 @@
 	unsigned long locRequestedStartTimeOffset =
 		locSeekTable->getStartPos(locRequestedStartTime).second;
 
-	// Re-open the file, to avoid any fallout from reading the headers
+	// Clear the file's flags, to avoid any fallout from reading the headers
 	locFile.clear();
 	locFile.seekg(locRequestedStartTimeOffset);
 
@@ -148,6 +160,13 @@
 	mDebugFile << "Current position: " << locFile.tellg() << endl;
 #endif
 
+	// TODO: This is a hack, since sometimes AutoAnxTable returns 0 when it
+	// really shouldn't ...
+	size_t locCurrentPosition = locFile.tellg();
+	if (locCurrentPosition == 0) {
+		mDemuxState = SEEN_NOTHING;
+	}
+
 	mDemuxParserState = LOOK_FOR_BODY;
 	{
 		OggDataBuffer locOggBuffer;
@@ -165,6 +184,12 @@
 		}
 	}
 
+	// Output CMML preamble if the user wants it
+	if (wantOnlyCMML(mWantedMIMETypes)) {
+		const string CMML_POSTAMBLE = "\n</cmml>";
+		mBufferWriter((unsigned char *) CMML_POSTAMBLE.c_str(), (unsigned long) CMML_POSTAMBLE.length(), mBufferWriterUserData);
+	}
+
 	// Tidy up
 	locFile.close();
 
@@ -289,8 +314,6 @@
 								mBufferWriter(inOggPage->createRawPageData(),
 									inOggPage->pageSize(), mBufferWriterUserData);
 							}
-
-							break;
 						}
 					}
 				} else if (isAnnodexEOSPage(inOggPage, mAnnodexSerialNumber)) {
@@ -356,15 +379,63 @@
 		switch (mDemuxState) {
 
 			case SEEN_NOTHING:
+				if (isAnnodexBOSPage(inOggPage)) {
+					mDemuxState = SEEN_ANNODEX_BOS;
+				} else {
+					// The Annodex BOS page should always be the very first page of
+					// the stream, so if we don't see it, the stream's invalid
+					mDemuxState = INVALID;
+				}
+				break;
+
 			case SEEN_ANNODEX_BOS:
+				if (isAnxDataPage(inOggPage)) {
+					// Do nothing
+				} else if (isAnnodexEOSPage(inOggPage, mAnnodexSerialNumber)) {
+					mDemuxState = SEEN_ANNODEX_EOS;
+				} else {
+					// We didn't spot either an AnxData page or the Annodex EOS: WTF?
+					mDemuxState = INVALID;
+				}
+				break;
+
 			case SEEN_ANNODEX_EOS:
-#ifdef DEBUG
-			mDebugFile << "Looking for body, state is " << mDemuxState << endl;
-#endif		
-			break;
+				{
+					// Only output headers for the streams that the user wants
+					// in their request
+					for (unsigned int i = 0; i < mWantedStreamSerialNumbers.size(); i++) {
+						if (mWantedStreamSerialNumbers[i].first == inOggPage->header()->StreamSerialNo()) {
+							if (mWantedStreamSerialNumbers[i].second >= 1) {
+								mWantedStreamSerialNumbers[i].second--;
+							} 
+#if 0
+							else {
+								mDemuxState = INVALID;
+							}
+#endif
+						}
+					}
 
+					bool allEmpty = true;
+					for (unsigned int i = 0; i < mWantedStreamSerialNumbers.size(); i++) {
+						if (mWantedStreamSerialNumbers[i].second != 0) {
+							allEmpty = false;
+						}
+					}
+
+					if (allEmpty) {
+						mDemuxState = SEEN_ALL_CODEC_HEADERS;
+					}
+				}
+				break;
+
 			case SEEN_ALL_CODEC_HEADERS:
 				{
+					// Ignore any header packets which we may encounter
+					if ((inOggPage->header()->HeaderFlags() & OggPageHeader::BOS) != 0) {
+						break;
+					}
+
 					// Only output streams which the user requested
 					for (unsigned int i = 0; i < mWantedStreamSerialNumbers.size(); i++) {
 						if (	mWantedStreamSerialNumbers[i].first

Modified: trunk/oggdsf/src/lib/helper/libOOOggChef/AnnodexRecomposer.h
===================================================================
--- trunk/oggdsf/src/lib/helper/libOOOggChef/AnnodexRecomposer.h	2005-01-04 07:53:54 UTC (rev 8607)
+++ trunk/oggdsf/src/lib/helper/libOOOggChef/AnnodexRecomposer.h	2005-01-04 09:27:33 UTC (rev 8608)
@@ -54,7 +54,6 @@
 	AnnodexRecomposer(string inFilename, BufferWriter inBufferWriter, void* inBufferWriterUserData);
 	~AnnodexRecomposer(void);
 
-	/// Recompose a stream from a particular time offset and/or only selecting certain logical bitstreams (specified as MIME types)
 	void recomposeStreamFrom(double inStartingTimeOffset, const vector<string>* inWantedMIMETypes);
 	bool acceptOggPage(OggPage* inOggPage);
 

Modified: trunk/oggdsf/src/lib/helper/libOOOggChef/IRecomposer.h
===================================================================
--- trunk/oggdsf/src/lib/helper/libOOOggChef/IRecomposer.h	2005-01-04 07:53:54 UTC (rev 8607)
+++ trunk/oggdsf/src/lib/helper/libOOOggChef/IRecomposer.h	2005-01-04 09:27:33 UTC (rev 8608)
@@ -47,6 +47,7 @@
 	IRecomposer(void);
 	virtual ~IRecomposer(void);
 
+	/// Recompose a stream from a particular time offset and/or only selecting certain logical bitstreams (specified as MIME types)
 	virtual void recomposeStreamFrom(double inStartingTimeOffset, const vector<string>* inWantedMIMETypes) = 0;
+};
 
-};

Modified: trunk/oggdsf/src/tools/mod_oggchef/mod_oggchef.cpp
===================================================================
--- trunk/oggdsf/src/tools/mod_oggchef/mod_oggchef.cpp	2005-01-04 07:53:54 UTC (rev 8607)
+++ trunk/oggdsf/src/tools/mod_oggchef/mod_oggchef.cpp	2005-01-04 09:27:33 UTC (rev 8608)
@@ -161,8 +161,12 @@
 	// Find out what time we're meant to start serving stuff out at
 	const char* locRequestedStartTimeAsCString =
 		(const char *) apr_table_get (locCGITable, "t");
-	double locRequestedStartTime =
-		anx_parse_time(locRequestedStartTimeAsCString);
+	double locRequestedStartTime;
+	if (locRequestedStartTimeAsCString) {
+		locRequestedStartTime = anx_parse_time(locRequestedStartTimeAsCString);
+	} else {
+		locRequestedStartTime = 0;
+	}
 
 	// What's the output MIME type requested?
 	const vector<string>* locOutputMIMETypes = preferredOutputMIMETypes(inRequest);



More information about the commits mailing list