Skip to content

Commit cd8a1bd

Browse files
committed
remeber av selected devices
1 parent 51f37f9 commit cd8a1bd

File tree

3 files changed

+176
-29
lines changed

3 files changed

+176
-29
lines changed

src/main/kotlin/Main.kt

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,8 @@ fun App()
348348
val audio_in_sources by remember { mutableStateOf(ArrayList<String>()) }
349349
var video_in_devices by remember { mutableStateOf(ArrayList<String>()) }
350350
val video_in_sources by remember { mutableStateOf(ArrayList<String>()) }
351-
avstatestore.state.audio_in_device
352351
Column {
353-
Text(text = "audio in: " + avstatestore.state.audio_in_device + " " + avstatestore.state.audio_in_source
352+
Text(text = "audio in: " + avstatestore.state.audio_in_device_get() + " " + avstatestore.state.audio_in_source_get()
354353
, fontSize = 13.sp, modifier = Modifier.fillMaxWidth(),
355354
maxLines = 1)
356355
Box {
@@ -379,17 +378,17 @@ fun App()
379378
audio_in_devices.forEach() {
380379
if (it != null)
381380
{
382-
DropdownMenuItem(onClick = { avstatestore.state.audio_in_source = "";audio_in_sources.clear(); avstatestore.state.audio_in_device = it;expanded_a = false }) {
381+
DropdownMenuItem(onClick = { avstatestore.state.audio_in_source_set("");audio_in_sources.clear(); avstatestore.state.audio_in_device_set(it);expanded_a = false }) {
383382
Text(""+it)
384383
}
385384
}
386385
}
387386
}
388387
DropdownMenuItem(
389388
onClick = {
390-
avstatestore.state.audio_in_source = ""
389+
avstatestore.state.audio_in_source_set("")
391390
audio_in_sources.clear()
392-
avstatestore.state.audio_in_device = ""
391+
avstatestore.state.audio_in_device_set("")
393392
expanded_a = false
394393
})
395394
{
@@ -399,7 +398,7 @@ fun App()
399398
}
400399
Box {
401400
IconButton(onClick = {
402-
if ((avstatestore.state.audio_in_device != null) && (avstatestore.state.audio_in_device != ""))
401+
if ((avstatestore.state.audio_in_device_get() != null) && (avstatestore.state.audio_in_device_get() != ""))
403402
{
404403
if (!avstatestore.state.ffmpeg_init_done)
405404
{
@@ -408,7 +407,7 @@ fun App()
408407
avstatestore.state.ffmpeg_init_done = true
409408
}
410409
var audio_in_sources_get: Array<String> = emptyArray()
411-
val tmp = AVActivity.ffmpegav_get_in_sources(avstatestore.state.audio_in_device, 0)
410+
val tmp = AVActivity.ffmpegav_get_in_sources(avstatestore.state.audio_in_device_get(), 0)
412411
if (tmp == null)
413412
{
414413
audio_in_sources_get = emptyArray()
@@ -438,15 +437,15 @@ fun App()
438437
audio_in_sources.forEach() {
439438
if (it != null)
440439
{
441-
DropdownMenuItem(onClick = { avstatestore.state.audio_in_source = it;expanded_as = false }) {
440+
DropdownMenuItem(onClick = { avstatestore.state.audio_in_source_set(it);expanded_as = false }) {
442441
Text(""+it)
443442
}
444443
}
445444
}
446445
}
447446
DropdownMenuItem(
448447
onClick = {
449-
avstatestore.state.audio_in_source = ""
448+
avstatestore.state.audio_in_source_set("")
450449
expanded_as = false
451450
})
452451
{
@@ -456,7 +455,7 @@ fun App()
456455
}
457456

458457

459-
Text("video in: " + avstatestore.state.video_in_device + " " + avstatestore.state.video_in_source
458+
Text("video in: " + avstatestore.state.video_in_device_get() + " " + avstatestore.state.video_in_source_get()
460459
, fontSize = 13.sp, modifier = Modifier.fillMaxWidth(),
461460
maxLines = 1)
462461
Box {
@@ -485,17 +484,17 @@ fun App()
485484
video_in_devices.forEach() {
486485
if (it != null)
487486
{
488-
DropdownMenuItem(onClick = { avstatestore.state.video_in_source = "";video_in_sources.clear(); avstatestore.state.video_in_device = it;expanded_v = false }) {
487+
DropdownMenuItem(onClick = { avstatestore.state.video_in_source_set("");video_in_sources.clear(); avstatestore.state.video_in_device_set(it);expanded_v = false }) {
489488
Text("" + it)
490489
}
491490
}
492491
}
493492
}
494493
DropdownMenuItem(
495494
onClick = {
496-
avstatestore.state.video_in_source = ""
495+
avstatestore.state.video_in_source_set("")
497496
video_in_sources.clear()
498-
avstatestore.state.video_in_device = ""
497+
avstatestore.state.video_in_device_set("")
499498
expanded_v = false
500499
})
501500
{
@@ -505,7 +504,7 @@ fun App()
505504
}
506505
Box {
507506
IconButton(onClick = {
508-
if ((avstatestore.state.video_in_device != null) && (avstatestore.state.video_in_device != ""))
507+
if ((avstatestore.state.video_in_device_get() != null) && (avstatestore.state.video_in_device_get() != ""))
509508
{
510509
if (!avstatestore.state.ffmpeg_init_done)
511510
{
@@ -514,7 +513,7 @@ fun App()
514513
avstatestore.state.ffmpeg_init_done = true
515514
}
516515
var video_in_sources_get: Array<String> = emptyArray()
517-
if (avstatestore.state.video_in_device == "video4linux2,v4l2")
516+
if (avstatestore.state.video_in_device_get() == "video4linux2,v4l2")
518517
{
519518
val tmp = AVActivity.ffmpegav_get_in_sources("v4l2", 1)
520519
if (tmp == null)
@@ -528,7 +527,7 @@ fun App()
528527
}
529528
else
530529
{
531-
val tmp = AVActivity.ffmpegav_get_in_sources(avstatestore.state.video_in_device, 1)
530+
val tmp = AVActivity.ffmpegav_get_in_sources(avstatestore.state.video_in_device_get(), 1)
532531
if (tmp == null)
533532
{
534533
video_in_sources_get = emptyArray()
@@ -538,8 +537,8 @@ fun App()
538537
video_in_sources_get = tmp
539538
}
540539
}
541-
Log.i(TAG, "video_in_device=" + avstatestore.state.video_in_device)
542-
if (avstatestore.state.video_in_device == "x11grab")
540+
Log.i(TAG, "video_in_device=" + avstatestore.state.video_in_device_get())
541+
if (avstatestore.state.video_in_device_get() == "x11grab")
543542
{
544543
video_in_sources_get += listOf(":0.0", ":1.0", ":2.0", ":3.0", ":4.0", ":5.0")
545544
}
@@ -564,15 +563,15 @@ fun App()
564563
video_in_sources.forEach() {
565564
if (it != null)
566565
{
567-
DropdownMenuItem(onClick = { avstatestore.state.video_in_source = it;expanded_vs = false }) {
566+
DropdownMenuItem(onClick = { avstatestore.state.video_in_source_set(it);expanded_vs = false }) {
568567
Text(""+it)
569568
}
570569
}
571570
}
572571
}
573572
DropdownMenuItem(
574573
onClick = {
575-
avstatestore.state.video_in_source = ""
574+
avstatestore.state.video_in_source_set("")
576575
expanded_vs = false
577576
})
578577
{

src/main/kotlin/com/zoffcc/applications/trifa/AVState.kt

Lines changed: 153 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.zoffcc.applications.trifa
22

3+
import global_prefs
34
import kotlinx.coroutines.CoroutineScope
45
import kotlinx.coroutines.flow.MutableStateFlow
56
import kotlinx.coroutines.flow.StateFlow
6-
import org.briarproject.briar.desktop.contact.ContactItem
77

88
data class AVState(val a: Int)
99
{
@@ -27,17 +27,165 @@ data class AVState(val a: Int)
2727
CALLAUDIO_ENDING
2828
}
2929
var ffmpeg_init_done: Boolean = false
30-
var audio_in_device = ""
31-
var audio_in_source = ""
32-
var video_in_device = ""
33-
var video_in_source = ""
30+
private var audio_in_device = ""
31+
private var audio_in_source = ""
32+
private var video_in_device = ""
33+
private var video_in_source = ""
3434
var calling_state = CALL_STATUS.CALL_NONE
3535
var calling_vstate = CALLVIDEO.CALLVIDEO_NONE
3636
var calling_astate = CALLAUDIO.CALLAUDIO_NONE
3737
var call_with_friend_pubkey: String? = null
3838

3939
init
4040
{
41+
load_device_information()
42+
}
43+
44+
fun audio_in_device_get(): String
45+
{
46+
return if (audio_in_device == null) "" else audio_in_device
47+
}
48+
49+
fun audio_in_source_get(): String
50+
{
51+
return if (audio_in_source == null) "" else audio_in_source
52+
}
53+
54+
fun video_in_device_get(): String
55+
{
56+
return if (video_in_device == null) "" else video_in_device
57+
}
58+
59+
fun video_in_source_get(): String
60+
{
61+
return if (video_in_source == null) "" else video_in_source
62+
}
63+
64+
fun audio_in_device_set(value: String?)
65+
{
66+
if (value == null)
67+
{
68+
audio_in_device = ""
69+
}
70+
else
71+
{
72+
audio_in_device = value
73+
}
74+
save_device_information()
75+
}
76+
77+
fun audio_in_source_set(value: String?)
78+
{
79+
if (value == null)
80+
{
81+
audio_in_source = ""
82+
}
83+
else
84+
{
85+
audio_in_source = value
86+
}
87+
save_device_information()
88+
}
89+
90+
fun video_in_device_set(value: String?)
91+
{
92+
if (value == null)
93+
{
94+
video_in_device = ""
95+
}
96+
else
97+
{
98+
video_in_device = value
99+
}
100+
save_device_information()
101+
}
102+
103+
fun video_in_source_set(value: String?)
104+
{
105+
if (value == null)
106+
{
107+
video_in_source = ""
108+
}
109+
else
110+
{
111+
video_in_source = value
112+
}
113+
save_device_information()
114+
}
115+
116+
fun load_device_information()
117+
{
118+
try
119+
{
120+
val tmp = global_prefs.get("main.av.audio_in_device", "")
121+
if (tmp != null)
122+
{
123+
audio_in_device = tmp
124+
}
125+
} catch (_: Exception)
126+
{
127+
}
128+
129+
try
130+
{
131+
val tmp = global_prefs.get("main.av.audio_in_source", "")
132+
if (tmp != null)
133+
{
134+
audio_in_source = tmp
135+
}
136+
} catch (_: Exception)
137+
{
138+
}
139+
140+
try
141+
{
142+
val tmp = global_prefs.get("main.av.video_in_device", "")
143+
if (tmp != null)
144+
{
145+
video_in_device = tmp
146+
}
147+
} catch (_: Exception)
148+
{
149+
}
150+
151+
try
152+
{
153+
val tmp = global_prefs.get("main.av.video_in_source", "")
154+
if (tmp != null)
155+
{
156+
video_in_source = tmp
157+
}
158+
} catch (_: Exception)
159+
{
160+
}
161+
}
162+
163+
fun save_device_information()
164+
{
165+
try
166+
{
167+
global_prefs.put("main.av.audio_in_device", audio_in_device)
168+
} catch (_: Exception)
169+
{
170+
}
171+
try
172+
{
173+
global_prefs.put("main.av.audio_in_source", audio_in_source)
174+
} catch (_: Exception)
175+
{
176+
}
177+
try
178+
{
179+
global_prefs.put("main.av.video_in_device", video_in_device)
180+
} catch (_: Exception)
181+
{
182+
}
183+
try
184+
{
185+
global_prefs.put("main.av.video_in_source", video_in_source)
186+
} catch (_: Exception)
187+
{
188+
}
41189
}
42190
}
43191

src/main/kotlin/com/zoffcc/applications/trifa2/ChatApp.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ fun start_outgoing_video(friendpubkey: String)
163163
println("ffmpeg init: $res")
164164
avstatestore.state.ffmpeg_init_done = true
165165
}
166-
val video_in_device = avstatestore.state.video_in_device
167-
val video_in_source = avstatestore.state.video_in_source
166+
val video_in_device = avstatestore.state.video_in_device_get()
167+
val video_in_source = avstatestore.state.video_in_source_get()
168168
var video_buffer_2: ByteBuffer? = null
169169

170170
if ((video_in_device != null) && (video_in_device != ""))
@@ -192,8 +192,8 @@ fun start_outgoing_video(friendpubkey: String)
192192
AVActivity.ffmpegav_set_JNI_video_buffer2(video_buffer_2_y, video_buffer_2_u, video_buffer_2_v, frame_width_px2, frame_height_px2)
193193

194194

195-
val audio_in_device = avstatestore.state.audio_in_device
196-
val audio_in_source = avstatestore.state.audio_in_source
195+
val audio_in_device = avstatestore.state.audio_in_device_get()
196+
val audio_in_source = avstatestore.state.audio_in_source_get()
197197
var audio_buffer_2: ByteBuffer? = null
198198

199199
if ((audio_in_device != null) && (audio_in_device != ""))

0 commit comments

Comments
 (0)