OOOggPacketise.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 // OOOggStat.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 #include <libOOOgg/OggPacketiser.h>
00039 #include "OOOggPacketDumper.h"
00040 #include <iostream>
00041 
00042 #include <map>
00043 #include <fstream>
00044 
00045 //This will be called by the callback
00046 
00047 //OggPacketiser* testPacketiser  = new OggPacketiser(&testPacketDumper);
00048 
00049 typedef map<unsigned long, OggPacketiser*> tStreamMap;
00050 
00051 tStreamMap streamMap;
00052 OOOggPacketDumper testPacketDumper;
00053 
00054 
00055 
00056 bool pageCB(OggPage* inOggPage, void *inUserData /* ignored */) {
00057 
00058         tStreamMap::iterator locIt = streamMap.find(inOggPage->header()->StreamSerialNo());
00059 
00060         if (locIt == streamMap.end()) {
00061                 //Not found
00062                 OggPacketiser* locPacketiser = new OggPacketiser(&testPacketDumper);
00063 
00064                 streamMap.insert(tStreamMap::value_type(inOggPage->header()->StreamSerialNo(), locPacketiser));
00065                 locIt = streamMap.find(inOggPage->header()->StreamSerialNo());
00066         }
00067 
00068         if (locIt == streamMap.end()) {
00069                 cout<<"FAILED !!!!!!!!"<<endl;
00070         }
00071 
00072         //Assume we have a valid packetiser...
00073 
00074         cout<<"======================================="<<endl;
00075         cout    << "Stream : "<<inOggPage->header()->StreamSerialNo()
00076                 << "   Gran : "<<inOggPage->header()->GranulePos()<<endl<<endl;
00077 
00078         (*locIt).second->acceptOggPage(inOggPage);
00079 
00080         return true;
00081 
00082 
00083 
00084 
00085 
00086 }
00087 
00088 #ifdef WIN32
00089 int __cdecl _tmain(int argc, _TCHAR* argv[])
00090 #else
00091 int main (int argc, char * argv[])
00092 #endif
00093 {
00094 
00095 
00096         int x;
00097         cin>>x;
00098         //This program just dumps the packets of the first stream out of a file in ogg format.
00099         // Currently does not error checking. Check your command line carefully !
00100         // USAGE :: OOOggPacketise <OggFile>
00101         //
00102         if (argc < 2) {
00103                 cout<<"Usage : OOOggPacketise <filename>"<<endl;
00104         } else {
00105 
00106                 OggDataBuffer testOggBuff;
00107                 
00108                 
00109         
00110                 //testOggBuff.registerVirtualCallback(testPacketiser);
00111                 
00112 
00113                 const BUFF_SIZE = 8092;
00114                 testOggBuff.registerStaticCallback(&pageCB, NULL);
00115 
00116                 fstream testFile;
00117                 testFile.open(argv[1], ios_base::in | ios_base::binary);
00118                 char* locBuff = new char[BUFF_SIZE];
00119                 while (!testFile.eof()) {
00120                         testFile.read(locBuff, BUFF_SIZE);
00121                         unsigned long locBytesRead = testFile.gcount();
00122                 testOggBuff.feed((const unsigned char*)locBuff, locBytesRead);
00123                 }
00124 
00125                 delete locBuff;
00126         }
00127 
00128 
00129         return 0;
00130 }
00131 
00132 

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