diff --git a/programs/dtchat/localui.c b/programs/dtchat/localui.c index 632b6716..a05cf4a4 100644 --- a/programs/dtchat/localui.c +++ b/programs/dtchat/localui.c @@ -591,6 +591,59 @@ call_stop(DtLocal *local, Peer *peer) peer->call_state = DC_CALL_ENDED; } +/* the Camera button: the next source (the camera nodes, then the pattern) */ +static const char * +call_camera_cycle(void *arg) +{ + Peer *peer = arg; + static const char *const sources[] = { + "/dev/video0", "/dev/video1", "/dev/video2", "/dev/video3", + "pattern" + }; + int cur = -1; + int k; + char err[256] = ""; + + if (peer == NULL || peer->call == NULL) + return NULL; + if (peer->capture != NULL) { + const char *b = dc_capture_backend(peer->capture); + unsigned int i; + + if (strcmp(b, "test-pattern") == 0) { + cur = 4; + } else { + for (i = 0; i < 4; i++) + if (strcmp(b, sources[i]) == 0) { + cur = (int)i; + break; + } + } + if (strncmp(b, "v4l2:", 5) == 0) { + int n = -1; + + if (sscanf(b, "v4l2:/dev/video%d", &n) == 1 && + n >= 0 && n <= 3) + cur = n; + } + } + for (k = 1; k <= 5; k++) { + int idx = (cur + k + 5) % 5; + DcCapture *cap = dc_capture_open(DC_VIDEO_W, DC_VIDEO_H, + DC_VIDEO_FPS, sources[idx], err, sizeof(err)); + + if (cap == NULL) + continue; + dc_capture_close(peer->capture); + peer->capture = cap; + if (getenv("DTCHAT_CALL_DEBUG") != NULL) + fprintf(stderr, "call %s: camera %s\n", peer->name, + dc_capture_backend(cap)); + return dc_capture_backend(cap); + } + return NULL; +} + static void call_hangup_cb(void *arg) { @@ -688,6 +741,8 @@ start_call(DtLocal *local, Peer *peer, DcLocalConn *conn, int initiator) MCDE_SYS_PCM_DEFAULT, DC_AUDIO_RATE, 1); peer->call_window = dtchat_call_window_create(dtchat_ui_shell( local->ui), peer->call, peer->name, call_hangup_cb, peer); + dtchat_call_window_set_camera_hook(peer->call_window, + call_camera_cycle, peer); if (initiator) { dtchat_call_window_set_status(peer->call_window, "ringing"); @@ -1155,7 +1210,8 @@ pump_cb(XtPointer client, XtIntervalId *id) peer->call_state = state; if (state == DC_CALL_IN_CALL) { dtchat_call_window_set_status( - peer->call_window, "in the call"); + peer->call_window, + "in the call - LAN only, no relay"); call_debug(local, peer, "in call"); call_video_start(local, peer); if (peer->call_initiator && diff --git a/programs/dtchat/ui_call.c b/programs/dtchat/ui_call.c index db343151..18685210 100644 --- a/programs/dtchat/ui_call.c +++ b/programs/dtchat/ui_call.c @@ -58,7 +58,10 @@ struct DtCallWindow { int dirty; XtIntervalId size_timer; Widget video_toggle; + Widget camera; Widget full_toggle; + DtCallCameraFn camera_fn; + void *camera_arg; int video_on; int fullscreen; int screen_w; @@ -242,6 +245,29 @@ video_cb(Widget widget, XtPointer client, XtPointer call) dtchat_call_window_set_status(w, "video is off"); } +static void +camera_cb(Widget widget, XtPointer client, XtPointer call) +{ + DtCallWindow *w = client; + const char *name; + + (void)widget; + (void)call; + if (w->camera_fn == NULL) + return; + name = w->camera_fn(w->camera_arg); + if (name == NULL) { + dtchat_call_window_set_status(w, "no camera"); + return; + } + { + char line[160]; + + snprintf(line, sizeof(line), "video source: %s", name); + dtchat_call_window_set_status(w, line); + } +} + static void full_cb(Widget widget, XtPointer client, XtPointer call) { @@ -416,6 +442,13 @@ dtchat_call_window_create(Widget parent, DcMediaCall *call, XmNleftOffset, 12, XmNtopOffset, 6, NULL); XtAddCallback(w->video_toggle, XmNvalueChangedCallback, video_cb, w); XtManageChild(w->video_toggle); + w->camera = XmCreatePushButton(buttons, "camera", NULL, 0); + set_label(w->camera, "Camera"); + XtVaSetValues(w->camera, XmNtopAttachment, XmATTACH_FORM, + XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, + w->video_toggle, XmNleftOffset, 12, XmNtopOffset, 6, NULL); + XtAddCallback(w->camera, XmNactivateCallback, camera_cb, w); + XtManageChild(w->camera); w->full_toggle = XmCreateToggleButton(buttons, "full", NULL, 0); set_label(w->full_toggle, "Full screen"); XtVaSetValues(w->full_toggle, XmNtopAttachment, XmATTACH_FORM, @@ -448,6 +481,7 @@ dtchat_call_window_create(Widget parent, DcMediaCall *call, XtSetSensitive(w->talk, False); XtSetSensitive(w->hangup, False); XtSetSensitive(w->answer, False); + XtSetSensitive(w->camera, False); } XtManageChild(form); XtPopup(w->shell, XtGrabNone); @@ -546,6 +580,18 @@ dtchat_call_window_has_frame(const DtCallWindow *w) return w != NULL ? w->has_frame : 0; } +void +dtchat_call_window_set_camera_hook(DtCallWindow *w, DtCallCameraFn fn, + void *arg) +{ + if (w == NULL) + return; + w->camera_fn = fn; + w->camera_arg = arg; + if (w->camera != NULL) + XtSetSensitive(w->camera, fn != NULL ? True : False); +} + void dtchat_call_window_set_incoming(DtCallWindow *w, int incoming) { diff --git a/programs/dtchat/ui_call.h b/programs/dtchat/ui_call.h index 6c94f969..f3b1e803 100644 --- a/programs/dtchat/ui_call.h +++ b/programs/dtchat/ui_call.h @@ -36,5 +36,10 @@ void dtchat_call_window_set_talking(DtCallWindow *window, int on); /* an incoming call: the Answer button becomes sensitive and answers with * dc_call_accept() */ void dtchat_call_window_set_incoming(DtCallWindow *window, int incoming); +/* the Camera button: the hook cycles the source and answers its name, or + * NULL when there is none; it is called with the window's ARG */ +typedef const char *(*DtCallCameraFn)(void *arg); +void dtchat_call_window_set_camera_hook(DtCallWindow *window, + DtCallCameraFn fn, void *arg); #endif /* _Dtchat_ui_call_h */