Class: Video4Linux2::Camera
- Inherits:
-
Object
- Object
- Video4Linux2::Camera
- Defined in:
- ext/v4l2/v4l2.c
Defined Under Namespace
Classes: BooleanControl, Control, FormatDescription, FrameCapability, IntegerControl, MenuControl, MenuItem
Class Method Summary collapse
Instance Method Summary collapse
- #busy? ⇒ Boolean
- #capture ⇒ Object
- #close ⇒ Object
- #controls ⇒ Object
- #error? ⇒ Boolean
- #format=(fmt) ⇒ Object
- #frame_capabilities(fmt) ⇒ Object
- #framerate ⇒ Object
- #framerate=(val) ⇒ Object
- #get_control(id) ⇒ Object
- #image_height ⇒ Object
- #image_height=(val) ⇒ Object
- #image_width ⇒ Object
- #image_width=(val) ⇒ Object
- #initialize(dev) ⇒ Object constructor
- #set_control(id, val) ⇒ Object
- #start ⇒ Object
- #state ⇒ Object
- #stop ⇒ Object
- #support_formats ⇒ Object
Constructor Details
#initialize(dev) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'ext/v4l2/v4l2.c', line 84
static VALUE
rb_camera_initialize(VALUE self, VALUE dev)
{
int err;
camera_t* ptr;
/*
* argument check
*/
Check_Type(dev, T_STRING);
/*
* strip object
*/
Data_Get_Struct(self, camera_t, ptr);
/*
* initialize struct
*/
err = camera_initialize(ptr, RSTRING_PTR(dev));
if (err) {
rb_raise(rb_eRuntimeError, "initialize camera context failed.");
}
/*
* set default instance variable
*/
rb_ivar_set(self, id_iv_name,
rb_enc_str_new_cstr(ptr->name, rb_utf8_encoding()));
rb_ivar_set(self, id_iv_driver,
rb_enc_str_new_cstr(ptr->driver, rb_utf8_encoding()));
rb_ivar_set(self, id_iv_bus,
rb_enc_str_new_cstr(ptr->bus, rb_utf8_encoding()));
return Qtrue;
}
|
Class Method Details
.open(device) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'ext/v4l2/v4l2.c', line 73
static VALUE
rb_camera_open(VALUE self, VALUE device)
{
VALUE ret;
ret = rb_obj_alloc(camera_klass);
rb_obj_call_init(ret, 1, &device);
return ret;
}
|
Instance Method Details
#busy? ⇒ Boolean
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 |
# File 'ext/v4l2/v4l2.c', line 822
static VALUE
rb_camera_is_busy(VALUE self)
{
camera_t* ptr;
int err;
int busy;
/*
* strip object
*/
Data_Get_Struct(self, camera_t, ptr);
/*
* do check
*/
err = camera_check_busy(ptr, &busy);
if (err) {
rb_raise(rb_eRuntimeError, "check failed.");
}
return (busy)? Qtrue: Qfalse;
}
|
#capture ⇒ Object
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 |
# File 'ext/v4l2/v4l2.c', line 788
static VALUE
rb_camera_capture(VALUE self)
{
VALUE ret;
camera_t* ptr;
size_t used;
int err;
/*
* strip object
*/
Data_Get_Struct(self, camera_t, ptr);
/*
* allocate return value.
*/
ret = rb_str_buf_new(ptr->image_size);
rb_str_set_len(ret, ptr->image_size);
/*
* do capture
*/
err = camera_get_image(ptr, RSTRING_PTR(ret), &used);
if (err) {
rb_raise(rb_eRuntimeError, "capture failed.");
}
if (ptr->image_size != used) {
rb_str_set_len(ret, used);
}
return ret;
}
|
#close ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'ext/v4l2/v4l2.c', line 121
static VALUE
rb_camera_close( VALUE self)
{
int err;
camera_t* ptr;
/*
* strip object
*/
Data_Get_Struct(self, camera_t, ptr);
/*
* convert
*/
err = camera_finalize(ptr);
if (err) {
rb_raise(rb_eRuntimeError, "finalize camera context failed.");
}
return Qnil;
}
|
#controls ⇒ Object
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'ext/v4l2/v4l2.c', line 249
static VALUE
rb_camera_get_controls(VALUE self)
{
VALUE ret;
camera_t* ptr;
int i;
VALUE info;
Data_Get_Struct(self, camera_t, ptr);
ret = rb_ary_new();
for (i = 0; i < 43; i++) {
info = get_control_info(ptr, V4L2_CID_BASE + i);
if (info != Qnil) rb_ary_push(ret, info);
}
for (i = 0; i < 30; i++) {
info = get_control_info(ptr, V4L2_CID_CAMERA_CLASS_BASE + i);
if (info != Qnil) rb_ary_push(ret, info);
}
for (i = 0; i < 20; i++) {
info = get_control_info(ptr, V4L2_CID_JPEG_CLASS_BASE + i);
if (info != Qnil) rb_ary_push(ret, info);
}
return ret;
}
|
#error? ⇒ Boolean
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 |
# File 'ext/v4l2/v4l2.c', line 845
static VALUE
rb_camera_is_error(VALUE self)
{
camera_t* ptr;
int err;
int error;
/*
* strip object
*/
Data_Get_Struct(self, camera_t, ptr);
/*
* do check
*/
err = camera_check_error(ptr, &error);
if (err) {
rb_raise(rb_eRuntimeError, "check failed.");
}
return (error)? Qtrue: Qfalse;
}
|
#format=(fmt) ⇒ Object
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
# File 'ext/v4l2/v4l2.c', line 516
static VALUE
rb_camera_set_format(VALUE self, VALUE fmt)
{
camera_t* ptr;
int err;
/*
* argument check
*/
Check_Type(fmt, T_SYMBOL);
/*
* strip object
*/
Data_Get_Struct(self, camera_t, ptr);
/*
* set parameter
*/
err = camera_set_format(ptr, to_pixfmt(fmt));
if (err) {
rb_raise(rb_eRuntimeError, "set format failed.");
}
return Qnil;
}
|
#frame_capabilities(fmt) ⇒ Object
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'ext/v4l2/v4l2.c', line 439
static VALUE
rb_camera_get_frame_capabilities(VALUE self, VALUE fmt)
{
VALUE ret;
camera_t* ptr;
int i;
int j;
int err;
struct v4l2_frmsizeenum size;
VALUE capa;
VALUE list;
VALUE rate;
Check_Type(fmt, T_SYMBOL);
Data_Get_Struct(self, camera_t, ptr);
ret = rb_ary_new();
for (i = 0; ;i++){
err = camera_get_frame_size(ptr, to_pixfmt(fmt), i, &size);
if (err) break;
if (size.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
capa = rb_obj_alloc(frame_cap_klass);
rb_ivar_set(capa, id_iv_width, INT2NUM(size.discrete.width));
rb_ivar_set(capa, id_iv_height, INT2NUM(size.discrete.height));
rb_ivar_set(capa, id_iv_rate, get_framerate_list(ptr, &size.discrete));
rb_ary_push(ret, capa);
} else if (size.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
make_dummy_capabilities(ptr, ret,
size.stepwise.max_width,
size.stepwise.max_height);
break;
}
}
return ret;
}
|
#framerate ⇒ Object
643 644 645 646 647 |
# File 'ext/v4l2/v4l2.c', line 643
static VALUE
rb_camera_get_framerate(VALUE self)
{
return Qnil;
}
|
#framerate=(val) ⇒ Object
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 |
# File 'ext/v4l2/v4l2.c', line 649
static VALUE
rb_camera_set_framerate(VALUE self, VALUE val)
{
camera_t* ptr;
int num;
int denom;
int err;
/*
* argument check
*/
switch (TYPE(val)) {
case T_FIXNUM:
num = 1;
denom = FIX2INT(val);
break;
case T_FLOAT:
num = 1000;
denom = (int)(NUM2DBL(val) * 1000.0);
break;
case T_RATIONAL:
num = FIX2INT(rb_rational_den(val));
denom = FIX2INT(rb_rational_num(val));
break;
default:
rb_raise(rb_eArgError, "illeagal framerate value.");
}
/*
* strip object
*/
Data_Get_Struct(self, camera_t, ptr);
/*
* set framerate
*/
err = camera_set_framerate(ptr, num, denom);
if (err) {
rb_raise(rb_eRuntimeError, "set framerate failed.");
}
return Qnil;
}
|
#get_control(id) ⇒ Object
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'ext/v4l2/v4l2.c', line 499
static VALUE
rb_camera_get_control(VALUE self, VALUE id)
{
camera_t* ptr;
int err;
int32_t value;
Data_Get_Struct( self, camera_t, ptr);
err = camera_get_control(ptr, FIX2INT(id), &value);
if (err) {
rb_raise(rb_eRuntimeError, "get control failed.");
}
return INT2FIX(value);
}
|
#image_height ⇒ Object
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
# File 'ext/v4l2/v4l2.c', line 593
static VALUE
rb_camera_get_image_height(VALUE self)
{
int ret;
camera_t* ptr;
int err;
/*
* strip object
*/
Data_Get_Struct(self, camera_t, ptr);
/*
* get parameter
*/
err = camera_get_image_height(ptr, &ret);
if (err) {
rb_raise(rb_eRuntimeError, "get image height failed.");
}
return INT2FIX(ret);
}
|
#image_height=(val) ⇒ Object
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
# File 'ext/v4l2/v4l2.c', line 616
static VALUE
rb_camera_set_image_height(VALUE self, VALUE val)
{
camera_t* ptr;
int err;
/*
* argument check
*/
Check_Type(val, T_FIXNUM);
/*
* strip object
*/
Data_Get_Struct(self, camera_t, ptr);
/*
* set parameter
*/
err = camera_set_image_height(ptr, FIX2INT(val));
if (err) {
rb_raise(rb_eRuntimeError, "set image height failed.");
}
return Qnil;
}
|
#image_width ⇒ Object
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'ext/v4l2/v4l2.c', line 543
static VALUE
rb_camera_get_image_width(VALUE self)
{
int ret;
camera_t* ptr;
int err;
/*
* strip object
*/
Data_Get_Struct(self, camera_t, ptr);
/*
* get parameter
*/
err = camera_get_image_width(ptr, &ret);
if (err) {
rb_raise(rb_eRuntimeError, "get image width failed.");
}
return INT2FIX(ret);
}
|
#image_width=(val) ⇒ Object
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
# File 'ext/v4l2/v4l2.c', line 566
static VALUE
rb_camera_set_image_width(VALUE self, VALUE val)
{
camera_t* ptr;
int err;
/*
* argument check
*/
Check_Type(val, T_FIXNUM);
/*
* strip object
*/
Data_Get_Struct(self, camera_t, ptr);
/*
* set parameter
*/
err = camera_set_image_width(ptr, FIX2INT(val));
if (err) {
rb_raise(rb_eRuntimeError, "set image width failed.");
}
return Qnil;
}
|
#set_control(id, val) ⇒ Object
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
# File 'ext/v4l2/v4l2.c', line 483
static VALUE
rb_camera_set_control(VALUE self, VALUE id, VALUE val)
{
camera_t* ptr;
int err;
Data_Get_Struct(self, camera_t, ptr);
err = camera_set_control(ptr, FIX2INT(id), FIX2INT(val));
if (err) {
rb_raise(rb_eRuntimeError, "set control failed.");
}
return Qnil;
}
|
#start ⇒ Object
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 |
# File 'ext/v4l2/v4l2.c', line 743
static VALUE
rb_camera_start(VALUE self)
{
int err;
camera_t* ptr;
/*
* strip object
*/
Data_Get_Struct(self, camera_t, ptr);
/*
* convert
*/
err = camera_start(ptr);
if (err) {
rb_raise(rb_eRuntimeError, "start capture failed.");
}
return Qnil;
}
|
#state ⇒ Object
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 |
# File 'ext/v4l2/v4l2.c', line 696
static VALUE
rb_camera_state( VALUE self)
{
camera_t* ptr;
const char* str;
/*
* strip object
*/
Data_Get_Struct(self, camera_t, ptr);
/*
* convert state code
*/
switch (ptr->state) {
case -1:
str = "ERROR";
break;
case 0:
str = "FINALIZED";
break;
case 1:
str = "INITIALIZED";
break;
case 2:
str = "PREAPARE";
break;
case 3:
str = "READY";
break;
case 4:
str = "ST_REQUESTED";
break;
default:
str = "unknown";
break;
}
return ID2SYM(rb_intern(str));
}
|
#stop ⇒ Object
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 |
# File 'ext/v4l2/v4l2.c', line 765
static VALUE
rb_camera_stop(VALUE self)
{
int err;
camera_t* ptr;
/*
* strip object
*/
Data_Get_Struct(self, camera_t, ptr);
/*
* convert
*/
err = camera_stop(ptr);
if (err) {
rb_raise(rb_eRuntimeError, "stop capture failed.");
}
return Qnil;
}
|
#support_formats ⇒ Object
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'ext/v4l2/v4l2.c', line 343
static VALUE
rb_camera_get_support_formats(VALUE self)
{
VALUE ret;
camera_t* ptr;
int i;
int err;
struct v4l2_fmtdesc desc;
VALUE fmt;
VALUE fcc;
Data_Get_Struct(self, camera_t, ptr);
ret = rb_ary_new();
for (i = 0; ;i++) {
err = camera_get_format_desc(ptr, i, &desc);
if (err) break;
fmt = rb_obj_alloc(fmt_desc_klass);
fcc = rb_sprintf("%c%c%c%c",
desc.pixelformat >> 0 & 0xff,
desc.pixelformat >> 8 & 0xff,
desc.pixelformat >> 16 & 0xff,
desc.pixelformat >> 24 & 0xff);
rb_ivar_set(fmt, id_iv_fcc, fcc);
rb_ivar_set(fmt, id_iv_desc, rb_str_new2(desc.description));
rb_ary_push(ret, fmt);
}
return ret;
}
|