00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "stdafx.h"
00033 #include "FileComments.h"
00034
00035 FileComments::FileComments(void)
00036 : mMinorStreamCount(0)
00037 {
00038 }
00039
00040 FileComments::~FileComments(void)
00041 {
00042 }
00043
00044 bool FileComments::acceptOggPage(OggPage* inOggPage) {
00045
00046 VorbisComments* locVorbisComments = NULL;
00047 StreamCommentInfo* locStreamInfo = NULL;
00048 for (unsigned long i = 0; i < inOggPage->numPackets(); i++) {
00049 OggPacket* locPacket = NULL;
00050 locPacket = inOggPage->getPacket(i);
00051 if (strncmp((const char*)locPacket->packetData(), "\003vorbis", 7) == 0) {
00052
00053 locVorbisComments = new VorbisComments;
00054 locStreamInfo = new StreamCommentInfo;
00055 bool locIsOK = locVorbisComments->parseOggPacket(locPacket, 7);
00056
00057 locStreamInfo->setCodecID(StreamCommentInfo::VORBIS);
00058 locStreamInfo->setPageStart(mBytePos);
00059 locStreamInfo->setComments(locVorbisComments);
00060 locStreamInfo->setMajorStreamNo(0);
00061 locStreamInfo->setMinorStreamNo(mMinorStreamCount);
00062 mStreams.push_back(locStreamInfo);
00063 mMinorStreamCount++;
00064
00065
00066 } else if ((strncmp((char*)locPacket->packetData(), "\201theora", 7)) == 0) {
00067 locVorbisComments = new VorbisComments;
00068 locStreamInfo = new StreamCommentInfo;
00069 bool locIsOK = locVorbisComments->parseOggPacket(locPacket, 7);
00070 locStreamInfo->setCodecID(StreamCommentInfo::THEORA);
00071 locStreamInfo->setPageStart(mBytePos);
00072 locStreamInfo->setComments(locVorbisComments);
00073 locStreamInfo->setMajorStreamNo(0);
00074 locStreamInfo->setMinorStreamNo(mMinorStreamCount);
00075 mStreams.push_back(locStreamInfo);
00076
00077 mMinorStreamCount++;
00078 }
00079 }
00080 mBytePos += inOggPage->pageSize();
00081
00082 delete inOggPage;
00083 return true;
00084
00085 }
00086 bool FileComments::loadFile(string inFileName) {
00087 mBytePos = 0;
00088 const unsigned long BUFF_SIZE = 4096;
00089 OggDataBuffer locOggBuff;
00090
00091 locOggBuff.registerVirtualCallback(this);
00092
00093 fstream locFile;
00094 locFile.open(inFileName.c_str(), ios_base::in | ios_base::binary);
00095 if (locFile.is_open() != true) {
00096 return false;
00097 }
00098 char* locBuff = new char[BUFF_SIZE];
00099 unsigned long locBytesRead = 0;
00100 while (!locFile.eof()) {
00101 locFile.read(locBuff, BUFF_SIZE);
00102 locBytesRead = locFile.gcount();
00103 locOggBuff.feed((const unsigned char*)locBuff, locBytesRead);
00104 }
00105
00106 delete[] locBuff;
00107 return true;
00108
00109 }
00110 string FileComments::fileName() {
00111 return mFileName;
00112 }
00113
00114 bool FileComments::writeOutAll(string inFileName) {
00115
00116 fstream locFile;
00117 locFile.open(inFileName.c_str(), ios_base::out | ios_base::in | ios_base::binary);
00118
00119 if (locFile.is_open()) {
00120
00121
00122 }
00123 return false;
00124 }
00125 bool FileComments::writeOutStream(unsigned long inIndex) {
00126 return false;
00127 }
00128
00129 bool FileComments::addStreamComment(StreamCommentInfo* inStreamComment) {
00130 mStreams.push_back(inStreamComment);
00131 return true;
00132 }
00133 StreamCommentInfo* FileComments::getStreamComment(unsigned long inIndex) {
00134 if (inIndex < mStreams.size()) {
00135 return mStreams[inIndex];
00136 } else {
00137 return NULL;
00138 }
00139 }
00140
00141 unsigned long FileComments::streamCount() {
00142 return (unsigned long)mStreams.size();
00143 }