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
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 120 |
# File 'ext/v4l2/v4l2.c', line 85 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
74 75 76 77 78 79 80 81 82 83 |
# File 'ext/v4l2/v4l2.c', line 74 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
895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 |
# File 'ext/v4l2/v4l2.c', line 895 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
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 |
# File 'ext/v4l2/v4l2.c', line 861 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
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'ext/v4l2/v4l2.c', line 122 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
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'ext/v4l2/v4l2.c', line 269 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
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 |
# File 'ext/v4l2/v4l2.c', line 918 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
589 590 591 592 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 589 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
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 |
# File 'ext/v4l2/v4l2.c', line 488 static VALUE rb_camera_get_frame_capabilities(VALUE self, VALUE _fmt) { VALUE ret; camera_t* ptr; int i; int j; uint32_t fmt; 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(); fmt = to_pixfmt(_fmt); for (i = 0; ;i++){ err = camera_get_frame_size(ptr, fmt, i, &size); if (err) break; if (size.type == V4L2_FRMSIZE_TYPE_DISCRETE) { capa = rb_obj_alloc(frame_cap_klass); list = get_framerate_list(ptr, fmt, &size.discrete); 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, list); rb_ary_push(ret, capa); } else if (size.type == V4L2_FRMSIZE_TYPE_STEPWISE) { make_dummy_capabilities(ptr, ret, fmt, size.stepwise.max_width, size.stepwise.max_height); break; } } return ret; } |
#framerate ⇒ Object
716 717 718 719 720 |
# File 'ext/v4l2/v4l2.c', line 716 static VALUE rb_camera_get_framerate(VALUE self) { return Qnil; } |
#framerate=(val) ⇒ Object
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 |
# File 'ext/v4l2/v4l2.c', line 722 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
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 |
# File 'ext/v4l2/v4l2.c', line 572 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
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 |
# File 'ext/v4l2/v4l2.c', line 666 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
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 |
# File 'ext/v4l2/v4l2.c', line 689 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
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
# File 'ext/v4l2/v4l2.c', line 616 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
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 |
# File 'ext/v4l2/v4l2.c', line 639 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
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 |
# File 'ext/v4l2/v4l2.c', line 538 static VALUE rb_camera_set_control(VALUE self, VALUE id, VALUE _val) { camera_t* ptr; int err; int val; Data_Get_Struct(self, camera_t, ptr); switch (TYPE(_val)) { case T_TRUE: val = 1; break; case T_FALSE: val = 0; break; case T_FIXNUM: val = FIX2INT(_val); break; default: rb_raise(rb_eTypeError, "invalid type of control value"); } err = camera_set_control(ptr, FIX2INT(id), val); if (err) { rb_raise(rb_eRuntimeError, "set control failed."); } return Qnil; } |
#start ⇒ Object
816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 |
# File 'ext/v4l2/v4l2.c', line 816 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
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 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 |
# File 'ext/v4l2/v4l2.c', line 769 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
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 |
# File 'ext/v4l2/v4l2.c', line 838 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
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'ext/v4l2/v4l2.c', line 385 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; VALUE str; 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_enc_sprintf(rb_utf8_encoding(), "%c%c%c%c", desc.pixelformat >> 0 & 0xff, desc.pixelformat >> 8 & 0xff, desc.pixelformat >> 16 & 0xff, desc.pixelformat >> 24 & 0xff); str = rb_enc_str_new_cstr((const char*)desc.description, rb_utf8_encoding()); rb_ivar_set(fmt, id_iv_fcc, fcc); rb_ivar_set(fmt, id_iv_desc, str); rb_ary_push(ret, fmt); } return ret; } |