[xiph-commits] r6882 -

illiminable at dactyl.lonelymoon.com illiminable
Sat Jun 26 02:50:40 PDT 2004


trunk/oggdsf/src/lib/core/ogg/libVorbisComment
Message-ID: <20040626095040.DD56F9AAAB at dactyl.lonelymoon.com>

Author: illiminable
Date: Sat Jun 26 02:50:40 2004
New Revision: 6882

Modified:
trunk/oggdsf/src/lib/core/ogg/libVorbisComment/SingleVorbisComment.cpp
trunk/oggdsf/src/lib/core/ogg/libVorbisComment/SingleVorbisComment.h
trunk/oggdsf/src/lib/core/ogg/libVorbisComment/VorbisComments.cpp
trunk/oggdsf/src/lib/core/ogg/libVorbisComment/VorbisComments.h
trunk/oggdsf/src/lib/core/ogg/libVorbisComment/libVorbisComment.vcproj
trunk/oggdsf/src/lib/core/ogg/libVorbisComment/stdafx.h
Log:
* Added the vorbis comment parsing code... totally untested.

Modified: trunk/oggdsf/src/lib/core/ogg/libVorbisComment/SingleVorbisComment.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libVorbisComment/SingleVorbisComment.cpp	2004-06-26 08:18:27 UTC (rev 6881)
+++ trunk/oggdsf/src/lib/core/ogg/libVorbisComment/SingleVorbisComment.cpp	2004-06-26 09:50:39 UTC (rev 6882)
@@ -36,4 +36,28 @@
unsigned long SingleVorbisComment::length() {
//FIX::: This would be faster to add them manually.
return toString().length();
+}
+
+bool SingleVorbisComment::parseComment(string inCommentString) {
+	size_t pos = 0;
+	size_t pos2 = 0;
+	pos = inCommentString.find('=');
+	if ((pos == string::npos) && (pos != 0)) {
+		//FAILED - No equals sign
+		return false;
+	} else {
+		pos2 = inCommentString.find('=', pos + 1);
+		if (pos2 == string::npos) {
+			//OK - no other equals signs
+			mKey = inCommentString.substr(0, pos);
+			mValue = inCommentString.substr(pos + 1);
+		} else {
+			//FAILED : Too many = signs
+			return false;
+		}
+
+		return true;
+	}
+
+
}
\ No newline at end of file

Modified: trunk/oggdsf/src/lib/core/ogg/libVorbisComment/SingleVorbisComment.h
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libVorbisComment/SingleVorbisComment.h	2004-06-26 08:18:27 UTC (rev 6881)
+++ trunk/oggdsf/src/lib/core/ogg/libVorbisComment/SingleVorbisComment.h	2004-06-26 09:50:39 UTC (rev 6882)
@@ -4,6 +4,7 @@

using namespace std;

