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 // OOOggPageInfo.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 struct sOggStreamInfo {
00043         unsigned long mSerialNo;
00044         unsigned long mNumPages;
00045         unsigned long mMinPageSize;
00046         unsigned long mMaxPageSize;
00047         unsigned long mMinPacksPerPage;
00048         unsigned long mMaxPacksPerPage;
00049         unsigned long mTotalPacketCount;
00050         unsigned long mTotalStreamSize;
00051         unsigned long mTotalDataSize;
00052 
00053 };
00054 
00055 void dumpStreamInfo(sOggStreamInfo* inInfo)
00056 {
00057 
00058         cout<<"=== Stream "<<inInfo->mSerialNo<<endl;
00059         cout<<"=================="<<endl;
00060         cout<<"Num Pages      :  "<<inInfo->mNumPages<<endl;
00061 
00062         cout<<"Min Page Size  :  "<<inInfo->mMinPageSize<<endl;
00063         cout<<"Max Page Size  :  "<<inInfo->mMaxPageSize<<endl;
00064         cout<<"Avg Page Size  :  "<<inInfo->mTotalStreamSize / inInfo->mNumPages<<endl;
00065         cout<<"Num Pages      :  "<<inInfo->mNumPages<<endl;
00066         cout<<"Num Pages      :  "<<inInfo->mNumPages<<endl;
00067         cout<<"Num Pages      :  "<<inInfo->mNumPages<<endl;
00068         cout<<"Num Pages      :  "<<inInfo->mNumPages<<endl;
00069         cout<<"Num Pages      :  "<<inInfo->mNumPages<<endl;
00070         cout<<"Num Pages      :  "<<inInfo->mNumPages<<endl<<endl;
00071 
00072 }
00073 unsigned long bytePos;
00074 //vector<unsigned long> streamSerials;
00075 //vector<unsigned long*> maxPacks;
00076 vector<sOggStreamInfo*> streamInfos;
00077 
00078 //This will be called by the callback
00079 bool pageCB(OggPage* inOggPage, void* inUserData /* ignored */) {
00080         bool locFoundStream = false;
00081         size_t locFoundPos = 0;
00082 
00083         unsigned long locSerialNo = inOggPage->header()->StreamSerialNo();
00084         for (size_t i = 0; i < streamInfos.size(); i++) {
00085                 if (locSerialNo == streamInfos[i]->mSerialNo) {
00086                         locFoundStream = true;
00087                         locFoundPos = i;
00088                         break;
00089                 }
00090         }
00091         
00092         if (!locFoundStream) {
00093                 //streamSerials.push_back(locSerialNo);
00094                 //maxPacks.push_back(new unsigned long(0));
00095                 sOggStreamInfo* locStreamInfo = new sOggStreamInfo;
00096                 locStreamInfo->mMaxPacksPerPage = 0;
00097                 locStreamInfo->mMaxPageSize = 0;
00098                 locStreamInfo->mMinPacksPerPage = (unsigned long)-1;
00099                 locStreamInfo->mMinPageSize = (unsigned long)-1;
00100                 locStreamInfo->mNumPages = 0;
00101                 locStreamInfo->mSerialNo = locSerialNo;
00102                 locStreamInfo->mTotalDataSize = 0;
00103                 locStreamInfo->mTotalPacketCount = 0;
00104                 locStreamInfo->mTotalStreamSize = 0;
00105 
00106                 streamInfos.push_back(locStreamInfo);
00107         }
00108         unsigned long locNumPacks = 0;
00109         for (size_t i = 0; i < streamInfos.size(); i++) {
00110                 
00111                 if (locSerialNo == streamInfos[i]->mSerialNo) {
00112                         locFoundPos = i;
00113                         
00114                         //Fill in the stats
00115 
00116                         if (streamInfos[i]->mMaxPacksPerPage < inOggPage->numPackets()) {
00117                                 streamInfos[i]->mMaxPacksPerPage = inOggPage->numPackets();
00118                         }
00119 
00120                         if (streamInfos[i]->mMaxPageSize < inOggPage->pageSize()) {
00121                                 streamInfos[i]->mMaxPageSize = inOggPage->pageSize();
00122                         }
00123 
00124                         if (streamInfos[i]->mMinPacksPerPage > inOggPage->numPackets()) {
00125                                 streamInfos[i]->mMinPacksPerPage = inOggPage->numPackets();
00126                         }
00127 
00128                         if (streamInfos[i]->mMinPageSize > inOggPage->pageSize()) {
00129 
00130                                 streamInfos[i]->mMinPageSize = inOggPage->pageSize();
00131                         }
00132 
00133                         streamInfos[i]->mNumPages++;
00134                         //streamInfos[i]->mSerialNo = locSerialNo;
00135                         streamInfos[i]->mTotalDataSize += inOggPage->dataSize();
00136                         streamInfos[i]->mTotalPacketCount += inOggPage->numPackets();
00137                         streamInfos[i]->mTotalStreamSize += inOggPage->pageSize();
00138 
00139 
00140 
00141                         cout << "Stream "<<(unsigned long)i<<"  : Granule = "<<inOggPage->header()->GranulePos()<<"   - ";
00142                         locNumPacks = 0;
00143                         if (inOggPage->numPackets() == 0) {
00144                                 cout<<"EMPTY PAGE"<<endl;
00145                         } else if (inOggPage->numPackets() == 1) {
00146                                 if (inOggPage->getPacket(0)->isContinuation() || inOggPage->getPacket(0)->isTruncated()) {
00147                                         cout<<" 1 Partial Packet";
00148                                 } else {
00149                                         cout<<" 1 Full Packet";
00150                                         locNumPacks = 1;
00151                                 }
00152                         } else {
00153                                 locNumPacks = inOggPage->numPackets();
00154 
00155                                 unsigned long locPartials = 0;
00156                                 if (inOggPage->getPacket(0)->isContinuation()) {
00157                                         locNumPacks--;
00158                                         locPartials++;
00159                                 }
00160 
00161                                 if (inOggPage->getPacket(inOggPage->numPackets() - 1)->isTruncated()) {
00162                                         locNumPacks--;
00163                                         locPartials++;
00164                                 }
00165 
00166                                 if (locPartials == 1) {
00167                                         cout << " 1 Partial Packet";
00168                                 } else if (locPartials >= 2) {
00169                                         cout<<" "<<locPartials<<" Full Packets";
00170                                 }
00171 
00172                                 if (locNumPacks == 1) {
00173                                         cout<<" 1 Full Packet";
00174                                 } else if (locNumPacks >= 2) {
00175                                         cout<<" "<<locNumPacks<<" Full Packets";
00176                                 }
00177                         }
00178                         cout<<endl;
00179 
00180                         break;
00181                 }
00182         }
00183 
00184         
00185         //if (*maxPacks[locFoundPos] < locNumPacks) {
00186         //      *maxPacks[locFoundPos] = locNumPacks;
00187         //}
00188 
00189         return true;
00190 }
00191 
00192 
00193 #ifdef WIN32
00194 int __cdecl _tmain(int argc, _TCHAR* argv[])
00195 #else
00196 int main (int argc, char * argv[])
00197 #endif
00198 {
00199         //This program just gives some info about number of packets
00200         // Currently does not error checking. Check your command line carefully !
00201         // USAGE :: OOOggPageInfo <OggFile>
00202         //
00203 
00204         bytePos = 0;
00205 
00206         if (argc < 2) {
00207                 cout<<"Usage : OOOggPageInfo <filename>"<<endl;
00208         } else {
00209                 OggDataBuffer testOggBuff;
00210                 
00211                 testOggBuff.registerStaticCallback(&pageCB, NULL);
00212 
00213                 fstream testFile;
00214                 testFile.open(argv[1], ios_base::in | ios_base::binary);
00215                 
00216                 const unsigned short BUFF_SIZE = 8092;
00217                 char* locBuff = new char[BUFF_SIZE];
00218                 while (!testFile.eof()) {
00219                         testFile.read(locBuff, BUFF_SIZE);
00220                         unsigned long locBytesRead = testFile.gcount();
00221                 testOggBuff.feed((const unsigned char*)locBuff, locBytesRead);
00222                 }
00223 
00224                 cout<<endl;
00225                 cout<<endl;
00226 
00227                 for (size_t i = 0; i < streamInfos.size(); i++) {
00228                         dumpStreamInfo(streamInfos[i]);
00229                         //cout<<"Stream "<<(unsigned long)i<<" max Packets = "<<*maxPacks[i]<<endl;
00230                 }
00231 
00232 
00233                 for (size_t i = 0; i < streamInfos.size(); i++) {
00234                         delete streamInfos[i];
00235                 }
00236 
00237                 delete[] locBuff;
00238         }
00239 
00240         return 0;
00241 }
00242 

Generated on Thu Feb 16 23:48:19 2006 for oggdsf by  doxygen 1.3.9