From 799992d4909423331f8789e8a280c4a7197875e4 Mon Sep 17 00:00:00 2001 From: zoff99 Date: Sun, 7 Jan 2024 19:53:29 +0100 Subject: [PATCH 1/4] less av play buffer --- src/main/java/com/zoffcc/applications/trifa/TRIFAGlobals.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/zoffcc/applications/trifa/TRIFAGlobals.java b/src/main/java/com/zoffcc/applications/trifa/TRIFAGlobals.java index 3148ca7f..d7b66ea2 100644 --- a/src/main/java/com/zoffcc/applications/trifa/TRIFAGlobals.java +++ b/src/main/java/com/zoffcc/applications/trifa/TRIFAGlobals.java @@ -66,7 +66,7 @@ public class TRIFAGlobals public final static int ABSOLUTE_MINIMUM_GLOBAL_VIDEO_BITRATE = 95; public final static int NORMAL_GLOBAL_INCOMING_AV_BUFFER_MS = 0; - public final static int HIGH_GLOBAL_INCOMING_AV_BUFFER_MS = 500; + public final static int HIGH_GLOBAL_INCOMING_AV_BUFFER_MS = 60; final static int HIGHER_GLOBAL_AUDIO_BITRATE = 128; final static int NORMAL_GLOBAL_AUDIO_BITRATE = 16; // 64; From 4a8b12bb3cf6dce88a601037ea184334ba40ec09 Mon Sep 17 00:00:00 2001 From: zoff99 Date: Sun, 7 Jan 2024 21:30:21 +0100 Subject: [PATCH 2/4] WIP: fix some message and msgV3 issues --- .../applications/trifa/HelperMessage.java | 13 ++++++-- .../applications/trifa/HelperGeneric.kt | 7 +++++ .../zoffcc/applications/trifa/MainActivity.kt | 31 ++++++++++++++----- .../applications/trifa/TrifaToxService.kt | 2 +- 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/zoffcc/applications/trifa/HelperMessage.java b/src/main/java/com/zoffcc/applications/trifa/HelperMessage.java index c68de40e..2aa3cf96 100644 --- a/src/main/java/com/zoffcc/applications/trifa/HelperMessage.java +++ b/src/main/java/com/zoffcc/applications/trifa/HelperMessage.java @@ -481,19 +481,25 @@ public static void take_screen_shot_with_selection(final String selected_friend_ public static MainActivity.Companion.send_message_result tox_friend_send_message_wrapper(final String friend_pubkey, int a_TOX_MESSAGE_TYPE, String message, long timestamp_unixtime_seconds) { Log.i(TAG, "tox_friend_send_message_wrapper:" + friend_pubkey); + FriendList f = main_get_friend(friend_pubkey); + if (f == null) + { + return null; + } + long friendnum_to_use = tox_friend_by_public_key(friend_pubkey); boolean need_call_push_url = false; - final long fcap = tox_friend_get_capabilities(friendnum_to_use); final long fconnstatus = tox_friend_get_connection_status(friendnum_to_use); boolean msgv1 = true; - if ((fcap & TOX_CAPABILITY_MSGV2) != 0) + if ((f.capabilities & TOX_CAPABILITY_MSGV2) != 0) { msgv1 = false; } + Log.i(TAG, "tox_friend_send_message_wrapper:msgv1=" + msgv1); - Log.i(TAG, "tox_friend_send_message_wrapper:f conn" + fconnstatus); + Log.i(TAG, "tox_friend_send_message_wrapper:f conn=" + fconnstatus); if (fconnstatus == TOX_CONNECTION_NONE.value) { String relay_pubkey = HelperRelay.get_relay_for_friend(friend_pubkey); @@ -526,6 +532,7 @@ public static MainActivity.Companion.send_message_result tox_friend_send_message result.msg_v2 = false; result.msg_hash_hex = ""; result.msg_hash_v3_hex = bytebuffer_to_hexstring(hash_bytes, true); + Log.i(TAG, "tox_friend_send_message_wrapper:msg_hash_v3_hex=" + result.msg_hash_v3_hex); result.raw_message_buf_hex = ""; if (need_call_push_url) diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/HelperGeneric.kt b/src/main/kotlin/com/zoffcc/applications/trifa/HelperGeneric.kt index cea60fc1..a049fbcd 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/HelperGeneric.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/HelperGeneric.kt @@ -519,21 +519,25 @@ object HelperGeneric { } if (result.msg_v2) { + Log.i(TAG, "send_message_onclick:2: msg_v2=" + m.msg_version) m.msg_version = 1 } else { + Log.i(TAG, "send_message_onclick:2: msg_v2=" + m.msg_version) m.msg_version = 0 } if (result.msg_hash_hex != null && !result.msg_hash_hex.equals("", true)) { // msgV2 message ----------- m.msg_id_hash = result.msg_hash_hex + Log.i(TAG, "send_message_onclick:2: msg_id_hash=" + m.msg_id_hash) // msgV2 message ----------- } if (result.msg_hash_v3_hex != null && !result.msg_hash_v3_hex.equals("", true)) { // msgV3 message ----------- m.msg_idv3_hash = result.msg_hash_v3_hex + Log.i(TAG, "send_message_onclick:2: msg_idv3_hash=" + m.msg_idv3_hash) // msgV3 message ----------- } if (result.raw_message_buf_hex != null && !result.raw_message_buf_hex.equals("", true)) @@ -541,6 +545,7 @@ object HelperGeneric { // save raw message bytes of this v2 msg into the database // we need it if we want to resend it later m.raw_msgv2_bytes = result.raw_message_buf_hex + Log.i(TAG, "send_message_onclick:2: raw_msgv2_bytes=" + m.raw_msgv2_bytes) } // TODO: typing indicator **// stop_self_typing_indicator_s() var row_id: Long = -1 @@ -600,11 +605,13 @@ object HelperGeneric { { m.resend_count++ update_message_in_db_resend_count(m) + Log.i(TAG, "tox_friend_resend_msgv3_wrapper:1: msg_idv3_hash=" + m.msg_idv3_hash) return false } if (m.msg_idv3_hash.length < TOX_HASH_LENGTH) { m.resend_count++ + Log.i(TAG, "tox_friend_resend_msgv3_wrapper:2: msg_idv3_hash=" + m.msg_idv3_hash) update_message_in_db_resend_count(m) return false } diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt b/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt index 52177587..1fe998cb 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt @@ -1554,6 +1554,7 @@ class MainActivity @JvmStatic fun android_tox_callback_friend_read_receipt_cb_method(friend_number: Long, message_id: Long) { + Log.i(TAG, "friend_read_receipt:friend_number=" + friend_number + " message_id=" + message_id) try { val toxpk = tox_friend_get_public_key(friend_number)!!.uppercase() @@ -1577,11 +1578,11 @@ class MainActivity Log.i(TAG, "friend_read_receipt:m:message_id=" + m.message_id + " text=" + m.text + " friendpubkey=" + m.tox_friendpubkey + " read=" + m.read + " direction=" + m.direction); if (m != null) { + m.rcvd_timestamp = System.currentTimeMillis() + m.read = true Log.i(TAG, "friend_read_receipt:friend:" + get_friend_name_from_num(friend_number) + " message:" + m.text + " m=" + m); - m.rcvd_timestamp = System.currentTimeMillis() - m.read = true update_message_in_db_read_rcvd_timestamp_rawmsgbytes(m) // TODO: update message in UI } @@ -1628,7 +1629,7 @@ class MainActivity @JvmStatic fun android_tox_callback_friend_message_cb_method(friend_number: Long, message_type: Int, friend_message: String?, length: Long, msgV3hash_bin: ByteArray?, message_timestamp: Long) { - // Log.i(TAG, "android_tox_callback_friend_message_cb_method: fn=" + friend_number + " friend_message=" + friend_message) + // Log.i(TAG, "friend_message_cb_method: fn=" + friend_number + " friend_message=" + friend_message) val toxpk = tox_friend_get_public_key(friend_number)!!.uppercase() if ((toxpk == null) || (toxpk.equals("-1", true))) { @@ -1651,6 +1652,7 @@ class MainActivity // HINT: we already have received a message with this hash // still send the msgV3 high level ACK, and then ignore Log.i(TAG, "TOX_MESSAGEv3:ignore double message") + // Log.i(TAG, "send_msgv3_high_level_ack:001") HelperMessage.send_msgv3_high_level_ack(friend_number, msgV3hash_hex_string) return } @@ -1662,7 +1664,8 @@ class MainActivity return } - GlobalScope.launch(Dispatchers.IO) { + //GlobalScope.launch(Dispatchers.IO) { + var new_msgv3_cap = 0 if (msgV3hash_bin != null) { val got_messages_mirrored = orma!!.selectFromMessage(). @@ -1672,21 +1675,32 @@ class MainActivity // msgV3hash_bin + " " + msgV3hash_hex_string); if (got_messages_mirrored > 0) { + Log.i(TAG, "update_friend_msgv3_capability:got_messages_mirrored=" + got_messages_mirrored) update_friend_msgv3_capability(friend_number, 0) - } else + new_msgv3_cap = 0 + } + else { update_friend_msgv3_capability(friend_number, 1) + new_msgv3_cap = 1 } } else { // Log.i(TAG, "update_friend_msgv3_capability:hash0=" + msgV3hash_bin + " " + msgV3hash_hex_string); update_friend_msgv3_capability(friend_number, 0) + new_msgv3_cap = 0 } if (msgV3hash_hex_string != null) { - HelperMessage.send_msgv3_high_level_ack(friend_number, msgV3hash_hex_string); + // Log.i(TAG, "send_msgv3_high_level_ack:002") + if (new_msgv3_cap == 1) + { + // send high level ack only if the friend actually understand it + // and it's not a mirrored high level ACK + HelperMessage.send_msgv3_high_level_ack(friend_number, msgV3hash_hex_string); + } try { // ("msgv3:"+friend_message) @@ -1703,7 +1717,8 @@ class MainActivity } catch (_: Exception) { } - } else + } + else { try { // ("msgv1:"+friend_message) @@ -1721,7 +1736,7 @@ class MainActivity { } } - } + //} } @JvmStatic diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt b/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt index 20bcfc8a..9d6460ae 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt @@ -908,7 +908,7 @@ class TrifaToxService get_friend_name_from_pubkey(m_resend_v1.tox_friendpubkey)) continue } - Log.i(TAG, "resend_v3_messages:tox_friend_resend_msgv3_wrapper:" + m_resend_v1.text + " : m=" + + Log.i(TAG, "resend_v3_messages:tox_friend_resend_msgv3_wrapper:msg_idv3_hash=" + m_resend_v1.msg_idv3_hash + " text=" + m_resend_v1.text + " : m=" + m_resend_v1 + " : " + get_friend_name_from_pubkey(m_resend_v1.tox_friendpubkey)); tox_friend_resend_msgv3_wrapper(m_resend_v1) cur_resend_count_per_iteration++ From b7a7abd73441d764aae55ef254622ffcc83af01a Mon Sep 17 00:00:00 2001 From: zoff99 Date: Mon, 8 Jan 2024 10:43:57 +0100 Subject: [PATCH 3/4] also save incoming PCM to file if debug mode is switched on --- .../com/zoffcc/applications/trifa/MainActivity.kt | 4 ++-- .../zoffcc/applications/trifa/TrifaToxService.kt | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt b/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt index 1fe998cb..13bc580d 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt @@ -136,8 +136,8 @@ class MainActivity // --------- global config --------- // --------- global config --------- - const val CTOXCORE_NATIVE_LOGGING = false // set "false" for release builds - const val AUDIO_PCM_DEBUG_FILES = false // set "false" for release builds + const val CTOXCORE_NATIVE_LOGGING = true // set "false" for release builds + const val AUDIO_PCM_DEBUG_FILES = true // set "false" for release builds // --------- global config --------- // --------- global config --------- diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt b/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt index 9d6460ae..3ed78f2d 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt @@ -75,6 +75,7 @@ import org.briarproject.briar.desktop.contact.GroupPeerItem import set_tox_running_state import toxdatastore import unlock_data_dir_input +import java.io.File import java.nio.ByteBuffer import java.util.* @@ -427,6 +428,18 @@ class TrifaToxService // sleep(30) } + if (MainActivity.AUDIO_PCM_DEBUG_FILES) + { + val f = File("/tmp/toxaudio_play.txt") + try + { + f.appendBytes(buf) + } catch (e: Exception) + { + e.printStackTrace() + } + } + update_audio_bar++ if (update_audio_bar >= 1) { From bb5e828cdd6e6619fb9d786f36156d19d712c338 Mon Sep 17 00:00:00 2001 From: zoff99 Date: Mon, 8 Jan 2024 21:30:25 +0100 Subject: [PATCH 4/4] set debugging flags OFF again --- src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt b/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt index 13bc580d..1fe998cb 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt @@ -136,8 +136,8 @@ class MainActivity // --------- global config --------- // --------- global config --------- - const val CTOXCORE_NATIVE_LOGGING = true // set "false" for release builds - const val AUDIO_PCM_DEBUG_FILES = true // set "false" for release builds + const val CTOXCORE_NATIVE_LOGGING = false // set "false" for release builds + const val AUDIO_PCM_DEBUG_FILES = false // set "false" for release builds // --------- global config --------- // --------- global config ---------