Skip to content

Commit

Permalink
Merge pull request #176 from SakulFlee/SakulFlee/issue175
Browse files Browse the repository at this point in the history
Demo: VideoCall; characteristics need to be in a list
  • Loading branch information
SakulFlee authored Dec 10, 2024
2 parents cf719d7 + 4ac4af0 commit b67a613
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
25 changes: 20 additions & 5 deletions Godot Project/Demos/VideoCall/VideoCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public partial class VideoCall : Node
private MatchMaker matchMaker;

private ItemList captureDeviceList;
private ItemList captureModeList;

private TextureRect localVideo;
private Label localFrameLabel;
Expand All @@ -24,7 +25,9 @@ public partial class VideoCall : Node

private CaptureDevices captureDevices;
private CaptureDevice captureDevice;
private VideoCharacteristics characteristics;
private CaptureDeviceDescriptor selectedCaptureDevice;
private VideoCharacteristics selectedCharacteristics;


public override void _EnterTree()
{
Expand All @@ -40,6 +43,8 @@ public override void _EnterTree()

captureDeviceList = GetNode<ItemList>("%CaptureDeviceList");
captureDeviceList.Clear();
captureModeList = GetNode<ItemList>("%CaptureModeList");
captureModeList.Clear();

remoteVideo = GetNode<TextureRect>("%RemoteVideo");
remoteFrameLabel = GetNode<Label>("%LabelRemoteFrame");
Expand Down Expand Up @@ -116,14 +121,24 @@ private async void OnCaptureDeviceSelected(int index)
await captureDevice.StopAsync();
}

var selectedCaptureDevice = captureDevices.EnumerateDescriptors().ElementAt(index);
selectedCaptureDevice = captureDevices.EnumerateDescriptors().ElementAt(index);
GD.Print($"[VideoCall] Device selected: {selectedCaptureDevice}");

characteristics = selectedCaptureDevice.Characteristics[0];
GD.Print($"[VideoCall] Characteristics chosen: {characteristics}");
selectedCharacteristics = null;
foreach (var characteristics in selectedCaptureDevice.Characteristics)
{
captureModeList.Clear();
captureModeList.AddItem(characteristics.ToString());
}
}

private async void OnCaptureModeSelected(int index)
{
selectedCharacteristics = selectedCaptureDevice.Characteristics[index];
GD.Print($"[VideoCall] Characteristics chosen: {selectedCharacteristics}");

captureDevice = await selectedCaptureDevice.OpenAsync(
characteristics,
selectedCharacteristics,
OnNewFrame
);
await captureDevice.StartAsync();
Expand Down
11 changes: 10 additions & 1 deletion Godot Project/Demos/VideoCall/VideoCall.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ custom_minimum_size = Vector2(0, 128)
layout_mode = 2
size_flags_vertical = 10
item_count = 1
item_0/text = "Some webcam here ..."
item_0/text = "Webcam devices go here ..."

[node name="AudioTickTimer" type="Timer" parent="MarginContainer/HBoxContainer/Local"]
unique_name_in_owner = true
Expand Down Expand Up @@ -144,6 +144,14 @@ vertical_alignment = 2
unique_name_in_owner = true
stream = SubResource("AudioStreamGenerator_dml4y")

[node name="CaptureModeList" type="ItemList" parent="MarginContainer/HBoxContainer/Remote"]
unique_name_in_owner = true
custom_minimum_size = Vector2(0, 128)
layout_mode = 2
size_flags_vertical = 10
item_count = 1
item_0/text = "Webcam capture modes go here ..."

[node name="DebugPanel" parent="." instance=ExtResource("2_0o60d")]
unique_name_in_owner = true
visible = false
Expand All @@ -154,3 +162,4 @@ visible = false

[connection signal="item_selected" from="MarginContainer/HBoxContainer/Local/CaptureDeviceList" to="." method="OnCaptureDeviceSelected"]
[connection signal="timeout" from="MarginContainer/HBoxContainer/Local/AudioTickTimer" to="." method="AudioTick"]
[connection signal="item_selected" from="MarginContainer/HBoxContainer/Remote/CaptureModeList" to="." method="OnCaptureModeSelected"]

0 comments on commit b67a613

Please sign in to comment.