Fix returning buffer size 0 before prepare 53/108253/4
authorSeungbae Shin <seungbae.shin@samsung.com>
Tue, 3 Jan 2017 14:10:14 +0000 (23:10 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Thu, 5 Jan 2017 05:45:18 +0000 (14:45 +0900)
[Version] 0.3.50
[Profile] Common
[Issue Type] Bug

Change-Id: I61299c7bb60c128ca66b5ef79f2de366709cc254

include/CAudioIODef.h
include/CAudioInfo.h
packaging/capi-media-audio-io.spec
src/cpp/CAudioInfo.cpp
src/cpp/CAudioInput.cpp
src/cpp/CAudioOutput.cpp

index 04c2e55..9d710d3 100644 (file)
 #define SAFE_FINALIZE(_x_) {if ((_x_)) {(_x_)->finalize();}};
 #define SAFE_REMOVE(_x_)   {if ((_x_)) {(_x_)->finalize(); delete (_x_); (_x_) = NULL;}};
 
+#define DEFAULT_PERIOD_SIZE 50
 
 #endif
 #endif /* __TIZEN_MEDIA_CPP_OBJECTS_IO_H__ */
index 5e4741e..00236a7 100644 (file)
@@ -105,6 +105,7 @@ namespace tizen_media_audio {
         void convertAudioType2StreamType(CAudioInfo::EAudioType audioType, char **streamType);
         void convertInputStreamType2AudioType(char *streamType, CAudioInfo::EAudioType *audioType);
         void convertOutputStreamType2AudioType(char *streamType, CAudioInfo::EAudioType *audioType);
+        int getSampleSize();
 
     private:
         const char *__STREAM_TYPE_TABLE[(unsigned int)EAudioType::AUDIO_TYPE_MAX] = {
index 5346f2b..6351a45 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.49
+Version:        0.3.50
 Release:        0
 Group:          Multimedia/API
 License:        Apache-2.0
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);
index 4cee3e1..760c834 100644 (file)
@@ -397,20 +397,8 @@ int CAudioInput::getBufferSize() throw(CAudioError) {
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CAudioInput");
     }
 
-    if (__IsReady() == false) {
-        AUDIO_IO_LOGD("Warning: Did not prepare CAudioInput, then return zero");
-        return 0;
-    }
-
-    int size = 0;
-
-    try {
-        size = mpPulseAudioClient->getBufferSize();
-    } catch (CAudioError err) {
-        throw err;
-    }
-
-    return size;
+    /* FIXME : return calculated size here to satisfy backward compatibility */
+    return (mAudioInfo.getSampleRate() * DEFAULT_PERIOD_SIZE) / 1000 * mAudioInfo.getSampleSize();
 }
 
 void CAudioInput::setStreamCallback(SStreamCallback callback) throw(CAudioError) {
index ae33c40..e0524f6 100644 (file)
@@ -302,20 +302,8 @@ int CAudioOutput::getBufferSize() throw(CAudioError) {
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CAudioOutput");
     }
 
-    if (__IsReady() == false) {
-        AUDIO_IO_LOGD("Warning: Did not prepare CAudioOutput, then return zero");
-        return 0;
-    }
-
-    int size = 0;
-
-    try {
-        size = mpPulseAudioClient->getBufferSize();
-    } catch (CAudioError err) {
-        throw err;
-    }
-
-    return size;
+    /* FIXME : return calculated size here to satisfy backward compatibility */
+    return (mAudioInfo.getSampleRate() * DEFAULT_PERIOD_SIZE) / 1000 * mAudioInfo.getSampleSize();
 }
 
 size_t CAudioOutput::write(const void* buffer, size_t length) throw(CAudioError) {