*/
+#include <new>
+
#include <pulse/pulseaudio.h>
#include "CAudioIODef.h"
#include <sched.h>
// Create ASM Handler
mpAudioSessionHandler = new CAudioSessionHandler(CAudioSessionHandler::EAudioSessionType::AUDIO_SESSION_TYPE_CAPTURE, mAudioInfo, this);
- if (mpAudioSessionHandler == NULL) {
- THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed to allocate CAudioSessionHandler object");
- }
// Initialize ASM Handler
mpAudioSessionHandler->initialize();
} catch (CAudioError err) {
finalize();
throw err;
+ } catch (std::bad_alloc&) {
+ finalize();
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed to allocate CAudioSessionHandler object");
}
}
// Create PulseAudio Handler
mpPulseAudioClient = new CPulseAudioClient(CPulseAudioClient::EStreamDirection::STREAM_DIRECTION_RECORD, spec, this);
- if (mpPulseAudioClient == NULL) {
- THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY,
- "Failed to allocate CPulseAudioClient object");
- }
// Initialize PulseAudio Handler
mpPulseAudioClient->initialize();
} catch (CAudioError e) {
internalUnlock();
throw e;
+ } catch (std::bad_alloc&) {
+ internalUnlock();
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed to allocate CPulseAudioClient object");
}
}
*/
+#include <new>
+
#include "CAudioIODef.h"
#include <sched.h>
// Create ASM Handler
mpAudioSessionHandler = new CAudioSessionHandler(CAudioSessionHandler::EAudioSessionType::AUDIO_SESSION_TYPE_PLAYBACK, mAudioInfo, this);
- if (mpAudioSessionHandler == NULL) {
- THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY,
- "Failed to allocate CAudioSessionHandler object");
- }
// Initialize ASM Handler
mpAudioSessionHandler->initialize();
} catch (CAudioError err) {
finalize();
throw err;
+ } catch (std::bad_alloc&) {
+ finalize();
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed to allocate CAudioSessionHandler object");
}
}
// Create PulseAudio Handler
mpPulseAudioClient = new CPulseAudioClient(CPulseAudioClient::EStreamDirection::STREAM_DIRECTION_PLAYBACK, spec, this);
- if (mpPulseAudioClient == NULL) {
- THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY,
- "Failed to allocate CPulseAudioClient object");
- }
// Initialize PulseAudio Handler
mpPulseAudioClient->initialize();
} catch (CAudioError e) {
internalUnlock();
throw e;
+ } catch (std::bad_alloc&) {
+ internalUnlock();
+ THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed to allocate CPulseAudioClient object");
}
}
*/
+#include <new>
+
#include "cpp_audio_io.h"
#include <sound_manager_internal.h>
#include "audio_io.h"
}
}
+static void __handle_safe_free(audio_io_s* handle, void *obj, bool is_output) {
+ VALID_POINTER_START(handle)
+ SAFE_FINALIZE(handle->audioIoHandle);
+ SAFE_DELETE(handle->audioIoHandle);
+ SAFE_DELETE(handle);
+ VALID_POINTER_END
+
+ VALID_POINTER_START(obj)
+ if (is_output)
+ *(audio_out_h *)obj = NULL;
+ else
+ *(audio_in_h *)obj = NULL;
+ VALID_POINTER_END
+}
+
/**
* Implements CAPI functions
*/
}
handle = new audio_io_s;
- if (handle == NULL) {
- THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed allocation handle");
- }
CAudioInfo audioInfo = __generate_audio_input_info(sample_rate, channel, type);
handle->audioIoHandle = new CAudioInput(audioInfo);
- if (handle->audioIoHandle == NULL) {
- THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed allocation internal handle");
- }
handle->audioIoHandle->initialize();
*input = handle;
} catch (CAudioError e) {
AUDIO_IO_LOGE("%s", e.getErrorMsg());
-
- VALID_POINTER_START(handle)
- SAFE_FINALIZE(handle->audioIoHandle);
- SAFE_DELETE(handle->audioIoHandle);
- SAFE_DELETE(handle);
- VALID_POINTER_END
-
- VALID_POINTER_START(input)
- *input = NULL;
- VALID_POINTER_END
-
+ __handle_safe_free(handle, (void *)input, false);
+ return __convert_CAudioError(e);
+ } catch (std::bad_alloc&) {
+ CAudioError e = CAudioError::EError::ERROR_OUT_OF_MEMORY;
+ AUDIO_IO_LOGE("Failed to allocate handle");
+ __handle_safe_free(handle, (void *)input, false);
return __convert_CAudioError(e);
}
__check_audio_param(sample_rate, channel, type);
handle = new audio_io_s;
- if (handle == NULL) {
- THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed allocation handle");
- }
CAudioInfo audioInfo = __generate_audio_input_loopback_info(sample_rate, channel, type);
handle->audioIoHandle = new CAudioInput(audioInfo);
- if (handle->audioIoHandle == NULL) {
- THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed allocation internal handle");
- }
handle->audioIoHandle->initialize();
*input = handle;
} catch (CAudioError e) {
AUDIO_IO_LOGE("%s", e.getErrorMsg());
-
- VALID_POINTER_START(handle)
- SAFE_FINALIZE(handle->audioIoHandle);
- SAFE_DELETE(handle->audioIoHandle);
- SAFE_DELETE(handle);
- VALID_POINTER_END
-
- VALID_POINTER_START(input)
- *input = NULL;
- VALID_POINTER_END
-
+ __handle_safe_free(handle, (void *)input, false);
+ return __convert_CAudioError(e);
+ } catch (std::bad_alloc&) {
+ CAudioError e = CAudioError::EError::ERROR_OUT_OF_MEMORY;
+ AUDIO_IO_LOGE("Failed to allocate handle");
+ __handle_safe_free(handle, (void *)input, false);
return __convert_CAudioError(e);
}
__check_audio_param(sample_rate, channel, type, sound_type);
handle = new audio_io_s;
- if (handle == NULL) {
- THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed allocation handle");
- }
CAudioInfo audioInfo = __generate_audio_output_info(sample_rate, channel, type, sound_type);
handle->audioIoHandle = new CAudioOutput(audioInfo);
- if (handle->audioIoHandle == NULL) {
- THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed allocation internal handle");
- }
handle->audioIoHandle->initialize();
*output = handle;
} catch (CAudioError e) {
AUDIO_IO_LOGE("%s", e.getErrorMsg());
-
- VALID_POINTER_START(handle)
- SAFE_FINALIZE(handle->audioIoHandle);
- SAFE_DELETE(handle->audioIoHandle);
- SAFE_DELETE(handle);
- VALID_POINTER_END
-
- VALID_POINTER_START(output)
- *output = NULL;
- VALID_POINTER_END
-
+ __handle_safe_free(handle, (void *)output, true);
+ return __convert_CAudioError(e);
+ } catch (std::bad_alloc&) {
+ CAudioError e = CAudioError::EError::ERROR_OUT_OF_MEMORY;
+ AUDIO_IO_LOGE("Failed to allocate handle");
+ __handle_safe_free(handle, (void *)output, true);
return __convert_CAudioError(e);
}
__check_audio_param(sample_rate, channel, type, SOUND_TYPE_SYSTEM /*default check */);
handle = new audio_io_s;
- if (handle == NULL) {
- THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed allocation handle");
- }
CAudioInfo audioInfo = __generate_audio_output_info(sample_rate, channel, type, SOUND_TYPE_MEDIA);
handle->audioIoHandle = new CAudioOutput(audioInfo);
- if (handle->audioIoHandle == NULL) {
- THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed allocation internal handle");
- }
handle->audioIoHandle->initialize();
*output = handle;
} catch (CAudioError e) {
AUDIO_IO_LOGE("%s", e.getErrorMsg());
-
- VALID_POINTER_START(handle)
- SAFE_FINALIZE(handle->audioIoHandle);
- SAFE_DELETE(handle->audioIoHandle);
- SAFE_DELETE(handle);
- VALID_POINTER_END
-
- VALID_POINTER_START(output)
- *output = NULL;
- VALID_POINTER_END
-
+ __handle_safe_free(handle, (void *)output, true);
+ return __convert_CAudioError(e);
+ } catch (std::bad_alloc&) {
+ CAudioError e = CAudioError::EError::ERROR_OUT_OF_MEMORY;
+ AUDIO_IO_LOGE("Failed to allocate handle");
+ __handle_safe_free(handle, (void *)output, true);
return __convert_CAudioError(e);
}