format.c 2.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/********************************************************************
 *                                                                  *
 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
 * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE.    *
 * PLEASE READ THESE TERMS BEFORE DISTRIBUTING.                     *
 *                                                                  *
 * THE Ogg123 SOURCE CODE IS (C) COPYRIGHT 2000-2001                *
 * by Stan Seibert <volsung@xiph.org> AND OTHER CONTRIBUTORS        *
 * http://www.xiph.org/                                             *
 *                                                                  *
 ********************************************************************

14
 last mod: $Id: format.c,v 1.5 2003/01/12 20:19:22 volsung Exp $
15 16 17 18 19 20

 ********************************************************************/

#include <stdio.h>
#include <string.h>

21 22 23
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
24 25
#include "transport.h"
#include "format.h"
26
#include "i18n.h"
27 28

extern format_t oggvorbis_format;
29
extern format_t speex_format;
30

Stan Seibert's avatar
Stan Seibert committed
31 32 33 34 35
#ifdef HAVE_LIBFLAC
extern format_t flac_format;
extern format_t oggflac_format;
#endif

36 37 38
#ifdef HAVE_LIBSPEEX
extern format_t speex_format;
#endif
Stan Seibert's avatar
Stan Seibert committed
39 40 41 42 43

format_t *formats[] = { 
#ifdef HAVE_LIBFLAC
			&flac_format,
			&oggflac_format,
44 45 46
#endif
#ifdef HAVE_LIBSPEEX
			&speex_format,
Stan Seibert's avatar
Stan Seibert committed
47 48 49
#endif
			&oggvorbis_format, 
			NULL };
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80


format_t *get_format_by_name (char *name)
{
  int i = 0;

  while (formats[i] != NULL && strcmp(name, formats[i]->name) != 0)
    i++;

  return formats[i];
}


format_t *select_format (data_source_t *source)
{
  int i = 0;

  while (formats[i] != NULL && !formats[i]->can_decode(source))
    i++;

  return formats[i];
}


decoder_stats_t *malloc_decoder_stats (decoder_stats_t *to_copy)
{
  decoder_stats_t *new_stats;

  new_stats = malloc(sizeof(decoder_stats_t));

  if (new_stats == NULL) {
81
    fprintf(stderr, _("Error: Could not allocate memory in malloc_decoder_stats()\n"));
82 83 84 85 86 87 88
    exit(1);
  }

  *new_stats = *to_copy;  /* Copy the data */

  return new_stats;
}