Skip to content

Commit 2484620

Browse files
committed
feat: add video frame handling
1 parent eb5827c commit 2484620

22 files changed

+1963
-2280
lines changed

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ GO_ARGS := GOOS=linux GOARCH=arm GOARM=7 ARCHFLAGS="-arch arm"
2424
# if BUILDKIT_PATH exists, use buildkit to build
2525
ifneq ($(wildcard $(BUILDKIT_PATH)),)
2626
GO_ARGS := $(GO_ARGS) \
27-
CGO_CFLAGS="-Ijetkvm-native -Ijetkvm-native/ui -I$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/include -I$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/sysroot/usr/include" \
28-
CGO_LDFLAGS="-Ljetkvm-native/build -Ljetkvm-native/build/lib -L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/lib -L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/sysroot/usr/lib -ljknative -lrockit -lrockchip_mpp -lrga -lpthread -lm -llvgl" \
27+
CGO_CFLAGS="-I$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/include -I$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/sysroot/usr/include" \
28+
CGO_LDFLAGS="-L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/lib -L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/sysroot/usr/lib -lrockit -lrockchip_mpp -lrga -lpthread -lm" \
2929
CC="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-gcc" \
3030
LD="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-ld" \
31-
CGO_ENABLED=1
31+
CGO_ENABLED=1
32+
# GO_RELEASE_BUILD_ARGS := $(GO_RELEASE_BUILD_ARGS) -x -work
3233
endif
3334

3435
GO_CMD := $(GO_ARGS) go