+
class LIBVORBISCOMMENT_API SingleVorbisComment
{
public:
@@ -20,6 +21,8 @@

unsigned long length();

+	bool parseComment(string inCommentString);
+
protected:
string mKey;
string mValue;

Modified: trunk/oggdsf/src/lib/core/ogg/libVorbisComment/VorbisComments.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libVorbisComment/VorbisComments.cpp	2004-06-26 08:18:27 UTC (rev 6881)
+++ trunk/oggdsf/src/lib/core/ogg/libVorbisComment/VorbisComments.cpp	2004-06-26 09:50:39 UTC (rev 6882)
@@ -51,4 +51,167 @@
locComment.setValue(inValue);
mCommentList.push_back(locComment);
return true;
-}
\ No newline at end of file
+}
+
+bool VorbisComments::parseOggPacket(OggPacket* inPacket) {
+	//FIX::: Validate it is a comment packet
+	unsigned long locPackSize = inPacket->packetSize();
+	unsigned long locUpto = 0;
+	unsigned long locVendorLength = 0;
+	string locVendorString;
+	char* tempBuff = NULL;
+	unsigned char* locPackBuff = inPacket->packetData();
+	unsigned long locNumComments = 0;
+	vector<SingleVorbisComment> locCommentList;
+
+	if (locPackSize < locUpto + 4 - 1) {
+		//FAILED - No vendor length
+		return false;
+	}
+
+	locVendorLength = OggMath::charArrToULong(inPacket->packetData());
+	locUpto+=4;
+
+	if (locPackSize < locUpto + locVendorLength - 1) {
+		//FAILED - Vendor string not present
+		return false;
+	}
+
+	tempBuff = new char[locVendorLength + 1];
+
+	if (tempBuff == NULL) {
+		//FAILED - Vendor length too big, out of memory
+		return false;
+	}
+
+	memcpy((void*)tempBuff, (const void*)(locPackBuff + locUpto), locVendorLength);
+	tempBuff[locVendorLength] = '\0';
+
+	locVendorString = tempBuff;
+	delete tempBuff;
+	tempBuff = NULL;
+
+	locUpto += locVendorLength;
+
+	if (locPackSize < locUpto + 4 - 1) {
+		//FAILED - User comment list length not present
+		return false;
+	}
+
+	locNumComments = OggMath::charArrToULong(locPackBuff + locUpto);
+	locUpto += 4;
+
+	unsigned long locUserCommentLength = 0;
+	bool locFailed = false;
+	string locUserComment;
+	unsigned long i = 0;
+	while (!locFailed && (i < locNumComments)) {
+		if (locPackSize < locUpto + 4 -1) {
+			//FAILED - User comment string length not present
+			return false;
+		}
+
+		locUserCommentLength = OggMath::charArrToULong(locPackBuff + locUpto);
+		locUpto += 4;
+
+
+		if (locPackSize < locUpto + locUserCommentLength - 1) {
+			//FAILED - User comment string not present
+			return false;
+		}
+
+		memcpy((void*)tempBuff, (const void*)(locPackBuff + locUpto), locUserCommentLength);
+		tempBuff[locUserCommentLength] = '\0';
+
+        locUserComment = tempBuff;
+		delete tempBuff;
+		locUpto += locVendorLength;
+
+
+		SingleVorbisComment locComment;
+		if (locComment.parseComment(locUserComment)) {
+			locCommentList.push_back(locComment);
+		} else {
+			//FAILED - Comment not parsable
+			return false;
+		}
+
+		i++;
+
+	}
+
+	//Check the bit.
+	if (locPackSize < locUpto) {
+		//FAILED - No check bit
+		return false;
+	}
+
+	if ((locPackBuff[locUpto] & 1) == 1) {
+		//OK
+		mVendorString = locVendorString;
+
+		for (int j = 0; j < locCommentList.size(); j++) {
+			mCommentList.push_back(locCommentList[j]);
+		}
+	} else {
+		//FAILED - Check bit not set
+		return false;
+	}
+
+	return true;
+
+
+
+
+
+
+}
+
+string VorbisComments::toString() {
+	return "";
+
+}
+unsigned long VorbisComments::size() {
+	unsigned long locPackSize = 0;
+
+	locPackSize = mVendorString.size() + 4;
+
+	for (int i = 0; i < mCommentList.size(); i++) {
+		locPackSize += mCommentList[i].length() + 4;
+	}
+
+	//Check bit
+	locPackSize++;
+
+	return locPackSize;
+}
+OggPacket* VorbisComments::toOggPacket() {
+	unsigned long locPackSize = size();
+	unsigned long locUpto = 0;
+	unsigned char* locPackData = new unsigned char[locPackSize];
+
+	OggMath::ULongToCharArr(mVendorString.length(), locPackData);
+	locUpto += 4;
+
+	memcpy((void*)(locPackData + locUpto), (const void*)mVendorString.c_str(), mVendorString.length());
+	locUpto += mVendorString.length();
+
+	OggMath::ULongToCharArr(mCommentList.size(), locPackData + locUpto);
+	locUpto += 4;
+
+	for (int i = 0; i < mCommentList.size(); i++) {
+		OggMath::ULongToCharArr(mCommentList[i].length(), locPackData + locUpto);
+		locUpto += 4;
+
+		memcpy((void*)(locPackData + locUpto), (const void*)mCommentList[i].toString().c_str(), mCommentList[i].length());
+		locUpto += mCommentList[i].length();
+	}
+
+	locPackData[locUpto] = 1;
+
+	OggPacket* locPacket = NULL;
+	locPacket = new OggPacket(locPackData, locPackSize, true);
+
+	return locPacket;
+
+}

