| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
#include "asterisk.h" |
| 86 |
#include "console_video.h" |
| 87 |
#include "asterisk/lock.h" |
| 88 |
#include "asterisk/frame.h" |
| 89 |
#include "asterisk/utils.h" |
| 90 |
#include <math.h> |
| 91 |
|
| 92 |
|
| 93 |
enum { WIN_LOCAL, WIN_REMOTE, WIN_KEYPAD, WIN_SRC1, |
| 94 |
WIN_SRC2, WIN_SRC3, WIN_SRC4, WIN_SRC5, |
| 95 |
WIN_SRC6, WIN_SRC7, WIN_SRC8, WIN_SRC9, WIN_MAX }; |
| 96 |
|
| 97 |
#ifndef HAVE_SDL |
| 98 |
static void show_frame(struct video_desc *env, int out) {} |
| 99 |
static void sdl_setup(struct video_desc *env) {} |
| 100 |
static struct gui_info *cleanup_sdl(struct gui_info* g, int n) { return NULL; } |
| 101 |
static void eventhandler(struct video_desc *env, const char *caption) {} |
| 102 |
static int keypad_cfg_read(struct gui_info *gui, const char *val) { return 0; } |
| 103 |
|
| 104 |
#else |
| 105 |
|
| 106 |
#include <SDL/SDL.h> |
| 107 |
#include <SDL/SDL_syswm.h> |
| 108 |
#ifdef HAVE_SDL_IMAGE |
| 109 |
#include <SDL/SDL_image.h> |
| 110 |
#endif |
| 111 |
|
| 112 |
#ifdef HAVE_X11 |
| 113 |
|
| 114 |
#include <X11/Xlib.h> |
| 115 |
#endif |
| 116 |
|
| 117 |
#define BORDER 5 |
| 118 |
#define SRC_MSG_BD_H 20 |
| 119 |
|
| 120 |
enum kp_type { KP_NONE, KP_RECT, KP_CIRCLE }; |
| 121 |
struct keypad_entry { |
| 122 |
int c; |
| 123 |
int x0, y0, x1, y1, h; |
| 124 |
enum kp_type type; |
| 125 |
}; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
struct display_window { |
| 131 |
SDL_Overlay *bmp; |
| 132 |
SDL_Rect rect; |
| 133 |
}; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
struct thumb_bd { |
| 138 |
SDL_Rect rect; |
| 139 |
struct board *board; |
| 140 |
}; |
| 141 |
|
| 142 |
struct gui_info { |
| 143 |
enum kb_output kb_output; |
| 144 |
struct drag_info drag; |
| 145 |
|
| 146 |
SDL_Surface *screen; |
| 147 |
|
| 148 |
int outfd; |
| 149 |
SDL_Surface *keypad; |
| 150 |
SDL_Rect kp_rect; |
| 151 |
SDL_Surface *font; |
| 152 |
SDL_Rect font_rects[96]; |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
SDL_Rect kp_msg[2]; |
| 161 |
struct board *bd_msg; |
| 162 |
|
| 163 |
SDL_Rect kp_edit[2]; |
| 164 |
struct board *bd_edit; |
| 165 |
|
| 166 |
SDL_Rect kp_dialed[2]; |
| 167 |
struct board *bd_dialed; |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
struct thumb_bd thumb_bd_array[MAX_VIDEO_SOURCES]; |
| 174 |
|
| 175 |
|
| 176 |
int kp_size, kp_used; |
| 177 |
struct keypad_entry *kp; |
| 178 |
|
| 179 |
struct display_window win[WIN_MAX]; |
| 180 |
}; |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
static struct gui_info *cleanup_sdl(struct gui_info *gui, int device_num) |
| 186 |
{ |
| 187 |
int i; |
| 188 |
|
| 189 |
if (gui == NULL) |
| 190 |
return NULL; |
| 191 |
|
| 192 |
|
| 193 |
if (gui->font) { |
| 194 |
SDL_FreeSurface(gui->font); |
| 195 |
gui->font = NULL; |
| 196 |
} |
| 197 |
|
| 198 |
if (gui->outfd > -1) |
| 199 |
close(gui->outfd); |
| 200 |
if (gui->keypad) |
| 201 |
SDL_FreeSurface(gui->keypad); |
| 202 |
gui->keypad = NULL; |
| 203 |
if (gui->kp) |
| 204 |
ast_free(gui->kp); |
| 205 |
|
| 206 |
|
| 207 |
for (i = 0; i < WIN_MAX; i++) { |
| 208 |
if (gui->win[i].bmp) |
| 209 |
SDL_FreeYUVOverlay(gui->win[i].bmp); |
| 210 |
} |
| 211 |
memset(gui, '\0', sizeof(gui)); |
| 212 |
|
| 213 |
|
| 214 |
if (gui->bd_dialed) |
| 215 |
delete_board(gui->bd_dialed); |
| 216 |
if (gui->bd_msg) |
| 217 |
delete_board(gui->bd_msg); |
| 218 |
|
| 219 |
|
| 220 |
for (i = 0; i < device_num; i++) { |
| 221 |
if (gui->thumb_bd_array[i].board) |
| 222 |
delete_board(gui->thumb_bd_array[i].board); |
| 223 |
} |
| 224 |
|
| 225 |
ast_free(gui); |
| 226 |
SDL_Quit(); |
| 227 |
return NULL; |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
#define IS_PRIMARY 1 |
| 236 |
#define IS_SECONDARY 2 |
| 237 |
#define IS_ON 4 |
| 238 |
|
| 239 |
char* src_msgs[] = { |
| 240 |
" OFF", |
| 241 |
"1 OFF", |
| 242 |
" 2 OFF", |
| 243 |
"1+2 OFF", |
| 244 |
" ON", |
| 245 |
"1 ON", |
| 246 |
" 2 ON", |
| 247 |
"1+2 ON", |
| 248 |
}; |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
static void show_frame(struct video_desc *env, int out) |
| 260 |
{ |
| 261 |
AVPicture *p_in, p_out; |
| 262 |
struct fbuf_t *b_in, *b_out; |
| 263 |
SDL_Overlay *bmp; |
| 264 |
struct gui_info *gui = env->gui; |
| 265 |
|
| 266 |
if (!gui) |
| 267 |
return; |
| 268 |
|
| 269 |
if (out == WIN_LOCAL) { |
| 270 |
b_in = &env->enc_in; |
| 271 |
b_out = &env->loc_dpy; |
| 272 |
p_in = NULL; |
| 273 |
} else if (out == WIN_REMOTE) { |
| 274 |
|
| 275 |
AVCodecContext *c; |
| 276 |
if (env->in == NULL) |
| 277 |
return; |
| 278 |
c = env->in->dec_ctx; |
| 279 |
b_in = &env->in->dec_out; |
| 280 |
b_in->pix_fmt = c->pix_fmt; |
| 281 |
b_in->w = c->width; |
| 282 |
b_in->h = c->height; |
| 283 |
|
| 284 |
b_out = &env->rem_dpy; |
| 285 |
p_in = (AVPicture *)env->in->d_frame; |
| 286 |
} else { |
| 287 |
int i = out-WIN_SRC1; |
| 288 |
b_in = env->out.devices[i].dev_buf; |
| 289 |
if (b_in == NULL) |
| 290 |
return; |
| 291 |
p_in = NULL; |
| 292 |
b_out = &env->src_dpy[i]; |
| 293 |
} |
| 294 |
bmp = gui->win[out].bmp; |
| 295 |
SDL_LockYUVOverlay(bmp); |
| 296 |
|
| 297 |
memset(&p_out, '\0', sizeof(p_out)); |
| 298 |
p_out.data[0] = bmp->pixels[0]; |
| 299 |
p_out.data[1] = bmp->pixels[1]; |
| 300 |
p_out.data[2] = bmp->pixels[2]; |
| 301 |
p_out.linesize[0] = bmp->pitches[0]; |
| 302 |
p_out.linesize[1] = bmp->pitches[1]; |
| 303 |
p_out.linesize[2] = bmp->pitches[2]; |
| 304 |
|
| 305 |
my_scale(b_in, p_in, b_out, &p_out); |
| 306 |
|
| 307 |
|
| 308 |
SDL_DisplayYUVOverlay(bmp, &gui->win[out].rect); |
| 309 |
SDL_UnlockYUVOverlay(bmp); |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
enum skin_area { |
| 319 |
|
| 320 |
KEY_PICK_UP = 128, |
| 321 |
KEY_HANG_UP = 129, |
| 322 |
|
| 323 |
KEY_MUTE = 130, |
| 324 |
KEY_AUTOANSWER = 131, |
| 325 |
KEY_SENDVIDEO = 132, |
| 326 |
KEY_LOCALVIDEO = 133, |
| 327 |
KEY_REMOTEVIDEO = 134, |
| 328 |
KEY_FLASH = 136, |
| 329 |
|
| 330 |
|
| 331 |
KEY_MESSAGEBOARD = 140, |
| 332 |
KEY_DIALEDBOARD = 141, |
| 333 |
KEY_EDITBOARD = 142, |
| 334 |
|
| 335 |
KEY_GUI_CLOSE = 199, |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
KEY_KEYPAD = 200, |
| 340 |
KEY_FONT = 201, |
| 341 |
KEY_MESSAGE = 202, |
| 342 |
KEY_DIALED = 203, |
| 343 |
KEY_EDIT = 204, |
| 344 |
|
| 345 |
#ifdef notyet |
| 346 |
KEY_AUDIO_SRCS = 210, |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
#endif |
| 352 |
|
| 353 |
KEY_FREEZE = 220, |
| 354 |
KEY_CAPTURE = 221, |
| 355 |
KEY_PIP = 230, |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
KEY_SRCS_WIN = 231, |
| 360 |
|
| 361 |
KEY_OUT_OF_KEYPAD = 241, |
| 362 |
KEY_REM_DPY = 242, |
| 363 |
KEY_LOC_DPY = 243, |
| 364 |
KEY_RESET = 253, |
| 365 |
KEY_NONE = 254, |
| 366 |
KEY_DIGIT_BACKGROUND = 255, |
| 367 |
}; |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
static void keypad_digit(struct video_desc *env, int digit) |
| 375 |
{ |
| 376 |
if (env->owner) { |
| 377 |
struct ast_frame f = { AST_FRAME_DTMF, 0 }; |
| 378 |
|
| 379 |
f.subclass = digit; |
| 380 |
ast_queue_frame(env->owner, &f); |
| 381 |
} else { |
| 382 |
char buf[2] = { digit, '\0' }; |
| 383 |
if (env->gui->bd_msg) |
| 384 |
print_message(env->gui->bd_msg, buf); |
| 385 |
} |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
static char *keypad_toggle(struct video_desc *env, int index) |
| 390 |
{ |
| 391 |
ast_log(LOG_WARNING, "keypad_toggle(%i) called\n", index); |
| 392 |
|
| 393 |
switch (index) { |
| 394 |
case KEY_SENDVIDEO: |
| 395 |
env->out.sendvideo = !env->out.sendvideo; |
| 396 |
break; |
| 397 |
|
| 398 |
case KEY_PIP: |
| 399 |
env->out.picture_in_picture = !env->out.picture_in_picture; |
| 400 |
break; |
| 401 |
|
| 402 |
case KEY_MUTE: |
| 403 |
ast_cli_command(env->gui->outfd, "console mute toggle"); |
| 404 |
break; |
| 405 |
|
| 406 |
case KEY_FREEZE: |
| 407 |
env->frame_freeze = !env->frame_freeze; |
| 408 |
break; |
| 409 |
|
| 410 |
#ifdef notyet |
| 411 |
case KEY_AUTOANSWER: { |
| 412 |
struct chan_oss_pvt *o = find_desc(oss_active); |
| 413 |
o->autoanswer = !o->autoanswer; |
| 414 |
} |
| 415 |
break; |
| 416 |
#endif |
| 417 |
} |
| 418 |
return NULL; |
| 419 |
} |
| 420 |
|
| 421 |
char *console_do_answer(int fd); |
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
static void keypad_pick_up(struct video_desc *env) |
| 433 |
{ |
| 434 |
struct gui_info *gui = env->gui; |
| 435 |
|
| 436 |
ast_log(LOG_WARNING, "keypad_pick_up called\n"); |
| 437 |
|
| 438 |
if (env->owner) { |
| 439 |
ast_cli_command(gui->outfd, "console answer"); |
| 440 |
} else { |
| 441 |
char buf[160]; |
| 442 |
const char *who = ast_skip_blanks(read_message(gui->bd_msg)); |
| 443 |
buf[sizeof(buf) - 1] = '\0'; |
| 444 |
snprintf(buf, sizeof(buf), "console dial %s", who); |
| 445 |
ast_log(LOG_WARNING, "doing <%s>\n", buf); |
| 446 |
print_message(gui->bd_dialed, "\n"); |
| 447 |
print_message(gui->bd_dialed, who); |
| 448 |
reset_board(gui->bd_msg); |
| 449 |
ast_cli_command(gui->outfd, buf); |
| 450 |
} |
| 451 |
} |
| 452 |
|
| 453 |
#if 0 |
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
static int gui_output(struct video_desc *env, const char *text) |
| 473 |
{ |
| 474 |
return 1; |
| 475 |
} |
| 476 |
#endif |
| 477 |
|
| 478 |
static int video_geom(struct fbuf_t *b, const char *s); |
| 479 |
static void sdl_setup(struct video_desc *env); |
| 480 |
static int kp_match_area(const struct keypad_entry *e, int x, int y); |
| 481 |
|
| 482 |
static void set_drag(struct drag_info *drag, int x, int y, enum drag_window win) |
| 483 |
{ |
| 484 |
drag->x_start = x; |
| 485 |
drag->y_start = y; |
| 486 |
drag->drag_window = win; |
| 487 |
} |
| 488 |
|
| 489 |
static int update_device_info(struct video_desc *env, int i) |
| 490 |
{ |
| 491 |
reset_board(env->gui->thumb_bd_array[i].board); |
| 492 |
print_message(env->gui->thumb_bd_array[i].board, |
| 493 |
src_msgs[env->out.devices[i].status_index]); |
| 494 |
return 0; |
| 495 |
} |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
static int switch_video_out(struct video_desc *env, int index, Uint8 button) |
| 517 |
{ |
| 518 |
int *p; |
| 519 |
|
| 520 |
if (index >= env->out.device_num) { |
| 521 |
ast_log(LOG_WARNING, "no devices\n"); |
| 522 |
return 1; |
| 523 |
} |
| 524 |
|
| 525 |
p = (button == SDL_BUTTON_LEFT) ? &env->out.device_primary : |
| 526 |
&env->out.device_secondary; |
| 527 |
|
| 528 |
if (index == *p) { |
| 529 |
ast_log(LOG_WARNING, "device %s already selected\n", env->out.devices[index].name); |
| 530 |
return 0; |
| 531 |
} |
| 532 |
ast_log(LOG_WARNING, "switching to %s...\n", env->out.devices[index].name); |
| 533 |
|
| 534 |
if (env->out.devices[index].grabber) { |
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
if (p == &env->out.device_primary) |
| 539 |
env->out.devices[*p].status_index &= ~IS_PRIMARY; |
| 540 |
else |
| 541 |
env->out.devices[*p].status_index &= ~IS_SECONDARY; |
| 542 |
update_device_info(env, *p); |
| 543 |
|
| 544 |
*p = index; |
| 545 |
ast_log(LOG_WARNING, "done\n"); |
| 546 |
|
| 547 |
if (p == &env->out.device_primary) |
| 548 |
env->out.devices[*p].status_index |= IS_PRIMARY; |
| 549 |
else |
| 550 |
env->out.devices[*p].status_index |= IS_SECONDARY; |
| 551 |
update_device_info(env, *p); |
| 552 |
return 0; |
| 553 |
} |
| 554 |
|
| 555 |
ast_log(LOG_WARNING, "device is down\n"); |
| 556 |
return 1; |
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
static int turn_on_off(int index, struct video_desc *env) |
| 571 |
{ |
| 572 |
struct video_device *p = &env->out.devices[index]; |
| 573 |
|
| 574 |
if (index >= env->out.device_num) { |
| 575 |
ast_log(LOG_WARNING, "no devices\n"); |
| 576 |
return 0; |
| 577 |
} |
| 578 |
|
| 579 |
if (!p->grabber) { |
| 580 |
void *g_data; |
| 581 |
struct grab_desc *g; |
| 582 |
int i; |
| 583 |
|
| 584 |
|
| 585 |
for (i = 0; (g = console_grabbers[i]); i++) { |
| 586 |
|
| 587 |
g_data = g->open(p->name, &env->out.loc_src_geometry, env->out.fps); |
| 588 |
if (!g_data) |
| 589 |
continue; |
| 590 |
p->grabber = g; |
| 591 |
p->grabber_data = g_data; |
| 592 |
|
| 593 |
p->status_index |= IS_ON; |
| 594 |
|
| 595 |
update_device_info(env, index); |
| 596 |
return 1; |
| 597 |
} |
| 598 |
return 0; |
| 599 |
} else { |
| 600 |
|
| 601 |
p->grabber_data = p->grabber->close(p->grabber_data); |
| 602 |
p->grabber = NULL; |
| 603 |
|
| 604 |
p->dev_buf = NULL; |
| 605 |
|
| 606 |
p->status_index &= ~IS_ON; |
| 607 |
|
| 608 |
update_device_info(env, index); |
| 609 |
return 2; |
| 610 |
} |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
static void handle_mousedown(struct video_desc *env, SDL_MouseButtonEvent button) |
| 620 |
{ |
| 621 |
uint8_t index = KEY_OUT_OF_KEYPAD; |
| 622 |
struct gui_info *gui = env->gui; |
| 623 |
|
| 624 |
int i; |
| 625 |
|
| 626 |
int x; |
| 627 |
|
| 628 |
|
| 629 |
int src_wins_tot_w = env->out.device_num*(SRC_WIN_W+BORDER)+BORDER; |
| 630 |
|
| 631 |
|
| 632 |
int x0 = MAX(env->rem_dpy.w+gui->keypad->w/2+2*BORDER, src_wins_tot_w/2); |
| 633 |
|
| 634 |
#if 0 |
| 635 |
ast_log(LOG_WARNING, "event %d %d have %d/%d regions at %p\n", |
| 636 |
button.x, button.y, gui->kp_used, gui->kp_size, gui->kp); |
| 637 |
#endif |
| 638 |
|
| 639 |
gui->drag.drag_window = DRAG_NONE; |
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
if (button.y >= (env->out.device_num ? SRC_WIN_H+2*BORDER+SRC_MSG_BD_H : 0)) { |
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
button.y -= (env->out.device_num ? SRC_WIN_H+2*BORDER+SRC_MSG_BD_H : 0); |
| 648 |
if (button.y < BORDER) |
| 649 |
index = KEY_OUT_OF_KEYPAD; |
| 650 |
else if (button.y >= MAX(MAX(env->rem_dpy.h, env->loc_dpy.h), gui->keypad->h)) |
| 651 |
index = KEY_OUT_OF_KEYPAD; |
| 652 |
else if (button.x < x0 - gui->keypad->w/2 - BORDER - env->rem_dpy.w) |
| 653 |
index = KEY_OUT_OF_KEYPAD; |
| 654 |
else if (button.x < x0 - gui->keypad->w/2 - BORDER) |
| 655 |
index = KEY_REM_DPY; |
| 656 |
else if (button.x < x0 - gui->keypad->w/2) |
| 657 |
index = KEY_OUT_OF_KEYPAD; |
| 658 |
else if (button.x >= x0 + gui->keypad->w/2 + BORDER + env->loc_dpy.w) |
| 659 |
index = KEY_OUT_OF_KEYPAD; |
| 660 |
else if (button.x >= x0 + gui->keypad->w/2 + BORDER) |
| 661 |
index = KEY_LOC_DPY; |
| 662 |
else if (button.x >= x0 + gui->keypad->w/2) |
| 663 |
index = KEY_OUT_OF_KEYPAD; |
| 664 |
else if (gui->kp) { |
| 665 |
|
| 666 |
|
| 667 |
int x_keypad = button.x - (x0 - gui->keypad->w/2); |
| 668 |
|
| 669 |
for (i = 0; i < gui->kp_used; i++) { |
| 670 |
if (kp_match_area(&gui->kp[i],x_keypad, button.y - BORDER)) { |
| 671 |
index = gui->kp[i].c; |
| 672 |
break; |
| 673 |
} |
| 674 |
} |
| 675 |
} |
| 676 |
} else if (button.y < BORDER) { |
| 677 |
index = KEY_OUT_OF_KEYPAD; |
| 678 |
} else { |
| 679 |
x = x0 - src_wins_tot_w/2 + BORDER; |
| 680 |
if (button.y >= BORDER + SRC_WIN_H) |
| 681 |
index = KEY_OUT_OF_KEYPAD; |
| 682 |
else if (button.x < x) |
| 683 |
index = KEY_OUT_OF_KEYPAD; |
| 684 |
else if (button.x < x + src_wins_tot_w - BORDER) { |
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
for (i = 1; i <= env->out.device_num; i++) { |
| 690 |
if (button.x < x+i*(SRC_WIN_W+BORDER)-BORDER) { |
| 691 |
index = KEY_SRCS_WIN+i-1; |
| 692 |
break; |
| 693 |
} else if (button.x < x+i*(SRC_WIN_W+BORDER)) { |
| 694 |
index = KEY_OUT_OF_KEYPAD; |
| 695 |
break; |
| 696 |
} |
| 697 |
} |
| 698 |
} else |
| 699 |
index = KEY_OUT_OF_KEYPAD; |
| 700 |
} |
| 701 |
|
| 702 |
|
| 703 |
if (index < 128) { |
| 704 |
keypad_digit(env, index); |
| 705 |
return; |
| 706 |
} |
| 707 |
|
| 708 |
else if (index >= KEY_SRCS_WIN && index < KEY_SRCS_WIN+env->out.device_num) { |
| 709 |
index -= KEY_SRCS_WIN; |
| 710 |
|
| 711 |
|
| 712 |
if (button.button == SDL_BUTTON_RIGHT || button.button == SDL_BUTTON_LEFT) { |
| 713 |
switch_video_out(env, index, button.button); |
| 714 |
return; |
| 715 |
} |
| 716 |
|
| 717 |
else { |
| 718 |
int ret = turn_on_off(index, env); |
| 719 |
|
| 720 |
if (!ret) |
| 721 |
ast_log(LOG_WARNING, "unable to turn on device %s\n", |
| 722 |
env->out.devices[index].name); |
| 723 |
else if (ret == 1) |
| 724 |
ast_log(LOG_WARNING, "device %s changed state to on\n", |
| 725 |
env->out.devices[index].name); |
| 726 |
else if (ret == 2) |
| 727 |
ast_log(LOG_WARNING, "device %s changed state to off\n", |
| 728 |
env->out.devices[index].name); |
| 729 |
return; |
| 730 |
} |
| 731 |
} |
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
switch (index) { |
| 739 |
|
| 740 |
case KEY_PICK_UP: |
| 741 |
keypad_pick_up(env); |
| 742 |
break; |
| 743 |
case KEY_HANG_UP: |
| 744 |
ast_cli_command(gui->outfd, "console hangup"); |
| 745 |
break; |
| 746 |
|
| 747 |
|
| 748 |
case KEY_MUTE: |
| 749 |
case KEY_AUTOANSWER: |
| 750 |
case KEY_SENDVIDEO: |
| 751 |
case KEY_PIP: |
| 752 |
case KEY_FREEZE: |
| 753 |
keypad_toggle(env, index); |
| 754 |
break; |
| 755 |
|
| 756 |
case KEY_LOCALVIDEO: |
| 757 |
break; |
| 758 |
case KEY_REMOTEVIDEO: |
| 759 |
break; |
| 760 |
|
| 761 |
#ifdef notyet |
| 762 |
case KEY_CAPTURE: |
| 763 |
break; |
| 764 |
#endif |
| 765 |
|
| 766 |
case KEY_MESSAGEBOARD: |
| 767 |
if (button.button == SDL_BUTTON_LEFT) |
| 768 |
set_drag(&gui->drag, button.x, button.y, DRAG_MESSAGE); |
| 769 |
break; |
| 770 |
|
| 771 |
|
| 772 |
case KEY_LOC_DPY: |
| 773 |
case KEY_REM_DPY: |
| 774 |
if (button.button == SDL_BUTTON_LEFT) { |
| 775 |
|
| 776 |
int pip_loc_x = (double)env->out.pip_x/env->enc_in.w * env->loc_dpy.w; |
| 777 |
int pip_loc_y = (double)env->out.pip_y/env->enc_in.h * env->loc_dpy.h; |
| 778 |
|
| 779 |
if (index == KEY_LOC_DPY && env->out.picture_in_picture && |
| 780 |
button.x >= x0+gui->keypad->w/2+BORDER+pip_loc_x && |
| 781 |
button.x < x0+gui->keypad->w/2+BORDER+pip_loc_x+env->loc_dpy.w/3 && |
| 782 |
button.y >= BORDER+pip_loc_y && |
| 783 |
button.y < BORDER+pip_loc_y+env->loc_dpy.h/3) { |
| 784 |
|
| 785 |
button.y += (env->out.device_num ? SRC_WIN_H+2*BORDER+SRC_MSG_BD_H : 0); |
| 786 |
|
| 787 |
set_drag(&gui->drag, button.x, button.y, DRAG_PIP); |
| 788 |
} |
| 789 |
else if (index == KEY_LOC_DPY) { |
| 790 |
|
| 791 |
button.y += (env->out.device_num ? SRC_WIN_H+2*BORDER+SRC_MSG_BD_H : 0); |
| 792 |
|
| 793 |
set_drag(&gui->drag, button.x, button.y, DRAG_LOCAL); |
| 794 |
} |
| 795 |
break; |
| 796 |
} else { |
| 797 |
char buf[128]; |
| 798 |
struct fbuf_t *fb = index == KEY_LOC_DPY ? &env->loc_dpy : &env->rem_dpy; |
| 799 |
sprintf(buf, "%c%dx%d", button.button == SDL_BUTTON_RIGHT ? '>' : '<', |
| 800 |
fb->w, fb->h); |
| 801 |
video_geom(fb, buf); |
| 802 |
sdl_setup(env); |
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
for (i = 0; i < env->out.device_num; i++) { |
| 808 |
update_device_info(env, i); |
| 809 |
} |
| 810 |
|
| 811 |
|
| 812 |
print_message(gui->bd_msg, " \b"); |
| 813 |
print_message(gui->bd_dialed, " \b"); |
| 814 |
} |
| 815 |
break; |
| 816 |
case KEY_OUT_OF_KEYPAD: |
| 817 |
ast_log(LOG_WARNING, "nothing clicked, coordinates: %d, %d\n", button.x, button.y); |
| 818 |
break; |
| 819 |
|
| 820 |
case KEY_DIGIT_BACKGROUND: |
| 821 |
break; |
| 822 |
|
| 823 |
default: |
| 824 |
ast_log(LOG_WARNING, "function not yet defined %i\n", index); |
| 825 |
} |
| 826 |
} |
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
static const char * const us_kbd_map[] = { |
| 840 |
"`~", "1!", "2@", "3#", "4$", "5%", "6^", |
| 841 |
"7&", "8*", "9(", "0)", "-_", "=+", "[{", |
| 842 |
"]}", "\\|", ";:", "'\"", ",<", ".>", "/?", |
| 843 |
"jJ\n", |
| 844 |
NULL |
| 845 |
}; |
| 846 |
|
| 847 |
static char map_key(SDL_keysym *ks) |
| 848 |
{ |
| 849 |
const char *s, **p = us_kbd_map; |
| 850 |
int c = ks->sym; |
| 851 |
|
| 852 |
if (c == '\r') |
| 853 |
c = '\n'; |
| 854 |
if (c >= SDLK_NUMLOCK && c <= SDLK_COMPOSE) |
| 855 |
return 0; |
| 856 |
if (ks->mod == 0) |
| 857 |
return c; |
| 858 |
while ((s = *p) && s[0] != c) |
| 859 |
p++; |
| 860 |
if (s) { |
| 861 |
int l = strlen(s), mod = 0; |
| 862 |
if (l > 1) |
| 863 |
mod |= (ks->mod & KMOD_SHIFT) ? 1 : 0; |
| 864 |
if (l > 2 + mod) |
| 865 |
mod |= (ks->mod & KMOD_CTRL) ? 2 : 0; |
| 866 |
if (l > 4 + mod) |
| 867 |
mod |= (ks->mod & KMOD_ALT) ? 4 : 0; |
| 868 |
c = s[mod]; |
| 869 |
} |
| 870 |
if (ks->mod & (KMOD_CAPS|KMOD_SHIFT) && c >= 'a' && c <='z') |
| 871 |
c += 'A' - 'a'; |
| 872 |
return c; |
| 873 |
} |
| 874 |
|
| 875 |
static void handle_keyboard_input(struct video_desc *env, SDL_keysym *ks) |
| 876 |
{ |
| 877 |
char buf[2] = { map_key(ks), '\0' }; |
| 878 |
struct gui_info *gui = env->gui; |
| 879 |
if (buf[0] == 0) |
| 880 |
return; |
| 881 |
switch (gui->kb_output) { |
| 882 |
default: |
| 883 |
break; |
| 884 |
case KO_INPUT: |
| 885 |
break; |
| 886 |
case KO_MESSAGE: |
| 887 |
if (gui->bd_msg) { |
| 888 |
print_message(gui->bd_msg, buf); |
| 889 |
if (buf[0] == '\r' || buf[0] == '\n') { |
| 890 |
keypad_pick_up(env); |
| 891 |
} |
| 892 |
} |
| 893 |
break; |
| 894 |
|
| 895 |
case KO_DIALED: |
| 896 |
break; |
| 897 |
} |
| 898 |
|
| 899 |
return; |
| 900 |
} |
| 901 |
|
| 902 |
static void grabber_move(struct video_device *, int dx, int dy); |
| 903 |
|
| 904 |
int compute_drag(int *start, int end, int magnifier); |
| 905 |
int compute_drag(int *start, int end, int magnifier) |
| 906 |
{ |
| 907 |
int delta = end - *start; |
| 908 |
#define POLARITY -1 |
| 909 |
|
| 910 |
delta += delta * delta * (delta > 0 ? 1 : -1 )/100; |
| 911 |
delta *= POLARITY * magnifier; |
| 912 |
#undef POLARITY |
| 913 |
*start = end; |
| 914 |
return delta; |
| 915 |
} |
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
static void pip_move(struct video_desc* env, int dx, int dy) { |
| 926 |
int new_pip_x = env->out.pip_x+dx; |
| 927 |
int new_pip_y = env->out.pip_y+dy; |
| 928 |
|
| 929 |
if (new_pip_x < 0) |
| 930 |
new_pip_x = 0; |
| 931 |
|
| 932 |
else if (new_pip_x > env->enc_in.w - env->enc_in.w/3) |
| 933 |
new_pip_x = env->enc_in.w - env->enc_in.w/3; |
| 934 |
|
| 935 |
if (new_pip_y < 0) |
| 936 |
new_pip_y = 0; |
| 937 |
|
| 938 |
else if (new_pip_y > env->enc_in.h - env->enc_in.h/3) |
| 939 |
new_pip_y = env->enc_in.h - env->enc_in.h/3; |
| 940 |
env->out.pip_x = new_pip_x; |
| 941 |
env->out.pip_y = new_pip_y; |
| 942 |
} |
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
static void eventhandler(struct video_desc *env, const char *caption) |
| 954 |
{ |
| 955 |
struct gui_info *gui = env->gui; |
| 956 |
struct drag_info *drag; |
| 957 |
#define N_EVENTS 32 |
| 958 |
int i, n; |
| 959 |
SDL_Event ev[N_EVENTS]; |
| 960 |
|
| 961 |
if (!gui) |
| 962 |
return; |
| 963 |
drag = &gui->drag; |
| 964 |
if (caption) |
| 965 |
SDL_WM_SetCaption(caption, NULL); |
| 966 |
|
| 967 |
#define MY_EV (SDL_MOUSEBUTTONDOWN|SDL_KEYDOWN) |
| 968 |
while ( (n = SDL_PeepEvents(ev, N_EVENTS, SDL_GETEVENT, SDL_ALLEVENTS)) > 0) { |
| 969 |
for (i = 0; i < n; i++) { |
| 970 |
#if 0 |
| 971 |
ast_log(LOG_WARNING, "------ event %d at %d %d\n", |
| 972 |
ev[i].type, ev[i].button.x, ev[i].button.y); |
| 973 |
#endif |
| 974 |
switch (ev[i].type) { |
| 975 |
default: |
| 976 |
ast_log(LOG_WARNING, "------ event %d at %d %d\n", |
| 977 |
ev[i].type, ev[i].button.x, ev[i].button.y); |
| 978 |
break; |
| 979 |
|
| 980 |
case SDL_ACTIVEEVENT: |
| 981 |
#if 0 |
| 982 |
if (ev[i].active.gain == 0 && ev[i].active.state & SDL_APPACTIVE) { |
| 983 |
ast_log(LOG_WARNING, "/* somebody has killed us ? */\n"); |
| 984 |
ast_cli_command(gui->outfd, "stop now"); |
| 985 |
} |
| 986 |
#endif |
| 987 |
break; |
| 988 |
|
| 989 |
case SDL_KEYUP: |
| 990 |
break; |
| 991 |
|
| 992 |
case SDL_KEYDOWN: |
| 993 |
handle_keyboard_input(env, &ev[i].key.keysym); |
| 994 |
break; |
| 995 |
|
| 996 |
case SDL_MOUSEMOTION: |
| 997 |
case SDL_MOUSEBUTTONUP: |
| 998 |
if (drag->drag_window == DRAG_LOCAL && env->out.device_num) { |
| 999 |
|
| 1000 |
int dx = compute_drag(&drag->x_start, ev[i].motion.x, 3); |
| 1001 |
int dy = compute_drag(&drag->y_start, ev[i].motion.y, 3); |
| 1002 |
grabber_move(&env->out.devices[env->out.device_primary], dx, dy); |
| 1003 |
} else if (drag->drag_window == DRAG_PIP) { |
| 1004 |
|
| 1005 |
int dx = ev[i].motion.x - drag->x_start; |
| 1006 |
int dy = ev[i].motion.y - drag->y_start; |
| 1007 |
|
| 1008 |
|
| 1009 |
dx = (double)dx*env->enc_in.w/env->loc_dpy.w; |
| 1010 |
dy = (double)dy*env->enc_in.h/env->loc_dpy.h; |
| 1011 |
|
| 1012 |
drag->x_start = ev[i].motion.x; |
| 1013 |
drag->y_start = ev[i].motion.y; |
| 1014 |
|
| 1015 |
pip_move(env, dx, dy); |
| 1016 |
} else if (drag->drag_window == DRAG_MESSAGE) { |
| 1017 |
|
| 1018 |
int dy = compute_drag(&drag->y_start, ev[i].motion.y, 1); |
| 1019 |
move_message_board(gui->bd_msg, dy); |
| 1020 |
} |
| 1021 |
if (ev[i].type == SDL_MOUSEBUTTONUP) |
| 1022 |
drag->drag_window = DRAG_NONE; |
| 1023 |
break; |
| 1024 |
case SDL_MOUSEBUTTONDOWN: |
| 1025 |
handle_mousedown(env, ev[i].button); |
| 1026 |
break; |
| 1027 |
} |
| 1028 |
} |
| 1029 |
} |
| 1030 |
if (1) { |
| 1031 |
struct timeval b, a = ast_tvnow(); |
| 1032 |
int i; |
| 1033 |
|
| 1034 |
SDL_PumpEvents(); |
| 1035 |
b = ast_tvnow(); |
| 1036 |
i = ast_tvdiff_ms(b, a); |
| 1037 |
if (i > 3) |
| 1038 |
fprintf(stderr, "-------- SDL_PumpEvents took %dms\n", i); |
| 1039 |
|
| 1040 |
} |
| 1041 |
} |
| 1042 |
|
| 1043 |
static SDL_Surface *load_image(const char *file) |
| 1044 |
{ |
| 1045 |
SDL_Surface *temp; |
| 1046 |
|
| 1047 |
#ifdef HAVE_SDL_IMAGE |
| 1048 |
temp = IMG_Load(file); |
| 1049 |
#else |
| 1050 |
temp = SDL_LoadBMP(file); |
| 1051 |
#endif |
| 1052 |
if (temp == NULL) |
| 1053 |
fprintf(stderr, "Unable to load image %s: %s\n", |
| 1054 |
file, SDL_GetError()); |
| 1055 |
return temp; |
| 1056 |
} |
| 1057 |
|
| 1058 |
static void keypad_setup(struct gui_info *gui, const char *kp_file); |
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
static struct gui_info *gui_init(const char *keypad_file, const char *font) |
| 1063 |
{ |
| 1064 |
struct gui_info *gui = ast_calloc(1, sizeof(*gui)); |
| 1065 |
|
| 1066 |
if (gui == NULL) |
| 1067 |
return NULL; |
| 1068 |
|
| 1069 |
gui->kb_output = KO_MESSAGE; |
| 1070 |
gui->drag.drag_window = DRAG_NONE; |
| 1071 |
gui->outfd = -1; |
| 1072 |
|
| 1073 |
keypad_setup(gui, keypad_file); |
| 1074 |
if (gui->keypad == NULL) |
| 1075 |
return gui; |
| 1076 |
|
| 1077 |
if (!ast_strlen_zero(font)) { |
| 1078 |
int i; |
| 1079 |
SDL_Rect *r; |
| 1080 |
|
| 1081 |
gui->font = load_image(font); |
| 1082 |
if (!gui->font) { |
| 1083 |
ast_log(LOG_WARNING, "Unable to load font %s, no output available\n", font); |
| 1084 |
goto error; |
| 1085 |
} |
| 1086 |
ast_log(LOG_WARNING, "Loaded font %s\n", font); |
| 1087 |
|
| 1088 |
r = gui->font_rects; |
| 1089 |
#define FONT_H 20 |
| 1090 |
#define FONT_W 9 |
| 1091 |
for (i = 0; i < 96; r++, i++) { |
| 1092 |
r->x = (i % 32 ) * FONT_W; |
| 1093 |
r->y = (i / 32 ) * FONT_H; |
| 1094 |
r->w = FONT_W; |
| 1095 |
r->h = FONT_H; |
| 1096 |
} |
| 1097 |
} |
| 1098 |
|
| 1099 |
gui->outfd = open ("/dev/null", O_WRONLY); |
| 1100 |
if (gui->outfd < 0) { |
| 1101 |
ast_log(LOG_WARNING, "Unable output fd\n"); |
| 1102 |
goto error; |
| 1103 |
} |
| 1104 |
return gui; |
| 1105 |
|
| 1106 |
error: |
| 1107 |
ast_free(gui); |
| 1108 |
return NULL; |
| 1109 |
} |
| 1110 |
|
| 1111 |
|
| 1112 |
static int set_win(SDL_Surface *screen, struct display_window *win, int fmt, |
| 1113 |
int w, int h, int x, int y) |
| 1114 |
{ |
| 1115 |
win->bmp = SDL_CreateYUVOverlay(w, h, fmt, screen); |
| 1116 |
if (win->bmp == NULL) |
| 1117 |
return -1; |
| 1118 |
win->rect.x = x; |
| 1119 |
win->rect.y = y; |
| 1120 |
win->rect.w = w; |
| 1121 |
win->rect.h = h; |
| 1122 |
return 0; |
| 1123 |
} |
| 1124 |
|
| 1125 |
static int keypad_cfg_read(struct gui_info *gui, const char *val); |
| 1126 |
|
| 1127 |
static void keypad_setup(struct gui_info *gui, const char *kp_file) |
| 1128 |
{ |
| 1129 |
FILE *fd; |
| 1130 |
char buf[1024]; |
| 1131 |
const char region[] = "region"; |
| 1132 |
int reg_len = strlen(region); |
| 1133 |
int in_comment = 0; |
| 1134 |
|
| 1135 |
if (gui->keypad) |
| 1136 |
return; |
| 1137 |
gui->keypad = load_image(kp_file); |
| 1138 |
if (!gui->keypad) |
| 1139 |
return; |
| 1140 |
|
| 1141 |
fd = fopen(kp_file, "r"); |
| 1142 |
if (fd == NULL) { |
| 1143 |
ast_log(LOG_WARNING, "fail to open %s\n", kp_file); |
| 1144 |
return; |
| 1145 |
} |
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
while (fgets(buf, sizeof(buf), fd)) { |
| 1156 |
char *s; |
| 1157 |
|
| 1158 |
if (!strstr(buf, region)) { |
| 1159 |
if (!in_comment) |
| 1160 |
continue; |
| 1161 |
else |
| 1162 |
break; |
| 1163 |
} |
| 1164 |
if (!in_comment) { |
| 1165 |
keypad_cfg_read(gui, "reset"); |
| 1166 |
in_comment = 1; |
| 1167 |
} |
| 1168 |
s = ast_skip_blanks(buf); |
| 1169 |
ast_trim_blanks(s); |
| 1170 |
if (memcmp(s, region, reg_len)) |
| 1171 |
break; |
| 1172 |
s = ast_skip_blanks(s + reg_len); |
| 1173 |
if (*s++ != '=') |
| 1174 |
break; |
| 1175 |
if (*s == '>') |
| 1176 |
s++; |
| 1177 |
keypad_cfg_read(gui, ast_skip_blanks(s)); |
| 1178 |
} |
| 1179 |
fclose(fd); |
| 1180 |
} |
| 1181 |
|
| 1182 |
struct board *board_setup(SDL_Surface *screen, SDL_Rect *dest, |
| 1183 |
SDL_Surface *font, SDL_Rect *font_rects); |
| 1184 |
|
| 1185 |
|
| 1186 |
static void init_board(struct gui_info *gui, struct board **dst, SDL_Rect *r, int dx, int dy) |
| 1187 |
{ |
| 1188 |
if (r[0].w == 0 || r[0].h == 0) |
| 1189 |
return; |
| 1190 |
r[1] = r[0]; |
| 1191 |
r[1].x += dx; |
| 1192 |
r[1].y += dy; |
| 1193 |
if (*dst == NULL) { |
| 1194 |
*dst = board_setup(gui->screen, &r[1], gui->font, gui->font_rects); |
| 1195 |
} else { |
| 1196 |
|
| 1197 |
} |
| 1198 |
} |
| 1199 |
|
| 1200 |
#ifdef HAVE_X11 |
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
static int my_x_handler(Display *d, XErrorEvent *e) |
| 1209 |
{ |
| 1210 |
ast_log(LOG_WARNING, "%s error_code %d\n", __FUNCTION__, e->error_code); |
| 1211 |
return 0; |
| 1212 |
} |
| 1213 |
#endif |
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
static void sdl_setup(struct video_desc *env) |
| 1220 |
{ |
| 1221 |
int dpy_fmt = SDL_IYUV_OVERLAY; |
| 1222 |
int depth, maxw, maxh; |
| 1223 |
const SDL_VideoInfo *info; |
| 1224 |
int kp_w = 0, kp_h = 0; |
| 1225 |
struct gui_info *gui = env->gui; |
| 1226 |
|
| 1227 |
|
| 1228 |
int x0; |
| 1229 |
int x1; |
| 1230 |
int y0; |
| 1231 |
int src_wins_tot_w; |
| 1232 |
int i; |
| 1233 |
int x; |
| 1234 |
|
| 1235 |
#ifdef HAVE_X11 |
| 1236 |
const char *e = getenv("SDL_WINDOWID"); |
| 1237 |
|
| 1238 |
if (!ast_strlen_zero(e)) { |
| 1239 |
XWindowAttributes a; |
| 1240 |
int (*old_x_handler)(Display *d, XErrorEvent *e) = XSetErrorHandler(my_x_handler); |
| 1241 |
Display *d = XOpenDisplay(getenv("DISPLAY")); |
| 1242 |
long w = atol(e); |
| 1243 |
int success = w ? XGetWindowAttributes(d, w, &a) : 0; |
| 1244 |
|
| 1245 |
XSetErrorHandler(old_x_handler); |
| 1246 |
if (!success) { |
| 1247 |
ast_log(LOG_WARNING, "%s error in window\n", __FUNCTION__); |
| 1248 |
return; |
| 1249 |
} |
| 1250 |
} |
| 1251 |
#endif |
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
if (gui == NULL && SDL_Init(SDL_INIT_VIDEO)) { |
| 1266 |
ast_log(LOG_WARNING, "Could not initialize SDL - %s\n", |
| 1267 |
SDL_GetError()); |
| 1268 |
|
| 1269 |
return; |
| 1270 |
} |
| 1271 |
info = SDL_GetVideoInfo(); |
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
if (!info || !info->vfmt) { |
| 1276 |
ast_log(LOG_WARNING, "Bad SDL_GetVideoInfo - %s\n", |
| 1277 |
SDL_GetError()); |
| 1278 |
return; |
| 1279 |
} |
| 1280 |
depth = info->vfmt->BitsPerPixel; |
| 1281 |
if (depth < 16) |
| 1282 |
depth = 16; |
| 1283 |
if (!gui) |
| 1284 |
env->gui = gui = gui_init(env->keypad_file, env->keypad_font); |
| 1285 |
if (!gui) |
| 1286 |
goto no_sdl; |
| 1287 |
|
| 1288 |
if (gui->keypad) { |
| 1289 |
if (gui->kp_rect.w > 0 && gui->kp_rect.h > 0) { |
| 1290 |
kp_w = gui->kp_rect.w; |
| 1291 |
kp_h = gui->kp_rect.h; |
| 1292 |
} else { |
| 1293 |
kp_w = gui->keypad->w; |
| 1294 |
kp_h = gui->keypad->h; |
| 1295 |
} |
| 1296 |
} |
| 1297 |
|
| 1298 |
|
| 1299 |
src_wins_tot_w = env->out.device_num*(SRC_WIN_W+BORDER)+BORDER; |
| 1300 |
|
| 1301 |
|
| 1302 |
x0 = MAX(env->rem_dpy.w+kp_w/2+2*BORDER, src_wins_tot_w/2); |
| 1303 |
|
| 1304 |
|
| 1305 |
x1 = MAX(env->loc_dpy.w+kp_w/2+2*BORDER, src_wins_tot_w/2); |
| 1306 |
|
| 1307 |
|
| 1308 |
maxw = x0+x1; |
| 1309 |
|
| 1310 |
|
| 1311 |
maxh = MAX( MAX(env->rem_dpy.h, env->loc_dpy.h), kp_h)+2*BORDER; |
| 1312 |
maxh += env->out.device_num ? (2*BORDER+SRC_WIN_H+SRC_MSG_BD_H) : 0; |
| 1313 |
|
| 1314 |
gui->screen = SDL_SetVideoMode(maxw, maxh, depth, 0); |
| 1315 |
if (!gui->screen) { |
| 1316 |
ast_log(LOG_ERROR, "SDL: could not set video mode - exiting\n"); |
| 1317 |
goto no_sdl; |
| 1318 |
} |
| 1319 |
|
| 1320 |
#ifdef HAVE_X11 |
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
do { |
| 1328 |
|
| 1329 |
XWindowAttributes attr; |
| 1330 |
long want; |
| 1331 |
SDL_SysWMinfo info; |
| 1332 |
Display *SDL_Display; |
| 1333 |
Window win; |
| 1334 |
|
| 1335 |
const char *e = getenv("SDL_WINDOWID"); |
| 1336 |
if (ast_strlen_zero(e)) |
| 1337 |
break; |
| 1338 |
SDL_VERSION(&info.version); |
| 1339 |
if (SDL_GetWMInfo(&info) != 1) { |
| 1340 |
fprintf(stderr, "no wm info\n"); |
| 1341 |
break; |
| 1342 |
} |
| 1343 |
SDL_Display = info.info.x11.display; |
| 1344 |
if (SDL_Display == NULL) |
| 1345 |
break; |
| 1346 |
win = info.info.x11.window; |
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
want = KeyPressMask | KeyReleaseMask | ButtonPressMask | |
| 1353 |
ButtonReleaseMask | EnterWindowMask | |
| 1354 |
LeaveWindowMask | PointerMotionMask | |
| 1355 |
Button1MotionMask | |
| 1356 |
Button2MotionMask | Button3MotionMask | |
| 1357 |
Button4MotionMask | Button5MotionMask | |
| 1358 |
ButtonMotionMask | KeymapStateMask | |
| 1359 |
ExposureMask | VisibilityChangeMask | |
| 1360 |
StructureNotifyMask | |
| 1361 |
SubstructureNotifyMask | SubstructureRedirectMask | |
| 1362 |
FocusChangeMask | PropertyChangeMask | |
| 1363 |
ColormapChangeMask | OwnerGrabButtonMask; |
| 1364 |
|
| 1365 |
memset(&attr, '\0', sizeof(attr)); |
| 1366 |
XGetWindowAttributes(SDL_Display, win, &attr); |
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
{ |
| 1373 |
|
| 1374 |
long ev = ButtonPressMask | ResizeRedirectMask | |
| 1375 |
SubstructureRedirectMask; |
| 1376 |
ev &= (attr.all_event_masks & ~attr.your_event_mask); |
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
want &= ~ev; |
| 1382 |
want |= attr.your_event_mask; |
| 1383 |
} |
| 1384 |
XSelectInput(SDL_Display, win, want); |
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
XResizeWindow(SDL_Display, win, maxw, maxh); |
| 1393 |
{ |
| 1394 |
XConfigureEvent ce = { |
| 1395 |
.type = ConfigureNotify, |
| 1396 |
.serial = 0, |
| 1397 |
.send_event = 1, |
| 1398 |
.display = SDL_Display, |
| 1399 |
.event = win, |
| 1400 |
.window = win, |
| 1401 |
.x = 0, |
| 1402 |
.y = 0, |
| 1403 |
.width = maxw, |
| 1404 |
.height = maxh, |
| 1405 |
.border_width = 0, |
| 1406 |
.above = 0, |
| 1407 |
.override_redirect = 0 }; |
| 1408 |
XSendEvent(SDL_Display, win, 1 , StructureNotifyMask, (XEvent *)&ce); |
| 1409 |
} |
| 1410 |
} while (0); |
| 1411 |
#endif |
| 1412 |
|
| 1413 |
y0 = env->out.device_num ? (3*BORDER+SRC_WIN_H+SRC_MSG_BD_H) : BORDER; |
| 1414 |
|
| 1415 |
SDL_WM_SetCaption("Asterisk console Video Output", NULL); |
| 1416 |
|
| 1417 |
|
| 1418 |
if (set_win(gui->screen, &gui->win[WIN_REMOTE], dpy_fmt, |
| 1419 |
env->rem_dpy.w, env->rem_dpy.h, x0-kp_w/2-BORDER-env->rem_dpy.w, y0)) |
| 1420 |
goto no_sdl; |
| 1421 |
|
| 1422 |
env->frame_freeze = 0; |
| 1423 |
|
| 1424 |
if (set_win(gui->screen, &gui->win[WIN_LOCAL], dpy_fmt, |
| 1425 |
env->loc_dpy.w, env->loc_dpy.h, |
| 1426 |
x0+kp_w/2+BORDER, y0)) |
| 1427 |
goto no_sdl; |
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
x = x0 - src_wins_tot_w/2 + BORDER; |
| 1432 |
for (i = 0; i < env->out.device_num; i++){ |
| 1433 |
struct thumb_bd *p = &gui->thumb_bd_array[i]; |
| 1434 |
if (set_win(gui->screen, &gui->win[i+WIN_SRC1], dpy_fmt, |
| 1435 |
SRC_WIN_W, SRC_WIN_H, x+i*(BORDER+SRC_WIN_W), BORDER)) |
| 1436 |
goto no_sdl; |
| 1437 |
|
| 1438 |
p->rect.w = SRC_WIN_W; |
| 1439 |
p->rect.h = SRC_MSG_BD_H; |
| 1440 |
p->rect.x = x+i*(BORDER+SRC_WIN_W); |
| 1441 |
p->rect.y = 2*BORDER+SRC_WIN_H; |
| 1442 |
|
| 1443 |
SDL_FillRect(gui->screen, &p->rect, |
| 1444 |
SDL_MapRGB(gui->screen->format, 255, 255, 255)); |
| 1445 |
|
| 1446 |
if (!p->board) |
| 1447 |
p->board = |
| 1448 |
board_setup(gui->screen, &p->rect, |
| 1449 |
gui->font, gui->font_rects); |
| 1450 |
|
| 1451 |
SDL_UpdateRect(gui->screen, p->rect.x, p->rect.y, p->rect.w, p->rect.h); |
| 1452 |
} |
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
if (gui->keypad) { |
| 1457 |
struct SDL_Rect *dest = &gui->win[WIN_KEYPAD].rect; |
| 1458 |
struct SDL_Rect *src = (gui->kp_rect.w > 0 && gui->kp_rect.h > 0) ? & gui->kp_rect : NULL; |
| 1459 |
|
| 1460 |
dest->x = x0-kp_w/2; |
| 1461 |
dest->y = y0; |
| 1462 |
dest->w = kp_w; |
| 1463 |
dest->h = kp_h; |
| 1464 |
SDL_BlitSurface(gui->keypad, src, gui->screen, dest); |
| 1465 |
init_board(gui, &gui->bd_msg, gui->kp_msg, dest->x, dest->y); |
| 1466 |
init_board(gui, &gui->bd_dialed, gui->kp_dialed, dest->x, dest->y); |
| 1467 |
SDL_UpdateRects(gui->screen, 1, dest); |
| 1468 |
} |
| 1469 |
return; |
| 1470 |
|
| 1471 |
no_sdl: |
| 1472 |
|
| 1473 |
env->gui = cleanup_sdl(gui, env->out.device_num); |
| 1474 |
} |
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
static int kp_match_area(const struct keypad_entry *e, int x, int y) |
| 1488 |
{ |
| 1489 |
double xp, dx = (e->x1 - e->x0); |
| 1490 |
double yp, dy = (e->y1 - e->y0); |
| 1491 |
double l = sqrt(dx*dx + dy*dy); |
| 1492 |
int ret = 0; |
| 1493 |
|
| 1494 |
if (l > 1) { |
| 1495 |
xp = ((x - e->x0)*dx + (y - e->y0)*dy)/l; |
| 1496 |
yp = (-(x - e->x0)*dy + (y - e->y0)*dx)/l; |
| 1497 |
if (e->type == KP_RECT) { |
| 1498 |
ret = (xp >= 0 && xp < l && yp >=0 && yp < e->h); |
| 1499 |
} else if (e->type == KP_CIRCLE) { |
| 1500 |
dx = xp*xp/(l*l) + yp*yp/(e->h*e->h); |
| 1501 |
ret = (dx < 1); |
| 1502 |
} |
| 1503 |
} |
| 1504 |
#if 0 |
| 1505 |
ast_log(LOG_WARNING, "result %d [%d] for match %d,%d in type %d p0 %d,%d p1 %d,%d h %d\n", |
| 1506 |
ret, e->c, x, y, e->type, e->x0, e->y0, e->x1, e->y1, e->h); |
| 1507 |
#endif |
| 1508 |
return ret; |
| 1509 |
} |
| 1510 |
|
| 1511 |
struct _s_k { const char *s; int k; }; |
| 1512 |
static const struct _s_k gui_key_map[] = { |
| 1513 |
{"FREEZE", KEY_FREEZE}, |
| 1514 |
{"PIP", KEY_PIP}, |
| 1515 |
{"PICK_UP", KEY_PICK_UP }, |
| 1516 |
{"PICKUP", KEY_PICK_UP }, |
| 1517 |
{"HANG_UP", KEY_HANG_UP }, |
| 1518 |
{"HANGUP", KEY_HANG_UP }, |
| 1519 |
{"MUTE", KEY_MUTE }, |
| 1520 |
{"FLASH", KEY_FLASH }, |
| 1521 |
{"AUTOANSWER", KEY_AUTOANSWER }, |
| 1522 |
{"SENDVIDEO", KEY_SENDVIDEO }, |
| 1523 |
{"LOCALVIDEO", KEY_LOCALVIDEO }, |
| 1524 |
{"REMOTEVIDEO", KEY_REMOTEVIDEO }, |
| 1525 |
{"GUI_CLOSE", KEY_GUI_CLOSE }, |
| 1526 |
{"MESSAGEBOARD", KEY_MESSAGEBOARD }, |
| 1527 |
{"DIALEDBOARD", KEY_DIALEDBOARD }, |
| 1528 |
{"EDITBOARD", KEY_EDITBOARD }, |
| 1529 |
{"KEYPAD", KEY_KEYPAD }, |
| 1530 |
{"MESSAGE", KEY_MESSAGE }, |
| 1531 |
{"DIALED", KEY_DIALED }, |
| 1532 |
{"EDIT", KEY_EDIT }, |
| 1533 |
{"FONT", KEY_FONT }, |
| 1534 |
{NULL, 0 } }; |
| 1535 |
|
| 1536 |
static int gui_map_token(const char *s) |
| 1537 |
{ |
| 1538 |
|
| 1539 |
int i = atoi(s); |
| 1540 |
struct _s_k *p; |
| 1541 |
if (i > 0 || s[1] == '\0') |
| 1542 |
return (i > 9) ? i : s[0]; |
| 1543 |
for (p = gui_key_map; p->s; p++) { |
| 1544 |
if (!strcasecmp(p->s, s)) |
| 1545 |
return p->k; |
| 1546 |
} |
| 1547 |
return KEY_NONE; |
| 1548 |
} |
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
static int keypad_cfg_read(struct gui_info *gui, const char *val) |
| 1562 |
{ |
| 1563 |
struct keypad_entry e; |
| 1564 |
SDL_Rect *r = NULL; |
| 1565 |
char s1[16], s2[16]; |
| 1566 |
int i, ret = 0; |
| 1567 |
|
| 1568 |
if (gui == NULL || val == NULL) |
| 1569 |
return 0; |
| 1570 |
|
| 1571 |
s1[0] = s2[0] = '\0'; |
| 1572 |
memset(&e, '\0', sizeof(e)); |
| 1573 |
i = sscanf(val, "%14s %14s %d %d %d %d %d", |
| 1574 |
s1, s2, &e.x0, &e.y0, &e.x1, &e.y1, &e.h); |
| 1575 |
|
| 1576 |
e.c = gui_map_token(s1); |
| 1577 |
if (e.c == KEY_NONE) |
| 1578 |
return 0; |
| 1579 |
switch (i) { |
| 1580 |
default: |
| 1581 |
break; |
| 1582 |
case 1: |
| 1583 |
if (e.c != KEY_RESET) |
| 1584 |
break; |
| 1585 |
if (gui->kp) |
| 1586 |
gui->kp_used = 0; |
| 1587 |
break; |
| 1588 |
case 5: |
| 1589 |
if (e.c == KEY_KEYPAD) |
| 1590 |
r = &gui->kp_rect; |
| 1591 |
else if (e.c == KEY_MESSAGE) |
| 1592 |
r = gui->kp_msg; |
| 1593 |
else if (e.c == KEY_DIALED) |
| 1594 |
r = gui->kp_dialed; |
| 1595 |
else if (e.c == KEY_EDIT) |
| 1596 |
r = gui->kp_edit; |
| 1597 |
if (r) { |
| 1598 |
r->x = atoi(s2); |
| 1599 |
r->y = e.x0; |
| 1600 |
r->w = e.y0; |
| 1601 |
r->h = e.x1; |
| 1602 |
break; |
| 1603 |
} |
| 1604 |
if (strcasecmp(s2, "circle")) |
| 1605 |
break; |
| 1606 |
|
| 1607 |
e.h = e.x1; |
| 1608 |
e.y1 = e.y0; |
| 1609 |
e.x1 = e.x0 + e.h; |
| 1610 |
e.x0 = e.x0 - e.h; |
| 1611 |
|
| 1612 |
|
| 1613 |
case 7: |
| 1614 |
if (e.c == KEY_FONT) { |
| 1615 |
ast_log(LOG_WARNING, "font not supported yet\n"); |
| 1616 |
break; |
| 1617 |
} |
| 1618 |
|
| 1619 |
if (e.x1 < e.x0 || e.h <= 0) { |
| 1620 |
ast_log(LOG_WARNING, "error in coordinates\n"); |
| 1621 |
e.type = 0; |
| 1622 |
break; |
| 1623 |
} |
| 1624 |
if (!strcasecmp(s2, "circle")) { |
| 1625 |
|
| 1626 |
e.type = KP_CIRCLE; |
| 1627 |
e.x0 = (e.x1 + e.x0) / 2; |
| 1628 |
e.y0 = (e.y1 + e.y0) / 2; |
| 1629 |
e.h = e.h / 2; |
| 1630 |
} else if (!strcasecmp(s2, "rect")) { |
| 1631 |
e.type = KP_RECT; |
| 1632 |
} else |
| 1633 |
break; |
| 1634 |
ret = 1; |
| 1635 |
} |
| 1636 |
|
| 1637 |
if (ret == 0) |
| 1638 |
return 0; |
| 1639 |
if (gui->kp_size == 0) { |
| 1640 |
gui->kp = ast_calloc(10, sizeof(e)); |
| 1641 |
if (gui->kp == NULL) { |
| 1642 |
ast_log(LOG_WARNING, "cannot allocate kp\n"); |
| 1643 |
return 0; |
| 1644 |
} |
| 1645 |
gui->kp_size = 10; |
| 1646 |
} |
| 1647 |
if (gui->kp_size == gui->kp_used) { |
| 1648 |
struct keypad_entry *a = ast_realloc(gui->kp, sizeof(e)*(gui->kp_size+10)); |
| 1649 |
if (a == NULL) { |
| 1650 |
ast_log(LOG_WARNING, "cannot reallocate kp\n"); |
| 1651 |
return 0; |
| 1652 |
} |
| 1653 |
gui->kp = a; |
| 1654 |
gui->kp_size += 10; |
| 1655 |
} |
| 1656 |
if (gui->kp_size == gui->kp_used) |
| 1657 |
return 0; |
| 1658 |
gui->kp[gui->kp_used++] = e; |
| 1659 |
|
| 1660 |
return 1; |
| 1661 |
} |
| 1662 |
#endif |