More on codecs handling
First of all, people are often AVI-centric and decide that you can always use 4-character code to identify a codec. Well, technically it’s true because there’s significantly less than 4 billion codecs in existence (I hope). The problem is uneven mapping — MPEG containers use integers for codec IDs, AVI uses 4-character code for video and 2-byte integer for audio, MOV uses 4-character code for both audio and video, Matroska uses long strings like V_MPEG4/MS/V3
etc etc. So in any case you have a problem of mapping codecs found by demuxers to internal decoders. In libavcodec
it’s handled by having an insane enumeration of codec IDs and I’ve mentioned in part 2 that I’m not a fan of such approach.
So what I suggest instead? A global registry of codec names in string form. And splitting out media information database explicitly. After all, why not provide some codec information even if we cannot support it? Less effort when you add a new decoder and you can query some information about codec even if it’s not supported. Demuxer maps internal ID to codec name (if it can), codec database can be queried about that codec at any time to see what information is known about it and a decoder can be requested for that codec as well.
Here’s an example:
- Bink demuxer encounters
KB2g
; - It reports
binkvideo2
decoder; - (optional) From database one can retrieve its name — “Bink Video 2”;
- A decoder for
binkvideo2
is requested for it but that request is failed because noone has bothered to write such decoder; - Or a decoder implemented by a special plugin that calls TotallyRADVideo.dll is called.
Just replace enum with string and you get better flexibility and only VideoLAN won’t like it.