display.go

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,35 @@ var (
3030

3131
func updateDisplay() {
3232
nativeInstance.UpdateLabelIfChanged("home_info_ipv4_addr", networkState.IPv4String())
33-
nativeInstance.UpdateLabelIfChanged("home_info_ipv6_addr", networkState.IPv6String())
33+
ipv6 := networkState.IPv6String()
34+
if ipv6 != "" {
35+
nativeInstance.UpdateLabelIfChanged("home_info_ipv6_addr", ipv6)
36+
nativeInstance.ObjShow("home_info_ipv6_addr")
37+
} else {
38+
nativeInstance.UpdateLabelIfChanged("home_info_ipv6_addr", "")
39+
nativeInstance.ObjHide("home_info_ipv6_addr")
40+
}
41+
42+
nativeInstance.ObjHide("menu_btn_network")
43+
nativeInstance.ObjHide("menu_btn_access")
3444

3545
nativeInstance.UpdateLabelIfChanged("home_info_mac_addr", networkState.MACString())
3646

3747
if usbState == "configured" {
38-
nativeInstance.UpdateLabelIfChanged("ui_Home_Footer_Usb_Status_Label", "Connected")
39-
_, _ = nativeInstance.ObjSetState("ui_Home_Footer_Usb_Status_Label", "LV_STATE_DEFAULT")
48+
nativeInstance.UpdateLabelIfChanged("usb_status_label", "Connected")
49+
_, _ = nativeInstance.ObjSetState("usb_status", "LV_STATE_DEFAULT")
4050
} else {
41-
nativeInstance.UpdateLabelIfChanged("ui_Home_Footer_Usb_Status_Label", "Disconnected")
42-
_, _ = nativeInstance.ObjSetState("ui_Home_Footer_Usb_Status_Label", "LV_STATE_USER_2")
51+
nativeInstance.UpdateLabelIfChanged("usb_status_label", "Disconnected")
52+
_, _ = nativeInstance.ObjSetState("usb_status", "LV_STATE_USER_2")
4353
}
4454
if lastVideoState.Ready {
45-
nativeInstance.UpdateLabelIfChanged("ui_Home_Footer_Hdmi_Status_Label", "Connected")
46-
_, _ = nativeInstance.ObjSetState("ui_Home_Footer_Hdmi_Status_Label", "LV_STATE_DEFAULT")
55+
nativeInstance.UpdateLabelIfChanged("hdmi_status_label", "Connected")
56+
_, _ = nativeInstance.ObjSetState("hdmi_status", "LV_STATE_DEFAULT")
4757
} else {
48-
nativeInstance.UpdateLabelIfChanged("ui_Home_Footer_Hdmi_Status_Label", "Disconnected")
49-
_, _ = nativeInstance.ObjSetState("ui_Home_Footer_Hdmi_Status_Label", "LV_STATE_USER_2")
58+
nativeInstance.UpdateLabelIfChanged("hdmi_status_label", "Disconnected")
59+
_, _ = nativeInstance.ObjSetState("hdmi_status", "LV_STATE_USER_2")
5060
}
51-
nativeInstance.UpdateLabelIfChanged("ui_Home_Header_Cloud_Status_Label", fmt.Sprintf("%d active", actionSessions))
61+
nativeInstance.UpdateLabelIfChanged("cloud_status_label", fmt.Sprintf("%d active", actionSessions))
5262

5363
if networkState.IsUp() {
5464
nativeInstance.SwitchToScreenIf("home_screen", []string{"no_network_screen", "boot_screen"})
@@ -57,20 +67,20 @@ func updateDisplay() {
5767
}
5868

5969
if cloudConnectionState == CloudConnectionStateNotConfigured {
60-
_, _ = nativeInstance.ObjHide("ui_Home_Header_Cloud_Status_Icon")
70+
_, _ = nativeInstance.ObjHide("cloud_status_icon")
6171
} else {
62-
_, _ = nativeInstance.ObjShow("ui_Home_Header_Cloud_Status_Icon")
72+
_, _ = nativeInstance.ObjShow("cloud_status_icon")
6373
}
6474

6575
switch cloudConnectionState {
6676
case CloudConnectionStateDisconnected:
67-
_, _ = nativeInstance.ImgSetSrc("ui_Home_Header_Cloud_Status_Icon", "cloud_disconnected.png")
77+
_, _ = nativeInstance.ImgSetSrc("cloud_status_icon", "cloud_disconnected")
6878
stopCloudBlink()
6979
case CloudConnectionStateConnecting:
70-
_, _ = nativeInstance.ImgSetSrc("ui_Home_Header_Cloud_Status_Icon", "cloud.png")
80+
_, _ = nativeInstance.ImgSetSrc("cloud_status_icon", "cloud")
7181
startCloudBlink()
7282
case CloudConnectionStateConnected:
73-
_, _ = nativeInstance.ImgSetSrc("ui_Home_Header_Cloud_Status_Icon", "cloud.png")
83+
_, _ = nativeInstance.ImgSetSrc("cloud_status_icon", "cloud")
7484
stopCloudBlink()
7585
}
7686
}
@@ -94,9 +104,9 @@ func startCloudBlink() {
94104
if cloudConnectionState != CloudConnectionStateConnecting {
95105
continue
96106
}
97-
_, _ = nativeInstance.ObjFadeOut("ui_Home_Header_Cloud_Status_Icon", 1000)
107+
_, _ = nativeInstance.ObjFadeOut("cloud_status_icon", 1000)
98108
time.Sleep(1000 * time.Millisecond)
99-
_, _ = nativeInstance.ObjFadeIn("ui_Home_Header_Cloud_Status_Icon", 1000)
109+
_, _ = nativeInstance.ObjFadeIn("cloud_status_icon", 1000)
100110
time.Sleep(1000 * time.Millisecond)
101111
}
102112
}()
@@ -146,14 +156,14 @@ func waitCtrlAndRequestDisplayUpdate(shouldWakeDisplay bool) {
146156

147157
func updateStaticContents() {
148158
//contents that never change
149-
nativeInstance.UpdateLabelIfChanged("ui_Home_Content_Mac", networkState.MACString())
159+
nativeInstance.UpdateLabelIfChanged("home_info_mac_addr", networkState.MACString())
150160
systemVersion, appVersion, err := GetLocalVersion()
151161
if err == nil {
152-
nativeInstance.UpdateLabelIfChanged("ui_About_Content_Operating_System_Version_ContentLabel", systemVersion.String())
153-
nativeInstance.UpdateLabelIfChanged("ui_About_Content_App_Version_Content_Label", appVersion.String())
162+
nativeInstance.UpdateLabelIfChanged("boot_screen_version", systemVersion.String())
163+
nativeInstance.UpdateLabelIfChanged("boot_screen_app_version", appVersion.String())
154164
}
155165

156-
nativeInstance.UpdateLabelIfChanged("ui_Status_Content_Device_Id_Content_Label", GetDeviceID())
166+
nativeInstance.UpdateLabelIfChanged("boot_screen_device_id", GetDeviceID())
157167
}
158168

159169
// setDisplayBrightness sets /sys/class/backlight/backlight/brightness to alter

internal/logging/sse.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
this.statsElement = statsElement;
129129
this.stream = null;
130130
this.reconnectAttempts = 0;
131-
this.maxReconnectAttempts = 10;
131+
this.maxReconnectAttempts = 500;
132132
this.reconnectDelay = 1000; // Start with 1 second
133133
this.maxReconnectDelay = 30000; // Max 30 seconds
134134
this.isConnecting = false;

internal/native/cgo/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ FetchContent_Declare(
4141
FetchContent_MakeAvailable(lv_drivers)
4242

4343
# Get source files, excluding CMake generated files
44-
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.c")
44+
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.c" "ui/*.c")
4545
list(FILTER sources EXCLUDE REGEX "CMakeFiles.*CompilerId.*\\.c$")
4646

47-
add_library(jknative STATIC ${sources} ${CMAKE_CURRENT_SOURCE_DIR}/jknative.h)
47+
add_library(jknative STATIC ${sources} ${CMAKE_CURRENT_SOURCE_DIR}/ctrl.h)
4848

4949
# Include directories
5050
target_include_directories(jknative PRIVATE

internal/native/cgo/ctrl.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,28 @@
77
#include <pthread.h>
88
#include <stdint.h>
99
#include <fcntl.h>
10-
#include "frozen.h"
1110
#include "video.h"
1211
#include "screen.h"
1312
#include "edid.h"
1413
#include "ctrl.h"
1514
#include <lvgl.h>
15+
#include "log.h"
16+
#include "log_handler.h"
1617

1718
jetkvm_video_state_t state;
1819
jetkvm_video_state_handler_t *video_state_handler = NULL;
1920

21+
jetkvm_video_handler_t *video_handler = NULL;
22+
23+
24+
void jetkvm_set_log_handler(jetkvm_log_handler_t *handler) {
25+
log_set_handler(handler);
26+
}
27+
28+
void jetkvm_set_video_handler(jetkvm_video_handler_t *handler) {
29+
video_handler = handler;
30+
}
31+
2032
void report_video_format(bool ready, const char *error, u_int16_t width, u_int16_t height, double frame_per_second)
2133
{
2234
state.ready = ready;
@@ -29,6 +41,21 @@ void report_video_format(bool ready, const char *error, u_int16_t width, u_int16
2941
}
3042
}
3143

44+
int socket_send_frame(const uint8_t *frame, ssize_t len)
45+
{
46+
if (video_handler != NULL) {
47+
(*video_handler)(frame, len);
48+
} else {
49+
log_error("video handler is not set");
50+
}
51+
return 0;
52+
// if (video_client_fd <= 0)
53+
// {
54+
// return -1;
55+
// }
56+
// return send(video_client_fd, frame, len, 0);
57+
}
58+
3259
/**
3360
* @brief Convert a hexadecimal string to an array of uint8_t bytes
3461
*
@@ -284,6 +311,10 @@ int jetkvm_video_set_quality_factor(float quality_factor) {
284311
return 0;
285312
}
286313

314+
float jetkvm_video_get_quality_factor() {
315+
return video_get_quality_factor();
316+
}
317+
287318
int jetkvm_video_set_edid(const char *edid_hex) {
288319
uint8_t edid[256];
289320
int edid_len = hex_to_bytes(edid_hex, edid, 256);

internal/native/cgo/ctrl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define VIDEO_DAEMON_CTRL_H
33

44
#include <stdbool.h>
5+
#include <stdint.h>
56
#include <sys/types.h>
67

78
typedef struct
@@ -14,6 +15,12 @@ typedef struct
1415
} jetkvm_video_state_t;
1516

1617
typedef void (jetkvm_video_state_handler_t)(jetkvm_video_state_t *state);
18+
typedef void (jetkvm_log_handler_t)(int level, const char *filename, const char *funcname, int line, const char *message);
19+
20+
typedef void (jetkvm_video_handler_t)(const uint8_t *frame, ssize_t len);
21+
22+
void jetkvm_set_log_handler(jetkvm_log_handler_t *handler);
23+
void jetkvm_set_video_handler(jetkvm_video_handler_t *handler);
1724

1825
void jetkvm_ui_init();
1926
void jetkvm_ui_tick();
@@ -37,6 +44,7 @@ void jetkvm_video_shutdown();
3744
void jetkvm_video_start();
3845
void jetkvm_video_stop();
3946
int jetkvm_video_set_quality_factor(float quality_factor);
47+
float jetkvm_video_get_quality_factor();
4048
int jetkvm_video_set_edid(const char *edid_hex);
4149
char *jetkvm_video_get_edid_hex();
4250
jetkvm_video_state_t *jetkvm_video_get_status();

internal/native/cgo/edid.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "edid.h"
2+
#include "log.h"
23

34
#include <stdio.h>
45
#include <stdbool.h>
@@ -172,7 +173,7 @@ const char *videoc_log_status()
172173
}
173174
else
174175
{
175-
printf("Failed to read kernel log\n");
176+
log_error("Failed to read kernel log\n");
176177
return NULL;
177178
}
178179

0 commit comments

Comments
 (0)