Roger,

My code is for RF so you'll need to change polarities. I'm checking for timeout during the initial pulse of each bit but am not recording the duration. It shouldn't take much modification.

Is this a commercial project? If it's just a one-off for your own use, you might want to consider a ZX328n from ZBasic. At $10 (plus some supporting components), it comes with a bootloader preloaded. ZBasic (free compiler) has built-in functions (InputCapture and InputCaptureEx) that will do what you wish with 37.8nS resolution.

However, I doubt you need better than 50µS resolution. Years ago I did what you're doing only instead of doing it in real-time, recorded codes as .WAV files using a soundcard and then decoded them afterwards. As I recall I was able to automatically handle all of the protocols I came across.

You might also consider USB-UIRT which not only captures the codes (as Philips Pronto CCF files) but also measures the IR carrier frequency.