#include <fcntl.h>
#include <polyp/polypaudio.h>
-#include <polyp/mainloop.h>
-#include <polyp/mainloop-signal.h>
#include <polypcore/util.h>
#define TIME_EVENT_USEC 50000
buffer_index += l;
if (!buffer_length) {
- free(buffer);
+ pa_xfree(buffer);
buffer = NULL;
buffer_index = buffer_length = 0;
}
return;
}
- buffer = malloc(buffer_length = length);
- assert(buffer);
+ buffer = pa_xmalloc(buffer_length = length);
memcpy(buffer, data, length);
buffer_index = 0;
pa_stream_drop(s);
if (!stream || pa_stream_get_state(stream) != PA_STREAM_READY || !(l = w = pa_stream_writable_size(stream)))
l = 4096;
- buffer = malloc(l);
- assert(buffer);
+ buffer = pa_xmalloc(l);
+
if ((r = read(fd, buffer, l)) <= 0) {
if (r == 0) {
pa_operation *o;
buffer_index += r;
if (!buffer_length) {
- free(buffer);
+ pa_xfree(buffer);
buffer = NULL;
buffer_length = buffer_index = 0;
}
if (verbose)
fprintf(stderr, "Got signal, exiting.\n");
quit(0);
-
}
/* Show the current latency */
break;
case 'd':
- free(device);
- device = strdup(optarg);
+ pa_xfree(device);
+ device = pa_xstrdup(optarg);
break;
case 's':
- free(server);
- server = strdup(optarg);
+ pa_xfree(server);
+ server = pa_xstrdup(optarg);
break;
case 'n':
- free(client_name);
- client_name = strdup(optarg);
+ pa_xfree(client_name);
+ client_name = pa_xstrdup(optarg);
break;
case ARG_STREAM_NAME:
- free(stream_name);
- stream_name = strdup(optarg);
+ pa_xfree(stream_name);
+ stream_name = pa_xstrdup(optarg);
break;
case 'v':
close(fd);
if (!stream_name)
- stream_name = strdup(argv[optind]);
+ stream_name = pa_xstrdup(argv[optind]);
} else {
fprintf(stderr, "Too many arguments.\n");
}
if (!client_name)
- client_name = strdup(bn);
+ client_name = pa_xstrdup(bn);
if (!stream_name)
- stream_name = strdup(client_name);
+ stream_name = pa_xstrdup(client_name);
/* Set up a new main loop */
if (!(m = pa_mainloop_new())) {
pa_mainloop_free(m);
}
- free(buffer);
+ pa_xfree(buffer);
- free(server);
- free(device);
- free(client_name);
- free(stream_name);
+ pa_xfree(server);
+ pa_xfree(device);
+ pa_xfree(client_name);
+ pa_xfree(stream_name);
return ret;
}
#include <sndfile.h>
#include <polyp/polypaudio.h>
-#include <polyp/mainloop.h>
-#include <polyp/mainloop-signal.h>
#if PA_API_VERSION != 9
#error Invalid Polypaudio API version
float *d;
assert(s && length && sndfile);
- d = malloc(length);
- assert(d);
+ d = pa_xmalloc(length);
assert(sample_length >= length);
l = length/pa_frame_size(&sample_spec);
if ((sf_readf_float(sndfile, d, l)) != l) {
- free(d);
+ pa_xfree(d);
fprintf(stderr, "Premature end of file\n");
quit(1);
}
- pa_stream_write(s, d, length, free, 0, PA_SEEK_RELATIVE);
+ pa_stream_write(s, d, length, pa_xfree, 0, PA_SEEK_RELATIVE);
sample_length -= length;
goto quit;
case 's':
- free(server);
- server = strdup(optarg);
+ pa_xfree(server);
+ server = pa_xstrdup(optarg);
break;
case 'n':
- free(client_name);
- client_name = strdup(optarg);
+ pa_xfree(client_name);
+ client_name = pa_xstrdup(optarg);
break;
default:
}
if (!client_name)
- client_name = strdup(bn);
+ client_name = pa_xstrdup(bn);
if (optind < argc) {
if (!strcmp(argv[optind], "stat"))
}
if (optind+2 < argc)
- sample_name = strdup(argv[optind+2]);
+ sample_name = pa_xstrdup(argv[optind+2]);
else {
char *f = strrchr(argv[optind+1], '/');
size_t n;
n = strcspn(f, ".");
strncpy(tmp, f, n);
tmp[n] = 0;
- sample_name = strdup(tmp);
+ sample_name = pa_xstrdup(tmp);
}
memset(&sfinfo, 0, sizeof(sfinfo));
goto quit;
}
- sample_name = strdup(argv[optind+1]);
+ sample_name = pa_xstrdup(argv[optind+1]);
if (optind+2 < argc)
- device = strdup(argv[optind+2]);
+ device = pa_xstrdup(argv[optind+2]);
} else if (!strcmp(argv[optind], "remove-sample")) {
action = REMOVE_SAMPLE;
goto quit;
}
- sample_name = strdup(argv[optind+1]);
+ sample_name = pa_xstrdup(argv[optind+1]);
}
}
if (sndfile)
sf_close(sndfile);
- free(server);
- free(device);
- free(sample_name);
+ pa_xfree(server);
+ pa_xfree(device);
+ pa_xfree(sample_name);
return ret;
}
#include <sndfile.h>
#include <polyp/polypaudio.h>
-#include <polyp/mainloop.h>
-#include <polyp/mainloop-signal.h>
#if PA_API_VERSION != 9
#error Invalid Polypaudio API version
if (!sndfile)
return;
- data = malloc(length);
+ data = pa_xmalloc(length);
if (readf_function) {
size_t k = pa_frame_size(&sample_spec);
bytes = sf_read_raw(sndfile, data, length);
if (bytes > 0)
- pa_stream_write(s, data, bytes, free, 0, PA_SEEK_RELATIVE);
+ pa_stream_write(s, data, bytes, pa_xfree, 0, PA_SEEK_RELATIVE);
else
- free(data);
+ pa_xfree(data);
if (bytes < length) {
sf_close(sndfile);
goto quit;
case 'd':
- free(device);
- device = strdup(optarg);
+ pa_xfree(device);
+ device = pa_xstrdup(optarg);
break;
case 's':
- free(server);
- server = strdup(optarg);
+ pa_xfree(server);
+ server = pa_xstrdup(optarg);
break;
case 'n':
- free(client_name);
- client_name = strdup(optarg);
+ pa_xfree(client_name);
+ client_name = pa_xstrdup(optarg);
break;
case ARG_STREAM_NAME:
- free(stream_name);
- stream_name = strdup(optarg);
+ pa_xfree(stream_name);
+ stream_name = pa_xstrdup(optarg);
break;
case 'v':
}
if (!client_name)
- client_name = strdup(bn);
+ client_name = pa_xstrdup(bn);
if (!stream_name) {
const char *n = sf_get_string(sndfile, SF_STR_TITLE);
- stream_name = strdup(n ? n : filename);
+ stream_name = pa_xstrdup(n ? n : filename);
}
if (verbose) {
pa_mainloop_free(m);
}
- free(server);
- free(device);
- free(client_name);
- free(stream_name);
+ pa_xfree(server);
+ pa_xfree(device);
+ pa_xfree(client_name);
+ pa_xfree(stream_name);
if (sndfile)
sf_close(sndfile);