hornetseye-v4l2 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require 'rake/loaders/makefile'
7
7
  require 'rbconfig'
8
8
 
9
9
  PKG_NAME = 'hornetseye-v4l2'
10
- PKG_VERSION = '0.3.3'
10
+ PKG_VERSION = '0.3.4'
11
11
  CFG = RbConfig::CONFIG
12
12
  CXX = ENV[ 'CXX' ] || 'g++'
13
13
  RB_FILES = FileList[ 'lib/**/*.rb' ]
data/ext/v4l2input.cc CHANGED
@@ -64,6 +64,9 @@ V4L2Input::V4L2Input( const std::string &device, V4L2SelectPtr select ) throw (E
64
64
  format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
65
65
  format.index = formatIndex++;
66
66
  int r = xioctl( VIDIOC_ENUM_FMT, &format );
67
+ #ifndef NDEBUG
68
+ cerr << "Requesting format " << (formatIndex - 1) << " with result " << r << endl;
69
+ #endif
67
70
  if ( r != 0 ) break;
68
71
  unsigned int frameSizeIndex = 0;
69
72
  while ( true ) {
@@ -72,6 +75,10 @@ V4L2Input::V4L2Input( const std::string &device, V4L2SelectPtr select ) throw (E
72
75
  pix.pixel_format = format.pixelformat;
73
76
  pix.index = frameSizeIndex++;
74
77
  int r = xioctl( VIDIOC_ENUM_FRAMESIZES, &pix );
78
+ #ifndef NDEBUG
79
+ cerr << "Requesting frame size " << (frameSizeIndex - 1) << " for format "
80
+ << (formatIndex - 1) << " with result " << r << endl;
81
+ #endif
75
82
  if ( r != 0 ) break;
76
83
  if ( pix.type == V4L2_FRMSIZE_TYPE_DISCRETE )
77
84
  select->add( format.pixelformat, pix.discrete.width, pix.discrete.height );
@@ -90,18 +97,17 @@ V4L2Input::V4L2Input( const std::string &device, V4L2SelectPtr select ) throw (E
90
97
  };
91
98
  };
92
99
  };
93
- unsigned int selection = select->make();
94
- unsigned int coding = select->coding( selection );
100
+ select->make();
101
+ unsigned int coding = select->coding();
95
102
  #ifndef NDEBUG
96
- cerr << "selection = " << selection << endl
97
- << "coding = " << select->coding( selection ) << endl
98
- << "w = " << select->width( selection ) << endl
99
- << "h = " << select->height( selection ) << endl;
103
+ cerr << "coding = " << select->coding() << endl
104
+ << "w = " << select->width() << endl
105
+ << "h = " << select->height() << endl;
100
106
  #endif
101
107
  m_format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
102
108
  m_format.fmt.pix.field = V4L2_FIELD_NONE;
103
- m_format.fmt.pix.width = select->width( selection );
104
- m_format.fmt.pix.height = select->height( selection );
109
+ m_format.fmt.pix.width = select->width();
110
+ m_format.fmt.pix.height = select->height();
105
111
  m_format.fmt.pix.pixelformat = coding;
106
112
  m_format.fmt.pix.field = V4L2_FIELD_SEQ_TB;
107
113
  ERRORMACRO( xioctl( VIDIOC_S_FMT, &m_format ) == 0, Error, ,
data/ext/v4l2select.cc CHANGED
@@ -17,7 +17,7 @@
17
17
  #include "v4l2select.hh"
18
18
 
19
19
  V4L2Select::V4L2Select(void) throw (Error):
20
- m_rbArray(rb_ary_new())
20
+ m_rbArray(rb_ary_new()), m_rbSelection(Qnil)
21
21
  {
22
22
  }
23
23
 
@@ -36,33 +36,32 @@ static VALUE yield( VALUE arg )
36
36
  return rb_yield( arg );
37
37
  }
38
38
 
39
- unsigned int V4L2Select::make(void) throw (Error)
39
+ void V4L2Select::make(void) throw (Error)
40
40
  {
41
41
  int error;
42
- VALUE rbRetVal = rb_protect( yield, m_rbArray, &error );
42
+ m_rbSelection = rb_protect( yield, m_rbArray, &error );
43
43
  if ( error ) {
44
44
  VALUE rbError = rb_funcall( rb_gv_get( "$!" ), rb_intern( "message" ), 0 );
45
45
  ERRORMACRO( false, Error, , "Error in block to \"V4L2Input.new\": "
46
46
  << StringValuePtr( rbError ) );
47
47
  };
48
- ERRORMACRO( TYPE( rbRetVal ) == T_FIXNUM, Error, , "Block must return a value of "
49
- "type 'Fixnum'" );
50
- return NUM2UINT(rbRetVal);
48
+ ERRORMACRO( TYPE( m_rbSelection ) == T_ARRAY, Error, , "Block must return a value of "
49
+ "type 'Array'" );
51
50
  }
52
51
 
53
- unsigned int V4L2Select::coding( unsigned int selection )
52
+ unsigned int V4L2Select::coding(void)
54
53
  {
55
- return NUM2INT( RARRAY_PTR( RARRAY_PTR(m_rbArray)[ selection ] )[ 0 ] );
54
+ return NUM2INT(RARRAY_PTR(m_rbSelection)[ 0 ]);
56
55
  }
57
56
 
58
- unsigned int V4L2Select::width( unsigned int selection )
57
+ unsigned int V4L2Select::width(void)
59
58
  {
60
- return NUM2INT( RARRAY_PTR( RARRAY_PTR(m_rbArray)[ selection ] )[ 1 ] );
59
+ return NUM2INT(RARRAY_PTR(m_rbSelection)[ 1 ]);
61
60
  }
62
61
 
63
- unsigned int V4L2Select::height( unsigned int selection )
62
+ unsigned int V4L2Select::height(void)
64
63
  {
65
- return NUM2INT( RARRAY_PTR( RARRAY_PTR(m_rbArray)[ selection ] )[ 2 ] );
64
+ return NUM2INT(RARRAY_PTR(m_rbSelection)[ 2 ]);
66
65
  }
67
66
 
68
67
  VALUE V4L2Select::wrapRescue( VALUE rbValue )
data/ext/v4l2select.hh CHANGED
@@ -26,13 +26,14 @@ public:
26
26
  V4L2Select(void) throw (Error);
27
27
  virtual ~V4L2Select(void);
28
28
  void add( unsigned int coding, unsigned int width, unsigned int height );
29
- unsigned int make(void) throw (Error);
30
- unsigned int coding( unsigned int selection );
31
- unsigned int width( unsigned int selection );
32
- unsigned int height( unsigned int selection );
29
+ void make(void) throw (Error);
30
+ unsigned int coding(void);
31
+ unsigned int width(void);
32
+ unsigned int height(void);
33
33
  static VALUE wrapRescue( VALUE rbValue );
34
34
  protected:
35
35
  VALUE m_rbArray;
36
+ VALUE m_rbSelection;
36
37
  };
