summaryrefslogtreecommitdiff
path: root/src/lib/ecore_audio/ecore_audio_sndfile_vio.c
blob: 06268069aa9715bddc8b5aa2045d12eb4a94356d (plain) (blame)
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
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef HAVE_FEATURES_H
#include <features.h>
#endif

#include <Eo.h>

#include "ecore_audio_private.h"
#include <sndfile.h>

/* Virtual IO wrapper functions */

static sf_count_t _wrap_get_filelen(void *data)
{
  Eo *eo_obj = data;
  Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);

  if (!ea_obj->vio->vio)
    goto error;

  if (ea_obj->vio->vio->get_length)
    return ea_obj->vio->vio->get_length(ea_obj->vio->data, eo_obj);

error:
  return -1;
}

static sf_count_t _wrap_seek(sf_count_t offset, int whence, void *data)
{
  Eo *eo_obj = data;
  Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);

  if (!ea_obj->vio->vio)
    goto error;

  if (ea_obj->vio->vio->seek)
    return ea_obj->vio->vio->seek(ea_obj->vio->data, eo_obj, offset, whence);

error:
  return -1;
}

static sf_count_t _wrap_read(void *buffer, sf_count_t count, void *data)
{
  Eo *eo_obj = data;
  Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);

  if (!ea_obj->vio->vio)
    goto error;

  if (ea_obj->vio->vio->read)
    return ea_obj->vio->vio->read(ea_obj->vio->data, eo_obj, buffer, count);

error:
  return 0;
}

static sf_count_t _wrap_write(const void *buffer, sf_count_t count, void *data)
{
  Eo *eo_obj = data;
  Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);

  if (!ea_obj->vio->vio)
    goto error;

  if (ea_obj->vio->vio->write)
    return ea_obj->vio->vio->write(ea_obj->vio->data, eo_obj, buffer, count);

error:
  return 0;
}

static sf_count_t _wrap_tell(void *data)
{
  Eo *eo_obj = data;
  Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);

  if (!ea_obj->vio->vio)
    goto error;

  if (ea_obj->vio->vio->tell)
    return ea_obj->vio->vio->tell(ea_obj->vio->data, eo_obj);

error:
  return -1;
}

SF_VIRTUAL_IO vio_wrapper = {
    .get_filelen = _wrap_get_filelen,
    .seek = _wrap_seek,
    .read = _wrap_read,
    .write = _wrap_write,
    .tell = _wrap_tell,
};

/* End virtual IO wrapper functions */