| C# + Pointers = A Better C |
|
|
|
| Written by Daniel P | |
| Thursday, 08 February 2007 | |
|
I've mentioned that I was toying with Mpeg decoding in C# in this blog. As I was reflecting on my experience, I believe that I would describe my impression as: C# + Pointers = A Better C. C is a fine language, but it's almost forty years old. C# with its rich class libraries has a lot of attractive features. But if you use C# with pointers (ie unsafe switch) you get the best of both worlds. When you worry about speed, you can inspect the actual assembly code executed by the processor (eg in VS, in the Disassembly window), then you realize that there is very little overhead involve if you're careful. I've decided to post the decoding application that I've written. The code is not included yet. It has to be cleaned up but I've included the .pdb and if you're curious, you can always use the Reflector utility to see its details. It's not a complete Mpeg-1 decoder. If you've read my previous entries, I started with the task of extracting the I-frames of a mpeg stream. After completing this work, and since I had written quite a bit of code, I told myself: the next logical step would be to decode the motion vectors. Since I was always curious about the details of the encoding of this information, it was tempting to continue working on this. After finishing this second task, I said I might as well continue and get a decoder. As I mentioned before, the code was written as I was reading the standard (where I cut some corners to get results as quickly as possible). I spent a day and a half profiling and getting rid of the most obvious bottlenecks. I also rewrote the rendering code to avoid dependencies on MDX so you can play video without having to download any extra libraries. I chose Mpeg-1 because the standard for stream and video decoding is around 180 pages versus 430 pages for Mpeg-2, for example. So here's some video processing done in 100% pure C# (with very little optimization work). |
|
| Last Updated ( Tuesday, 13 February 2007 ) |
| < Prev | Next > |
|---|














