/* GStreamer libsndfile plugin
 * Copyright (C) 2003 Andy Wingo <wingo at pobox dot com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gst/gst-i18n-plugin.h>
#include <string.h>

#include "gstsf.h"

/* sf formats */

GstCaps *
gst_sf_create_audio_template_caps (void)
{
  GstCaps *caps = gst_caps_new_empty ();
  SF_FORMAT_INFO format_info;
  const gchar *fmt;
  gint k, count;

  sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (gint));

  for (k = 0; k < count; k++) {
    format_info.format = k;
    sf_command (NULL, SFC_GET_FORMAT_MAJOR, &format_info, sizeof (format_info));

    switch (format_info.format) {
      case SF_FORMAT_AIFF:     /* Apple/SGI AIFF format */
        fmt = "audio/x-aiff";
        break;
      case SF_FORMAT_AU:       /* Sun/NeXT AU format */
        fmt = "audio/x-au";
        break;
      case SF_FORMAT_FLAC:     /* FLAC lossless file format */
        fmt = "audio/x-flac";
        break;
      case SF_FORMAT_IRCAM:    /* Berkeley/IRCAM/CARL */
        fmt = "audio/x-ircam";
        break;
      case SF_FORMAT_NIST:     /* Sphere NIST format. */
        fmt = "audio/x-nist";
        break;
      case SF_FORMAT_OGG:      /* Xiph OGG container */
        fmt = "audio/ogg";
        break;
      case SF_FORMAT_PAF:      /* Ensoniq PARIS file format. */
        fmt = "audio/x-paris";
        break;
      case SF_FORMAT_RAW:      /* RAW PCM data. */
        fmt = "audio/x-raw";
        break;
      case SF_FORMAT_SDS:      /* Midi Sample Dump Standard */
        fmt = "audio/x-sds";
        break;
      case SF_FORMAT_SVX:      /* Amiga IFF / SVX8 / SV16 format. */
        fmt = "audio/x-svx";
        break;
      case SF_FORMAT_VOC:      /* VOC files. */
        fmt = "audio/x-voc";
        break;
      case SF_FORMAT_WAV:      /* Microsoft WAV format */
      case SF_FORMAT_WAVEX:    /* MS WAVE with WAVEFORMATEX */
        fmt = "audio/x-wav";
        break;
      case SF_FORMAT_W64:      /* Sonic Foundry's 64 bit RIFF/WAV */
        fmt = "audio/x-w64";
        break;
      case SF_FORMAT_XI:       /* Fasttracker 2 Extended Instrument */
        fmt = "audio/x-xi";
        break;
      case SF_FORMAT_RF64:     /* RF64 WAV file */
        fmt = "audio/x-rf64";
        break;
      case SF_FORMAT_MAT4:     /* Matlab (tm) V4.2 / GNU Octave 2.0 */
      case SF_FORMAT_MAT5:     /* Matlab (tm) V5.0 / GNU Octave 2.1 */
      case SF_FORMAT_PVF:      /* Portable Voice Format */
      case SF_FORMAT_HTK:      /* HMM Tool Kit format */
      case SF_FORMAT_AVR:      /* Audio Visual Research */
      case SF_FORMAT_SD2:      /* Sound Designer 2 */
      case SF_FORMAT_CAF:      /* Core Audio File format */
      case SF_FORMAT_WVE:      /* Psion WVE format */
      case SF_FORMAT_MPC2K:    /* Akai MPC 2000 sampler */
      default:
        fmt = NULL;
        GST_WARNING ("format 0x%x: '%s' is not mapped", format_info.format,
            format_info.name);
    }
    if (fmt != NULL) {
      gst_caps_append_structure (caps, gst_structure_new_empty (fmt));
    }
  }
  return gst_caps_simplify (caps);
}

static gboolean
plugin_init (GstPlugin * plugin)
{
#ifdef ENABLE_NLS
  GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
      LOCALEDIR);
  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
#endif /* ENABLE_NLS */

  if (!gst_element_register (plugin, "sfdec", GST_RANK_MARGINAL,
          gst_sf_dec_get_type ()))
    return FALSE;

  return TRUE;
}

GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
    GST_VERSION_MINOR,
    sndfile,
    "use libsndfile to read and write various audio formats",
    plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