Modified: trunk/oggdsf/src/lib/core/ogg/libVorbisComment/VorbisComments.h
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libVorbisComment/VorbisComments.h	2004-06-26 08:18:27 UTC (rev 6881)
+++ trunk/oggdsf/src/lib/core/ogg/libVorbisComment/VorbisComments.h	2004-06-26 09:50:39 UTC (rev 6882)
@@ -5,6 +5,8 @@

using namespace std;
#include "SingleVorbisComment.h"
+#include "OggPacket.h"
+#include "OggMath.h"

class LIBVORBISCOMMENT_API VorbisComments
{
@@ -22,6 +24,12 @@

bool addComment(SingleVorbisComment inComment);
bool addComment(string inKey, string inValue);
+
+	bool parseOggPacket(OggPacket* inPacket);
+	OggPacket* toOggPacket();
+	string toString();
+
+	unsigned long size();
protected:
string mVendorString;
vector<SingleVorbisComment> mCommentList;

Modified: trunk/oggdsf/src/lib/core/ogg/libVorbisComment/libVorbisComment.vcproj
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libVorbisComment/libVorbisComment.vcproj	2004-06-26 08:18:27 UTC (rev 6881)
+++ trunk/oggdsf/src/lib/core/ogg/libVorbisComment/libVorbisComment.vcproj	2004-06-26 09:50:39 UTC (rev 6882)
@@ -19,20 +19,24 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
+				AdditionalIncludeDirectories="..\libOOOgg"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBVORBISCOMMENT_EXPORTS"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
-				RuntimeLibrary="1"
+				RuntimeLibrary="3"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
-				DebugInformationFormat="4"/>
+				DebugInformationFormat="4"
+				CallingConvention="2"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
+				AdditionalDependencies="libOOOgg.lib"
OutputFile="$(OutDir)/libVorbisComment.dll"
LinkIncremental="2"
+				AdditionalLibraryDirectories="..\libOOOgg\Debug"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/libVorbisComment.pdb"
SubSystem="2"
@@ -64,9 +68,10 @@
Optimization="2"
InlineFunctionExpansion="1"
OmitFramePointers="TRUE"
+				AdditionalIncludeDirectories="..\libOOOgg"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBVORBISCOMMENT_EXPORTS"
StringPooling="TRUE"
-				RuntimeLibrary="0"
+				RuntimeLibrary="2"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="3"
WarningLevel="3"
@@ -76,8 +81,10 @@
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
+				AdditionalDependencies="libOOOgg.lib"
OutputFile="$(OutDir)/libVorbisComment.dll"
LinkIncremental="1"
+				AdditionalLibraryDirectories="..\libOOOgg\Release"
GenerateDebugInformation="TRUE"
SubSystem="2"
OptimizeReferences="2"

Modified: trunk/oggdsf/src/lib/core/ogg/libVorbisComment/stdafx.h
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libVorbisComment/stdafx.h	2004-06-26 08:18:27 UTC (rev 6881)
+++ trunk/oggdsf/src/lib/core/ogg/libVorbisComment/stdafx.h	2004-06-26 09:50:39 UTC (rev 6882)
@@ -10,3 +10,8 @@
#include <windows.h>

// TODO: reference additional headers your program requires here
+#ifdef LIBOOOGG_EXPORTS
+#define LIBOOOGG_API __declspec(dllexport)
+#else
+#define LIBOOOGG_API __declspec(dllimport)
+#endif
\ No newline at end of file



More information about the commits mailing list