ref: 98a38878b102b20a08c16c1efde89896e2d9e0d2
parent: 16dda037d1ce8a8762ed515212833aae09d3c021
author: Paul Brossier <piem@piem.org>
date: Fri Jan 24 08:09:50 EST 2014
src/io/*apple*: improve error messages
--- a/src/io/sink_apple_audio.c
+++ b/src/io/sink_apple_audio.c
@@ -36,6 +36,7 @@
extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
extern void freeAudioBufferList(AudioBufferList *bufferList);
extern CFURLRef getURLFromPath(const char * path);
+char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
#define MAX_SIZE 4096 // the maximum number of frames that can be written at a time
@@ -78,11 +79,15 @@
err = ExtAudioFileCreateWithURL(fileURL, fileType, &clientFormat, NULL,
overwrite ? kAudioFileFlags_EraseFile : 0, &s->audioFile);
if (err) {
- AUBIO_ERR("error when trying to create %s, in ExtAudioFileCreateWithURL, %d\n", s->path, (int)err);
+ char_t errorstr[20];
+ AUBIO_ERR("sink_apple_audio: error when trying to create %s with "
+ "ExtAudioFileCreateWithURL (%s)\n", s->path,
+ getPrintableOSStatusError(errorstr, err));
goto beach;
}
if (createAubioBufferList(&s->bufferList, s->channels, s->max_frames * s->channels)) {
- AUBIO_ERR("error when creating buffer list for %s, out of memory? \n", s->path);
+ AUBIO_ERR("sink_apple_audio: error when creating buffer list for %s, "
+ "out of memory? \n", s->path);
goto beach;
}
return s;
@@ -114,8 +119,10 @@
err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList);
if (err) {
- AUBIO_ERROR("in aubio_sink_apple_audio_do, writing %s\n", s->path);
- AUBIO_ERROR("ExtAudioFileWriteAsync failed with %d, switching to sync\n", (int)err);
+ char_t errorstr[20];
+ AUBIO_ERROR("sink_apple_audio: error while writing %s "
+ "in ExtAudioFileWriteAsync (%s), switching to sync\n", s->path,
+ getPrintableOSStatusError(errorstr, err));
s->async = false;
} else {
return;
@@ -125,8 +132,10 @@
err = ExtAudioFileWrite(s->audioFile, write, &s->bufferList);
if (err) {
- AUBIO_ERROR("in aubio_sink_apple_audio_do, writing %s\n", s->path);
- AUBIO_ERROR("ExtAudioFileWrite failed with %d, aborting\n", (int)err);
+ char_t errorstr[20];
+ AUBIO_ERROR("sink_apple_audio: error while writing %s "
+ "in ExtAudioFileWrite (%s)\n", s->path,
+ getPrintableOSStatusError(errorstr, err));
}
}
return;
@@ -135,11 +144,16 @@
void del_aubio_sink_apple_audio(aubio_sink_apple_audio_t * s) {
OSStatus err = noErr;
if (!s || !s->audioFile) {
- AUBIO_ERR("failed erasing sink_apple_audio\n");
+ AUBIO_ERR("sink_apple_audio: failed erasing\n");
return;
}
err = ExtAudioFileDispose(s->audioFile);
- if (err) AUBIO_ERROR("error in ExtAudioFileDispose, %d\n", (int)err);
+ if (err) {
+ char_t errorstr[20];
+ AUBIO_ERROR("sink_apple_audio: error while closing %s "
+ "in ExtAudioFileDispose (%s)\n", s->path,
+ getPrintableOSStatusError(errorstr, err));
+ }
s->audioFile = NULL;
freeAudioBufferList(&s->bufferList);
AUBIO_FREE(s);
--- a/src/io/source_apple_audio.c
+++ b/src/io/source_apple_audio.c
@@ -50,6 +50,7 @@
extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);
extern void freeAudioBufferList(AudioBufferList *bufferList);
extern CFURLRef getURLFromPath(const char * path);
+char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, char_t * path);
@@ -79,7 +80,17 @@
// open the resource url
CFURLRef fileURL = getURLFromPath(path);
err = ExtAudioFileOpenURL(fileURL, &s->audioFile);
- if (err) { AUBIO_ERR("error when trying to access %s, in ExtAudioFileOpenURL, %d\n", s->path, (int)err); goto beach;}
+ if (err == -43) {
+ AUBIO_ERR("source_apple_audio: Failed opening %s, "
+ "file not found, or no read access\n", s->path);
+ goto beach;
+ } else if (err) {
+ char_t errorstr[20];
+ AUBIO_ERR("source_apple_audio: Failed opening %s, "
+ "error in ExtAudioFileOpenURL (%s)\n", s->path,
+ getPrintableOSStatusError(errorstr, err));
+ goto beach;
+ }
// create an empty AudioStreamBasicDescription
AudioStreamBasicDescription fileFormat;
@@ -89,7 +100,13 @@
// fill it with the file description
err = ExtAudioFileGetProperty(s->audioFile,
kExtAudioFileProperty_FileDataFormat, &propSize, &fileFormat);
- if (err) { AUBIO_ERROR("error in ExtAudioFileGetProperty, %d\n", (int)err); goto beach;}
+ if (err) {
+ char_t errorstr[20];
+ AUBIO_ERROR("source_apple_audio: Failed opening %s, "
+ "error in ExtAudioFileGetProperty (%s)\n", s->path,
+ getPrintableOSStatusError(errorstr, err));
+ goto beach;
+ }
if (s->samplerate == 0) {
s->samplerate = fileFormat.mSampleRate;
@@ -116,7 +133,10 @@
err = ExtAudioFileSetProperty(s->audioFile, kExtAudioFileProperty_ClientDataFormat,
propSize, &clientFormat);
if (err) {
- AUBIO_ERROR("error in ExtAudioFileSetProperty, %d\n", (int)err);
+ char_t errorstr[20];
+ AUBIO_ERROR("source_apple_audio: Failed opening %s, "
+ "error in ExtAudioFileSetProperty (%s)\n", s->path,
+ getPrintableOSStatusError(errorstr, err));
#if 1
// print client and format descriptions
AUBIO_DBG("Opened %s\n", s->path);
@@ -157,7 +177,13 @@
void aubio_source_apple_audio_do(aubio_source_apple_audio_t *s, fvec_t * read_to, uint_t * read) {
UInt32 c, v, loadedPackets = s->block_size;
OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);
- if (err) { AUBIO_ERROR("error in ExtAudioFileRead %s %d\n", s->path, (int)err); goto beach;}
+ if (err) {
+ char_t errorstr[20];
+ AUBIO_ERROR("source_apple_audio: error while reading %s "
+ "with ExtAudioFileRead (%s)\n", s->path,
+ getPrintableOSStatusError(errorstr, err));
+ goto beach;
+ }
short *data = (short*)s->bufferList.mBuffers[0].mData;
@@ -187,7 +213,13 @@
void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t *s, fmat_t * read_to, uint_t * read) {
UInt32 c, v, loadedPackets = s->block_size;
OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);
- if (err) { AUBIO_ERROR("source_apple_audio: error in ExtAudioFileRead, %d\n", (int)err); goto beach;}
+ if (err) {
+ char_t errorstr[20];
+ AUBIO_ERROR("source_apple_audio: error while reading %s "
+ "with ExtAudioFileRead (%s)\n", s->path,
+ getPrintableOSStatusError(errorstr, err));
+ goto beach;
+ }
short *data = (short*)s->bufferList.mBuffers[0].mData;
@@ -225,11 +257,17 @@
uint_t aubio_source_apple_audio_close (aubio_source_apple_audio_t *s)
{
OSStatus err = noErr;
- if (!s || !s->audioFile) { return 1; }
+ if (!s || !s->audioFile) { return AUBIO_FAIL; }
err = ExtAudioFileDispose(s->audioFile);
- if (err) AUBIO_ERROR("error in ExtAudioFileDispose, %d\n", (int)err);
s->audioFile = NULL;
- return err;
+ if (err) {
+ char_t errorstr[20];
+ AUBIO_ERROR("source_apple_audio: error while closing %s "
+ "in ExtAudioFileDispose (%s)\n", s->path,
+ getPrintableOSStatusError(errorstr, err));
+ return err;
+ }
+ return AUBIO_OK;
}
void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){
@@ -247,7 +285,12 @@
smpl_t ratio = s->source_samplerate * 1. / s->samplerate;
SInt64 resampled_pos = (SInt64)ROUND( pos * ratio );
OSStatus err = ExtAudioFileSeek(s->audioFile, resampled_pos);
- if (err) AUBIO_ERROR("source_apple_audio: error in ExtAudioFileSeek (%d)\n", (int)err);
+ if (err) {
+ char_t errorstr[20];
+ AUBIO_ERROR("source_apple_audio: error while seeking %s at %d "
+ "in ExtAudioFileSeek (%s)\n", s->path, pos,
+ getPrintableOSStatusError(errorstr, err));
+ }
return err;
}
--- a/src/io/utils_apple_audio.c
+++ b/src/io/utils_apple_audio.c
@@ -9,6 +9,7 @@
int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
void freeAudioBufferList(AudioBufferList *bufferList);
CFURLRef getURLFromPath(const char * path);
+char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
int createAubioBufferList(AudioBufferList * bufferList, int channels, int max_source_samples) {
bufferList->mNumberBuffers = 1;
@@ -36,6 +37,19 @@
return CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath,
kCFURLPOSIXPathStyle, false);
+}
+
+char_t *getPrintableOSStatusError(char_t *str, OSStatus error)
+{
+ // see if it appears to be a 4-char-code
+ *(UInt32 *)(str + 1) = CFSwapInt32HostToBig(error);
+ if (isprint(str[1]) && isprint(str[2]) && isprint(str[3]) && isprint(str[4])) {
+ str[0] = str[5] = '\'';
+ str[6] = '\0';
+ } else
+ // no, format it as an integer
+ sprintf(str, "%d", (int)error);
+ return str;
}
#endif /* __APPLE__ */