Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Diff of /libkwave/VirtualAudioFile.cpp [7e28dd] .. [a9046a] Maximize Restore

  Switch to unified view

a/libkwave/VirtualAudioFile.cpp b/libkwave/VirtualAudioFile.cpp
...
...
14
 *   (at your option) any later version.                                   *
14
 *   (at your option) any later version.                                   *
15
 *                                                                         *
15
 *                                                                         *
16
 ***************************************************************************/
16
 ***************************************************************************/
17
17
18
#include "config.h"
18
#include "config.h"
19
#include <stdlib.h>
19
#include <qiodevice.h>
20
#include <qiodevice.h>
20
#include "libkwave/VirtualAudioFile.h"
21
#include "libkwave/VirtualAudioFile.h"
21
22
22
/**
23
/**
23
 * map for finding the corresponding VirtualAudioFile
24
 * map for finding the corresponding VirtualAudioFile
...
...
26
static QMap<AFvirtualfile*,VirtualAudioFile*> *_adapter_map = 0;
27
static QMap<AFvirtualfile*,VirtualAudioFile*> *_adapter_map = 0;
27
28
28
/** Last error number from libaudiofile. -1 if no error occurred */
29
/** Last error number from libaudiofile. -1 if no error occurred */
29
static long _last_audiofile_error = -1;
30
static long _last_audiofile_error = -1;
30
31
32
//***************************************************************************
31
/**
33
/**
32
 * Error handler for libaudiofile
34
 * Error handler for libaudiofile
33
 * @warning NOT THREADSAFE!
35
 * @warning NOT THREADSAFE!
34
 * @param error the numeric error code, >=0, defined in audiofile.h,
36
 * @param error the numeric error code, >=0, defined in audiofile.h,
35
 *        something starting with AF_BAD_...
37
 *        something starting with AF_BAD_...
...
...
39
{
41
{
40
    qDebug("libaudiofile error %ld: '%s'", error, str);
42
    qDebug("libaudiofile error %ld: '%s'", error, str);
41
    _last_audiofile_error = error;
43
    _last_audiofile_error = error;
42
}
44
}
43
45
46
//***************************************************************************
44
/** Returns the last libaudiofile error and resets it to -1 */
47
/** Returns the last libaudiofile error and resets it to -1 */
45
static long _lastAudiofileError()
48
static long _lastAudiofileError()
46
{
49
{
47
    long err = _last_audiofile_error;
50
    long err = _last_audiofile_error;
48
    _last_audiofile_error = -1;
51
    _last_audiofile_error = -1;
52
53
    // ignore "bad alloc", which might occur on a "malloc(0)"
54
    if (err == AF_BAD_MALLOC) err = -1;
49
    return err;
55
    return err;
50
}
56
}
51
57
52
//***************************************************************************
58
//***************************************************************************
53
static ssize_t af_file_read(AFvirtualfile *vfile, void *data,
59
static ssize_t af_file_read(AFvirtualfile *vfile, void *data,
54
                            size_t nbytes)
60
                            size_t nbytes)
55
{
61
{
56
    VirtualAudioFile *adapter = VirtualAudioFile::adapter(vfile);
62
    VirtualAudioFile *adapter = VirtualAudioFile::adapter(vfile);
57
    return (adapter) ? adapter->read((char*)data, nbytes) : 0;
63
    return (adapter) ? adapter->read(static_cast<char *>(data), nbytes) : 0;
58
}
64
}
59
65
60
//***************************************************************************
66
//***************************************************************************
61
static long af_file_length(AFvirtualfile *vfile)
67
static long af_file_length(AFvirtualfile *vfile)
62
{
68
{
...
...
67
//***************************************************************************
73
//***************************************************************************
68
static ssize_t af_file_write(AFvirtualfile *vfile, const void *data,
74
static ssize_t af_file_write(AFvirtualfile *vfile, const void *data,
69
                         size_t nbytes)
75
                         size_t nbytes)
70
{
76
{
71
    VirtualAudioFile *adapter = VirtualAudioFile::adapter(vfile);
77
    VirtualAudioFile *adapter = VirtualAudioFile::adapter(vfile);
72
    return (adapter) ? adapter->write((char*)data, nbytes) : 0;
78
    return (adapter) ?
79
  adapter->write(static_cast<const char *>(data), nbytes) : 0;
73
}
80
}
74
81
75
//***************************************************************************
82
//***************************************************************************
76
static void af_file_destroy(AFvirtualfile */*vfile*/)
83
static void af_file_destroy(AFvirtualfile */*vfile*/)
77
{
84
{
...
...
89
{
96
{
90
    VirtualAudioFile *adapter = VirtualAudioFile::adapter(vfile);
97
    VirtualAudioFile *adapter = VirtualAudioFile::adapter(vfile);
91
    return (adapter) ? adapter->tell() : -1;
98
    return (adapter) ? adapter->tell() : -1;
92
}
99
}
93
100
101
//***************************************************************************
102
/**
103
 * Replacement of af_virtual_file_new from original libaudiofile code.
104
 * Unfortunately the original is not usable because it is not available
105
 * through the shared library API of some libaudiofile versions.
106
 *
107
 * original version: see libaudiofile/af_vfs.c (GPL 2+)
108
 * original author: Copyright (C) 1999, Elliot Lee <sopwith@redhat.com>
109
 */
110
static AFvirtualfile *__af_virtual_file_new(void)
111
{
112
    return static_cast<AFvirtualfile *>(calloc(sizeof(AFvirtualfile), 1));
113
}
114
115
//***************************************************************************
94
//***************************************************************************
116
//***************************************************************************
95
VirtualAudioFile::VirtualAudioFile(QIODevice &device)
117
VirtualAudioFile::VirtualAudioFile(QIODevice &device)
96
     :m_device(device), m_file_handle(0), m_virtual_file(0),
118
     :m_device(device), m_file_handle(0), m_virtual_file(0),
97
      m_last_error(-1)
119
      m_last_error(-1)
98
{
120
{
99
    // create the virtual file structure for libaudiofile
121
    // create the virtual file structure for libaudiofile
100
    m_virtual_file = af_virtual_file_new();
122
    m_virtual_file = __af_virtual_file_new();
101
    Q_ASSERT(m_virtual_file);
123
    Q_ASSERT(m_virtual_file);
102
    if (!m_virtual_file) return;
124
    if (!m_virtual_file) return;
103
125
104
    // enter our wrapper functions
126
    // enter our wrapper functions
105
    m_virtual_file->closure = 0;
127
    m_virtual_file->closure = 0;