FileComments.cpp

Go to the documentation of this file.
00001 //===========================================================================
00002 //Copyright (C) 2004 Zentaro Kavanagh
00003 //
00004 //Redistribution and use in source and binary forms, with or without
00005 //modification, are permitted provided that the following conditions
00006 //are met:
00007 //
00008 //- Redistributions of source code must retain the above copyright
00009 //  notice, this list of conditions and the following disclaimer.
00010 //
00011 //- Redistributions in binary form must reproduce the above copyright
00012 //  notice, this list of conditions and the following disclaimer in the
00013 //  documentation and/or other materials provided with the distribution.
00014 //
00015 //- Neither the name of Zentaro Kavanagh nor the names of contributors 
00016 //  may be used to endorse or promote products derived from this software 
00017 //  without specific prior written permission.
00018 //
00019 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020 //``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021 //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00022 //PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
00023 //CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00024 //EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00025 //PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00026 //PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00027 //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00028 //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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) {          //Correctly deletes page.
00045         //Get a callback... check whether we have a comment.
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                         //Comment Packet
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);   //Temp... increase for chaining
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);   //Temp... increase for chaining
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 }

Generated on Tue Feb 15 14:54:21 2005 for oggdsf by  doxygen 1.3.9