summaryrefslogtreecommitdiff
path: root/ext/sndfile/gstsf.c
blob: e41586513219d395838b7b297cbf6003751861d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* 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., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */


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

#include <string.h>

#include "gstsf.h"


GType
gst_sf_major_types_get_type (void)
{
  static GType sf_major_types_type = 0;
  static GEnumValue *sf_major_types = NULL;

  if (!sf_major_types_type) {
    SF_FORMAT_INFO format_info;
    int k, count;

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

    sf_major_types = g_new0 (GEnumValue, count + 1);

    for (k = 0; k < count; k++) {
      format_info.format = k;
      sf_command (NULL, SFC_GET_FORMAT_MAJOR, &format_info,
          sizeof (format_info));
      sf_major_types[k].value = format_info.format;
      sf_major_types[k].value_name = g_strdup (format_info.name);
      sf_major_types[k].value_nick = g_strdup (format_info.extension);

      /* Irritatingly enough, there exist major_types with the same extension. Let's
         just hope that sndfile gives us the list in alphabetical order, as it
         currently does. */
      if (k > 0
          && strcmp (sf_major_types[k].value_nick,
              sf_major_types[k - 1].value_nick) == 0) {
        g_free ((gchar *) sf_major_types[k].value_nick);
        sf_major_types[k].value_nick =
            g_strconcat (sf_major_types[k - 1].value_nick, "-",
            sf_major_types[k].value_name, NULL);
        g_strcanon ((gchar *) sf_major_types[k].value_nick,
            G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
      }
    }

    sf_major_types_type =
        g_enum_register_static ("GstSndfileMajorTypes", sf_major_types);
  }
  return sf_major_types_type;
}

GType
gst_sf_minor_types_get_type (void)
{
  static GType sf_minor_types_type = 0;
  static GEnumValue *sf_minor_types = NULL;

  if (!sf_minor_types_type) {
    SF_FORMAT_INFO format_info;
    int k, count;

    sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int));

    sf_minor_types = g_new0 (GEnumValue, count + 1);

    for (k = 0; k < count; k++) {
      format_info.format = k;
      sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &format_info,
          sizeof (format_info));
      sf_minor_types[k].value = format_info.format;
      sf_minor_types[k].value_name = g_strdup (format_info.name);
      sf_minor_types[k].value_nick = g_ascii_strdown (format_info.name, -1);
      g_strcanon ((gchar *) sf_minor_types[k].value_nick,
          G_CSET_a_2_z G_CSET_DIGITS "-", '-');
    }

    sf_minor_types_type =
        g_enum_register_static ("GstSndfileMinorTypes", sf_minor_types);
  }
  return sf_minor_types_type;
}

static gboolean
plugin_init (GstPlugin * plugin)
{
  if (!gst_element_register (plugin, "sfsink", GST_RANK_NONE,
          gst_sf_sink_get_type ()))
    return FALSE;

  if (!gst_element_register (plugin, "sfsrc", GST_RANK_NONE,
          gst_sf_src_get_type ()))
    return FALSE;

  return TRUE;
}

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