From 8803cbe5ae10573e32dd42cd2563ab946dfb15d2 Mon Sep 17 00:00:00 2001 From: zoff99 Date: Sun, 31 Dec 2023 09:04:21 +0100 Subject: [PATCH 1/7] cahnge var name --- .../applications/trifa/CustomSemaphore.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/zoffcc/applications/trifa/CustomSemaphore.java b/src/main/java/com/zoffcc/applications/trifa/CustomSemaphore.java index 639d38db..8c0544af 100644 --- a/src/main/java/com/zoffcc/applications/trifa/CustomSemaphore.java +++ b/src/main/java/com/zoffcc/applications/trifa/CustomSemaphore.java @@ -7,7 +7,7 @@ public class CustomSemaphore extends Semaphore { private final static String TAG = "trifa.CstSemphr"; - private final boolean LOGGING = false; + private final boolean CUSTOM_SEMAPHORE_LOGGING = false; private boolean acquired = false; private String prev_acquired_sourcefile_line = ""; private final int BLOCKING_THRESHOLD_MS = 500; @@ -16,7 +16,7 @@ public class CustomSemaphore extends Semaphore { public CustomSemaphore(int permits) { super(permits); - if (LOGGING) Log.i(TAG, ""+SEM_ID + " " + "create"); + if (CUSTOM_SEMAPHORE_LOGGING) Log.i(TAG, ""+SEM_ID + " " + "create"); } @Override @@ -46,7 +46,7 @@ public void acquire(String sourcefile_line_) throws InterruptedException { } } - if (LOGGING) Log.i(TAG, ""+SEM_ID + " " + "acquire:start" + callerMethodName); + if (CUSTOM_SEMAPHORE_LOGGING) Log.i(TAG, ""+SEM_ID + " " + "acquire:start" + callerMethodName); acquired = false; final String callerMethodName_final = callerMethodName; try { @@ -65,17 +65,17 @@ public void acquire(String sourcefile_line_) throws InterruptedException { */ } } catch (Exception e) { - if (LOGGING) e.printStackTrace(); + if (CUSTOM_SEMAPHORE_LOGGING) e.printStackTrace(); } }); _t.start(); } catch (Exception e) { - if (LOGGING) e.printStackTrace(); + if (CUSTOM_SEMAPHORE_LOGGING) e.printStackTrace(); } super.acquire(); prev_acquired_sourcefile_line = sourcefile_line_; acquired = true; - if (LOGGING) Log.i(TAG, ""+SEM_ID + " " + "acquire:finish" + callerMethodName); + if (CUSTOM_SEMAPHORE_LOGGING) Log.i(TAG, ""+SEM_ID + " " + "acquire:finish" + callerMethodName); } public void release_passthru() @@ -85,8 +85,8 @@ public void release_passthru() @Override public void release() { - if (LOGGING) Log.i(TAG, ""+SEM_ID + " " + "release:start"); + if (CUSTOM_SEMAPHORE_LOGGING) Log.i(TAG, ""+SEM_ID + " " + "release:start"); super.release(); - if (LOGGING) Log.i(TAG, ""+SEM_ID + " " + "release:finish"); + if (CUSTOM_SEMAPHORE_LOGGING) Log.i(TAG, ""+SEM_ID + " " + "release:finish"); } } From 1731d32f9a3384b6d6d0b98941845bb1d3f38802 Mon Sep 17 00:00:00 2001 From: zoff99 Date: Sun, 31 Dec 2023 09:04:42 +0100 Subject: [PATCH 2/7] DEBUG:xxxx --- .../zoffcc/applications/trifa/MainActivity.kt | 18 +++-- .../applications/trifa/TrifaToxService.kt | 78 ++++++++++++++----- 2 files changed, 70 insertions(+), 26 deletions(-) diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt b/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt index 4c99a4e3..707d1155 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt @@ -169,7 +169,7 @@ class MainActivity var tox_a_queue_full_trigger = false var tox_a_queue_stop_trigger = true var tox_audio_in_queue: BlockingQueue = LinkedBlockingQueue(tox_audio_in_queue_max_capacity) - + var ta_2 = -1L // var PREF__ngc_video_bitrate: Int = LOWER_NGC_VIDEO_BITRATE // ~600 kbits/s -> ~60 kbytes/s var PREF__ngc_video_max_quantizer: Int = LOWER_NGC_VIDEO_QUANTIZER // 47 -> default, 51 -> lowest quality, 30 -> very high quality and lots of bandwidth! @@ -1268,6 +1268,11 @@ class MainActivity return } + Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:LLLLLAUDIO:001:" + + (System.currentTimeMillis() - ta_2) + " " + + friend_number + " " + sample_count + " " + channels + " " + sampling_rate) + ta_2 = System.currentTimeMillis() + try { _recBuffer!!.rewind() @@ -1284,24 +1289,23 @@ class MainActivity { if (tox_a_queue_full_trigger) { - if (tox_audio_in_queue.remainingCapacity() >= tox_audio_in_queue_max_capacity - 2) + if (tox_audio_in_queue.remainingCapacity() >= (tox_audio_in_queue_max_capacity - 2)) { tox_a_queue_full_trigger = false - // Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:release:") + Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:release:") } else { - // Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:-----------:" + - // audio_queue_full_trigger) + Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:-----------:" + + audio_queue_full_trigger) } } else { tox_audio_in_queue.offer(audio_out_byte_buffer) - // Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:offer:" + tox_audio_in_queue.size) + Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:offer:" + tox_audio_in_queue.size) } } - // } catch(_: Exception) { diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt b/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt index 72c99ff7..1fb3ccbe 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt @@ -337,6 +337,7 @@ class TrifaToxService fun tox_audio_play_thread_start() { + var sw_t = -1L Log.i(TAG, "[]tox_audio_frame:starting Thread") tox_audio_play_thread = object : Thread() { @@ -361,22 +362,22 @@ class TrifaToxService if ((tox_audio_in_queue.size < 2) && (!tox_a_queue_stop_trigger)) { tox_a_queue_stop_trigger = true - // Log.i(TAG, "[]tox_audio_frame:trigger:" + tox_audio_in_queue.size) + Log.i(TAG, "[]tox_audio_frame:trigger:(PAUSE playing):" + tox_audio_in_queue.size) } else { if (tox_a_queue_stop_trigger) { - if (tox_audio_in_queue.size >= 6) + if (tox_audio_in_queue.size >= (MainActivity.tox_audio_in_queue_max_capacity - 2)) { tox_a_queue_stop_trigger = false - // Log.i(TAG, "[]tox_audio_frame:release:" + tox_audio_in_queue.size) + Log.i(TAG, "[]tox_audio_frame:release:(resume playing):" + tox_audio_in_queue.size) } else { - //Log.i(TAG, "[]tox_audio_frame:+++++++++:" + tox_a_queue_play_trigger + " " - //+ tox_audio_in_queue.size + " " + tox_audio_in_queue.remainingCapacity()) - sleep(20) + Log.i(TAG, "[]tox_audio_frame:+++++++++:(paused):" + tox_a_queue_stop_trigger + " " + + tox_audio_in_queue.size + " " + tox_audio_in_queue.remainingCapacity()) + sleep(5) } } else { @@ -389,37 +390,58 @@ class TrifaToxService val sample_count = want_bytes / 2 try { - AudioSelectOutBox.semaphore_audio_out_convert.acquire_passthru() + Log.i(TAG, "[]tox_audio_frame:SEM_ACQUIRE:001a") + AudioSelectOutBox.semaphore_audio_out_convert.acquire() + Log.i(TAG, "[]tox_audio_frame:SEM_ACQUIRE:001b") if (AudioSelectOutBox.semaphore_audio_out_convert_active_threads >= AudioSelectOutBox.semaphore_audio_out_convert_max_active_threads) { Log.i(TAG, "[]tox_audio_frame:too many threads running: " + AudioSelectOutBox.semaphore_audio_out_convert_active_threads) - AudioSelectOutBox.semaphore_audio_out_convert.release_passthru() + Log.i(TAG, "[]tox_audio_frame:SEM_release:001a") + AudioSelectOutBox.semaphore_audio_out_convert.release() + Log.i(TAG, "[]tox_audio_frame:SEM_release:001b") continue } - AudioSelectOutBox.semaphore_audio_out_convert.release_passthru() + Log.i(TAG, "[]tox_audio_frame:SEM_release:002a") + AudioSelectOutBox.semaphore_audio_out_convert.release() + Log.i(TAG, "[]tox_audio_frame:SEM_release:002b") } catch (e: java.lang.Exception) { - AudioSelectOutBox.semaphore_audio_out_convert.release_passthru() + Log.i(TAG, "[]tox_audio_frame:SEM_release:003a") + AudioSelectOutBox.semaphore_audio_out_convert.release() + Log.i(TAG, "[]tox_audio_frame:SEM_release:003b") } val t_tox_audio_pcm_play = Thread{ try { - AudioSelectOutBox.semaphore_audio_out_convert.acquire_passthru() + Log.i(TAG, "[]tox_audio_frame:SEM_ACQUIRE:t004a") + AudioSelectOutBox.semaphore_audio_out_convert.acquire() + Log.i(TAG, "[]tox_audio_frame:SEM_ACQUIRE:t004b") AudioSelectOutBox.semaphore_audio_out_convert_active_threads++ - AudioSelectOutBox.semaphore_audio_out_convert.release_passthru() + Log.i(TAG, "[]tox_audio_frame:SEM_release:t004a") + AudioSelectOutBox.semaphore_audio_out_convert.release() + Log.i(TAG, "[]tox_audio_frame:SEM_release:t004b") } catch (e: java.lang.Exception) { - AudioSelectOutBox.semaphore_audio_out_convert.release_passthru() + Log.i(TAG, "[]tox_audio_frame:SEM_release:t005a") + AudioSelectOutBox.semaphore_audio_out_convert.release() + Log.i(TAG, "[]tox_audio_frame:SEM_release:t005b") } // HINT: this acutally plays incoming Audio // HINT: this may block!! try { + Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:sourceDataLine.write:loop_delta=" + (System.currentTimeMillis() - sw_t)) + sw_t = System.currentTimeMillis() val bytes_actually_written = AudioSelectOutBox.sourceDataLine.write(buf, 0, want_bytes) + Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:sourceDataLine.write:delta=" + (System.currentTimeMillis() - sw_t)) if (bytes_actually_written != want_bytes) { - Log.i(TAG, "[]tox_audio_frame:bytes_actually_written=" + bytes_actually_written + " want_bytes=" + want_bytes) + Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:ERR:=" + bytes_actually_written + " want_bytes=" + want_bytes) + } + else + { + Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:OK:=" + bytes_actually_written + " want_bytes=" + want_bytes) } } catch (e: java.lang.Exception) { @@ -427,14 +449,21 @@ class TrifaToxService } try { - AudioSelectOutBox.semaphore_audio_out_convert.acquire_passthru() + Log.i(TAG, "[]tox_audio_frame:SEM_ACQUIRE:t006a") + AudioSelectOutBox.semaphore_audio_out_convert.acquire() + Log.i(TAG, "[]tox_audio_frame:SEM_ACQUIRE:t006b") AudioSelectOutBox.semaphore_audio_out_convert_active_threads-- - AudioSelectOutBox.semaphore_audio_out_convert.release_passthru() + Log.i(TAG, "[]tox_audio_frame:SEM_release:t006a") + AudioSelectOutBox.semaphore_audio_out_convert.release() + Log.i(TAG, "[]tox_audio_frame:SEM_release:t006b") } catch (e: java.lang.Exception) { Log.i(TAG, "[]tox_audio_frame:--:EEEEEE") - AudioSelectOutBox.semaphore_audio_out_convert.release_passthru() + Log.i(TAG, "[]tox_audio_frame:SEM_release:t007a") + AudioSelectOutBox.semaphore_audio_out_convert.release() + Log.i(TAG, "[]tox_audio_frame:SEM_release:t007b") } + /* var global_audio_out_vu: Float = MainActivity.AUDIO_VU_MIN_VALUE if (sample_count > 0) { @@ -449,29 +478,40 @@ class TrifaToxService } val global_audio_out_vu_ = global_audio_out_vu AudioBar.set_cur_value(global_audio_out_vu_.toInt(), AudioBar.audio_out_bar) + */ } + Log.i(TAG, "[]tox_audio_frame:new thread TTTTTTTTT") t_tox_audio_pcm_play.start() } catch(e: Exception) { e.printStackTrace() + Log.i(TAG, "[]tox_audio_frame:EE:0021") } } + else + { + Log.i(TAG, "[]tox_audio_frame:EE:0033") + } } } } catch (e: java.lang.Exception) { + e.printStackTrace() + Log.i(TAG, "[]tox_audio_frame:EE:0064") } // -- play incoming bytes -- // -- play incoming bytes -- - sleep(20) if (avstatestorecallstate.state.call_state != AVState.CALL_STATUS.CALL_STATUS_CALLING) { + Log.i(TAG, "[]tox_audio_frame:long sleep SSSSSSSSSS") sleep(200) } } - } catch (_: Exception) + } catch (e: Exception) { + e.printStackTrace() + Log.i(TAG, "[]tox_audio_frame:EE:0078") } Log.i(TAG, "[]tox_audio_frame: Thread ending") } From dfc23fab8e55ba1a0044e8a0a8514a11663e27e1 Mon Sep 17 00:00:00 2001 From: zoff99 Date: Sun, 31 Dec 2023 13:12:12 +0100 Subject: [PATCH 3/7] rebugger --- build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle.kts b/build.gradle.kts index c627ae8a..bf39f25f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -77,6 +77,7 @@ dependencies { implementation("com.sksamuel.scrimage:scrimage-webp:4.1.1") implementation("com.google.code.gson:gson:2.10.1") implementation("io.github.alexzhirkevich:qrose:1.0.0-beta3") + // implementation("io.github.theapache64:rebugger:1.0.0-rc02") } compose.desktop { From eb05cc79b3c702fac4f57d1894c3a21e5162a81b Mon Sep 17 00:00:00 2001 From: zoff99 Date: Sun, 31 Dec 2023 13:12:28 +0100 Subject: [PATCH 4/7] remove some unused imports --- src/main/kotlin/Main.kt | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 6c146498..a6cdd10b 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -109,7 +109,6 @@ import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.compose.ui.window.Dialog -import androidx.compose.ui.window.Popup import androidx.compose.ui.window.Window import androidx.compose.ui.window.WindowPlacement import androidx.compose.ui.window.WindowPosition @@ -124,10 +123,7 @@ import com.zoffcc.applications.trifa.AudioBar import com.zoffcc.applications.trifa.AudioBar.audio_in_bar import com.zoffcc.applications.trifa.AudioBar.audio_out_bar import com.zoffcc.applications.trifa.CustomSemaphore -import com.zoffcc.applications.trifa.HelperGeneric import com.zoffcc.applications.trifa.HelperGeneric.PubkeyShort -import com.zoffcc.applications.trifa.HelperMessage -import com.zoffcc.applications.trifa.HelperNotification.displayNotification import com.zoffcc.applications.trifa.HelperNotification.init_system_tray import com.zoffcc.applications.trifa.HelperNotification.set_resouces_dir import com.zoffcc.applications.trifa.JPictureBox @@ -153,13 +149,7 @@ import com.zoffcc.applications.trifa.TrifaToxService.Companion.clear_grouppeers import com.zoffcc.applications.trifa.TrifaToxService.Companion.load_grouppeers import com.zoffcc.applications.trifa.TrifaToxService.Companion.orma import com.zoffcc.applications.trifa_material.trifa_material.BuildConfig -import io.github.alexzhirkevich.qrose.options.QrBallShape import io.github.alexzhirkevich.qrose.options.QrBrush -import io.github.alexzhirkevich.qrose.options.QrFrameShape -import io.github.alexzhirkevich.qrose.options.QrPixelShape -import io.github.alexzhirkevich.qrose.options.brush -import io.github.alexzhirkevich.qrose.options.circle -import io.github.alexzhirkevich.qrose.options.roundCorners import io.github.alexzhirkevich.qrose.options.solid import io.github.alexzhirkevich.qrose.rememberQrCodePainter import kotlinx.coroutines.CoroutineScope @@ -189,7 +179,6 @@ import org.briarproject.briar.desktop.ui.UiMode import org.briarproject.briar.desktop.ui.UiPlaceholder import org.briarproject.briar.desktop.ui.VerticalDivider import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n -import org.jetbrains.compose.resources.ExperimentalResourceApi import java.awt.Toolkit import java.io.File import java.net.URI @@ -199,10 +188,8 @@ import java.net.http.HttpResponse import java.util.* import java.util.concurrent.Executors import java.util.prefs.Preferences -import javax.swing.JFrame import javax.swing.JPanel import javax.swing.UIManager -import javax.swing.border.Border private const val TAG = "trifa.Main.kt" var tox_running_state_wrapper = "start" From 788232c648e191e65ccc589631d4242a1964cfa7 Mon Sep 17 00:00:00 2001 From: zoff99 Date: Sun, 31 Dec 2023 13:42:36 +0100 Subject: [PATCH 5/7] DEBUG:audio play --- .../zoffcc/applications/trifa/MainActivity.kt | 2 +- .../applications/trifa/TrifaToxService.kt | 129 ++++++------------ 2 files changed, 40 insertions(+), 91 deletions(-) diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt b/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt index 707d1155..d90cb318 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt @@ -1282,7 +1282,7 @@ class MainActivity // if ((tox_audio_in_queue.remainingCapacity() < 1) && (!tox_a_queue_full_trigger)) { - Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:trigger:" + tox_audio_in_queue.size) + Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:xxxxx !! FULL !! xxxxx:trigger:" + tox_audio_in_queue.size) tox_a_queue_full_trigger = true } else diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt b/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt index 1fb3ccbe..9de4679c 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt @@ -65,6 +65,8 @@ import contactstore import globalstore import grouppeerstore import groupstore +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import online_button_text_wrapper import org.briarproject.briar.desktop.contact.ContactItem import org.briarproject.briar.desktop.contact.GroupItem @@ -338,6 +340,7 @@ class TrifaToxService fun tox_audio_play_thread_start() { var sw_t = -1L + var update_audio_bar = 0 Log.i(TAG, "[]tox_audio_frame:starting Thread") tox_audio_play_thread = object : Thread() { @@ -368,15 +371,15 @@ class TrifaToxService { if (tox_a_queue_stop_trigger) { - if (tox_audio_in_queue.size >= (MainActivity.tox_audio_in_queue_max_capacity - 2)) + if (tox_audio_in_queue.size >= 5) { tox_a_queue_stop_trigger = false Log.i(TAG, "[]tox_audio_frame:release:(resume playing):" + tox_audio_in_queue.size) } else { - Log.i(TAG, "[]tox_audio_frame:+++++++++:(paused):" + tox_a_queue_stop_trigger + " " - + tox_audio_in_queue.size + " " + tox_audio_in_queue.remainingCapacity()) + // Log.i(TAG, "[]tox_audio_frame:+++++++++:(paused):" + tox_a_queue_stop_trigger + " " + // + tox_audio_in_queue.size + " " + tox_audio_in_queue.remainingCapacity()) sleep(5) } } else @@ -388,100 +391,45 @@ class TrifaToxService { val want_bytes = buf.size val sample_count = want_bytes / 2 - try + + // HINT: this acutally plays incoming Audio + // HINT: this may block!! + Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:sourceDataLine.write:loop_delta=" + (System.currentTimeMillis() - sw_t)) + sw_t = System.currentTimeMillis() + val bytes_actually_written = AudioSelectOutBox.sourceDataLine.write(buf, 0, want_bytes) + Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:sourceDataLine.write:delta=" + (System.currentTimeMillis() - sw_t)) + Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:ms=" + AudioSelectOutBox.sourceDataLine.microsecondPosition / 1000) + if (bytes_actually_written != want_bytes) { - Log.i(TAG, "[]tox_audio_frame:SEM_ACQUIRE:001a") - AudioSelectOutBox.semaphore_audio_out_convert.acquire() - Log.i(TAG, "[]tox_audio_frame:SEM_ACQUIRE:001b") - if (AudioSelectOutBox.semaphore_audio_out_convert_active_threads >= AudioSelectOutBox.semaphore_audio_out_convert_max_active_threads) - { - Log.i(TAG, "[]tox_audio_frame:too many threads running: " + AudioSelectOutBox.semaphore_audio_out_convert_active_threads) - Log.i(TAG, "[]tox_audio_frame:SEM_release:001a") - AudioSelectOutBox.semaphore_audio_out_convert.release() - Log.i(TAG, "[]tox_audio_frame:SEM_release:001b") - continue - } - Log.i(TAG, "[]tox_audio_frame:SEM_release:002a") - AudioSelectOutBox.semaphore_audio_out_convert.release() - Log.i(TAG, "[]tox_audio_frame:SEM_release:002b") - } catch (e: java.lang.Exception) + Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:ERR:=" + bytes_actually_written + " want_bytes=" + want_bytes) + } + else { - Log.i(TAG, "[]tox_audio_frame:SEM_release:003a") - AudioSelectOutBox.semaphore_audio_out_convert.release() - Log.i(TAG, "[]tox_audio_frame:SEM_release:003b") + Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:OK:=" + bytes_actually_written + " want_bytes=" + want_bytes) + // sleep(30) } - val t_tox_audio_pcm_play = Thread{ - try - { - Log.i(TAG, "[]tox_audio_frame:SEM_ACQUIRE:t004a") - AudioSelectOutBox.semaphore_audio_out_convert.acquire() - Log.i(TAG, "[]tox_audio_frame:SEM_ACQUIRE:t004b") - AudioSelectOutBox.semaphore_audio_out_convert_active_threads++ - Log.i(TAG, "[]tox_audio_frame:SEM_release:t004a") - AudioSelectOutBox.semaphore_audio_out_convert.release() - Log.i(TAG, "[]tox_audio_frame:SEM_release:t004b") - } catch (e: java.lang.Exception) - { - Log.i(TAG, "[]tox_audio_frame:SEM_release:t005a") - AudioSelectOutBox.semaphore_audio_out_convert.release() - Log.i(TAG, "[]tox_audio_frame:SEM_release:t005b") - } - // HINT: this acutally plays incoming Audio - // HINT: this may block!! - try - { - Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:sourceDataLine.write:loop_delta=" + (System.currentTimeMillis() - sw_t)) - sw_t = System.currentTimeMillis() - val bytes_actually_written = AudioSelectOutBox.sourceDataLine.write(buf, 0, want_bytes) - Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:sourceDataLine.write:delta=" + (System.currentTimeMillis() - sw_t)) - if (bytes_actually_written != want_bytes) - { - Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:ERR:=" + bytes_actually_written + " want_bytes=" + want_bytes) - } - else - { - Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:OK:=" + bytes_actually_written + " want_bytes=" + want_bytes) - } - } catch (e: java.lang.Exception) - { - Log.i(TAG, "[]tox_audio_frame:sourceDataLine.write:EE:" + e.message) // e.printStackTrace(); - } - try - { - Log.i(TAG, "[]tox_audio_frame:SEM_ACQUIRE:t006a") - AudioSelectOutBox.semaphore_audio_out_convert.acquire() - Log.i(TAG, "[]tox_audio_frame:SEM_ACQUIRE:t006b") - AudioSelectOutBox.semaphore_audio_out_convert_active_threads-- - Log.i(TAG, "[]tox_audio_frame:SEM_release:t006a") - AudioSelectOutBox.semaphore_audio_out_convert.release() - Log.i(TAG, "[]tox_audio_frame:SEM_release:t006b") - } catch (e: java.lang.Exception) - { - Log.i(TAG, "[]tox_audio_frame:--:EEEEEE") - Log.i(TAG, "[]tox_audio_frame:SEM_release:t007a") - AudioSelectOutBox.semaphore_audio_out_convert.release() - Log.i(TAG, "[]tox_audio_frame:SEM_release:t007b") - } - /* - var global_audio_out_vu: Float = MainActivity.AUDIO_VU_MIN_VALUE - if (sample_count > 0) - { - val vu_value = AudioBar.audio_vu(buf, sample_count) - global_audio_out_vu = if (vu_value > MainActivity.AUDIO_VU_MIN_VALUE) - { - vu_value - } else + update_audio_bar++ + if (update_audio_bar == 2) + { + update_audio_bar = 0 + GlobalScope.launch { + var global_audio_out_vu: Float = MainActivity.AUDIO_VU_MIN_VALUE + if (sample_count > 0) { - 0f + val vu_value = AudioBar.audio_vu(buf, sample_count) + global_audio_out_vu = if (vu_value > MainActivity.AUDIO_VU_MIN_VALUE) + { + vu_value + } else + { + 0f + } } + val global_audio_out_vu_ = global_audio_out_vu + AudioBar.set_cur_value(global_audio_out_vu_.toInt(), AudioBar.audio_out_bar) } - val global_audio_out_vu_ = global_audio_out_vu - AudioBar.set_cur_value(global_audio_out_vu_.toInt(), AudioBar.audio_out_bar) - */ } - Log.i(TAG, "[]tox_audio_frame:new thread TTTTTTTTT") - t_tox_audio_pcm_play.start() } catch(e: Exception) { @@ -502,9 +450,10 @@ class TrifaToxService } // -- play incoming bytes -- // -- play incoming bytes -- + //XXXXXXXXXX// sleep(59) if (avstatestorecallstate.state.call_state != AVState.CALL_STATUS.CALL_STATUS_CALLING) { - Log.i(TAG, "[]tox_audio_frame:long sleep SSSSSSSSSS") + // Log.i(TAG, "[]tox_audio_frame:long sleep SSSSSSSSSS") sleep(200) } } From 6fb904b09321adc45a7442546d7236bbc340b21e Mon Sep 17 00:00:00 2001 From: zoff99 Date: Sun, 31 Dec 2023 14:09:25 +0100 Subject: [PATCH 6/7] DEBUG:audio play --- .../zoffcc/applications/trifa/MainActivity.kt | 15 ++++++++------- .../applications/trifa/TrifaToxService.kt | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt b/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt index d90cb318..803c9ea6 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt @@ -1268,9 +1268,9 @@ class MainActivity return } - Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:LLLLLAUDIO:001:" - + (System.currentTimeMillis() - ta_2) + " " - + friend_number + " " + sample_count + " " + channels + " " + sampling_rate) + // Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:LLLLLAUDIO:001:" + // + (System.currentTimeMillis() - ta_2) + " " + // + friend_number + " " + sample_count + " " + channels + " " + sampling_rate) ta_2 = System.currentTimeMillis() try @@ -1282,7 +1282,7 @@ class MainActivity // if ((tox_audio_in_queue.remainingCapacity() < 1) && (!tox_a_queue_full_trigger)) { - Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:xxxxx !! FULL !! xxxxx:trigger:" + tox_audio_in_queue.size) + Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:--- DROP:1 !! FULL !! :trigger:" + tox_audio_in_queue.size) tox_a_queue_full_trigger = true } else @@ -1292,18 +1292,19 @@ class MainActivity if (tox_audio_in_queue.remainingCapacity() >= (tox_audio_in_queue_max_capacity - 2)) { tox_a_queue_full_trigger = false - Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:release:") + tox_audio_in_queue.offer(audio_out_byte_buffer) + // Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:release:") } else { - Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:-----------:" + + Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:--- DROP:2 ----:" + audio_queue_full_trigger) } } else { tox_audio_in_queue.offer(audio_out_byte_buffer) - Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:offer:" + tox_audio_in_queue.size) + // Log.i(TAG, "android_toxav_callback_audio_receive_frame_cb_method:offer:2:" + tox_audio_in_queue.size) } } } diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt b/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt index 9de4679c..c9198f52 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt @@ -365,7 +365,7 @@ class TrifaToxService if ((tox_audio_in_queue.size < 2) && (!tox_a_queue_stop_trigger)) { tox_a_queue_stop_trigger = true - Log.i(TAG, "[]tox_audio_frame:trigger:(PAUSE playing):" + tox_audio_in_queue.size) + // Log.i(TAG, "[]tox_audio_frame:trigger:(PAUSE playing):" + tox_audio_in_queue.size) } else { @@ -374,15 +374,17 @@ class TrifaToxService if (tox_audio_in_queue.size >= 5) { tox_a_queue_stop_trigger = false - Log.i(TAG, "[]tox_audio_frame:release:(resume playing):" + tox_audio_in_queue.size) + // Log.i(TAG, "[]tox_audio_frame:release:(resume playing):" + tox_audio_in_queue.size) } else { // Log.i(TAG, "[]tox_audio_frame:+++++++++:(paused):" + tox_a_queue_stop_trigger + " " // + tox_audio_in_queue.size + " " + tox_audio_in_queue.remainingCapacity()) - sleep(5) + sleep(4) } - } else + } + + if (!tox_a_queue_stop_trigger) { val buf: ByteArray = tox_audio_in_queue.poll() if (buf != null) @@ -394,18 +396,18 @@ class TrifaToxService // HINT: this acutally plays incoming Audio // HINT: this may block!! - Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:sourceDataLine.write:loop_delta=" + (System.currentTimeMillis() - sw_t)) + // Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:sourceDataLine.write:loop_delta=" + (System.currentTimeMillis() - sw_t)) sw_t = System.currentTimeMillis() val bytes_actually_written = AudioSelectOutBox.sourceDataLine.write(buf, 0, want_bytes) - Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:sourceDataLine.write:delta=" + (System.currentTimeMillis() - sw_t)) - Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:ms=" + AudioSelectOutBox.sourceDataLine.microsecondPosition / 1000) + // Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:sourceDataLine.write:delta=" + (System.currentTimeMillis() - sw_t)) + // Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:ms=" + AudioSelectOutBox.sourceDataLine.microsecondPosition / 1000) if (bytes_actually_written != want_bytes) { Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:ERR:=" + bytes_actually_written + " want_bytes=" + want_bytes) } else { - Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:OK:=" + bytes_actually_written + " want_bytes=" + want_bytes) + // Log.i(TAG, "[]tox_audio_frame:bytes_actually_written:OK:=" + bytes_actually_written + " want_bytes=" + want_bytes) // sleep(30) } From 138efeca189b431ebe74b2daf4530c94a6fb8fa5 Mon Sep 17 00:00:00 2001 From: zoff99 Date: Sun, 31 Dec 2023 14:33:35 +0100 Subject: [PATCH 7/7] audio play fixes --- .../applications/trifa/HelperGeneric.kt | 16 ++- .../applications/trifa/TrifaToxService.kt | 97 ++++++------------- 2 files changed, 41 insertions(+), 72 deletions(-) diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/HelperGeneric.kt b/src/main/kotlin/com/zoffcc/applications/trifa/HelperGeneric.kt index d2c687f0..cea60fc1 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/HelperGeneric.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/HelperGeneric.kt @@ -682,9 +682,9 @@ object HelperGeneric { //Log.i(TAG, "play_ngc_incoming_audio_frame:toxav_ngc_audio_decode:decoded_samples=" // + decoded_samples) // put pcm data into a FIFO - if ((ngc_audio_in_queue.remainingCapacity() < 2) && (!audio_queue_full_trigger)) + if ((ngc_audio_in_queue.remainingCapacity() < 1) && (!audio_queue_full_trigger)) { - Log.i(TAG, "play_ngc_incoming_audio_frame:trigger:" + ngc_audio_in_queue.size) + Log.i(TAG, "play_ngc_incoming_audio_frame:--- DROP:1 !! FULL !! :trigger:" + ngc_audio_in_queue.size) audio_queue_full_trigger = true } else @@ -694,12 +694,18 @@ object HelperGeneric { if (ngc_audio_in_queue.remainingCapacity() >= ngc_audio_in_queue_max_capacity - 2) { audio_queue_full_trigger = false - Log.i(TAG, "play_ngc_incoming_audio_frame:release:") + System.arraycopy(pcm_decoded_buf, 0, pcm_decoded_buf_delta_1, 0, bytes_in_40ms * 2) + ngc_audio_in_queue.offer(pcm_decoded_buf_delta_1) + System.arraycopy(pcm_decoded_buf, bytes_in_40ms * 2, pcm_decoded_buf_delta_2, 0, bytes_in_40ms * 2) + ngc_audio_in_queue.offer(pcm_decoded_buf_delta_2) + System.arraycopy(pcm_decoded_buf, bytes_in_40ms * 2 * 2, pcm_decoded_buf_delta_3, 0, bytes_in_40ms * 2) + ngc_audio_in_queue.offer(pcm_decoded_buf_delta_3) + // Log.i(TAG, "play_ngc_incoming_audio_frame:release:") } else { - //Log.i(TAG, "play_ngc_incoming_audio_frame:-----------:" + - // audio_queue_full_trigger) + Log.i(TAG, "play_ngc_incoming_audio_frame:--- DROP:2 ----:" + + audio_queue_full_trigger) } } else diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt b/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt index c9198f52..cd8bba57 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt @@ -486,13 +486,9 @@ class TrifaToxService try { - val sleep_millis: Long = 40 - var sleep_millis_current: Long = sleep_millis - var d1: Long = 0 val sampling_rate = 48000 val channels = 1 - val bytes_in_40ms = 1920 - // val sample_count = bytes_in_40ms / 2 + var update_audio_bar = 0 audio_queue_play_trigger = true while (ngc_audio_play_thread_running) { @@ -500,7 +496,7 @@ class TrifaToxService // -- play incoming bytes -- try { - if ((ngc_audio_in_queue.size < 3) && (!audio_queue_play_trigger)) + if ((ngc_audio_in_queue.size < 2) && (!audio_queue_play_trigger)) { audio_queue_play_trigger = true // Log.i(TAG, "()PLAY_ngc_audio_frame:trigger:" + ngc_audio_in_queue.size) @@ -509,7 +505,7 @@ class TrifaToxService { if (audio_queue_play_trigger) { - if (ngc_audio_in_queue.size >= 6) + if (ngc_audio_in_queue.size >= 5) { audio_queue_play_trigger = false // Log.i(TAG, "()PLAY_ngc_audio_frame:release:") @@ -518,9 +514,11 @@ class TrifaToxService { //Log.i(TAG, "()PLAY_ngc_audio_frame:+++++++++:" + audio_queue_play_trigger + " " //+ ngc_audio_in_queue.size + " " + ngc_audio_in_queue.remainingCapacity()) - sleep(20) + sleep(4) } - } else + } + + if (!audio_queue_play_trigger) { val buf: ByteArray = ngc_audio_in_queue.poll() if (buf != null) @@ -546,70 +544,36 @@ class TrifaToxService { val want_bytes = buf.size val sample_count = want_bytes / 2 - try - { - AudioSelectOutBox.semaphore_audio_out_convert.acquire_passthru() - if (AudioSelectOutBox.semaphore_audio_out_convert_active_threads >= AudioSelectOutBox.semaphore_audio_out_convert_max_active_threads) - { - Log.i(TAG, "()PLAY_ngc_audio_frame:too many threads running: " + AudioSelectOutBox.semaphore_audio_out_convert_active_threads) - AudioSelectOutBox.semaphore_audio_out_convert.release_passthru() - continue - } - AudioSelectOutBox.semaphore_audio_out_convert.release_passthru() - } catch (e: java.lang.Exception) + + // HINT: this acutally plays incoming Audio + // HINT: this may block!! + val bytes_actually_written = AudioSelectOutBox.sourceDataLine.write(buf, 0, want_bytes) + if (bytes_actually_written != want_bytes) { - AudioSelectOutBox.semaphore_audio_out_convert.release_passthru() + // Log.i(TAG, "()PLAY_ngc_audio_frame:bytes_actually_written=" + bytes_actually_written + " want_bytes=" + want_bytes) } - val t_ngc_audio_pcm_play = Thread{ - try - { - AudioSelectOutBox.semaphore_audio_out_convert.acquire_passthru() - AudioSelectOutBox.semaphore_audio_out_convert_active_threads++ - AudioSelectOutBox.semaphore_audio_out_convert.release_passthru() - } catch (e: java.lang.Exception) - { - AudioSelectOutBox.semaphore_audio_out_convert.release_passthru() - } - // HINT: this acutally plays incoming Audio - // HINT: this may block!! - try - { - val bytes_actually_written = AudioSelectOutBox.sourceDataLine.write(buf, 0, want_bytes) - if (bytes_actually_written != want_bytes) - { - Log.i(TAG, "()PLAY_ngc_audio_frame:bytes_actually_written=" + bytes_actually_written + " want_bytes=" + want_bytes) - } - } catch (e: java.lang.Exception) - { - Log.i(TAG, "()PLAY_ngc_audio_frame:sourceDataLine.write:EE:" + e.message) // e.printStackTrace(); - } - try - { - AudioSelectOutBox.semaphore_audio_out_convert.acquire_passthru() - AudioSelectOutBox.semaphore_audio_out_convert_active_threads-- - AudioSelectOutBox.semaphore_audio_out_convert.release_passthru() - } catch (e: java.lang.Exception) - { - Log.i(TAG, "()PLAY_ngc_audio_frame:--:EEEEEE") - AudioSelectOutBox.semaphore_audio_out_convert.release_passthru() - } - var global_audio_out_vu: Float = MainActivity.AUDIO_VU_MIN_VALUE - if (sample_count > 0) - { - val vu_value = AudioBar.audio_vu(buf, sample_count) - global_audio_out_vu = if (vu_value > MainActivity.AUDIO_VU_MIN_VALUE) - { - vu_value - } else + update_audio_bar++ + if (update_audio_bar == 2) + { + update_audio_bar = 0 + GlobalScope.launch { + var global_audio_out_vu: Float = MainActivity.AUDIO_VU_MIN_VALUE + if (sample_count > 0) { - 0f + val vu_value = AudioBar.audio_vu(buf, sample_count) + global_audio_out_vu = if (vu_value > MainActivity.AUDIO_VU_MIN_VALUE) + { + vu_value + } else + { + 0f + } } + val global_audio_out_vu_ = global_audio_out_vu + AudioBar.set_cur_value(global_audio_out_vu_.toInt(), AudioBar.audio_out_bar) } - val global_audio_out_vu_ = global_audio_out_vu - AudioBar.set_cur_value(global_audio_out_vu_.toInt(), AudioBar.audio_out_bar) } - t_ngc_audio_pcm_play.start() } catch(e: Exception) { @@ -623,7 +587,6 @@ class TrifaToxService } // -- play incoming bytes -- // -- play incoming bytes -- - sleep(20) if ((HelperGeneric.ngc_video_packet_last_incoming_ts + 5000) < System.currentTimeMillis()) { sleep(200)