Display device controls; device IDs in enum-devices; fix non-OK parse

Display controls (enum/get/set):
- Add PROTO_DISPLAY_CTRL_SCALE/ANCHOR/NO_SIGNAL_FPS constants to protocol.h
- handle_enum_controls: if device index maps to an active display slot,
  return the three display controls (scale, anchor, no_signal_fps)
- handle_get_control: read display control values from slot under mutex
- handle_set_control: write display control values to slot under mutex;
  scale/anchor are applied to the viewer by display_loop_tick each tick

Device IDs in enum-devices output:
- Proto_Display_Device_Info gains device_id field (wire format +2 bytes)
- handle_enum_devices computes device_id = total_v4l2 + display_index
- on_video_node/on_standalone callbacks take int* userdata to print [idx]
- on_display prints [device_id] from the wire field

Bug fix — protocol error on invalid device index:
- proto_read_enum_controls_response: early-return APP_OK after reading
  status if status != OK; error responses have no count/data fields, so
  the CUR_CHECK on count was failing with "payload too short"

Helpers added to main.c:
- count_v4l2_devices(): sum of media vnodes + standalone
- find_display_by_device_idx(): maps flat index to Display_Slot

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-29 22:02:42 +00:00
parent 1066f793e2
commit 8c4cd69443
4 changed files with 155 additions and 11 deletions

View File

@@ -149,9 +149,11 @@ struct Proto_Standalone_Device_Info {
/*
* An active display window (video sink role).
* device_id is the flat device index (follows all V4L2 devices).
* stream_id is the stream being displayed; win_* are current geometry.
*/
struct Proto_Display_Device_Info {
uint16_t device_id;
uint16_t stream_id;
int16_t win_x, win_y;
uint16_t win_w, win_h;
@@ -159,6 +161,15 @@ struct Proto_Display_Device_Info {
uint8_t anchor;
};
/* -------------------------------------------------------------------------
* Display device pseudo-control IDs — used in ENUM_CONTROLS / GET_CONTROL /
* SET_CONTROL for display device indices returned by ENUM_DEVICES.
* ------------------------------------------------------------------------- */
#define PROTO_DISPLAY_CTRL_SCALE 0x00D00001u /* int 0-3: stretch/fit/fill/1:1 */
#define PROTO_DISPLAY_CTRL_ANCHOR 0x00D00002u /* int 0-1: center/topleft */
#define PROTO_DISPLAY_CTRL_NO_SIGNAL_FPS 0x00D00003u /* int 1-60: no-signal animation fps */
struct Proto_Monitor_Info {
int32_t x, y;
uint32_t width, height;
@@ -495,6 +506,7 @@ struct App_Error proto_read_enum_devices_response(
const char *name, uint8_t name_len,
void *userdata),
void (*on_display)(
uint16_t device_id,
uint16_t stream_id,
int16_t win_x, int16_t win_y,
uint16_t win_w, uint16_t win_h,