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
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
00075
00076 vector<sOggStreamInfo*> streamInfos;
00077
00078
00079 bool pageCB(OggPage* inOggPage, void* inUserData ) {
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
00094
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
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
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
00186
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
00200
00201
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
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