Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

audio play fixes and other updates #94

Merged
merged 7 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/zoffcc/applications/trifa/CustomSemaphore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
Expand All @@ -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");
}
}
13 changes: 0 additions & 13 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down
16 changes: 11 additions & 5 deletions src/main/kotlin/com/zoffcc/applications/trifa/HelperGeneric.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
19 changes: 12 additions & 7 deletions src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<ByteArray> = 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!
Expand Down Expand Up @@ -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()
Expand All @@ -1277,31 +1282,31 @@ 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:--- DROP:1 !! FULL !! :trigger:" + tox_audio_in_queue.size)
tox_a_queue_full_trigger = true
}
else
{
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
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:-----------:" +
// audio_queue_full_trigger)
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)
}
}
//
}
catch(_: Exception)
{
Expand Down
Loading
Loading