#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <errno.h>
#include <tizen-audio.h>
#include <tizen-audio-internal.h>
#include <hal/hal-common-interface.h>
#include <tizen-audio-file.h>
+#define AUDIO_LOG_ERROR_WITH_STDERR(msg) __print_std_error(__LINE__, #msg)
+
+static void __print_std_error(int line, char *msg)
+{
+ char e[256];
+
+ strerror_r(errno, e, sizeof(e));
+
+ AUDIO_LOG_ERROR("line(%d). %s. err(%s)", line, msg, e);
+}
+
audio_return_e audio_file_open(const char *type, const char *filename, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods, void **handle)
{
FILE *f;
cur = ftell(f);
if (cur < 0) {
- AUDIO_LOG_ERROR("Failed to get ftell(%s)", strerror(errno));
+ AUDIO_LOG_ERROR_WITH_STDERR("Failed to get the current location");
return AUDIO_ERR_INTERNAL;
}
if (fseek(f, 0L, SEEK_END) < 0) {
- AUDIO_LOG_ERROR("Failed to seek. err(%s)", strerror(errno));
+ AUDIO_LOG_ERROR_WITH_STDERR("Failed to seek with SEEK_END");
return AUDIO_ERR_INTERNAL;
}
end = ftell(f);
if (end < 0) {
- AUDIO_LOG_ERROR("Failed to get ftell(%s)", strerror(errno));
+ AUDIO_LOG_ERROR_WITH_STDERR("Failed to get the end location");
return AUDIO_ERR_INTERNAL;
}
if (fseek(f, cur, SEEK_SET) < 0) {
- AUDIO_LOG_ERROR("Failed to seek. err(%s)", strerror(errno));
+ AUDIO_LOG_ERROR_WITH_STDERR("Failed to seek with SEEK_SET");
return AUDIO_ERR_INTERNAL;
}
ret = fwrite(buffer, sizeof(short), frames, f);
if (ret == 0) {
- AUDIO_LOG_ERROR("Failed to write(%s)", strerror(errno));
+ AUDIO_LOG_ERROR_WITH_STDERR("Failed to write");
return AUDIO_ERR_INTERNAL;
}
ret = fread(buffer, sizeof(short), frames, f);
if (ret == 0) {
- AUDIO_LOG_ERROR("Failed to read(%s)", strerror(errno));
+ AUDIO_LOG_ERROR_WITH_STDERR("Failed to read");
return AUDIO_ERR_INTERNAL;
}
audio_return_e audio_open(void *audio_handle, const char *card, const char *device, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods, void **handle)
{
- struct audio_interface_s *interface = (struct audio_interface_s *)calloc(1, sizeof(struct audio_interface_s));
+ struct audio_interface_s *interface;
void *glue_handle = NULL;
- AUDIO_RETURN_VAL_IF_FAIL(interface, AUDIO_ERR_RESOURCE);
-
AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_RESOURCE);
AUDIO_RETURN_VAL_IF_FAIL(card, AUDIO_ERR_RESOURCE);
AUDIO_RETURN_VAL_IF_FAIL(device, AUDIO_ERR_RESOURCE);
AUDIO_LOG_INFO("card(%s), device(%s), direction(%u), period_size(%u), periods(%u)",
card, device, direction, period_size, periods);
+ interface = (struct audio_interface_s *)calloc(1, sizeof(struct audio_interface_s));
+ if (!interface) {
+ AUDIO_LOG_INFO("Failed to allocate memory");
+ return AUDIO_ERR_INTERNAL;
+ }
+
if (!strcmp(card,"file")) {
interface->open = audio_file_open;
interface->start = audio_file_start;