00001 #include "stdafx.h" 00002 #include <libOOOggSeek/OGGSRecogniser.h> 00003 00004 OGGSRecogniser::OGGSRecogniser(void) 00005 : mState(OGGSRecogniser::STATE_START) 00006 { 00007 } 00008 00009 OGGSRecogniser::~OGGSRecogniser(void) 00010 { 00011 } 00012 00013 00014 long OGGSRecogniser::feed(unsigned char* inBuff, unsigned long inNumBytes) { 00015 00016 for (unsigned long i = 0; i < inNumBytes; i++) { 00017 switch (mState) { 00018 case STATE_START: 00019 //Haven't matched anything 00020 if (inBuff[i] == 'O') { 00021 mState = STATE_O; 00022 } 00023 break; 00024 case STATE_O: 00025 //Already matched an O 00026 if (inBuff[i] == 'g') { 00027 //Now advance t the g state 00028 mState = STATE_G1; 00029 } else { 00030 //Anything but a g and we move back to the start state. 00031 mState = STATE_START; 00032 } 00033 break; 00034 case STATE_G1: 00035 if (inBuff[i] == 'g') { 00036 mState = STATE_G2; 00037 } else { 00038 mState = STATE_START; 00039 } 00040 break; 00041 case STATE_G2: 00042 if (inBuff[i] == 'S') { 00043 mState = STATE_START; 00044 return (i); 00045 } else { 00046 mState = STATE_START; 00047 } 00048 00049 break; 00050 default: 00051 //Should never be in an invalid state. 00052 throw 0; 00053 } 00054 } 00055 00056 return -1; 00057 } 00058 void OGGSRecogniser::resetState() { 00059 mState = STATE_START; 00060 }