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 04c2e5535c13ead6cf767cfc4b10877fb7b906cb..9d710d3b6ed53cde669d5967f65c7d68f690982d 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 5e4741ed9388d97b05546a680190b3248a9b1181..00236a7e3ec76b04336006075ddf86186776b716 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 5346f2b343a98e6c26d5d2897b77b92fe66c237f..6351a455d4e997e2b358811310335d04ea64aa84 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 0e2f96da921d9149873415796771e3055fadaee1..47791a717228c52efe6512c8cb797050b5e60496 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 4cee3e17c10c2ad815a448544cb250ce698405b2..760c83434a87f579e5e4297e95840d7667df6c63 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 ae33c403346c37fd5cb50a0fc1a3bf8caaed4cd6..e0524f624b74e56b0037dc34c48c4ca379d07eef 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) {