Enable dummy write on streamCb only for async mode backward compatibility 02/159802/1 accepted/tizen/unified/20171115.061212 submit/tizen/20171114.101427
authorSeungbae Shin <seungbae.shin@samsung.com>
Tue, 7 Nov 2017 10:00:37 +0000 (19:00 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Mon, 13 Nov 2017 05:26:41 +0000 (05:26 +0000)
set started/underflow for playback debugging purpose

[Version] 0.4.5
[Issue Type] Bug Fix

Change-Id: I1c39d76895f93c6a6719d719c3382342f84be4d8
(cherry picked from commit 2f28d6f49ca602993014f849835865757e1f02b9)

include/CPulseAudioClient.h
packaging/capi-media-audio-io.spec
src/cpp/CAudioOutput.cpp
src/cpp/CPulseAudioClient.cpp

index 277e99f..d68e02c 100644 (file)
@@ -113,6 +113,8 @@ namespace tizen_media_audio {
         static void __streamCaptureCb(pa_stream* s, size_t length, void* user_data);
         static void __streamPlaybackCb(pa_stream* s, size_t length, void* user_data);
         static void __streamLatencyUpdateCb(pa_stream* s, void* user_data);
+        static void __streamStartedCb(pa_stream* s, void* user_data);
+        static void __streamUnderflowCb(pa_stream* s, void* user_data);
         static void __streamEventCb(pa_stream* s, const char *name, pa_proplist *pl, void *user_data);
         static void __successStreamCb(pa_stream* s, int success, void* user_data);
         static void __successDrainCb(pa_stream* s, int success, void* user_data);
index 4d2976b..5fb9918 100644 (file)
@@ -1,6 +1,6 @@
 Name:           capi-media-audio-io
 Summary:        An Audio Input & Audio Output library in Tizen Native API
-Version:        0.4.4
+Version:        0.4.5
 Release:        0
 Group:          Multimedia/API
 License:        Apache-2.0
index b4aeb8a..f96f78f 100644 (file)
@@ -224,9 +224,7 @@ void CAudioOutput::unprepare() {
     try {
         if (mpAudioSessionHandler->getId() >= 0 && !mIsInterrupted) {
             if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false) {
-                CPulseStreamSpec::EStreamLatency streamSpec;
-                streamSpec = mpPulseAudioClient->getStreamSpec().getStreamLatency();
-                if (CPulseStreamSpec::EStreamLatency::STREAM_LATENCY_OUTPUT_DEFAULT_ASYNC != streamSpec)
+                if (mStreamCallback.onStream == NULL)
                     CAudioIO::drain();
             }
         }
@@ -305,15 +303,12 @@ void CAudioOutput::resume() {
 }
 
 void CAudioOutput::drain() {
-    CPulseStreamSpec::EStreamLatency streamSpec;
-
     if (__IsInit() == false || __IsReady() == false) {
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED,
                         "Did not initialize or prepare CAudioOutput");
     }
 
-    streamSpec = mpPulseAudioClient->getStreamSpec().getStreamLatency();
-    if (CPulseStreamSpec::EStreamLatency::STREAM_LATENCY_OUTPUT_DEFAULT_ASYNC == streamSpec)
+    if (mStreamCallback.onStream)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_OPERATION, "async type don't support drain");
 
     try {
index 50ce02e..bd123bb 100644 (file)
@@ -195,18 +195,16 @@ void CPulseAudioClient::__streamPlaybackCb(pa_stream* s, size_t length, void* us
 
     pClient->__mpListener->onStream(pClient, length);
 
+#ifndef DISABLE_MOBILE_BACK_COMP
     /* If stream is not written in first callback during prepare,
        then write dummy data to ensure the start */
-    if (pClient->__mIsFirstStream) {
-        AUDIO_IO_LOGD("Write dummy, length [%d]", length);
-
-        char* dummy = new char[length];
-        memset(dummy, 0, length);
-        pa_stream_write(s, dummy, length, NULL, 0LL, PA_SEEK_RELATIVE);
-        delete [] dummy;
-
+    if (pClient->__mSpec.getStreamLatency() == CPulseStreamSpec::EStreamLatency::STREAM_LATENCY_OUTPUT_DEFAULT_ASYNC &&
+        pClient->__mIsFirstStream) {
+        AUDIO_IO_LOGW("[async] Write dummy of length[%d] since not written in first callback during prepare", length);
+        __dummy_write(s, length);
         pClient->__mIsFirstStream = false;
     }
+#endif
 }
 
 void CPulseAudioClient::__streamLatencyUpdateCb(pa_stream* s, void* user_data) {
@@ -218,6 +216,24 @@ void CPulseAudioClient::__streamLatencyUpdateCb(pa_stream* s, void* user_data) {
     pa_threaded_mainloop_signal(pClient->__mpMainloop, 0);
 }
 
+void CPulseAudioClient::__streamStartedCb(pa_stream* s, void* user_data) {
+    assert(s);
+    assert(user_data);
+
+    CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+
+    AUDIO_IO_LOGD("stream %p started.", pClient);
+}
+
+void CPulseAudioClient::__streamUnderflowCb(pa_stream* s, void* user_data) {
+    assert(s);
+    assert(user_data);
+
+    CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+
+    AUDIO_IO_LOGD("stream %p UnderFlow...", pClient);
+}
+
 void CPulseAudioClient::__streamEventCb(pa_stream* s, const char *name, pa_proplist *pl, void *user_data) {
     assert(s);
     assert(user_data);
@@ -360,6 +376,10 @@ void CPulseAudioClient::initialize() {
         pa_stream_set_write_callback(__mpStream, __streamPlaybackCb, this);
         pa_stream_set_latency_update_callback(__mpStream, __streamLatencyUpdateCb, this);
         pa_stream_set_event_callback(__mpStream, __streamEventCb, this);
+        if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK) {
+            pa_stream_set_started_callback(__mpStream, __streamStartedCb, this);
+            pa_stream_set_underflow_callback(__mpStream, __streamUnderflowCb, this);
+               }
 
         // Connect stream with PA Server
 
@@ -658,7 +678,7 @@ int CPulseAudioClient::write(const void* data, size_t length) {
     int ret = 0;
 
 #ifdef _AUDIO_IO_DEBUG_TIMING_
-    AUDIO_IO_LOGD("data[%p], length[%d]", data, length);
+    AUDIO_IO_LOGD("data[%p], length[%d], First[%d]", data, length, __mIsFirstStream);
 #endif
     if (pa_stream_is_corked(__mpStream)) {
         AUDIO_IO_LOGW("stream is corked...do uncork here first!!!!");