Skip to content

Commit 8da52c1

Browse files
committed
switch devices during a call
1 parent d4d2753 commit 8da52c1

File tree

1 file changed

+56
-0
lines changed
  • src/main/kotlin/com/zoffcc/applications/trifa

1 file changed

+56
-0
lines changed

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,41 @@ data class AVState(val a: Int)
5555
ffmpeg_init_done_set(false)
5656
}
5757

58+
fun ffmpeg_devices_start()
59+
{
60+
val devices_state_copy: CALL_DEVICES_STATE
61+
semaphore_avstate.acquire((Throwable().stackTrace[0].fileName + ":" + Throwable().stackTrace[0].lineNumber))
62+
devices_state_copy = devices_state
63+
semaphore_avstate.release()
64+
if (devices_state_copy == CALL_DEVICES_STATE.CALL_DEVICES_STATE_CLOSED)
65+
{
66+
if ((video_in_device != null) && (video_in_device != ""))
67+
{
68+
if ((video_in_source != null) && (video_in_source != ""))
69+
{
70+
println("ffmpeg video in device: " + video_in_device + " " + video_in_source)
71+
val res_vd = AVActivity.ffmpegav_open_video_in_device(video_in_device, video_in_source,
72+
CAPTURE_VIDEO_WIDTH, CAPTURE_VIDEO_HEIGHT, CAPTURE_VIDEO_FPS)
73+
println("ffmpeg open video capture device: $res_vd")
74+
}
75+
}
76+
if ((audio_in_device != null) && (audio_in_device != ""))
77+
{
78+
if ((audio_in_source != null) && (audio_in_source != ""))
79+
{
80+
println("ffmpeg audio in device: " + audio_in_device + " " + audio_in_source)
81+
val res_ad = AVActivity.ffmpegav_open_audio_in_device(audio_in_device, audio_in_source)
82+
println("ffmpeg open audio capture device: $res_ad")
83+
}
84+
}
85+
AVActivity.ffmpegav_start_video_in_capture()
86+
AVActivity.ffmpegav_start_audio_in_capture()
87+
}
88+
semaphore_avstate.acquire((Throwable().stackTrace[0].fileName + ":" + Throwable().stackTrace[0].lineNumber))
89+
devices_state = CALL_DEVICES_STATE.CALL_DEVICES_STATE_ACTIVE
90+
semaphore_avstate.release()
91+
}
92+
5893
fun ffmpeg_devices_stop()
5994
{
6095
val devices_state_copy: CALL_DEVICES_STATE
@@ -67,6 +102,10 @@ data class AVState(val a: Int)
67102
AVActivity.ffmpegav_close_audio_in_device()
68103
AVActivity.ffmpegav_stop_video_in_capture()
69104
AVActivity.ffmpegav_close_video_in_device()
105+
AudioBar.set_cur_value(0, AudioBar.audio_in_bar)
106+
AudioBar.set_cur_value(0, AudioBar.audio_out_bar)
107+
VideoOutFrame.clear_video_out_frame()
108+
VideoInFrame.clear_video_in_frame()
70109
}
71110
semaphore_avstate.acquire((Throwable().stackTrace[0].fileName + ":" + Throwable().stackTrace[0].lineNumber))
72111
devices_state = CALL_DEVICES_STATE.CALL_DEVICES_STATE_CLOSED
@@ -133,6 +172,19 @@ data class AVState(val a: Int)
133172
return if (video_in_source == null) "" else video_in_source
134173
}
135174

175+
fun restart_devices()
176+
{
177+
val devices_state_copy: CALL_DEVICES_STATE
178+
semaphore_avstate.acquire((Throwable().stackTrace[0].fileName + ":" + Throwable().stackTrace[0].lineNumber))
179+
devices_state_copy = devices_state
180+
semaphore_avstate.release()
181+
if (devices_state_copy == CALL_DEVICES_STATE.CALL_DEVICES_STATE_ACTIVE)
182+
{
183+
ffmpeg_devices_stop()
184+
ffmpeg_devices_start()
185+
}
186+
}
187+
136188
fun audio_in_device_set(value: String?)
137189
{
138190
if (value == null)
@@ -144,6 +196,7 @@ data class AVState(val a: Int)
144196
audio_in_device = value
145197
}
146198
save_device_information()
199+
restart_devices()
147200
}
148201

149202
fun audio_in_source_set(value: String?)
@@ -157,6 +210,7 @@ data class AVState(val a: Int)
157210
audio_in_source = value
158211
}
159212
save_device_information()
213+
restart_devices()
160214
}
161215

162216
fun video_in_device_set(value: String?)
@@ -170,6 +224,7 @@ data class AVState(val a: Int)
170224
video_in_device = value
171225
}
172226
save_device_information()
227+
restart_devices()
173228
}
174229

175230
fun video_in_source_set(value: String?)
@@ -183,6 +238,7 @@ data class AVState(val a: Int)
183238
video_in_source = value
184239
}
185240
save_device_information()
241+
restart_devices()
186242
}
187243

188244
fun load_device_information()

0 commit comments

Comments
 (0)