sad

simple audio daemon
git clone git://git.2f30.org/sad
Log | Files | Refs | LICENSE

decoder.c (588B)


      1 #include <sys/select.h>
      2 
      3 #include <err.h>
      4 #include <limits.h>
      5 #include <stdio.h>
      6 #include <string.h>
      7 #include <strings.h>
      8 
      9 #include "sad.h"
     10 
     11 static struct {
     12   char *ext;
     13   Decoder *decoder;
     14 } decodermap[] = {
     15     {".wav", &wavdecoder},
     16     {".flac", &wavdecoder},
     17     {".mp3", &mp3decoder},
     18     {".ogg", &vorbisdecoder},
     19 };
     20 
     21 Decoder *matchdecoder(const char *name) {
     22   char *ext;
     23   size_t i;
     24 
     25   ext = strrchr(name, '.');
     26   if (!ext)
     27     return NULL;
     28   for (i = 0; i < LEN(decodermap); i++)
     29     if (!strcasecmp(decodermap[i].ext, ext))
     30       return decodermap[i].decoder;
     31   return NULL;
     32 }