Change set_stream_info API name for consistency with other pkgs
[platform/core/api/audio-io.git] / src / cpp / cpp_audio_io.cpp
index 936873f..1f90406 100644 (file)
@@ -20,6 +20,9 @@
 #include "audio_io.h"
 #include "CAudioIODef.h"
 
+#include <system_info.h>
+
+#define FEATURE_MICROPHONE          "http://tizen.org/feature/microphone"
 
 using namespace std;
 using namespace tizen_media_audio;
@@ -363,6 +366,8 @@ static audio_io_interrupted_code_e __convert_interrupted_code(IAudioSessionEvent
  */
 int cpp_audio_in_create(int sample_rate, audio_channel_e channel, audio_sample_type_e type, audio_in_h *input) {
     audio_io_s* handle = NULL;
+    bool mic_enable = false;
+    int ret = 0;
     try {
         if (input == NULL) {
             THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "Parameters are NULL input:%p", input);
@@ -370,6 +375,13 @@ int cpp_audio_in_create(int sample_rate, audio_channel_e channel, audio_sample_t
 
         __check_audio_param(sample_rate, channel, type);
 
+        /* If MIC is not supported, return NOT_SUPPORTED error */
+        ret = system_info_get_platform_bool(FEATURE_MICROPHONE, &mic_enable);
+        AUDIO_IO_LOGD("system_info_platform [%s]=[%d], ret[%d]", FEATURE_MICROPHONE, mic_enable, ret);
+        if (ret != SYSTEM_INFO_ERROR_NONE || !mic_enable) {
+            THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "System doesn't support microphone!");
+        }
+
         handle = new audio_io_s;
         if (handle == NULL) {
             THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed allocation handle");
@@ -378,7 +390,7 @@ int cpp_audio_in_create(int sample_rate, audio_channel_e channel, audio_sample_t
         CAudioInfo audioInfo = __generate_audio_input_info(sample_rate, channel, type);
 
         handle->audioIoHandle = new CAudioInput(audioInfo);
-        if (handle == NULL) {
+        if (handle->audioIoHandle == NULL) {
             THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed allocation internal handle");
         }
 
@@ -421,7 +433,7 @@ int cpp_audio_in_create_loopback(int sample_rate, audio_channel_e channel, audio
         CAudioInfo audioInfo = __generate_audio_input_loopback_info(sample_rate, channel, type);
 
         handle->audioIoHandle = new CAudioInput(audioInfo);
-        if (handle == NULL) {
+        if (handle->audioIoHandle == NULL) {
             THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed allocation internal handle");
         }
 
@@ -468,7 +480,7 @@ int cpp_audio_in_destroy(audio_in_h input) {
     return AUDIO_IO_ERROR_NONE;
 }
 
-int cpp_audio_in_set_stream_info(audio_in_h input, sound_stream_info_h stream_info) {
+int cpp_audio_in_set_sound_stream_info(audio_in_h input, sound_stream_info_h stream_info) {
     audio_io_s* handle = static_cast<audio_io_s*>(input);
 
     try {
@@ -1054,7 +1066,7 @@ int cpp_audio_out_create_new(int sample_rate, audio_channel_e channel, audio_sam
         CAudioInfo audioInfo = __generate_audio_output_info(sample_rate, channel, type, SOUND_TYPE_MEDIA /* default sound_type */);
 
         handle->audioIoHandle = new CAudioOutput(audioInfo);
-        if (handle == NULL) {
+        if (handle->audioIoHandle == NULL) {
             THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed allocation internal handle");
         }
 
@@ -1101,7 +1113,7 @@ int cpp_audio_out_destroy(audio_out_h output) {
     return AUDIO_IO_ERROR_NONE;
 }
 
-int cpp_audio_out_set_stream_info(audio_out_h output, sound_stream_info_h stream_info) {
+int cpp_audio_out_set_sound_stream_info(audio_out_h output, sound_stream_info_h stream_info) {
     audio_io_s* handle = static_cast<audio_io_s*>(output);
 
     try {
@@ -1272,10 +1284,10 @@ int cpp_audio_out_write(audio_out_h output, void *buffer, unsigned int length) {
         if (outputHandle == NULL) {
             THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_HANDLE, "Handle is NULL");
         }
-        size_t writen = outputHandle->write(buffer, static_cast<size_t>(length));
-        ret = static_cast<int>(writen);
+        size_t written = outputHandle->write(buffer, static_cast<size_t>(length));
+        ret = static_cast<int>(written);
 #ifdef _AUDIO_IO_DEBUG_TIMING_
-        AUDIO_IO_LOGD("writen:%d", writen);
+        AUDIO_IO_LOGD("written:%d", written);
 #endif
     } catch (CAudioError e) {
         AUDIO_IO_LOGE("%s", e.getErrorMsg());