OOOggPageInfo.cpp

Go to the documentation of this file.
00001 //===========================================================================
00002 //Copyright (C) 2003, 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 // OggDump.cpp : Defines the entry point for the console application.
00033 //
00034 
00035 #include "stdafx.h"
00036 #include <libOOOgg/libOOOgg.h>
00037 #include <libOOOgg/dllstuff.h>
00038 
00039 #include <iostream>
00040 #include <fstream>
00041 
00042 unsigned long bytePos;
00043 vector<unsigned long> streamSerials;
00044 vector<unsigned long*> maxPacks;
00045 //This will be called by the callback
00046 bool pageCB(OggPage* inOggPage, void* inUserData /* ignored */) {
00047         bool locFoundStream = false;
00048         size_t locFoundPos = 0;
00049 
00050         unsigned long locSerialNo = inOggPage->header()->StreamSerialNo();
00051         for (size_t i = 0; i < streamSerials.size(); i++) {
00052                 if (locSerialNo == streamSerials[i]) {
00053                         locFoundStream = true;
00054                         locFoundPos = i;
00055                         break;
00056                 }
00057         }
00058         
00059         if (!locFoundStream) {
00060                 streamSerials.push_back(locSerialNo);
00061                 maxPacks.push_back(new unsigned long(0));
00062         }
00063         unsigned long locNumPacks = 0;
00064         for (size_t i = 0; i < streamSerials.size(); i++) {
00065                 
00066                 if (locSerialNo == streamSerials[i]) {
00067                         locFoundPos = i;
00068                         cout << "Stream "<<(unsigned long)i<<"  : Granule = "<<inOggPage->header()->GranulePos()<<"   - ";
00069                         locNumPacks = 0;
00070                         if (inOggPage->numPackets() == 0) {
00071                                 cout<<"EMPTY PAGE"<<endl;
00072                         } else if (inOggPage->numPackets() == 1) {
00073                                 if (inOggPage->getPacket(0)->isContinuation() || inOggPage->getPacket(0)->isTruncated()) {
00074                                         cout<<" 1 Partial Packet";
00075                                 } else {
00076                                         cout<<" 1 Full Packet";
00077                                         locNumPacks = 1;
00078                                 }
00079                         } else {
00080                                 locNumPacks = inOggPage->numPackets();
00081 
00082                                 unsigned long locPartials = 0;
00083                                 if (inOggPage->getPacket(0)->isContinuation()) {
00084                                         locNumPacks--;
00085                                         locPartials++;
00086                                 }
00087 
00088                                 if (inOggPage->getPacket(inOggPage->numPackets() - 1)->isTruncated()) {
00089                                         locNumPacks--;
00090                                         locPartials++;
00091                                 }
00092 
00093                                 if (locPartials == 1) {
00094                                         cout << " 1 Partial Packet";
00095                                 } else if (locPartials >= 2) {
00096                                         cout<<" "<<locPartials<<" Full Packets";
00097                                 }
00098 
00099                                 if (locNumPacks == 1) {
00100                                         cout<<" 1 Full Packet";
00101                                 } else if (locNumPacks >= 2) {
00102                                         cout<<" "<<locNumPacks<<" Full Packets";
00103                                 }
00104                         }
00105                         cout<<endl;
00106 
00107                         break;
00108                 }
00109         }
00110 
00111         
00112         if (*maxPacks[locFoundPos] < locNumPacks) {
00113                 *maxPacks[locFoundPos] = locNumPacks;
00114         }
00115 
00116         return true;
00117 }
00118 
00119 
00120 #ifdef WIN32
00121 int __cdecl _tmain(int argc, _TCHAR* argv[])
00122 #else
00123 int main (int argc, char * argv[])
00124 #endif
00125 {
00126         //This program just gives some info about number of packets
00127         // Currently does not error checking. Check your command line carefully !
00128         // USAGE :: OOOggPageInfo <OggFile>
00129         //
00130 
00131         bytePos = 0;
00132 
00133         if (argc < 2) {
00134                 cout<<"Usage : OOOggPageInfo <filename>"<<endl;
00135         } else {
00136                 OggDataBuffer testOggBuff;
00137                 
00138                 testOggBuff.registerStaticCallback(&pageCB, NULL);
00139 
00140                 fstream testFile;
00141                 testFile.open(argv[1], ios_base::in | ios_base::binary);
00142                 
00143                 const unsigned short BUFF_SIZE = 8092;
00144                 char* locBuff = new char[BUFF_SIZE];
00145                 while (!testFile.eof()) {
00146                         testFile.read(locBuff, BUFF_SIZE);
00147                         unsigned long locBytesRead = testFile.gcount();
00148                 testOggBuff.feed((const unsigned char*)locBuff, locBytesRead);
00149                 }
00150 
00151                 cout<<endl;
00152                 cout<<endl;
00153 
00154                 for (size_t i = 0; i < maxPacks.size(); i++) {
00155                         cout<<"Stream "<<(unsigned long)i<<" max Packets = "<<*maxPacks[i]<<endl;
00156                 }
00157 
00158 
00159                 for (size_t i = 0; i < maxPacks.size(); i++) {
00160                         delete maxPacks[i];
00161                 }
00162 
00163                 delete[] locBuff;
00164         }
00165 
00166         return 0;
00167 }
00168 

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