Check invalid parameter and operation 96/43896/1 submit/tizen/20150715.092047
authorJeongho Mok <jho.mok@samsung.com>
Wed, 15 Jul 2015 06:28:31 +0000 (15:28 +0900)
committerJeongho Mok <jho.mok@samsung.com>
Wed, 15 Jul 2015 06:34:20 +0000 (15:34 +0900)
1. Check invalid parameter when handle create
check sample rate, format, sample type, sound type
2. Check invalid operation
Do not permit ignore-session on ansyc mode

[Version] 0.3.6
[Profile] Common
[Issue Type] Fix bug

Change-Id: I4fcc99d7d0cfa21fd80ee4551a89dd8dbd861a51
Signed-off-by: Jeongho Mok <jho.mok@samsung.com>
packaging/capi-media-audio-io.spec
src/cpp/cpp_audio_io.cpp

index 28a2454..3d7dd30 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-audio-io
 Summary:    An Audio Input & Audio Output library in Tizen Native API
-Version:    0.3.5
+Version:    0.3.6
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 6f2f5fb..0c5571e 100644 (file)
@@ -283,6 +283,30 @@ static audio_io_state_e _convert_state_type(const CAudioInfo::EAudioIOState src_
     return dst_state;
 }
 
+static void _check_audio_param(int sample_rate, audio_channel_e channel, audio_sample_type_e type)  throw (CAudioError) {
+
+    if (sample_rate < 0) {
+        THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_INVALID_ARGUMENT, "Invalid sample rate :%d", sample_rate);
+    }
+
+    if (channel != AUDIO_CHANNEL_MONO && channel != AUDIO_CHANNEL_STEREO) {
+        THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_INVALID_ARGUMENT, "Invalid channel :%d", channel);
+    }
+
+    if (type != AUDIO_SAMPLE_TYPE_U8 && type != AUDIO_SAMPLE_TYPE_S16_LE) {
+        THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_INVALID_ARGUMENT, "Invalid sample type :%d", type);
+    }
+}
+
+static void _check_audio_param(int sample_rate, audio_channel_e channel, audio_sample_type_e type, sound_type_e sound_type) throw (CAudioError) {
+
+    _check_audio_param(sample_rate, channel, type);
+
+    if (sound_type < SOUND_TYPE_SYSTEM || sound_type > SOUND_TYPE_VOICE) {
+        THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_INVALID_ARGUMENT, "Invalid sound type : %d", sound_type);
+    }
+}
+
 static CAudioInfo _generate_audio_input_info(int sampleRate, audio_channel_e channel, audio_sample_type_e sample_type) throw (CAudioError) {
     CAudioInfo::EChannel     dstChannel;
     CAudioInfo::ESampleType dstSampleType;
@@ -350,6 +374,8 @@ int cpp_audio_in_create(int sample_rate, audio_channel_e channel, audio_sample_t
             THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_INVALID_ARGUMENT, "Parameters are NULL input:%p", input);
         }
 
+        _check_audio_param(sample_rate, channel, type);
+
         handle = new audio_io_s;
         if (handle == NULL) {
             THROW_ERROR_MSG(CAudioError::ERROR_OUT_OF_MEMORY, "Failed allocation handle");
@@ -773,6 +799,10 @@ int cpp_audio_in_ignore_session(audio_in_h input) {
             THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_INVALID_ARGUMENT, "Parameters are NULL input:%p", input);
         }
 
+        if (handle->stream_callback.onStream) {
+            THROW_ERROR_MSG(CAudioError::ERROR_INVALID_OPERATION, "Not support ignore session in async mode");
+        }
+
         assert(handle->audioIoHandle);
 
         handle->audioIoHandle->ignoreSession();
@@ -958,6 +988,8 @@ int cpp_audio_out_create(int sample_rate, audio_channel_e channel, audio_sample_
             THROW_ERROR_MSG(CAudioError::ERROR_OUT_OF_MEMORY, "Failed allocation handle");
         }
 
+        _check_audio_param(sample_rate, channel, type, sound_type);
+
         CAudioInfo audioInfo = _generate_audio_output_info(sample_rate, channel, type, sound_type);
 
         handle->audioIoHandle = new CAudioOutput(audioInfo);
@@ -1383,6 +1415,10 @@ int cpp_audio_out_ignore_session(audio_out_h output) {
             THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_INVALID_ARGUMENT, "Parameters are NULL output:%p", output);
         }
 
+        if (handle->stream_callback.onStream) {
+            THROW_ERROR_MSG(CAudioError::ERROR_INVALID_OPERATION, "Not support ignore session in async mode");
+        }
+
         assert(handle->audioIoHandle);
 
         handle->audioIoHandle->ignoreSession();