Fix returning buffer size 0 before prepare
[platform/core/api/audio-io.git] / src / cpp / CAudioInfo.cpp
index 0e2f96d..47791a7 100644 (file)
@@ -88,6 +88,39 @@ void CAudioInfo::setAudioIndex(int audioIndex) {
     return;
 }
 
+int CAudioInfo::getSampleSize() {
+    int bytes_in_sample = 0;
+    int number_of_channel = 0;
+
+    switch (__mSampleType) {
+    case ESampleType::SAMPLE_TYPE_U8:
+        bytes_in_sample = 1;
+        break;
+    case ESampleType::SAMPLE_TYPE_S16_LE:
+        bytes_in_sample = 2;
+        break;
+    default:
+        AUDIO_IO_LOGW("As unrecognized sample type %d, let's assume S16_LE", __mSampleType);
+        bytes_in_sample = 2;
+        break;
+    }
+
+    switch (__mChannel) {
+    case EChannel::CHANNEL_MONO:
+        number_of_channel = 1;
+        break;
+    case EChannel::CHANNEL_STEREO:
+        number_of_channel = 2;
+        break;
+    default:
+        AUDIO_IO_LOGW("As unrecognized channel %d, let's assume STEREO", __mChannel);
+        number_of_channel = 2;
+        break;
+    }
+
+    return bytes_in_sample * number_of_channel;
+}
+
 void CAudioInfo::convertAudioType2StreamType(CAudioInfo::EAudioType audioType, char **streamType) {
     if (audioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA || audioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX) {
         THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE, "The audioType is not supported [audioType:%d]", audioType);