37
38
 
38
39
  typedef boost::shared_ptr< V4L2Select > V4L2SelectPtr;
@@ -49,26 +49,24 @@ module Hornetseye
49
49
  MODE_GREY => UBYTE,
50
50
  MODE_RGB24 => UBYTERGB,
51
51
  MODE_BGR24 => BGR }
52
- frame_types, index = [], []
53
- modes.each_with_index do |mode,i|
54
- target = map[ mode.first ]
52
+ frame_types = []
53
+ modes.each_with_index do |mode|
54
+ target = map[mode.first]
55
55
  if target
56
- frame_types.push Hornetseye::Frame( target, *mode[ 1 .. 2 ] )
57
- index.push i
56
+ frame_types.push Hornetseye::Frame(target, *mode[1 .. 2])
58
57
  end
59
58
  end
60
59
  if action
61
60
  desired = action.call frame_types
62
61
  else
63
- preference = [ I420, UYVY, YUY2, UBYTERGB, BGR, UBYTE ]
62
+ preference = [I420, UYVY, YUY2, UBYTERGB, BGR, UBYTE]
64
63
  desired = frame_types.sort_by do |mode|
65
64
  [ -preference.index( mode.typecode ), mode.width * mode.height ]
66
65
  end.last
67
66
  end
68
- unless frame_types.member? desired
69
- raise "Frame type #{desired.inspect} not supported by camera"
70
- end
71
- index[ frame_types.index( desired ) ]
67
+ mode = map.invert[desired.typecode]
68
+ raise "Video mode #{desired.typecode} not supported" unless mode
69
+ [mode, desired.width, desired.height]
72
70
  end
73
71
  end
74
72
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 3
9
- version: 0.3.3
8
+ - 4
9
+ version: 0.3.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jan Wedekind
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-06-06 00:00:00 +01:00
17
+ date: 2011-06-10 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency