sad

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

decoder.c (585B)


      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 *
     22 matchdecoder(const char *name)
     23 {
     24 	char *ext;
     25 	size_t i;
     26 
     27 	ext = strrchr(name, '.');
     28 	if (!ext)
     29 		return NULL;
     30 	for (i = 0; i < LEN(decodermap); i++)
     31 		if (!strcasecmp(decodermap[i].ext, ext))
     32 			return decodermap[i].decoder;
     33 	return NULL;
     34 }